1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-24 21:48:35 +01:00

Compare commits

..

3 commits

3 changed files with 15 additions and 10 deletions

View file

@ -35,6 +35,7 @@ Improvements
Fixes Fixes
- Fixed VerticalSpace height parameter being an integer - Fixed VerticalSpace height parameter being an integer
- Fixed text not being pasted into a text field at all if it contains characters that don't match the input rule - Fixed text not being pasted into a text field at all if it contains characters that don't match the input rule
- Fixed panels that don't auto-hide their scroll bars ignoring their width for child padding
### MLEM.Data ### MLEM.Data
Additions Additions

View file

@ -53,6 +53,7 @@ namespace MLEM.Ui.Elements {
private RenderTarget2D renderTarget; private RenderTarget2D renderTarget;
private bool relevantChildrenDirty; private bool relevantChildrenDirty;
private float scrollBarChildOffset;
/// <summary> /// <summary>
/// Creates a new panel with the given settings. /// Creates a new panel with the given settings.
@ -76,12 +77,6 @@ namespace MLEM.Ui.Elements {
AutoHideWhenEmpty = autoHideScrollbar, AutoHideWhenEmpty = autoHideScrollbar,
IsHidden = autoHideScrollbar IsHidden = autoHideScrollbar
}; };
if (autoHideScrollbar) {
this.ScrollBar.OnAutoHide += e => {
this.ChildPadding += new Padding(0, this.ScrollerSize.Value.X + this.ScrollBarOffset, 0, 0) * (e.IsHidden ? -1 : 1);
this.SetAreaDirty();
};
}
// 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) => {
@ -237,6 +232,14 @@ namespace MLEM.Ui.Elements {
if (!this.ScrollBar.MaxValue.Equals(scrollBarMax, Epsilon)) { if (!this.ScrollBar.MaxValue.Equals(scrollBarMax, Epsilon)) {
this.ScrollBar.MaxValue = scrollBarMax; this.ScrollBar.MaxValue = scrollBarMax;
this.relevantChildrenDirty = true; this.relevantChildrenDirty = true;
// update child padding based on whether the scroll bar is visible
var childOffset = this.ScrollBar.IsHidden ? 0 : this.ScrollerSize.Value.X + this.ScrollBarOffset;
if (!this.scrollBarChildOffset.Equals(childOffset, Epsilon)) {
this.ChildPadding += new Padding(0, -this.scrollBarChildOffset + childOffset, 0, 0);
this.scrollBarChildOffset = childOffset;
this.SetAreaDirty();
}
} }
// the scroller height has the same relation to the scroll bar height as the visible area has to the total height of the panel's content // the scroller height has the same relation to the scroll bar height as the visible area has to the total height of the panel's content

View file

@ -43,7 +43,7 @@ namespace Tests {
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, 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, 5, 5, 5)
}); });
for (var i = 0; i < 5; i++) { for (var i = 0; i < 5; i++) {
var button = panel.AddChild(new Button(Anchor.AutoLeft, new Vector2(1)) { var button = panel.AddChild(new Button(Anchor.AutoLeft, new Vector2(1)) {
@ -66,10 +66,11 @@ namespace Tests {
Assert.AreEqual(11, panel.GetChildren(regardGrandchildren: true).Count()); Assert.AreEqual(11, panel.GetChildren(regardGrandchildren: true).Count());
var testBtn = panel.GetChildren<Button>().First(); var testBtn = panel.GetChildren<Button>().First();
// panel's width is 150, minus child padding of 5 left and 10 right // panel's width is 150, minus child padding of 5 on each side, and scroll bar's width of 5 and gap of 1
Assert.AreEqual(testBtn.DisplayArea.Width, 150 - 5 - 10); const int panelContentWidth = 150 - 5 - 5 - 5 - 1;
Assert.AreEqual(testBtn.DisplayArea.Width, panelContentWidth);
// button's width, minus child padding of 3 left and 3 right, divided by 2 because of group's width // button's width, minus child padding of 3 left and 3 right, divided by 2 because of group's width
Assert.AreEqual(testBtn.GetChildren<Group>().Single().DisplayArea.Width, (150 - 5 - 10 - 3 - 3) * 0.5F); Assert.AreEqual(testBtn.GetChildren<Group>().Single().DisplayArea.Width, (panelContentWidth - 3 - 3) * 0.5F);
} }
[Test] [Test]