A game framework written with osu! in mind.
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2// See the LICENCE file in the repository root for full licence text.
3
4using osu.Framework.Bindables;
5using osu.Framework.Graphics.Containers;
6using osu.Framework.Input.Events;
7
8namespace osu.Framework.Graphics.UserInterface
9{
10 /// <summary>
11 /// An abstract class that implements the functionality of a checkbox.
12 /// </summary>
13 public abstract class Checkbox : Container, IHasCurrentValue<bool>
14 {
15 private readonly BindableWithCurrent<bool> current = new BindableWithCurrent<bool>();
16
17 public Bindable<bool> Current
18 {
19 get => current.Current;
20 set => current.Current = value;
21 }
22
23 protected override bool OnClick(ClickEvent e)
24 {
25 if (!Current.Disabled)
26 {
27 Current.Value = !Current.Value;
28 OnUserChange(Current.Value);
29 }
30
31 base.OnClick(e);
32 return true;
33 }
34
35 /// <summary>
36 /// Triggered when the value is changed based on end-user input to this control.
37 /// </summary>
38 protected virtual void OnUserChange(bool value)
39 {
40 }
41 }
42}