blob: c6c375f899043d1eac8d355055db0a6ca7a940a9 (
plain)
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
54
55
56
57
58
59
60
61
62
63
64
65
|
using Microsoft.Xna.Framework;
namespace MonoGame.Extended.Gui.Controls
{
public class CheckBox : CompositeControl
{
public CheckBox()
{
_contentLabel = new Label();
_checkLabel = new Box {Width = 20, Height = 20};
_toggleButton = new ToggleButton
{
Margin = 0,
Padding = 0,
BackgroundColor = Color.Transparent,
BorderThickness = 0,
HoverStyle = null,
CheckedStyle = null,
PressedStyle = null,
Content = new StackPanel
{
Margin = 0,
Orientation = Orientation.Horizontal,
Items =
{
_checkLabel,
_contentLabel
}
}
};
_toggleButton.CheckedStateChanged += (sender, args) => OnIsCheckedChanged();
Template = _toggleButton;
OnIsCheckedChanged();
}
private readonly Label _contentLabel;
private readonly ToggleButton _toggleButton;
private readonly Box _checkLabel;
protected override Control Template { get; }
public override object Content
{
get => _contentLabel.Content;
set => _contentLabel.Content = value;
}
public bool IsChecked
{
get => _toggleButton.IsChecked;
set
{
_toggleButton.IsChecked = value;
OnIsCheckedChanged();
}
}
private void OnIsCheckedChanged()
{
_checkLabel.FillColor = IsChecked ? Color.White : Color.Transparent;
}
}
}
|