mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-25 05:58:35 +01:00
Compare commits
No commits in common. "cd48ad6e2ac01a95ce183ea9cc5c95c9e9f946c5" and "6702efd7faff85d7789c4ded977c87d8699e247c" have entirely different histories.
cd48ad6e2a
...
6702efd7fa
3 changed files with 10 additions and 15 deletions
|
@ -35,7 +35,6 @@ Improvements
|
|||
Fixes
|
||||
- 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 panels that don't auto-hide their scroll bars ignoring their width for child padding
|
||||
|
||||
### MLEM.Data
|
||||
Additions
|
||||
|
|
|
@ -53,7 +53,6 @@ namespace MLEM.Ui.Elements {
|
|||
|
||||
private RenderTarget2D renderTarget;
|
||||
private bool relevantChildrenDirty;
|
||||
private float scrollBarChildOffset;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new panel with the given settings.
|
||||
|
@ -77,6 +76,12 @@ namespace MLEM.Ui.Elements {
|
|||
AutoHideWhenEmpty = 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
|
||||
this.OnSelectedElementChanged += (element, otherElement) => {
|
||||
|
@ -232,14 +237,6 @@ namespace MLEM.Ui.Elements {
|
|||
if (!this.ScrollBar.MaxValue.Equals(scrollBarMax, Epsilon)) {
|
||||
this.ScrollBar.MaxValue = scrollBarMax;
|
||||
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
|
||||
|
|
|
@ -43,7 +43,7 @@ namespace Tests {
|
|||
public void TestComplexPanel() {
|
||||
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) {
|
||||
ChildPadding = new Padding(5, 5, 5, 5)
|
||||
ChildPadding = new Padding(5, 10, 5, 5)
|
||||
});
|
||||
for (var i = 0; i < 5; i++) {
|
||||
var button = panel.AddChild(new Button(Anchor.AutoLeft, new Vector2(1)) {
|
||||
|
@ -66,11 +66,10 @@ namespace Tests {
|
|||
Assert.AreEqual(11, panel.GetChildren(regardGrandchildren: true).Count());
|
||||
|
||||
var testBtn = panel.GetChildren<Button>().First();
|
||||
// panel's width is 150, minus child padding of 5 on each side, and scroll bar's width of 5 and gap of 1
|
||||
const int panelContentWidth = 150 - 5 - 5 - 5 - 1;
|
||||
Assert.AreEqual(testBtn.DisplayArea.Width, panelContentWidth);
|
||||
// panel's width is 150, minus child padding of 5 left and 10 right
|
||||
Assert.AreEqual(testBtn.DisplayArea.Width, 150 - 5 - 10);
|
||||
// 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, (panelContentWidth - 3 - 3) * 0.5F);
|
||||
Assert.AreEqual(testBtn.GetChildren<Group>().Single().DisplayArea.Width, (150 - 5 - 10 - 3 - 3) * 0.5F);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
|
Loading…
Reference in a new issue