2using System.Collections.Generic;
4using System.Reflection;
7using Microsoft.Xna.Framework;
8using Microsoft.Xna.Framework.Input;
9using Microsoft.Xna.Framework.Graphics;
21 public DDOption() :
this(
"") { }
22 public DDOption(
string text) : base(text) { }
34 get => OptionBox.Children.Cast<DDOption>().Select(o => o.Text);
38 foreach (
string option
in value) { Add(option); }
42 public string Selected
44 get => MainButton.Text;
48 public event Action<string> OnSelect;
49 public Action<string> AddOnSelect {
set { OnSelect += value; } }
52 public void Open() => OptionBox.Revealed =
true;
53 public void Close() => OptionBox.Revealed =
false;
57 OptionBox.RemoveAllChildren();
61 public void Add(
string option)
63 OptionBox.
Append(
new DDOption(option)
65 AddOnMouseDown = (e) => Select(option),
69 public void Select(
int i) => Select(
Options.ElementAtOrDefault(i));
70 public void Select(
string option)
72 MainButton.Text = option ??
"";
73 OptionBox.Revealed =
false;
74 OnSelect?.Invoke(MainButton.Text);
77 public void Remove(
int i) => Remove(
Options.ElementAtOrDefault(i));
78 public void Remove(
string option)
80 if (option ==
null)
return;
81 if (!
Options.Contains(option))
return;
83 DDOption ddoption = OptionBox.Children.Cast<DDOption>().FirstOrDefault(o => o.Text == option);
84 bool wasSelected = MainButton.Text == ddoption.Text;
85 OptionBox.RemoveChild(ddoption);
86 if (wasSelected) Select(0);
89 public CUIDropDown() : base()
92 OptionBox =
new CUIVerticalList()
96 Ghost =
new CUIBool2(
false,
true),
97 Anchor = CUIAnchor.TopLeft,
100 Style =
new CUIStyle(){
101 {
"BackgroundColor",
"CUIPalette.DDOption.Background"},
102 {
"Border",
"CUIPalette.DDOption.Border"},
106 MainButton =
new CUIButton()
108 Text =
"CUIDropDown",
109 Relative =
new CUINullRect(w: 1, h: 1),
120 if (CUI.Main is not
null) CUI.Main.OnMouseDown += (e) => Close();
Base class for all components.
bool Revealed
Visible + !IgnoreEvents.
CUINullRect Relative
Relative to parent size and position, [0..1].
virtual CUIComponent Append(CUIComponent child, string name=null, [CallerMemberName] string memberName="")
Adds children to the end of the list.
CUIStyle Style
Allows you to assing parsable string or link to CUIPalette to any prop It's indexable,...
Vector2 Anchor
this point of this component
CUIBool2 FitContent
Will resize itself to fit components with absolute size, e.g. text.
bool SerializeChildren
Is this a serialization cutoff point Parent will serialize children down to this component and stop...
Vector2? ParentAnchor
will be attached to this point of parent
CUIBool2 Ghost
Ghost components don't affect layout.
int? ZIndex
Components are drawn in order of their ZIndex Normally it's derived from component position in the ...
Drop down list, aka Select.
IEnumerable< string > Options
List of options Options are just strings.
Resizing components to it's Width and placing them sequentially.