mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 20:58:34 +01:00
Automatically set area dirty when changing child padding or paragraph fonts
This commit is contained in:
parent
79354c444b
commit
3541b8d3e1
8 changed files with 43 additions and 18 deletions
|
@ -50,6 +50,7 @@ Improvements
|
||||||
- Skip unnecessary area updates for elements with dirty parents
|
- Skip unnecessary area updates for elements with dirty parents
|
||||||
- Calculate panel scroll bar height based on content height
|
- Calculate panel scroll bar height based on content height
|
||||||
- Remember the location that a scroll bar scroller was grabbed in when scrolling
|
- Remember the location that a scroll bar scroller was grabbed in when scrolling
|
||||||
|
- Automatically set area dirty when changing child padding or paragraph fonts
|
||||||
|
|
||||||
Fixes
|
Fixes
|
||||||
- Fixed VerticalSpace height parameter being an integer
|
- Fixed VerticalSpace height parameter being an integer
|
||||||
|
|
|
@ -281,9 +281,14 @@ namespace MLEM.Ui.Elements {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The child padding that this element has.
|
/// The child padding that this element has.
|
||||||
/// The child padding moves any <see cref="Children"/> added to this element inwards by the given amount in each direction.
|
/// The child padding moves any <see cref="Children"/> added to this element inwards by the given amount in each direction.
|
||||||
/// When setting this style after this element has already been added to a ui, <see cref="SetAreaDirty"/> should be called.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public StyleProp<Padding> ChildPadding;
|
public StyleProp<Padding> ChildPadding {
|
||||||
|
get => this.childPadding;
|
||||||
|
set {
|
||||||
|
this.childPadding = value;
|
||||||
|
this.SetAreaDirty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Event that is called after this element is drawn, but before its children are drawn
|
/// Event that is called after this element is drawn, but before its children are drawn
|
||||||
|
@ -405,6 +410,7 @@ namespace MLEM.Ui.Elements {
|
||||||
private bool isHidden;
|
private bool isHidden;
|
||||||
private int priority;
|
private int priority;
|
||||||
private UiStyle style;
|
private UiStyle style;
|
||||||
|
private StyleProp<Padding> childPadding;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new element with the given anchor and size and sets up some default event reactions.
|
/// Creates a new element with the given anchor and size and sets up some default event reactions.
|
||||||
|
|
|
@ -211,8 +211,8 @@ namespace MLEM.Ui.Elements {
|
||||||
this.Texture.SetFromStyle(style.PanelTexture);
|
this.Texture.SetFromStyle(style.PanelTexture);
|
||||||
this.StepPerScroll.SetFromStyle(style.PanelStepPerScroll);
|
this.StepPerScroll.SetFromStyle(style.PanelStepPerScroll);
|
||||||
this.ScrollerSize.SetFromStyle(style.PanelScrollerSize);
|
this.ScrollerSize.SetFromStyle(style.PanelScrollerSize);
|
||||||
this.ChildPadding.SetFromStyle(style.PanelChildPadding);
|
|
||||||
this.ScrollBarOffset.SetFromStyle(style.PanelScrollBarOffset);
|
this.ScrollBarOffset.SetFromStyle(style.PanelScrollBarOffset);
|
||||||
|
this.ChildPadding = this.ChildPadding.CopyFromStyle(style.PanelChildPadding);
|
||||||
this.SetScrollBarStyle();
|
this.SetScrollBarStyle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,14 @@ namespace MLEM.Ui.Elements {
|
||||||
/// The font that this paragraph draws text with.
|
/// The font that this paragraph draws text with.
|
||||||
/// To set its bold and italic font, use <see cref="GenericFont.Bold"/> and <see cref="GenericFont.Italic"/>.
|
/// To set its bold and italic font, use <see cref="GenericFont.Bold"/> and <see cref="GenericFont.Italic"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public StyleProp<GenericFont> RegularFont;
|
public StyleProp<GenericFont> RegularFont {
|
||||||
|
get => this.regularFont;
|
||||||
|
set {
|
||||||
|
this.regularFont = value;
|
||||||
|
this.SetAreaDirty();
|
||||||
|
this.TokenizedText = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The tokenized version of the <see cref="Text"/>
|
/// The tokenized version of the <see cref="Text"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -53,7 +60,6 @@ namespace MLEM.Ui.Elements {
|
||||||
this.text = value;
|
this.text = value;
|
||||||
this.IsHidden = string.IsNullOrWhiteSpace(this.text);
|
this.IsHidden = string.IsNullOrWhiteSpace(this.text);
|
||||||
this.SetAreaDirty();
|
this.SetAreaDirty();
|
||||||
// force text to be re-tokenized
|
|
||||||
this.TokenizedText = null;
|
this.TokenizedText = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,6 +102,7 @@ namespace MLEM.Ui.Elements {
|
||||||
|
|
||||||
private string text;
|
private string text;
|
||||||
private TextAlignment alignment;
|
private TextAlignment alignment;
|
||||||
|
private StyleProp<GenericFont> regularFont;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new paragraph with the given settings.
|
/// Creates a new paragraph with the given settings.
|
||||||
|
@ -150,7 +157,7 @@ namespace MLEM.Ui.Elements {
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void InitStyle(UiStyle style) {
|
protected override void InitStyle(UiStyle style) {
|
||||||
base.InitStyle(style);
|
base.InitStyle(style);
|
||||||
this.RegularFont.SetFromStyle(style.Font ?? throw new NotSupportedException("Paragraphs cannot use ui styles that don't have a font. Please supply a custom font by setting UiStyle.Font."));
|
this.RegularFont = this.RegularFont.CopyFromStyle(style.Font ?? throw new NotSupportedException("Paragraphs cannot use ui styles that don't have a font. Please supply a custom font by setting UiStyle.Font."));
|
||||||
this.TextScale.SetFromStyle(style.TextScale);
|
this.TextScale.SetFromStyle(style.TextScale);
|
||||||
this.TextColor.SetFromStyle(style.TextColor);
|
this.TextColor.SetFromStyle(style.TextColor);
|
||||||
}
|
}
|
||||||
|
|
|
@ -211,7 +211,7 @@ namespace MLEM.Ui.Elements {
|
||||||
this.InputRule = rule ?? DefaultRule;
|
this.InputRule = rule ?? DefaultRule;
|
||||||
this.Multiline = multiline;
|
this.Multiline = multiline;
|
||||||
if (font != null)
|
if (font != null)
|
||||||
this.Font.Set(font);
|
this.Font = font;
|
||||||
if (text != null)
|
if (text != null)
|
||||||
this.SetText(text, true);
|
this.SetText(text, true);
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,7 @@ namespace MLEM.Ui.Elements {
|
||||||
this.Texture.SetFromStyle(style.TooltipBackground);
|
this.Texture.SetFromStyle(style.TooltipBackground);
|
||||||
this.MouseOffset.SetFromStyle(style.TooltipOffset);
|
this.MouseOffset.SetFromStyle(style.TooltipOffset);
|
||||||
this.Delay.SetFromStyle(style.TooltipDelay);
|
this.Delay.SetFromStyle(style.TooltipDelay);
|
||||||
this.ChildPadding.SetFromStyle(style.TooltipChildPadding);
|
this.ChildPadding = this.ChildPadding.CopyFromStyle(style.TooltipChildPadding);
|
||||||
if (this.Paragraph != null) {
|
if (this.Paragraph != null) {
|
||||||
this.Paragraph.TextColor.SetFromStyle(style.TooltipTextColor, 1);
|
this.Paragraph.TextColor.SetFromStyle(style.TooltipTextColor, 1);
|
||||||
this.Paragraph.Size = new Vector2(style.TooltipTextWidth, 0);
|
this.Paragraph.Size = new Vector2(style.TooltipTextWidth, 0);
|
||||||
|
|
|
@ -26,11 +26,12 @@ namespace MLEM.Ui.Style {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets this style property's value and marks it as being set by a <see cref="UiStyle"/>.
|
/// Sets this style property's value and marks it as being set by a <see cref="UiStyle"/> if it doesn't have a custom value yet.
|
||||||
/// This allows this property to be overridden by custom style settings using <see cref="Set"/>.
|
/// This allows this property to be overridden by custom style settings using <see cref="StyleProp{T}(T)"/> or a higher <paramref name="priority"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value">The style to apply</param>
|
/// <param name="value">The style to apply</param>
|
||||||
/// <param name="priority">The priority that this style value has. Higher priority style values will override lower priority style values.</param>
|
/// <param name="priority">The priority that this style value has. Higher priority style values will override lower priority style values.</param>
|
||||||
|
///<seealso cref="CopyFromStyle"/>
|
||||||
public void SetFromStyle(T value, byte priority = 0) {
|
public void SetFromStyle(T value, byte priority = 0) {
|
||||||
if (priority >= this.lastSetPriority) {
|
if (priority >= this.lastSetPriority) {
|
||||||
this.Value = value;
|
this.Value = value;
|
||||||
|
@ -39,13 +40,17 @@ namespace MLEM.Ui.Style {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets this style property's value and marks it as being custom.
|
/// Creates a copy of this style property and sets its value and marks it as being set by a <see cref="UiStyle"/> if it doesn't have a custom value yet.
|
||||||
/// This causes <see cref="SetFromStyle"/> not to override the style value through a <see cref="UiStyle"/>.
|
/// This allows this property to be overridden by custom style settings using <see cref="StyleProp{T}(T)"/> or a higher <paramref name="priority"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value"></param>
|
/// <param name="value">The style to apply</param>
|
||||||
public void Set(T value) {
|
/// <param name="priority">The priority that the style value has. Higher priority style values will override lower priority style values.</param>
|
||||||
this.lastSetPriority = byte.MaxValue;
|
/// <returns>The new style</returns>
|
||||||
this.Value = value;
|
/// <seealso cref="SetFromStyle"/>
|
||||||
|
public StyleProp<T> CopyFromStyle(T value, byte priority = 0) {
|
||||||
|
var ret = this;
|
||||||
|
ret.SetFromStyle(value, priority);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -58,7 +63,7 @@ namespace MLEM.Ui.Style {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns whether this style property has a value assigned to it using <see cref="SetFromStyle"/> or <see cref="Set"/>.
|
/// Returns whether this style property has a value assigned to it using <see cref="SetFromStyle"/> or <see cref="StyleProp{T}(T)"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Whether this style property has a value</returns>
|
/// <returns>Whether this style property has a value</returns>
|
||||||
public bool HasValue() {
|
public bool HasValue() {
|
||||||
|
|
|
@ -79,10 +79,16 @@ namespace Tests {
|
||||||
Assert.AreEqual(null, style.Value);
|
Assert.AreEqual(null, style.Value);
|
||||||
style.SetFromStyle("from style");
|
style.SetFromStyle("from style");
|
||||||
Assert.AreEqual("from style", style.Value);
|
Assert.AreEqual("from style", style.Value);
|
||||||
style.Set("custom");
|
style = "custom";
|
||||||
Assert.AreEqual("custom", style.Value);
|
Assert.AreEqual("custom", style.Value);
|
||||||
style.SetFromStyle("from style again");
|
style.SetFromStyle("from style again");
|
||||||
Assert.AreEqual("custom", style.Value);
|
Assert.AreEqual("custom", style.Value);
|
||||||
|
|
||||||
|
var copy = style.CopyFromStyle("copy from style", byte.MaxValue);
|
||||||
|
var weakCopy = style.CopyFromStyle("weak copy");
|
||||||
|
Assert.AreEqual("copy from style", copy.Value);
|
||||||
|
Assert.AreEqual("custom", weakCopy.Value);
|
||||||
|
Assert.AreEqual("custom", style.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|
Loading…
Reference in a new issue