Skip to content

Commit

Permalink
Fix child element resizing for panes (#1721)
Browse files Browse the repository at this point in the history
Co-authored-by: amylizzle <amylizzle@users.noreply.github.com>
  • Loading branch information
amylizzle and amylizzle authored Mar 22, 2024
1 parent ca5e207 commit 24ea5f2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion OpenDreamClient/Interface/Controls/ControlChild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private void UpdateGrid() {
_grid.SplitFraction = ChildDescriptor.Splitter / 100f;
}

public override bool TryGetProperty(string property, out string value) {
public override bool TryGetProperty(string property, out string value) {
switch (property) {
case "splitter":
value = $"{_grid.SplitFraction * 100}";
Expand Down
35 changes: 21 additions & 14 deletions OpenDreamClient/Interface/Controls/ControlWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,35 +92,42 @@ public void RegisterOnClydeWindow(IClydeWindow window) {
}

public void UpdateAnchors() {
var windowSize = Size.GetValueOrDefault();
var windowSize = Size;
if (windowSize.X == 0)
windowSize.X = 640;
windowSize.X = _canvas.PixelWidth;
if (windowSize.Y == 0)
windowSize.Y = 440;
windowSize.Y = _canvas.PixelHeight;

ChildControls.Sort((a, b) => { //need a resort if size and pos have changed
if(a.Pos.X <= b.Pos.X || a.Pos.Y <= b.Pos.Y)
return 1;
else
return -1;
});

for (int i = 0; i < ChildControls.Count; i++) {
InterfaceControl control = ChildControls[i];
var element = control.UIElement;
var elementPos = control.Pos.GetValueOrDefault();
var elementSize = control.Size.GetValueOrDefault();
var elementPos = control.Pos;
var elementSize = control.Size;

if (control.Size?.Y == 0) {
if (control.Size.Y == 0) {
elementSize.Y = (windowSize.Y - elementPos.Y);
if (ChildControls.Count - 1 > i) {
if (ChildControls[i + 1].Pos != null && ChildControls[i + 1].UIElement.Visible) {
var nextElementPos = ChildControls[i + 1].Pos.GetValueOrDefault();
if (ChildControls[i + 1].UIElement.Visible) {
var nextElementPos = ChildControls[i + 1].Pos;
elementSize.Y = nextElementPos.Y - elementPos.Y;
}
}

element.SetHeight = ((float)elementSize.Y / windowSize.Y) * _canvas.Height;
}

if (control.Size?.X == 0) {
if (control.Size.X == 0) {
elementSize.X = (windowSize.X - elementPos.X);
if (ChildControls.Count - 1 > i) {
if (ChildControls[i + 1].Pos != null && ChildControls[i + 1].UIElement.Visible) {
var nextElementPos = ChildControls[i + 1].Pos.GetValueOrDefault();
if (ChildControls[i + 1].UIElement.Visible) {
var nextElementPos = ChildControls[i + 1].Pos;
if (nextElementPos.X < (elementSize.X + elementPos.X) &&
nextElementPos.Y < (elementSize.Y + elementPos.Y))
elementSize.X = nextElementPos.X - elementPos.X;
Expand Down Expand Up @@ -225,8 +232,8 @@ public override void AddChild(ElementDescriptor descriptor) {

// Can't have out-of-order components, so make sure they're ordered properly
if (ChildControls.Count > 0) {
var prevPos = ChildControls[^1].Pos.GetValueOrDefault();
var curPos = control.Pos.GetValueOrDefault();
var prevPos = ChildControls[^1].Pos;
var curPos = control.Pos;
if (prevPos.X <= curPos.X && prevPos.Y <= curPos.Y)
ChildControls.Add(control);
else {
Expand All @@ -235,7 +242,7 @@ public override void AddChild(ElementDescriptor descriptor) {

int i = 0;
while (i < ChildControls.Count) {
prevPos = ChildControls[i].Pos.GetValueOrDefault();
prevPos = ChildControls[i].Pos;
if (prevPos.X <= curPos.X && prevPos.Y <= curPos.Y)
i++;
else
Expand Down
4 changes: 2 additions & 2 deletions OpenDreamClient/Interface/Controls/InterfaceControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace OpenDreamClient.Interface.Controls;
public abstract class InterfaceControl : InterfaceElement {
public readonly Control UIElement;
public bool IsDefault => ControlDescriptor.IsDefault;
public Vector2i? Size => ControlDescriptor.Size;
public Vector2i? Pos => ControlDescriptor.Pos;
public Vector2i Size => ControlDescriptor.Size.GetValueOrDefault();
public Vector2i Pos => ControlDescriptor.Pos.GetValueOrDefault();
public Vector2i? Anchor1 => ControlDescriptor.Anchor1;
public Vector2i? Anchor2 => ControlDescriptor.Anchor2;

Expand Down

0 comments on commit 24ea5f2

Please sign in to comment.