-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckBox.h
More file actions
53 lines (40 loc) · 1.49 KB
/
Copy pathCheckBox.h
File metadata and controls
53 lines (40 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#pragma once
#include <functional>
#include "Wnd.h"
#include "Text.h"
namespace FD2D
{
// Simple labeled checkbox (box + checkmark + label).
class CheckBox : public Wnd
{
public:
using CheckedChangedHandler = std::function<void(bool checked)>;
CheckBox();
explicit CheckBox(const std::wstring& name);
Size Measure(Size available) override;
void Arrange(Rect finalRect) override;
void SetLabel(const std::wstring& text);
void SetChecked(bool checked, bool notify = false);
bool Checked() const { return m_checked; }
// A disabled checkbox ignores all input and renders dimmed; its
// checked state is unchanged (owners may still SetChecked
// programmatically).
void SetEnabled(bool enabled);
bool IsEnabled() const { return m_enabled; }
void OnCheckedChanged(CheckedChangedHandler handler);
bool OnInputEvent(const InputEvent& event) override;
void OnRender(ID2D1RenderTarget* target) override;
private:
bool HitTest(const POINT& pt) const;
D2D1_RECT_F BoxRect() const;
bool m_checked { false };
bool m_hovered { false };
bool m_pressed { false };
bool m_enabled { true };
Text m_label {};
CheckedChangedHandler m_changed {};
Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> m_brush {};
static constexpr float kBoxSize = 16.0f;
static constexpr float kLabelGap = 8.0f;
};
}