summaryrefslogtreecommitdiff
path: root/Plugins/MonoGame.Extended/source/MonoGame.Extended.Gui/Controls/CheckBox.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2024-06-03 10:15:45 +0800
committerchai <215380520@qq.com>2024-06-03 10:15:45 +0800
commitacea7b2e728787a0d83bbf83c8c1f042d2c32e7e (patch)
tree0bfec05c1ca2d71be2c337bcd110a0421f19318b /Plugins/MonoGame.Extended/source/MonoGame.Extended.Gui/Controls/CheckBox.cs
parent88febcb02bf127d961c6471d9e846c0e1315f5c3 (diff)
+ plugins project
Diffstat (limited to 'Plugins/MonoGame.Extended/source/MonoGame.Extended.Gui/Controls/CheckBox.cs')
-rw-r--r--Plugins/MonoGame.Extended/source/MonoGame.Extended.Gui/Controls/CheckBox.cs65
1 files changed, 65 insertions, 0 deletions
diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Gui/Controls/CheckBox.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Gui/Controls/CheckBox.cs
new file mode 100644
index 0000000..c6c375f
--- /dev/null
+++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Gui/Controls/CheckBox.cs
@@ -0,0 +1,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;
+ }
+ }
+} \ No newline at end of file