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

added a style property for a panel's scroll bar offset

This commit is contained in:
Ell 2021-11-11 16:43:27 +01:00
parent 4e3d5705a4
commit 1fa9204680
2 changed files with 12 additions and 3 deletions

View file

@ -43,6 +43,10 @@ namespace MLEM.Ui.Elements {
/// The scroller size's height specified here is the minimum height, otherwise, it is automatically calculated based on panel content. /// The scroller size's height specified here is the minimum height, otherwise, it is automatically calculated based on panel content.
/// </summary> /// </summary>
public StyleProp<Vector2> ScrollerSize; public StyleProp<Vector2> ScrollerSize;
/// <summary>
/// The amount of pixels of room there should be between the <see cref="ScrollBar"/> and the rest of the content
/// </summary>
public StyleProp<float> ScrollBarOffset;
private readonly List<Element> relevantChildren = new List<Element>(); private readonly List<Element> relevantChildren = new List<Element>();
private readonly bool scrollOverflow; private readonly bool scrollOverflow;
@ -74,7 +78,7 @@ namespace MLEM.Ui.Elements {
}; };
if (autoHideScrollbar) { if (autoHideScrollbar) {
this.ScrollBar.OnAutoHide += e => { this.ScrollBar.OnAutoHide += e => {
this.ChildPadding += new Padding(0, this.ScrollerSize.Value.X, 0, 0) * (e.IsHidden ? -1 : 1); this.ChildPadding += new Padding(0, this.ScrollerSize.Value.X + this.ScrollBarOffset, 0, 0) * (e.IsHidden ? -1 : 1);
this.SetAreaDirty(); this.SetAreaDirty();
}; };
} }
@ -209,6 +213,7 @@ namespace MLEM.Ui.Elements {
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.ChildPadding.SetFromStyle(style.PanelChildPadding);
this.ScrollBarOffset.SetFromStyle(style.PanelScrollBarOffset);
this.SetScrollBarStyle(); this.SetScrollBarStyle();
} }
@ -264,7 +269,7 @@ namespace MLEM.Ui.Elements {
return; return;
this.ScrollBar.StepPerScroll = this.StepPerScroll; this.ScrollBar.StepPerScroll = this.StepPerScroll;
this.ScrollBar.Size = new Vector2(this.ScrollerSize.Value.X, 1); this.ScrollBar.Size = new Vector2(this.ScrollerSize.Value.X, 1);
this.ScrollBar.PositionOffset = new Vector2(-this.ScrollerSize.Value.X - 1, 0); this.ScrollBar.PositionOffset = new Vector2(-this.ScrollerSize.Value.X - this.ScrollBarOffset, 0);
} }
private void ForceUpdateRelevantChildren() { private void ForceUpdateRelevantChildren() {

View file

@ -11,7 +11,7 @@ namespace MLEM.Ui.Style {
/// <summary> /// <summary>
/// The style settings for a <see cref="UiSystem"/>. /// The style settings for a <see cref="UiSystem"/>.
/// Each <see cref="Element"/> uses these style settings by default, however you can also change these settings per element using the elements' individual style settings. /// Each <see cref="Element"/> uses these style settings by default, however you can also change these settings per element using the elements' individual style settings.
/// Note that this class is a <see cref="GenericDataHolder"/>, meaning additional styles for custom components can easily be added using <see cref="GenericDataHolder.SetData{T}"/> /// Note that this class is a <see cref="GenericDataHolder"/>, meaning additional styles for custom components can easily be added using <see cref="GenericDataHolder.SetData"/>
/// </summary> /// </summary>
public class UiStyle : GenericDataHolder { public class UiStyle : GenericDataHolder {
@ -57,6 +57,10 @@ namespace MLEM.Ui.Style {
/// </summary> /// </summary>
public Vector2 PanelScrollerSize = new Vector2(5, 10); public Vector2 PanelScrollerSize = new Vector2(5, 10);
/// <summary> /// <summary>
/// The amount of pixels of room there should be between a <see cref="Panel"/>'s scroll bar and the rest of its content
/// </summary>
public float PanelScrollBarOffset = 1;
/// <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;