Serenity Operating System
1/*
2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
3 * Copyright (c) 2022, the SerenityOS developers.
4 *
5 * SPDX-License-Identifier: BSD-2-Clause
6 */
7
8#pragma once
9
10#include <LibGUI/AbstractButton.h>
11
12namespace GUI {
13
14class CheckBox : public AbstractButton {
15 C_OBJECT(CheckBox);
16
17public:
18 virtual ~CheckBox() override = default;
19
20 virtual void click(unsigned modifiers = 0) override;
21
22 bool is_autosize() const { return m_autosize; }
23 void set_autosize(bool);
24
25 enum class CheckBoxPosition {
26 Left,
27 Right,
28 };
29 CheckBoxPosition checkbox_position() const { return m_checkbox_position; }
30 void set_checkbox_position(CheckBoxPosition value) { m_checkbox_position = value; }
31
32 virtual Optional<UISize> calculated_min_size() const override;
33
34protected:
35 explicit CheckBox(String = {});
36
37private:
38 void size_to_fit();
39
40 // These don't make sense for a check box, so hide them.
41 using AbstractButton::auto_repeat_interval;
42 using AbstractButton::set_auto_repeat_interval;
43
44 virtual void paint_event(PaintEvent&) override;
45
46 Gfx::IntRect box_rect() const;
47 int gap_between_box_and_rect() const;
48 int horizontal_padding() const;
49
50 bool m_autosize { false };
51 CheckBoxPosition m_checkbox_position { CheckBoxPosition::Left };
52};
53
54}