Implement bottom Padding for Dialog buttons - WIP

- Modified Dialog.AddButton() to add buttons to Padding when available
- Added EndInit() override to move buttons from Dialog to Padding
- Added UpdatePaddingBottom() to set Padding thickness based on button height
- Added FrameChanged event handler for dynamic padding updates
- Updated MessageBox tests to reflect new layout (buttons in separate Padding area)
- Dialog tests still passing

Co-authored-by: tig <585482+tig@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-12-22 03:54:01 +00:00
parent e69a82aea4
commit 804d874ba0
2 changed files with 71 additions and 3 deletions

View File

@@ -49,6 +49,7 @@ public class Dialog : Window
}
private readonly List<Button> _buttons = [];
private bool _endInitCalled;
private bool _canceled;
@@ -63,8 +64,26 @@ public class Dialog : Window
button.X = Pos.Align (ButtonAlignment, ButtonAlignmentModes, GetHashCode ());
button.Y = Pos.AnchorEnd ();
// Subscribe to FrameChanged to update padding dynamically
button.FrameChanged += Button_FrameChanged;
_buttons.Add (button);
Add (button);
// Add to Padding if it exists and EndInit has been called, otherwise add to the Dialog
if (Padding is { } && _endInitCalled)
{
Padding.Add (button);
UpdatePaddingBottom ();
}
else
{
Add (button);
}
}
private void Button_FrameChanged (object? sender, EventArgs e)
{
UpdatePaddingBottom ();
}
// TODO: Update button.X = Pos.Justify when alignment changes
@@ -197,4 +216,52 @@ public class Dialog : Window
return false;
}
/// <inheritdoc/>
public override void EndInit ()
{
// Move buttons from the Dialog to the Padding
if (Padding is { })
{
foreach (Button button in _buttons)
{
// Remove from Dialog if it was added there
Remove (button);
// Add to Padding
Padding.Add (button);
}
UpdatePaddingBottom ();
}
_endInitCalled = true;
base.EndInit ();
}
private void UpdatePaddingBottom ()
{
if (Padding is null || _buttons.Count == 0)
{
return;
}
// Find the maximum button height
var maxHeight = 0;
foreach (Button button in _buttons)
{
if (button.Frame.Height > maxHeight)
{
maxHeight = button.Frame.Height;
}
}
// Set the bottom padding to match button height
// Use at least 1 as a minimum if buttons haven't been laid out yet
if (maxHeight > 0 || Padding.Thickness.Bottom == 0)
{
Padding.Thickness = Padding.Thickness with { Bottom = Math.Max (1, maxHeight) };
}
}
}

View File

@@ -361,7 +361,7 @@ public class MessageBoxTests (ITestOutputHelper output)
║ff ff ff ff ff║
║ff ff ff ff ff║
║ff ff ff ff ff║
ff ff
║ ⟦► btn ◄⟧║
╚══════════════╝",
output,
@@ -382,7 +382,8 @@ public class MessageBoxTests (ITestOutputHelper output)
║ffffffffffffffff║
║ffffffffffffffff║
║ffffffffffffffff║
fffffff⟦► btn ◄⟧
║ ⟦► btn ◄⟧║
╚════════════════╝",
output,
app.Driver);