1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-25 14:08:34 +01:00

Added style properties for a lot of hardcoded default element styles

This commit is contained in:
Ell 2021-10-29 23:33:15 +02:00
parent 9ddc1f6975
commit 0809cd0218
15 changed files with 125 additions and 70 deletions

View file

@ -26,6 +26,7 @@ Improvements
- Cache TokenizedString inner offsets for non-Left text alignments to improve performance - Cache TokenizedString inner offsets for non-Left text alignments to improve performance
- Exposed the epsilon value used by Element calculations - Exposed the epsilon value used by Element calculations
- Made Image ScaleToImage take ui scale into account - Made Image ScaleToImage take ui scale into account
- Added style properties for a lot of hardcoded default element styles
Fixes Fixes
- Fixed VerticalSpace height parameter being an integer - Fixed VerticalSpace height parameter being an integer

View file

@ -63,7 +63,7 @@ namespace Demos {
this.UiSystem.AutoScaleWithScreen = true; this.UiSystem.AutoScaleWithScreen = true;
// create the root panel that all the other components sit on and add it to the ui system // create the root panel that all the other components sit on and add it to the ui system
this.root = new Panel(Anchor.Center, new Vector2(80, 100), Vector2.Zero, false, true, new Point(5, 10)); this.root = new Panel(Anchor.Center, new Vector2(80, 100), Vector2.Zero, false, true);
this.root.ScrollBar.SmoothScrolling = true; this.root.ScrollBar.SmoothScrolling = true;
// add the root to the demos' ui // add the root to the demos' ui
this.UiRoot.AddChild(this.root); this.UiRoot.AddChild(this.root);
@ -136,16 +136,16 @@ namespace Demos {
this.root.AddChild(new RadioButton(Anchor.AutoLeft, new Vector2(1, 10), "Radio button 1!")); this.root.AddChild(new RadioButton(Anchor.AutoLeft, new Vector2(1, 10), "Radio button 1!"));
this.root.AddChild(new RadioButton(Anchor.AutoLeft, new Vector2(1, 10), "Radio button 2!") {PositionOffset = new Vector2(0, 1)}); this.root.AddChild(new RadioButton(Anchor.AutoLeft, new Vector2(1, 10), "Radio button 2!") {PositionOffset = new Vector2(0, 1)});
var tooltip = new Tooltip(50, "I am tooltip!") {IsHidden = true}; var tooltip = new Tooltip("I am tooltip!") {IsHidden = true};
this.UiSystem.Add("TestTooltip", tooltip); this.UiSystem.Add("TestTooltip", tooltip);
this.root.AddChild(new VerticalSpace(3)); this.root.AddChild(new VerticalSpace(3));
this.root.AddChild(new Button(Anchor.AutoLeft, new Vector2(1, 10), "Toggle Mouse Tooltip") { this.root.AddChild(new Button(Anchor.AutoLeft, new Vector2(1, 10), "Toggle Mouse Tooltip") {
OnPressed = element => tooltip.IsHidden = !tooltip.IsHidden OnPressed = element => tooltip.IsHidden = !tooltip.IsHidden
}); });
var delayed = this.root.AddChild(new Button(Anchor.AutoLeft, new Vector2(1, 10), "Delayed Tooltip") {PositionOffset = new Vector2(0, 1)}); var delayed = this.root.AddChild(new Button(Anchor.AutoLeft, new Vector2(1, 10), "Delayed Tooltip") {PositionOffset = new Vector2(0, 1)});
delayed.AddTooltip(50, "This tooltip appears with a half second delay!").Delay = TimeSpan.FromSeconds(0.5); delayed.AddTooltip("This tooltip appears with a half second delay!").Delay = TimeSpan.FromSeconds(0.5);
var condition = this.root.AddChild(new Button(Anchor.AutoLeft, new Vector2(1, 10), "Hold Ctrl for Tooltip") {PositionOffset = new Vector2(0, 1)}); var condition = this.root.AddChild(new Button(Anchor.AutoLeft, new Vector2(1, 10), "Hold Ctrl for Tooltip") {PositionOffset = new Vector2(0, 1)});
condition.AddTooltip(50, p => this.InputHandler.IsModifierKeyDown(ModifierKey.Control) ? "This tooltip only appears when holding control!" : string.Empty); condition.AddTooltip(p => this.InputHandler.IsModifierKeyDown(ModifierKey.Control) ? "This tooltip only appears when holding control!" : string.Empty);
var slider = new Slider(Anchor.AutoLeft, new Vector2(1, 10), 5, 1) { var slider = new Slider(Anchor.AutoLeft, new Vector2(1, 10), 5, 1) {
StepPerScroll = 0.01F StepPerScroll = 0.01F

View file

@ -79,14 +79,13 @@ namespace MLEM.Ui.Elements {
/// <param name="size">The button's size</param> /// <param name="size">The button's size</param>
/// <param name="text">The text that should be displayed on the button</param> /// <param name="text">The text that should be displayed on the button</param>
/// <param name="tooltipText">The text that should be displayed in a <see cref="Tooltip"/> when hovering over this button</param> /// <param name="tooltipText">The text that should be displayed in a <see cref="Tooltip"/> when hovering over this button</param>
/// <param name="tooltipWidth">The width of this button's <see cref="Tooltip"/>, or 50 by default</param> public Button(Anchor anchor, Vector2 size, string text = null, string tooltipText = null) : base(anchor, size) {
public Button(Anchor anchor, Vector2 size, string text = null, string tooltipText = null, float tooltipWidth = 50) : base(anchor, size) {
if (text != null) { if (text != null) {
this.Text = new Paragraph(Anchor.Center, 1, text, true) {Padding = new Vector2(1)}; this.Text = new Paragraph(Anchor.Center, 1, text, true) {Padding = new Vector2(1)};
this.AddChild(this.Text); this.AddChild(this.Text);
} }
if (tooltipText != null) if (tooltipText != null)
this.Tooltip = this.AddTooltip(tooltipWidth, tooltipText); this.Tooltip = this.AddTooltip(tooltipText);
} }
/// <inheritdoc /> /// <inheritdoc />

View file

@ -36,7 +36,7 @@ namespace MLEM.Ui.Elements {
/// <summary> /// <summary>
/// The width of the space between this checkbox and its <see cref="Label"/> /// The width of the space between this checkbox and its <see cref="Label"/>
/// </summary> /// </summary>
public float TextOffsetX = 2; public StyleProp<float> TextOffsetX;
private bool checced; private bool checced;
/// <summary> /// <summary>
@ -106,6 +106,7 @@ namespace MLEM.Ui.Elements {
this.HoveredTexture.SetFromStyle(style.CheckboxHoveredTexture); this.HoveredTexture.SetFromStyle(style.CheckboxHoveredTexture);
this.HoveredColor.SetFromStyle(style.CheckboxHoveredColor); this.HoveredColor.SetFromStyle(style.CheckboxHoveredColor);
this.Checkmark.SetFromStyle(style.CheckboxCheckmark); this.Checkmark.SetFromStyle(style.CheckboxCheckmark);
this.TextOffsetX.SetFromStyle(style.CheckboxTextOffsetX);
} }
/// <summary> /// <summary>

View file

@ -35,8 +35,7 @@ namespace MLEM.Ui.Elements {
/// <param name="size">The dropdown button's size</param> /// <param name="size">The dropdown button's size</param>
/// <param name="text">The text displayed on the dropdown button</param> /// <param name="text">The text displayed on the dropdown button</param>
/// <param name="tooltipText">The text displayed as a tooltip when hovering over the dropdown button</param> /// <param name="tooltipText">The text displayed as a tooltip when hovering over the dropdown button</param>
/// <param name="tooltipWidth">The width of the dropdown button's tooltip</param> public Dropdown(Anchor anchor, Vector2 size, string text = null, string tooltipText = null) : base(anchor, size, text, tooltipText) {
public Dropdown(Anchor anchor, Vector2 size, string text = null, string tooltipText = null, float tooltipWidth = 50) : base(anchor, size, text, tooltipText, tooltipWidth) {
this.Panel = this.AddChild(new Panel(Anchor.TopCenter, size, Vector2.Zero, true) { this.Panel = this.AddChild(new Panel(Anchor.TopCenter, size, Vector2.Zero, true) {
IsHidden = true IsHidden = true
}); });

View file

@ -18,11 +18,10 @@ namespace MLEM.Ui.Elements {
/// <param name="texture">The texture of the image to render on the button</param> /// <param name="texture">The texture of the image to render on the button</param>
/// <param name="text">The text to display on the button</param> /// <param name="text">The text to display on the button</param>
/// <param name="tooltipText">The text of the button's tooltip</param> /// <param name="tooltipText">The text of the button's tooltip</param>
/// <param name="tooltipWidth">The width of the button's tooltip</param>
/// <param name="imagePadding">The <see cref="Element.Padding"/> of the button's image</param> /// <param name="imagePadding">The <see cref="Element.Padding"/> of the button's image</param>
/// <returns>An image button</returns> /// <returns>An image button</returns>
public static Button ImageButton(Anchor anchor, Vector2 size, TextureRegion texture, string text = null, string tooltipText = null, float tooltipWidth = 50, float imagePadding = 2) { public static Button ImageButton(Anchor anchor, Vector2 size, TextureRegion texture, string text = null, string tooltipText = null, float imagePadding = 2) {
var button = new Button(anchor, size, text, tooltipText, tooltipWidth); var button = new Button(anchor, size, text, tooltipText);
var image = new Image(Anchor.CenterLeft, Vector2.One, texture) {Padding = new Vector2(imagePadding)}; var image = new Image(Anchor.CenterLeft, Vector2.One, texture) {Padding = new Vector2(imagePadding)};
button.OnAreaUpdated += e => image.Size = new Vector2(e.Area.Height, e.Area.Height) / e.Scale; button.OnAreaUpdated += e => image.Size = new Vector2(e.Area.Height, e.Area.Height) / e.Scale;
button.AddChild(image, 0); button.AddChild(image, 0);
@ -172,25 +171,23 @@ namespace MLEM.Ui.Elements {
public static class ElementExtensions { public static class ElementExtensions {
/// <summary> /// <summary>
/// Adds a new <see cref="Tooltip"/> to the given element using the <see cref="Tooltip(float,Paragraph.TextCallback,Element)"/> constructor /// Adds a new <see cref="Tooltip"/> to the given element using the <see cref="Tooltip(Paragraph.TextCallback,Element)"/> constructor
/// </summary> /// </summary>
/// <param name="element"></param> /// <param name="element">The element to add the tooltip to</param>
/// <param name="width">The width of the tooltip</param>
/// <param name="textCallback">The text to display on the tooltip</param> /// <param name="textCallback">The text to display on the tooltip</param>
/// <returns>The created tooltip instance</returns> /// <returns>The created tooltip instance</returns>
public static Tooltip AddTooltip(this Element element, float width, Paragraph.TextCallback textCallback) { public static Tooltip AddTooltip(this Element element, Paragraph.TextCallback textCallback) {
return new Tooltip(width, textCallback, element); return new Tooltip(textCallback, element);
} }
/// <summary> /// <summary>
/// Adds a new <see cref="Tooltip"/> to the given element using the <see cref="Tooltip(float,string,Element)"/> constructor /// Adds a new <see cref="Tooltip"/> to the given element using the <see cref="Tooltip(string,Element)"/> constructor
/// </summary> /// </summary>
/// <param name="element"></param> /// <param name="element">The element to add the tooltip to</param>
/// <param name="width">The width of the tooltip</param>
/// <param name="text">The text to display on the tooltip</param> /// <param name="text">The text to display on the tooltip</param>
/// <returns>The created tooltip instance</returns> /// <returns>The created tooltip instance</returns>
public static Tooltip AddTooltip(this Element element, float width, string text) { public static Tooltip AddTooltip(this Element element, string text) {
return new Tooltip(width, text, element); return new Tooltip(text, element);
} }
} }

View file

@ -27,8 +27,18 @@ namespace MLEM.Ui.Elements {
/// </summary> /// </summary>
public StyleProp<Color> DrawColor; public StyleProp<Color> DrawColor;
/// <summary> /// <summary>
/// The amount that the scrollable area is moved per single movement of the scroll wheel
/// This value is passed to the <see cref="ScrollBar"/>'s <see cref="Elements.ScrollBar.StepPerScroll"/>
/// </summary>
public StyleProp<float> StepPerScroll;
/// <summary>
/// The size that the <see cref="ScrollBar"/>'s scroller should have, in pixels
/// </summary>
public StyleProp<Vector2> ScrollerSize;
/// <summary>
/// The scroll bar that this panel contains. /// The scroll bar that this panel contains.
/// This is only nonnull if <see cref="scrollOverflow"/> is true. /// This is only nonnull if <see cref="scrollOverflow"/> is true.
/// Note that some scroll bar styling is controlled by this panel, namely <see cref="StepPerScroll"/> and <see cref="ScrollerSize"/>.
/// </summary> /// </summary>
public readonly ScrollBar ScrollBar; public readonly ScrollBar ScrollBar;
private readonly bool scrollOverflow; private readonly bool scrollOverflow;
@ -44,29 +54,22 @@ namespace MLEM.Ui.Elements {
/// <param name="positionOffset">The panel's offset from its anchor point</param> /// <param name="positionOffset">The panel's offset from its anchor point</param>
/// <param name="setHeightBasedOnChildren">Whether the panel should automatically calculate its height based on its children's size</param> /// <param name="setHeightBasedOnChildren">Whether the panel should automatically calculate its height based on its children's size</param>
/// <param name="scrollOverflow">Whether this panel should automatically add a scroll bar to scroll towards elements that are beyond the area this panel covers</param> /// <param name="scrollOverflow">Whether this panel should automatically add a scroll bar to scroll towards elements that are beyond the area this panel covers</param>
/// <param name="scrollerSize">The size of the <see cref="ScrollBar"/>'s scroller</param>
/// <param name="autoHideScrollbar">Whether the scroll bar should be hidden automatically if the panel does not contain enough children to allow for scrolling</param> /// <param name="autoHideScrollbar">Whether the scroll bar should be hidden automatically if the panel does not contain enough children to allow for scrolling</param>
public Panel(Anchor anchor, Vector2 size, Vector2 positionOffset, bool setHeightBasedOnChildren = false, bool scrollOverflow = false, Point? scrollerSize = null, bool autoHideScrollbar = true) : base(anchor, size) { public Panel(Anchor anchor, Vector2 size, Vector2 positionOffset, bool setHeightBasedOnChildren = false, bool scrollOverflow = false, bool autoHideScrollbar = true) : base(anchor, size) {
this.PositionOffset = positionOffset; this.PositionOffset = positionOffset;
this.SetHeightBasedOnChildren = setHeightBasedOnChildren; this.SetHeightBasedOnChildren = setHeightBasedOnChildren;
this.scrollOverflow = scrollOverflow; this.scrollOverflow = scrollOverflow;
this.ChildPadding = new Vector2(5);
this.CanBeSelected = false; this.CanBeSelected = false;
if (scrollOverflow) { if (scrollOverflow) {
var (w, h) = scrollerSize ?? Point.Zero; this.ScrollBar = new ScrollBar(Anchor.TopRight, Vector2.Zero, 0, 0) {
this.ScrollBar = new ScrollBar(Anchor.TopRight, new Vector2(w, 1), h, 0) {
StepPerScroll = 10,
OnValueChanged = (element, value) => this.ScrollChildren(), OnValueChanged = (element, value) => this.ScrollChildren(),
CanAutoAnchorsAttach = false, CanAutoAnchorsAttach = false,
AutoHideWhenEmpty = autoHideScrollbar, AutoHideWhenEmpty = autoHideScrollbar,
IsHidden = autoHideScrollbar IsHidden = autoHideScrollbar
}; };
// modify the padding so that the scroll bar isn't over top of something else
this.ScrollBar.PositionOffset -= new Vector2(w + 1, 0);
if (autoHideScrollbar) if (autoHideScrollbar)
this.ScrollBar.OnAutoHide += e => this.ChildPadding += new Padding(0, w, 0, 0) * (e.IsHidden ? -1 : 1); this.ScrollBar.OnAutoHide += e => this.ChildPadding += new Padding(0, this.ScrollerSize.Value.X, 0, 0) * (e.IsHidden ? -1 : 1);
// handle automatic element selection, the scroller needs to scroll to the right location // handle automatic element selection, the scroller needs to scroll to the right location
this.OnSelectedElementChanged += (element, otherElement) => { this.OnSelectedElementChanged += (element, otherElement) => {
@ -99,6 +102,7 @@ namespace MLEM.Ui.Elements {
this.ScrollChildren(); this.ScrollChildren();
this.ScrollSetup(); this.ScrollSetup();
this.SetScrollBarStyle();
} }
private void ScrollChildren() { private void ScrollChildren() {
@ -207,6 +211,11 @@ namespace MLEM.Ui.Elements {
protected override void InitStyle(UiStyle style) { protected override void InitStyle(UiStyle style) {
base.InitStyle(style); base.InitStyle(style);
this.Texture.SetFromStyle(style.PanelTexture); this.Texture.SetFromStyle(style.PanelTexture);
this.StepPerScroll.SetFromStyle(style.PanelStepPerScroll);
this.ScrollerSize.SetFromStyle(style.PanelScrollerSize);
if (this.ChildPadding == default)
this.ChildPadding = style.PanelChildPadding;
this.SetScrollBarStyle();
} }
/// <summary> /// <summary>
@ -245,5 +254,14 @@ namespace MLEM.Ui.Elements {
base.Dispose(); base.Dispose();
} }
private void SetScrollBarStyle() {
if (this.ScrollBar == null)
return;
this.ScrollBar.StepPerScroll = this.StepPerScroll;
this.ScrollBar.Size = new Vector2(this.ScrollerSize.Value.X, 1);
this.ScrollBar.ScrollerSize = this.ScrollerSize;
this.ScrollBar.PositionOffset = new Vector2(-this.ScrollerSize.Value.X - 1, 0);
}
} }
} }

View file

@ -101,11 +101,11 @@ namespace MLEM.Ui.Elements {
/// Whether smooth scrolling should be enabled for this scroll bar. /// Whether smooth scrolling should be enabled for this scroll bar.
/// Smooth scrolling causes the <see cref="CurrentValue"/> to change gradually rather than instantly when scrolling. /// Smooth scrolling causes the <see cref="CurrentValue"/> to change gradually rather than instantly when scrolling.
/// </summary> /// </summary>
public bool SmoothScrolling; public StyleProp<bool> SmoothScrolling;
/// <summary> /// <summary>
/// The factor with which <see cref="SmoothScrolling"/> happens. /// The factor with which <see cref="SmoothScrolling"/> happens.
/// </summary> /// </summary>
public float SmoothScrollFactor = 0.75F; public StyleProp<float> SmoothScrollFactor;
static ScrollBar() { static ScrollBar() {
InputHandler.EnableGestures(GestureType.HorizontalDrag, GestureType.VerticalDrag); InputHandler.EnableGestures(GestureType.HorizontalDrag, GestureType.VerticalDrag);
@ -180,7 +180,7 @@ namespace MLEM.Ui.Elements {
if (this.SmoothScrolling && this.scrollAdded != 0) { if (this.SmoothScrolling && this.scrollAdded != 0) {
this.scrollAdded *= this.SmoothScrollFactor; this.scrollAdded *= this.SmoothScrollFactor;
if (Math.Abs(this.scrollAdded) <= 0.1F) if (Math.Abs(this.scrollAdded) <= Epsilon)
this.scrollAdded = 0; this.scrollAdded = 0;
this.OnValueChanged?.Invoke(this, this.CurrentValue); this.OnValueChanged?.Invoke(this, this.CurrentValue);
} }
@ -216,6 +216,8 @@ namespace MLEM.Ui.Elements {
base.InitStyle(style); base.InitStyle(style);
this.Background.SetFromStyle(style.ScrollBarBackground); this.Background.SetFromStyle(style.ScrollBarBackground);
this.ScrollerTexture.SetFromStyle(style.ScrollBarScrollerTexture); this.ScrollerTexture.SetFromStyle(style.ScrollBarScrollerTexture);
this.SmoothScrolling.SetFromStyle(style.ScrollBarSmoothScrolling);
this.SmoothScrollFactor.SetFromStyle(style.ScrollBarSmoothScrollFactor);
} }
/// <summary> /// <summary>

View file

@ -113,11 +113,11 @@ namespace MLEM.Ui.Elements {
/// <summary> /// <summary>
/// The x position that text should start rendering at, based on the x position of this text field. /// The x position that text should start rendering at, based on the x position of this text field.
/// </summary> /// </summary>
public float TextOffsetX = 4; public StyleProp<float> TextOffsetX;
/// <summary> /// <summary>
/// The width that the caret should render with. /// The width that the caret should render with, in pixels
/// </summary> /// </summary>
public float CaretWidth = 0.5F; public StyleProp<float> CaretWidth;
/// <summary> /// <summary>
/// The rule used for text input. /// The rule used for text input.
/// Rules allow only certain characters to be allowed inside of a text field. /// Rules allow only certain characters to be allowed inside of a text field.
@ -399,6 +399,8 @@ namespace MLEM.Ui.Elements {
this.Texture.SetFromStyle(style.TextFieldTexture); this.Texture.SetFromStyle(style.TextFieldTexture);
this.HoveredTexture.SetFromStyle(style.TextFieldHoveredTexture); this.HoveredTexture.SetFromStyle(style.TextFieldHoveredTexture);
this.HoveredColor.SetFromStyle(style.TextFieldHoveredColor); this.HoveredColor.SetFromStyle(style.TextFieldHoveredColor);
this.TextOffsetX.SetFromStyle(style.TextFieldTextOffsetX);
this.CaretWidth.SetFromStyle(style.TextFieldCaretWidth);
} }
private bool FilterText(ref string text, bool removeMismatching) { private bool FilterText(ref string text, bool removeMismatching) {

View file

@ -29,25 +29,23 @@ namespace MLEM.Ui.Elements {
/// <summary> /// <summary>
/// Creates a new tooltip with the given settings /// Creates a new tooltip with the given settings
/// </summary> /// </summary>
/// <param name="width">The width of the tooltip</param>
/// <param name="text">The text to display on the tooltip</param> /// <param name="text">The text to display on the tooltip</param>
/// <param name="elementToHover">The element that should automatically cause the tooltip to appear and disappear when hovered and not hovered, respectively</param> /// <param name="elementToHover">The element that should automatically cause the tooltip to appear and disappear when hovered and not hovered, respectively</param>
public Tooltip(float width, string text = null, Element elementToHover = null) : public Tooltip(string text = null, Element elementToHover = null) :
base(Anchor.TopLeft, Vector2.One, Vector2.Zero) { base(Anchor.TopLeft, Vector2.One, Vector2.Zero) {
if (text != null) if (text != null)
this.Paragraph = this.AddChild(new Paragraph(Anchor.TopLeft, width, text)); this.Paragraph = this.AddChild(new Paragraph(Anchor.TopLeft, 0, text));
this.Init(elementToHover); this.Init(elementToHover);
} }
/// <summary> /// <summary>
/// Creates a new tooltip with the given settings /// Creates a new tooltip with the given settings
/// </summary> /// </summary>
/// <param name="width">The width of the tooltip</param>
/// <param name="textCallback">The text to display on the tooltip</param> /// <param name="textCallback">The text to display on the tooltip</param>
/// <param name="elementToHover">The element that should automatically cause the tooltip to appear and disappear when hovered and not hovered, respectively</param> /// <param name="elementToHover">The element that should automatically cause the tooltip to appear and disappear when hovered and not hovered, respectively</param>
public Tooltip(float width, Paragraph.TextCallback textCallback, Element elementToHover = null) : public Tooltip(Paragraph.TextCallback textCallback, Element elementToHover = null) :
base(Anchor.TopLeft, Vector2.One, Vector2.Zero) { base(Anchor.TopLeft, Vector2.One, Vector2.Zero) {
this.Paragraph = this.AddChild(new Paragraph(Anchor.TopLeft, width, textCallback)); this.Paragraph = this.AddChild(new Paragraph(Anchor.TopLeft, 0, textCallback));
this.Init(elementToHover); this.Init(elementToHover);
} }
@ -81,8 +79,12 @@ 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);
// we can't set from style here since it's a different element this.ChildPadding = style.TooltipChildPadding;
this.Paragraph?.TextColor.Set(style.TooltipTextColor); if (this.Paragraph != null) {
// we can't set from style here since it's a different element
this.Paragraph.TextColor.Set(style.TooltipTextColor);
this.Paragraph.Size = new Vector2(style.TooltipTextWidth, 0);
}
} }
/// <summary> /// <summary>
@ -143,7 +145,6 @@ namespace MLEM.Ui.Elements {
this.SetWidthBasedOnChildren = true; this.SetWidthBasedOnChildren = true;
this.SetHeightBasedOnChildren = true; this.SetHeightBasedOnChildren = true;
this.ChildPadding = new Vector2(2);
this.CanBeMoused = false; this.CanBeMoused = false;
if (elementToHover != null) if (elementToHover != null)

View file

@ -31,9 +31,8 @@ namespace MLEM.Ui.Style {
/// </summary> /// </summary>
/// <param name="value">The style to apply</param> /// <param name="value">The style to apply</param>
public void SetFromStyle(T value) { public void SetFromStyle(T value) {
if (!this.isCustom) { if (!this.isCustom)
this.Value = value; this.Value = value;
}
} }
/// <summary> /// <summary>
@ -63,6 +62,11 @@ namespace MLEM.Ui.Style {
return !EqualityComparer<T>.Default.Equals(this.Value, default); return !EqualityComparer<T>.Default.Equals(this.Value, default);
} }
/// <inheritdoc />
public override string ToString() {
return $"{this.Value} (Custom: {this.isCustom})";
}
/// <summary> /// <summary>
/// Implicitly converts a style property to its value. /// Implicitly converts a style property to its value.
/// </summary> /// </summary>

View file

@ -31,7 +31,7 @@ namespace MLEM.Ui.Style {
/// <summary> /// <summary>
/// The color that the <see cref="Button"/> element renders with when it is moused over (<see cref="Element.IsMouseOver"/>) /// The color that the <see cref="Button"/> element renders with when it is moused over (<see cref="Element.IsMouseOver"/>)
/// </summary> /// </summary>
public Color ButtonHoveredColor; public Color ButtonHoveredColor = Color.LightGray;
/// <summary> /// <summary>
/// The texture that the <see cref="Button"/> element uses when it <see cref="Button.IsDisabled"/> /// The texture that the <see cref="Button"/> element uses when it <see cref="Button.IsDisabled"/>
/// </summary> /// </summary>
@ -39,12 +39,24 @@ namespace MLEM.Ui.Style {
/// <summary> /// <summary>
/// The color that the <see cref="Button"/> element uses when it <see cref="Button.IsDisabled"/> /// The color that the <see cref="Button"/> element uses when it <see cref="Button.IsDisabled"/>
/// </summary> /// </summary>
public Color ButtonDisabledColor; public Color ButtonDisabledColor = Color.Gray;
/// <summary> /// <summary>
/// The texture that the <see cref="Panel"/> element uses /// The texture that the <see cref="Panel"/> element uses
/// </summary> /// </summary>
public NinePatch PanelTexture; public NinePatch PanelTexture;
/// <summary> /// <summary>
/// The <see cref="Element.ChildPadding"/> to apply to a <see cref="Panel"/> by default
/// </summary>
public Padding PanelChildPadding = new Vector2(5);
/// <summary>
/// The amount that a <see cref="Panel"/>'s scrollable area is moved per single movement of the scroll wheel
/// </summary>
public float PanelStepPerScroll = 10;
/// <summary>
/// The size of the scroller of a <see cref="Panel"/>'s scroll bar
/// </summary>
public Vector2 PanelScrollerSize = new Vector2(5, 10);
/// <summary>
/// The texture that the <see cref="TextField"/> element uses /// The texture that the <see cref="TextField"/> element uses
/// </summary> /// </summary>
public NinePatch TextFieldTexture; public NinePatch TextFieldTexture;
@ -55,7 +67,15 @@ namespace MLEM.Ui.Style {
/// <summary> /// <summary>
/// The color that the <see cref="TextField"/> renders with when it is moused over (<see cref="Element.IsMouseOver"/>) /// The color that the <see cref="TextField"/> renders with when it is moused over (<see cref="Element.IsMouseOver"/>)
/// </summary> /// </summary>
public Color TextFieldHoveredColor; public Color TextFieldHoveredColor = Color.LightGray;
/// <summary>
/// The x position that a <see cref="TextField"/>'s text should start rendering at, based on the x position of the text field
/// </summary>
public float TextFieldTextOffsetX = 4;
/// <summary>
/// The width that a <see cref="TextField"/>'s caret should render with
/// </summary>
public float TextFieldCaretWidth = 0.5F;
/// <summary> /// <summary>
/// The background texture that the <see cref="ScrollBar"/> element uses /// The background texture that the <see cref="ScrollBar"/> element uses
/// </summary> /// </summary>
@ -65,6 +85,14 @@ namespace MLEM.Ui.Style {
/// </summary> /// </summary>
public NinePatch ScrollBarScrollerTexture; public NinePatch ScrollBarScrollerTexture;
/// <summary> /// <summary>
/// Whether or not a <see cref="ScrollBar"/> should use smooth scrolling
/// </summary>
public bool ScrollBarSmoothScrolling;
/// <summary>
/// The factor with which a <see cref="ScrollBar"/>'s smooth scrolling happens
/// </summary>
public float ScrollBarSmoothScrollFactor = 0.75F;
/// <summary>
/// The texture that the <see cref="Checkbox"/> element uses /// The texture that the <see cref="Checkbox"/> element uses
/// </summary> /// </summary>
public NinePatch CheckboxTexture; public NinePatch CheckboxTexture;
@ -75,12 +103,16 @@ namespace MLEM.Ui.Style {
/// <summary> /// <summary>
/// The color that the <see cref="Checkbox"/> element renders with when it is moused over (<see cref="Element.IsMouseOver"/>) /// The color that the <see cref="Checkbox"/> element renders with when it is moused over (<see cref="Element.IsMouseOver"/>)
/// </summary> /// </summary>
public Color CheckboxHoveredColor; public Color CheckboxHoveredColor = Color.LightGray;
/// <summary> /// <summary>
/// The texture that the <see cref="Checkbox"/> element renders on top of its regular texture when it is <see cref="Checkbox.Checked"/> /// The texture that the <see cref="Checkbox"/> element renders on top of its regular texture when it is <see cref="Checkbox.Checked"/>
/// </summary> /// </summary>
public TextureRegion CheckboxCheckmark; public TextureRegion CheckboxCheckmark;
/// <summary> /// <summary>
/// The width of the space between a <see cref="Checkbox"/> and its <see cref="Checkbox.Label"/>
/// </summary>
public float CheckboxTextOffsetX = 2;
/// <summary>
/// The texture that the <see cref="RadioButton"/> element uses /// The texture that the <see cref="RadioButton"/> element uses
/// </summary> /// </summary>
public NinePatch RadioTexture; public NinePatch RadioTexture;
@ -91,7 +123,7 @@ namespace MLEM.Ui.Style {
/// <summary> /// <summary>
/// The color that the <see cref="RadioButton"/> element renders with when it is moused over (<see cref="Element.IsMouseOver"/>) /// The color that the <see cref="RadioButton"/> element renders with when it is moused over (<see cref="Element.IsMouseOver"/>)
/// </summary> /// </summary>
public Color RadioHoveredColor; public Color RadioHoveredColor = Color.LightGray;
/// <summary> /// <summary>
/// The texture that the <see cref="RadioButton"/> renders on top of its regular texture when it is <see cref="Checkbox.Checked"/> /// The texture that the <see cref="RadioButton"/> renders on top of its regular texture when it is <see cref="Checkbox.Checked"/>
/// </summary> /// </summary>
@ -103,7 +135,7 @@ namespace MLEM.Ui.Style {
/// <summary> /// <summary>
/// The offset of the <see cref="Tooltip"/> element's top left corner from the mouse position /// The offset of the <see cref="Tooltip"/> element's top left corner from the mouse position
/// </summary> /// </summary>
public Vector2 TooltipOffset; public Vector2 TooltipOffset = new Vector2(8, 16);
/// <summary> /// <summary>
/// The color that the text of a <see cref="Tooltip"/> should have /// The color that the text of a <see cref="Tooltip"/> should have
/// </summary> /// </summary>
@ -113,17 +145,25 @@ namespace MLEM.Ui.Style {
/// </summary> /// </summary>
public TimeSpan TooltipDelay = TimeSpan.Zero; public TimeSpan TooltipDelay = TimeSpan.Zero;
/// <summary> /// <summary>
/// The width of a <see cref="Tooltip"/>'s default text <see cref="Paragraph"/>
/// </summary>
public float TooltipTextWidth = 50;
/// <summary>
/// The <see cref="Element.ChildPadding"/> to apply to a <see cref="Tooltip"/> by default
/// </summary>
public Padding TooltipChildPadding = new Vector2(2);
/// <summary>
/// The texture that the <see cref="ProgressBar"/> element uses for its background /// The texture that the <see cref="ProgressBar"/> element uses for its background
/// </summary> /// </summary>
public NinePatch ProgressBarTexture; public NinePatch ProgressBarTexture;
/// <summary> /// <summary>
/// The color that the <see cref="ProgressBar"/> element renders with /// The color that the <see cref="ProgressBar"/> element renders with
/// </summary> /// </summary>
public Color ProgressBarColor; public Color ProgressBarColor = Color.White;
/// <summary> /// <summary>
/// The padding that the <see cref="ProgressBar"/> uses for its progress texture (<see cref="ProgressBarProgressTexture"/>) /// The padding that the <see cref="ProgressBar"/> uses for its progress texture (<see cref="ProgressBarProgressTexture"/>)
/// </summary> /// </summary>
public Vector2 ProgressBarProgressPadding; public Vector2 ProgressBarProgressPadding = new Vector2(1);
/// <summary> /// <summary>
/// The texture that the <see cref="ProgressBar"/> uses for displaying its progress /// The texture that the <see cref="ProgressBar"/> uses for displaying its progress
/// </summary> /// </summary>
@ -131,7 +171,7 @@ namespace MLEM.Ui.Style {
/// <summary> /// <summary>
/// The color that the <see cref="ProgressBar"/> renders its progress texture with /// The color that the <see cref="ProgressBar"/> renders its progress texture with
/// </summary> /// </summary>
public Color ProgressBarProgressColor; public Color ProgressBarProgressColor = Color.Red;
/// <summary> /// <summary>
/// The font that <see cref="Paragraph"/> and other elements should use for rendering. /// The font that <see cref="Paragraph"/> and other elements should use for rendering.
/// Note that, to specify a bold and italic font for <see cref="TextFormatter"/>, you should use <see cref="GenericFont.Bold"/> and <see cref="GenericFont.Italic"/>. /// Note that, to specify a bold and italic font for <see cref="TextFormatter"/>, you should use <see cref="GenericFont.Bold"/> and <see cref="GenericFont.Italic"/>.

View file

@ -16,25 +16,16 @@ namespace MLEM.Ui.Style {
public UntexturedStyle(SpriteBatch batch) { public UntexturedStyle(SpriteBatch batch) {
this.SelectionIndicator = batch.GenerateTexture(Color.Transparent, Color.Red); this.SelectionIndicator = batch.GenerateTexture(Color.Transparent, Color.Red);
this.ButtonTexture = batch.GenerateTexture(Color.CadetBlue); this.ButtonTexture = batch.GenerateTexture(Color.CadetBlue);
this.ButtonHoveredColor = Color.LightGray;
this.ButtonDisabledColor = Color.Gray;
this.PanelTexture = batch.GenerateTexture(Color.Gray); this.PanelTexture = batch.GenerateTexture(Color.Gray);
this.TextFieldTexture = batch.GenerateTexture(Color.MediumBlue); this.TextFieldTexture = batch.GenerateTexture(Color.MediumBlue);
this.TextFieldHoveredColor = Color.LightGray;
this.ScrollBarBackground = batch.GenerateTexture(Color.LightBlue); this.ScrollBarBackground = batch.GenerateTexture(Color.LightBlue);
this.ScrollBarScrollerTexture = batch.GenerateTexture(Color.Blue); this.ScrollBarScrollerTexture = batch.GenerateTexture(Color.Blue);
this.CheckboxTexture = batch.GenerateTexture(Color.LightBlue); this.CheckboxTexture = batch.GenerateTexture(Color.LightBlue);
this.CheckboxHoveredColor = Color.LightGray;
this.CheckboxCheckmark = batch.GenerateTexture(Color.Blue).Region; this.CheckboxCheckmark = batch.GenerateTexture(Color.Blue).Region;
this.RadioTexture = batch.GenerateTexture(Color.AliceBlue); this.RadioTexture = batch.GenerateTexture(Color.AliceBlue);
this.RadioHoveredColor = Color.LightGray;
this.RadioCheckmark = batch.GenerateTexture(Color.CornflowerBlue).Region; this.RadioCheckmark = batch.GenerateTexture(Color.CornflowerBlue).Region;
this.TooltipBackground = batch.GenerateTexture(Color.Black * 0.65F, Color.Black * 0.65F); this.TooltipBackground = batch.GenerateTexture(Color.Black * 0.65F, Color.Black * 0.65F);
this.TooltipOffset = new Vector2(8, 16);
this.ProgressBarTexture = batch.GenerateTexture(Color.RoyalBlue); this.ProgressBarTexture = batch.GenerateTexture(Color.RoyalBlue);
this.ProgressBarColor = Color.White;
this.ProgressBarProgressPadding = new Vector2(1);
this.ProgressBarProgressColor = Color.Red;
} }
} }

View file

@ -217,7 +217,7 @@ namespace Sandbox {
this.UiSystem.Add("Invalid", invalidPanel);*/ this.UiSystem.Add("Invalid", invalidPanel);*/
var loadGroup = new Group(Anchor.TopLeft, Vector2.One, false); var loadGroup = new Group(Anchor.TopLeft, Vector2.One, false);
var loadPanel = loadGroup.AddChild(new Panel(Anchor.Center, new Vector2(150, 150), Vector2.Zero, false, true, new Point(5, 10), false) { var loadPanel = loadGroup.AddChild(new Panel(Anchor.Center, new Vector2(150, 150), Vector2.Zero, false, true, false) {
ChildPadding = new Padding(5, 10, 5, 5) ChildPadding = new Padding(5, 10, 5, 5)
}); });
for (var i = 0; i < 1; i++) { for (var i = 0; i < 1; i++) {

View file

@ -42,7 +42,7 @@ namespace Tests {
[Test] [Test]
public void TestComplexPanel() { public void TestComplexPanel() {
var group = new Group(Anchor.TopLeft, Vector2.One, false); var group = new Group(Anchor.TopLeft, Vector2.One, false);
var panel = group.AddChild(new Panel(Anchor.Center, new Vector2(150, 150), Vector2.Zero, false, true, new Point(5, 10), false) { var panel = group.AddChild(new Panel(Anchor.Center, new Vector2(150, 150), Vector2.Zero, false, true, false) {
ChildPadding = new Padding(5, 10, 5, 5) ChildPadding = new Padding(5, 10, 5, 5)
}); });
for (var i = 0; i < 5; i++) { for (var i = 0; i < 5; i++) {