Don't update MarginContainer if it already matches its parent size, update TestGame.

This commit is contained in:
2025-06-29 17:39:52 +02:00
parent 87e0a69dcf
commit 09c24e7123
2 changed files with 31 additions and 18 deletions

View File

@@ -20,7 +20,7 @@ public class TestGame : Game
InitializeSystemsDefault();
_uiSystem = new UISystem(Input, ResourceRef<Style>.Empty());
_uiSystem.RenderDebugRects = true;
// _uiSystem.RenderDebugRects = true;
_particleSystem = new ParticleSystem();
@@ -63,19 +63,32 @@ public class TestGame : Game
Input.AddInputMapping("reload", new IInputAction[] { new KeyInputAction(KeyboardKey.R) });
_emitterId = _particleSystem.CreateEmitter(Renderer.WindowSize / 2, _fireEffect);
var button = new Button("Add element", _defaultFontSet, () => { _container.AddChild(new Label("Hello, World!", _defaultFontSet)); });
button.Padding = new Margin(8.0f);
var addButton = new Button("Add element", _defaultFontSet, () => { _container.AddChild(new Label("Hello, World!", _defaultFontSet)); });
addButton.Padding = new Margin(8.0f);
_buttonContainer.AddChild(button);
var removeButton = new Button("Remove element", _defaultFontSet, () =>
{
if (_container.Children.Count == 0) return;
var lastChild = _container.Children.Last();
_container.RemoveChild(lastChild);
});
var c = new MarginContainer();
c.AddChild(_container);
removeButton.Padding = new Margin(8.0f);
_buttonContainer.AddChild(c);
_buttonContainer.AddChild(addButton);
_buttonContainer.AddChild(removeButton);
_root.AddChild(_buttonContainer);
var c = new VerticalContainer();
_uiSystem.AddElement(_root);
var m = new MarginContainer();
m.AddChild(_container);
c.AddChild(_buttonContainer);
c.AddChild(m);
_rootFill.AddChild(c);
_uiSystem.AddElement(_rootFill);
}
@@ -86,12 +99,6 @@ public class TestGame : Game
ResourceManager.Reload();
_particleSystem!.RestartEmitter(_emitterId);
}
if (Input.IsActionPressed("cancel") && _container.Children.Count != 0)
{
var lastChild = _container.Children.Last();
_container.RemoveChild(lastChild);
}
}
protected override void Render(double deltaTime)
@@ -150,6 +157,9 @@ public class TestGame : Game
[NotNull] private Label _label;
private FillContainer _root = new();
private VerticalContainer _buttonContainer = new(16);
private FillContainer _rootFill = new();
private HorizontalContainer _buttonContainer = new(16)
{
ConfineToContents = true,
};
}

View File

@@ -65,7 +65,10 @@ public class MarginContainer : Container
base.OnUpdate();
if (Parent == null) return;
Size = Parent.Size;
if (Size != Parent.Size)
{
Size = Parent.Size;
}
}
public override void Arrange()