1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 20:58:34 +01:00

organize ui stuff a bit better

This commit is contained in:
Ellpeck 2020-02-06 01:59:33 +01:00
parent b3331834e1
commit 31e2b72197
2 changed files with 76 additions and 65 deletions

View file

@ -23,11 +23,24 @@ namespace MLEM.Ui.Elements {
return this.sortedChildren; return this.sortedChildren;
} }
} }
private bool sortedChildrenDirty;
private UiSystem system;
public UiSystem System {
get => this.system;
internal set {
this.system = value;
if (this.system != null)
this.InitStyle(this.system.Style);
}
}
protected UiControls Controls => this.System.Controls;
protected InputHandler Input => this.Controls.Input;
public Element Parent { get; private set; }
public RootElement Root { get; internal set; }
public float Scale => this.Root.ActualScale;
private Anchor anchor; private Anchor anchor;
private Vector2 size;
private Vector2 offset;
public Padding Padding;
public Padding ScaledPadding => this.Padding * this.Scale;
public Anchor Anchor { public Anchor Anchor {
get => this.anchor; get => this.anchor;
set { set {
@ -37,6 +50,8 @@ namespace MLEM.Ui.Elements {
this.SetAreaDirty(); this.SetAreaDirty();
} }
} }
private Vector2 size;
public Vector2 Size { public Vector2 Size {
get => this.size; get => this.size;
set { set {
@ -47,6 +62,8 @@ namespace MLEM.Ui.Elements {
} }
} }
public Vector2 ScaledSize => this.size * this.Scale; public Vector2 ScaledSize => this.size * this.Scale;
private Vector2 offset;
public Vector2 PositionOffset { public Vector2 PositionOffset {
get => this.offset; get => this.offset;
set { set {
@ -57,6 +74,10 @@ namespace MLEM.Ui.Elements {
} }
} }
public Vector2 ScaledOffset => this.offset * this.Scale; public Vector2 ScaledOffset => this.offset * this.Scale;
public Padding Padding;
public Padding ScaledPadding => this.Padding * this.Scale;
private Padding childPadding; private Padding childPadding;
public Padding ChildPadding { public Padding ChildPadding {
get => this.childPadding; get => this.childPadding;
@ -67,8 +88,54 @@ namespace MLEM.Ui.Elements {
this.SetAreaDirty(); this.SetAreaDirty();
} }
} }
public RectangleF ChildPaddedArea => this.UnscrolledArea.Shrink(this.ScaledChildPadding);
public Padding ScaledChildPadding => this.childPadding * this.Scale; public Padding ScaledChildPadding => this.childPadding * this.Scale;
public RectangleF ChildPaddedArea => this.UnscrolledArea.Shrink(this.ScaledChildPadding);
private RectangleF area;
public RectangleF UnscrolledArea {
get {
this.UpdateAreaIfDirty();
return this.area;
}
}
private bool areaDirty;
public RectangleF Area => this.UnscrolledArea.OffsetCopy(this.ScaledScrollOffset);
public RectangleF DisplayArea => this.Area.Shrink(this.ScaledPadding);
public Vector2 ScrollOffset;
public Vector2 ScaledScrollOffset => this.ScrollOffset * this.Scale;
private bool isHidden;
public bool IsHidden {
get => this.isHidden;
set {
if (this.isHidden == value)
return;
this.isHidden = value;
this.SetAreaDirty();
}
}
private int priority;
public int Priority {
get => this.priority;
set {
this.priority = value;
if (this.Parent != null)
this.Parent.SetSortedChildrenDirty();
}
}
public bool CanBeSelected = true;
public bool CanBeMoused = true;
public bool CanBePressed = true;
public bool CanAutoAnchorsAttach = true;
public bool SetHeightBasedOnChildren;
public bool SetWidthBasedOnChildren;
public float DrawAlpha = 1;
public bool IsMouseOver { get; private set; }
public bool IsSelected { get; private set; }
public DrawCallback OnDrawn; public DrawCallback OnDrawn;
public TimeCallback OnUpdated; public TimeCallback OnUpdated;
@ -85,62 +152,6 @@ namespace MLEM.Ui.Elements {
public TabNextElementCallback GetTabNextElement; public TabNextElementCallback GetTabNextElement;
public GamepadNextElementCallback GetGamepadNextElement; public GamepadNextElementCallback GetGamepadNextElement;
private UiSystem system;
public UiSystem System {
get => this.system;
internal set {
this.system = value;
if (this.system != null)
this.InitStyle(this.system.Style);
}
}
protected UiControls Controls => this.System.Controls;
protected InputHandler Input => this.Controls.Input;
public RootElement Root { get; internal set; }
public float Scale => this.Root.ActualScale;
public Element Parent { get; private set; }
public bool IsMouseOver { get; private set; }
public bool IsSelected { get; private set; }
private bool isHidden;
public bool IsHidden {
get => this.isHidden;
set {
if (this.isHidden == value)
return;
this.isHidden = value;
this.SetAreaDirty();
}
}
public bool CanBeSelected = true;
public bool CanBeMoused = true;
public bool CanBePressed = true;
public float DrawAlpha = 1;
public bool SetHeightBasedOnChildren;
public bool SetWidthBasedOnChildren;
public bool CanAutoAnchorsAttach = true;
private RectangleF area;
public RectangleF UnscrolledArea {
get {
this.UpdateAreaIfDirty();
return this.area;
}
}
public RectangleF Area => this.UnscrolledArea.OffsetCopy(this.ScaledScrollOffset);
public Vector2 ScrollOffset;
public Vector2 ScaledScrollOffset => this.ScrollOffset * this.Scale;
public RectangleF DisplayArea => this.Area.Shrink(this.ScaledPadding);
private int priority;
public int Priority {
get => this.priority;
set {
this.priority = value;
if (this.Parent != null)
this.Parent.SetSortedChildrenDirty();
}
}
private bool areaDirty;
private bool sortedChildrenDirty;
public StyleProp<NinePatch> SelectionIndicator; public StyleProp<NinePatch> SelectionIndicator;
public StyleProp<SoundEffectInstance> ActionSound; public StyleProp<SoundEffectInstance> ActionSound;
public StyleProp<SoundEffectInstance> SecondActionSound; public StyleProp<SoundEffectInstance> SecondActionSound;
@ -153,8 +164,8 @@ namespace MLEM.Ui.Elements {
this.OnMouseExit += element => this.IsMouseOver = false; this.OnMouseExit += element => this.IsMouseOver = false;
this.OnSelected += element => this.IsSelected = true; this.OnSelected += element => this.IsSelected = true;
this.OnDeselected += element => this.IsSelected = false; this.OnDeselected += element => this.IsSelected = false;
this.GetTabNextElement = (backward, next) => next; this.GetTabNextElement += (backward, next) => next;
this.GetGamepadNextElement = (dir, next) => next; this.GetGamepadNextElement += (dir, next) => next;
this.SetAreaDirty(); this.SetAreaDirty();
} }

View file

@ -17,12 +17,11 @@ namespace MLEM.Ui {
public readonly GraphicsDevice GraphicsDevice; public readonly GraphicsDevice GraphicsDevice;
public readonly GameWindow Window; public readonly GameWindow Window;
public Rectangle Viewport { get; private set; }
private readonly List<RootElement> rootElements = new List<RootElement>(); private readonly List<RootElement> rootElements = new List<RootElement>();
public Rectangle Viewport { get; private set; }
public bool AutoScaleWithScreen; public bool AutoScaleWithScreen;
public Point AutoScaleReferenceSize; public Point AutoScaleReferenceSize;
private float globalScale = 1; private float globalScale = 1;
public float GlobalScale { public float GlobalScale {
get { get {
@ -36,6 +35,7 @@ namespace MLEM.Ui {
root.Element.ForceUpdateArea(); root.Element.ForceUpdateArea();
} }
} }
private UiStyle style; private UiStyle style;
public UiStyle Style { public UiStyle Style {
get => this.style; get => this.style;