Skip to content

Commit 513e256

Browse files
authored
Add various additional preset UiStyle configurations
* added radio group buttons * remove nullable ref types * added button color * added button colors to UiStyle * organized UiStyle * gitignore the .vs directory * delete RadioGroupButton per https://github.com/Ellpeck/MLEM/pull/38/files/48117a042c775032f4ee34a6de52ed6910d11ae0#r2333576826 * gitignore .suo and more in .vs/ * text field colors * scroll bar colors * checkbox colors * radio colors * tooltip backgorund color * selection color * copy constructor * gitignored again * Delete .vs directory * remove colors from untextured demo * remove gitignored files * deleted duped FNA and FontStashSharp
1 parent 4299314 commit 513e256

File tree

11 files changed

+126
-7
lines changed

11 files changed

+126
-7
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,10 @@ packages
55
*.user
66
tools
77
TestResults*
8+
.vs/**
9+
# User-specific files
10+
*.rsuser
11+
*.suo
12+
*.user
13+
*.userosscache
14+
*.sln.docstates

Demos/UiDemo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public override void LoadContent() {
5757
};
5858
var untexturedStyle = new UntexturedStyle(this.SpriteBatch) {
5959
TextScale = style.TextScale,
60-
Font = style.Font
60+
Font = style.Font,
6161
};
6262
// set the defined style as the current one
6363
this.UiSystem.Style = style;

MLEM.Ui/Elements/Button.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ public override void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteB
160160
protected override void InitStyle(UiStyle style) {
161161
base.InitStyle(style);
162162
this.Texture = this.Texture.OrStyle(style.ButtonTexture);
163+
this.NormalColor = this.NormalColor.OrStyle(style.ButtonColor);
163164
this.HoveredTexture = this.HoveredTexture.OrStyle(style.ButtonHoveredTexture);
164165
this.HoveredColor = this.HoveredColor.OrStyle(style.ButtonHoveredColor);
165166
this.DisabledTexture = this.DisabledTexture.OrStyle(style.ButtonDisabledTexture);

MLEM.Ui/Elements/Checkbox.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ public class Checkbox : Element {
1818
/// </summary>
1919
public StyleProp<NinePatch> Texture;
2020
/// <summary>
21+
/// The color that this checkbox uses for drawing.
22+
/// </summary>
23+
public StyleProp<Color> BackColor;
24+
/// <summary>
2125
/// The texture that this checkbox uses when it is hovered.
2226
/// If this is null, the default <see cref="Texture"/> is used.
2327
/// </summary>
@@ -39,6 +43,16 @@ public class Checkbox : Element {
3943
/// The texture that is rendered on top of this checkbox when it is <see cref="Checked"/>.
4044
/// </summary>
4145
public StyleProp<TextureRegion> Checkmark;
46+
/// <summary>
47+
/// The color of the check mark that is rendered on top of this checkbox when it is <see cref="Checked"/>.
48+
/// </summary>
49+
public StyleProp<Color> CheckColor;
50+
/// <summary>
51+
/// The color of the check mark that is rendered on top of this checkbox when it is not <see cref="Checked"/>.
52+
/// Set alpha to 0 to disable this behavior.
53+
/// </summary>
54+
public StyleProp<Color> UncheckColor;
55+
4256
/// <summary>
4357
/// The label <see cref="Paragraph"/> that displays next to this checkbox
4458
/// </summary>
@@ -117,7 +131,7 @@ public override void SetAreaAndUpdateChildren(RectangleF area) {
117131
/// <inheritdoc />
118132
public override void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteBatchContext context) {
119133
var tex = this.Texture;
120-
var color = Color.White * alpha;
134+
var color = this.BackColor.OrDefault(Color.White) * alpha;
121135
if (this.IsDisabled) {
122136
tex = this.DisabledTexture.OrDefault(tex);
123137
color = (Color) this.DisabledColor * alpha;
@@ -128,20 +142,27 @@ public override void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteB
128142

129143
var boxDisplayArea = new RectangleF(this.DisplayArea.Location, new Vector2(this.DisplayArea.Height));
130144
batch.Draw(tex, boxDisplayArea, color, this.Scale);
145+
var uncheckedColor = this.UncheckColor.OrDefault(Color.Transparent);
131146
if (this.Checked)
132-
batch.Draw(this.Checkmark, boxDisplayArea, Color.White * alpha);
147+
batch.Draw(this.Checkmark, boxDisplayArea, this.CheckColor.OrDefault(Color.White) * alpha);
148+
else if(uncheckedColor.A != 0) {
149+
batch.Draw(this.Checkmark, boxDisplayArea, uncheckedColor * alpha);
150+
}
133151
base.Draw(time, batch, alpha, context);
134152
}
135153

136154
/// <inheritdoc />
137155
protected override void InitStyle(UiStyle style) {
138156
base.InitStyle(style);
139157
this.Texture = this.Texture.OrStyle(style.CheckboxTexture);
158+
this.BackColor = this.BackColor.OrStyle(style.CheckboxColor);
140159
this.HoveredTexture = this.HoveredTexture.OrStyle(style.CheckboxHoveredTexture);
141160
this.HoveredColor = this.HoveredColor.OrStyle(style.CheckboxHoveredColor);
142161
this.DisabledTexture = this.DisabledTexture.OrStyle(style.CheckboxDisabledTexture);
143162
this.DisabledColor = this.DisabledColor.OrStyle(style.CheckboxDisabledColor);
144163
this.Checkmark = this.Checkmark.OrStyle(style.CheckboxCheckmark);
164+
this.CheckColor = this.CheckColor.OrStyle(style.CheckboxCheckColor);
165+
this.UncheckColor = this.UncheckColor.OrStyle(style.CheckboxUncheckedColor);
145166
this.TextOffsetX = this.TextOffsetX.OrStyle(style.CheckboxTextOffsetX);
146167
}
147168

MLEM.Ui/Elements/Element.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,10 @@ public StyleProp<UiStyle> Style {
349349
/// </summary>
350350
public StyleProp<NinePatch> SelectionIndicator;
351351
/// <summary>
352+
/// A style property that contains the color of the selection indicator that is displayed on this element if it is the <see cref="RootElement.SelectedElement"/>
353+
/// </summary>
354+
public StyleProp<Color> SelectionColor;
355+
/// <summary>
352356
/// A style property that contains the sound effect that is played when this element's <see cref="OnPressed"/> is called
353357
/// </summary>
354358
public StyleProp<SoundEffectInfo> ActionSound;

MLEM.Ui/Elements/RadioButton.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ public RadioButton(Anchor anchor, Vector2 size, string label, bool defaultChecke
4040
protected override void InitStyle(UiStyle style) {
4141
base.InitStyle(style);
4242
this.Texture = this.Texture.OrStyle(style.RadioTexture);
43+
this.BackColor = this.BackColor.OrStyle(style.RadioColor);
4344
this.HoveredTexture = this.HoveredTexture.OrStyle(style.RadioHoveredTexture);
4445
this.HoveredColor = this.HoveredColor.OrStyle(style.RadioHoveredColor);
4546
this.Checkmark = this.Checkmark.OrStyle(style.RadioCheckmark);
47+
this.CheckColor = this.CheckColor.OrStyle(style.RadioCheckColor);
48+
this.UncheckColor = this.UncheckColor.OrStyle(style.RadioUncheckedColor);
4649
}
4750

4851
}

MLEM.Ui/Elements/ScrollBar.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,18 @@ public class ScrollBar : Element {
2727
/// </summary>
2828
public StyleProp<NinePatch> Background;
2929
/// <summary>
30+
/// The background color for this scroll bar
31+
/// </summary>
32+
public StyleProp<Color> BackColor;
33+
/// <summary>
3034
/// The texture of this scroll bar's scroller indicator
3135
/// </summary>
3236
public StyleProp<NinePatch> ScrollerTexture;
3337
/// <summary>
38+
/// The color of this scroll bar's scroller indicator
39+
/// </summary>
40+
public StyleProp<Color> ScrollerColor;
41+
/// <summary>
3442
/// Whether smooth scrolling should be enabled for this scroll bar.
3543
/// Smooth scrolling causes the <see cref="CurrentValue"/> to change gradually rather than instantly when scrolling.
3644
/// </summary>
@@ -231,10 +239,10 @@ private void ScrollToPos(Vector2 position) {
231239

232240
/// <inheritdoc />
233241
public override void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteBatchContext context) {
234-
batch.Draw(this.Background, this.DisplayArea, Color.White * alpha, this.Scale);
242+
batch.Draw(this.Background, this.DisplayArea, this.BackColor.OrDefault(Color.White) * alpha, this.Scale);
235243
if (this.MaxValue > 0) {
236244
var scrollerRect = new RectangleF(this.ScrollerPosition, this.ScrollerSize * this.Scale);
237-
batch.Draw(this.ScrollerTexture, scrollerRect, Color.White * alpha, this.Scale);
245+
batch.Draw(this.ScrollerTexture, scrollerRect, this.ScrollerColor.OrDefault(Color.White) * alpha, this.Scale);
238246
}
239247
base.Draw(time, batch, alpha, context);
240248
}
@@ -243,7 +251,9 @@ public override void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteB
243251
protected override void InitStyle(UiStyle style) {
244252
base.InitStyle(style);
245253
this.Background = this.Background.OrStyle(style.ScrollBarBackground);
254+
this.BackColor = this.BackColor.OrStyle(style.ScrollBarBackColor);
246255
this.ScrollerTexture = this.ScrollerTexture.OrStyle(style.ScrollBarScrollerTexture);
256+
this.ScrollerColor = this.ScrollerColor.OrStyle(style.ScrollBarScrollerColor);
247257
this.SmoothScrolling = this.SmoothScrolling.OrStyle(style.ScrollBarSmoothScrolling);
248258
this.SmoothScrollFactor = this.SmoothScrollFactor.OrStyle(style.ScrollBarSmoothScrollFactor);
249259
}

MLEM.Ui/Elements/TextField.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ public class TextField : Element {
5656
/// </summary>
5757
public StyleProp<NinePatch> Texture;
5858
/// <summary>
59+
/// This text field's background color
60+
/// </summary>
61+
public StyleProp<Color> BackColor;
62+
/// <summary>
5963
/// This text field's texture while it is hovered
6064
/// </summary>
6165
public StyleProp<NinePatch> HoveredTexture;
@@ -239,7 +243,7 @@ public override void Update(GameTime time) {
239243
/// <inheritdoc />
240244
public override void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteBatchContext context) {
241245
var tex = this.Texture;
242-
var color = Color.White * alpha;
246+
var color = (Color) this.BackColor * alpha;
243247
if (this.IsMouseOver) {
244248
tex = this.HoveredTexture.OrDefault(tex);
245249
color = (Color) this.HoveredColor * alpha;
@@ -278,7 +282,9 @@ protected override void InitStyle(UiStyle style) {
278282
base.InitStyle(style);
279283
this.TextScale = this.TextScale.OrStyle(style.TextScale);
280284
this.Font = this.Font.OrStyle(style.Font);
285+
this.TextColor = this.TextColor.OrStyle(style.TextFieldTextColor);
281286
this.Texture = this.Texture.OrStyle(style.TextFieldTexture);
287+
this.BackColor = this.BackColor.OrStyle(style.TextFieldColor);
282288
this.HoveredTexture = this.HoveredTexture.OrStyle(style.TextFieldHoveredTexture);
283289
this.HoveredColor = this.HoveredColor.OrStyle(style.TextFieldHoveredColor);
284290
this.TextOffsetX = this.TextOffsetX.OrStyle(style.TextFieldTextOffsetX);

MLEM.Ui/Elements/Tooltip.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ public override void ForceUpdateArea() {
168168
protected override void InitStyle(UiStyle style) {
169169
base.InitStyle(style);
170170
this.Texture = this.Texture.OrStyle(style.TooltipBackground);
171+
this.DrawColor = this.DrawColor.OrStyle(style.TooltipBackColor);
171172
this.MouseOffset = this.MouseOffset.OrStyle(style.TooltipOffset);
172173
this.AutoNavOffset = this.AutoNavOffset.OrStyle(style.TooltipAutoNavOffset);
173174
this.MouseAnchor = this.MouseAnchor.OrStyle(style.TooltipMouseAnchor);

MLEM.Ui/Style/UiStyle.cs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ public class UiStyle : GenericDataHolder {
2323
/// </summary>
2424
public NinePatch SelectionIndicator;
2525
/// <summary>
26+
/// The color of the selector that is rendered on top of the <see cref="UiControls.SelectedElement"/>
27+
/// </summary>
28+
public Color SelectionColor = Color.White;
29+
/// <summary>
2630
/// A <see cref="UiAnimation"/> that is played when the mouse enters an element.
2731
/// </summary>
2832
public UiAnimation MouseEnterAnimation;
@@ -35,6 +39,10 @@ public class UiStyle : GenericDataHolder {
3539
/// </summary>
3640
public NinePatch ButtonTexture;
3741
/// <summary>
42+
/// The color that the <see cref="Button"/> element renders
43+
/// </summary>
44+
public Color ButtonColor = Color.White;
45+
/// <summary>
3846
/// The texture that the <see cref="Button"/> element uses when it is moused over (<see cref="Element.IsMouseOver"/>)
3947
/// Note that, if you just want to change the button's color when hovered, use <see cref="ButtonHoveredColor"/>.
4048
/// </summary>
@@ -76,10 +84,18 @@ public class UiStyle : GenericDataHolder {
7684
/// </summary>
7785
public float PanelScrollBarOffset = 1;
7886
/// <summary>
87+
/// The text color of text the <see cref="TextField"/> element uses
88+
/// </summary>
89+
public Color TextFieldTextColor = Color.White;
90+
/// <summary>
7991
/// The texture that the <see cref="TextField"/> element uses
8092
/// </summary>
8193
public NinePatch TextFieldTexture;
8294
/// <summary>
95+
/// The color that the <see cref="TextField"/> renders with when it is idle
96+
/// </summary>
97+
public Color TextFieldColor = Color.LightGray;
98+
/// <summary>
8399
/// The texture that the <see cref="TextField"/> element uses when it is moused over (<see cref="Element.IsMouseOver"/>)
84100
/// </summary>
85101
public NinePatch TextFieldHoveredTexture;
@@ -100,10 +116,18 @@ public class UiStyle : GenericDataHolder {
100116
/// </summary>
101117
public NinePatch ScrollBarBackground;
102118
/// <summary>
119+
/// The background color that the <see cref="ScrollBar"/> element uses
120+
/// </summary>
121+
public Color ScrollBarBackColor = Color.White;
122+
/// <summary>
103123
/// The texture that the scroll indicator of the <see cref="ScrollBar"/> element uses
104124
/// </summary>
105125
public NinePatch ScrollBarScrollerTexture;
106126
/// <summary>
127+
/// The color that the scroll indicator of the <see cref="ScrollBar"/> element uses
128+
/// </summary>
129+
public Color ScrollBarScrollerColor = Color.White;
130+
/// <summary>
107131
/// Whether or not a <see cref="ScrollBar"/> should use smooth scrolling
108132
/// </summary>
109133
public bool ScrollBarSmoothScrolling;
@@ -116,6 +140,10 @@ public class UiStyle : GenericDataHolder {
116140
/// </summary>
117141
public NinePatch CheckboxTexture;
118142
/// <summary>
143+
/// The color that the <see cref="Checkbox"/> element uses
144+
/// </summary>
145+
public Color CheckboxColor = Color.White;
146+
/// <summary>
119147
/// The texture that the <see cref="Checkbox"/> element uses when it is moused over (<see cref="Element.IsMouseOver"/>)
120148
/// </summary>
121149
public NinePatch CheckboxHoveredTexture;
@@ -136,6 +164,15 @@ public class UiStyle : GenericDataHolder {
136164
/// </summary>
137165
public TextureRegion CheckboxCheckmark;
138166
/// <summary>
167+
/// The color of the check mark that the <see cref="Checkbox"/> element uses when it is <see cref="Checkbox.Checked"/>
168+
/// </summary>
169+
public Color CheckboxCheckColor = Color.White;
170+
/// <summary>
171+
/// The color of the check mark that the <see cref="Checkbox"/> element uses when it is not <see cref="Checkbox.Checked"/>.
172+
/// Set alpha to 0 to disable this behavior
173+
/// </summary>
174+
public Color CheckboxUncheckedColor = Color.Transparent;
175+
/// <summary>
139176
/// The width of the space between a <see cref="Checkbox"/> and its <see cref="Checkbox.Label"/>
140177
/// </summary>
141178
public float CheckboxTextOffsetX = 2;
@@ -144,6 +181,10 @@ public class UiStyle : GenericDataHolder {
144181
/// </summary>
145182
public NinePatch RadioTexture;
146183
/// <summary>
184+
/// The color that the <see cref="RadioButton"/> element uses
185+
/// </summary>
186+
public Color RadioColor = Color.White;
187+
/// <summary>
147188
/// The texture that the <see cref="RadioButton"/> element uses when it is moused over (<see cref="Element.IsMouseOver"/>)
148189
/// </summary>
149190
public NinePatch RadioHoveredTexture;
@@ -156,10 +197,23 @@ public class UiStyle : GenericDataHolder {
156197
/// </summary>
157198
public TextureRegion RadioCheckmark;
158199
/// <summary>
200+
/// The color of the check mark that the <see cref="RadioButton"/> uses when it is <see cref="Checkbox.Checked"/>
201+
/// </summary>
202+
public Color RadioCheckColor = Color.White;
203+
/// <summary>
204+
/// The color of the check mark that the <see cref="RadioButton"/> uses when it is not <see cref="Checkbox.Checked"/>
205+
/// Set the alpha to 0 to disable this behavior
206+
/// </summary>
207+
public Color RadioUncheckedColor = Color.Transparent;
208+
/// <summary>
159209
/// The texture that the <see cref="Tooltip"/> uses for its background
160210
/// </summary>
161211
public NinePatch TooltipBackground;
162212
/// <summary>
213+
/// The color that the <see cref="Tooltip"/> uses for its background
214+
/// </summary>
215+
public Color TooltipBackColor = Color.White;
216+
/// <summary>
163217
/// The offset of the <see cref="Tooltip"/> element's top left corner from the mouse position
164218
/// </summary>
165219
public Vector2 TooltipOffset = new Vector2(8, 16);
@@ -286,9 +340,11 @@ public UiStyle() {}
286340
/// <param name="original">The original style settings, to copy into the new instance.</param>
287341
public UiStyle(UiStyle original) {
288342
this.SelectionIndicator = original.SelectionIndicator;
343+
this.SelectionColor = original.SelectionColor;
289344
this.MouseEnterAnimation = original.MouseEnterAnimation;
290345
this.MouseExitAnimation = original.MouseExitAnimation;
291346
this.ButtonTexture = original.ButtonTexture;
347+
this.ButtonColor = original.ButtonColor;
292348
this.ButtonHoveredTexture = original.ButtonHoveredTexture;
293349
this.ButtonHoveredColor = original.ButtonHoveredColor;
294350
this.ButtonDisabledTexture = original.ButtonDisabledTexture;
@@ -300,26 +356,36 @@ public UiStyle(UiStyle original) {
300356
this.PanelScrollerSize = original.PanelScrollerSize;
301357
this.PanelScrollBarOffset = original.PanelScrollBarOffset;
302358
this.TextFieldTexture = original.TextFieldTexture;
359+
this.TextFieldColor = original.TextFieldColor;
303360
this.TextFieldHoveredTexture = original.TextFieldHoveredTexture;
304361
this.TextFieldHoveredColor = original.TextFieldHoveredColor;
305362
this.TextFieldTextOffsetX = original.TextFieldTextOffsetX;
306363
this.TextFieldCaretWidth = original.TextFieldCaretWidth;
307364
this.ScrollBarBackground = original.ScrollBarBackground;
365+
this.ScrollBarBackColor = original.ScrollBarBackColor;
308366
this.ScrollBarScrollerTexture = original.ScrollBarScrollerTexture;
367+
this.ScrollBarScrollerColor = original.ScrollBarScrollerColor;
309368
this.ScrollBarSmoothScrolling = original.ScrollBarSmoothScrolling;
310369
this.ScrollBarSmoothScrollFactor = original.ScrollBarSmoothScrollFactor;
311370
this.CheckboxTexture = original.CheckboxTexture;
371+
this.CheckboxColor = original.CheckboxColor;
312372
this.CheckboxHoveredTexture = original.CheckboxHoveredTexture;
313373
this.CheckboxHoveredColor = original.CheckboxHoveredColor;
314374
this.CheckboxDisabledTexture = original.CheckboxDisabledTexture;
315375
this.CheckboxDisabledColor = original.CheckboxDisabledColor;
316376
this.CheckboxCheckmark = original.CheckboxCheckmark;
377+
this.CheckboxCheckColor = original.CheckboxCheckColor;
378+
this.CheckboxUncheckedColor = original.CheckboxUncheckedColor;
317379
this.CheckboxTextOffsetX = original.CheckboxTextOffsetX;
318380
this.RadioTexture = original.RadioTexture;
381+
this.RadioColor = original.RadioColor;
319382
this.RadioHoveredTexture = original.RadioHoveredTexture;
320383
this.RadioHoveredColor = original.RadioHoveredColor;
321384
this.RadioCheckmark = original.RadioCheckmark;
385+
this.RadioCheckColor = original.RadioCheckColor;
386+
this.RadioUncheckedColor = original.RadioUncheckedColor;
322387
this.TooltipBackground = original.TooltipBackground;
388+
this.TooltipBackColor = original.TooltipBackColor;
323389
this.TooltipOffset = original.TooltipOffset;
324390
this.TooltipAutoNavOffset = original.TooltipAutoNavOffset;
325391
this.TooltipAutoNavAnchor = original.TooltipAutoNavAnchor;

0 commit comments

Comments
 (0)