mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
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:
@@ -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) };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user