Skip to content

Commit

Permalink
ButtonFlag and better formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
Titian3 committed Aug 5, 2024
1 parent 896d12c commit 8da6dac
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Robust.Client/UserInterface/IUserInterfaceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public partial interface IUserInterfaceManager

IDebugMonitors DebugMonitors { get; }

void Popup(string contents, string title = "Alert!", string clipboardButton = "Copy");
void Popup(string contents, string title = "Alert!", bool clipboardButton = true);

Control? MouseGetControl(ScreenCoordinates coordinates);

Expand Down
55 changes: 33 additions & 22 deletions Robust.Client/UserInterface/UserInterfaceManager.Layout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,44 +53,55 @@ private void RunArrange(Control control)
}
}

public void Popup(string contents, string title = "Alert!", string clipboardButton = "Copy")
public void Popup(string contents, string title = "Alert!", bool clipboardButton = true)
{
var popup = new DefaultWindow
{
Title = title,
Title = title
};

var label = new Label { Text = contents };
var copyButton = new Button
{
Text = clipboardButton,
MinSize = new Vector2(100, 30),
};

copyButton.OnPressed += _ =>
// Create a vertical box container to stack the elements vertically
var vBox = new BoxContainer
{
_clipboard.SetText(contents);
Orientation = BoxContainer.LayoutOrientation.Vertical
};

var grid = new GridContainer
vBox.AddChild(label);

if (clipboardButton)
{
Columns = 1,
VSeparationOverride = 10,
};
var copyButton = new Button
{
Text = "Copy",
MinSize = new Vector2(100, 30)
};

copyButton.OnPressed += _ =>
{
_clipboard.SetText(contents);
};

grid.AddChild(label);
// Create a horizontal box container to align the button to the right
var hBox = new BoxContainer
{
Orientation = BoxContainer.LayoutOrientation.Horizontal
};

var buttonContainer = new GridContainer
{
Columns = 2,
HSeparationOverride = 10,
};
var spacer = new Control
{
MinSize = new Vector2(0, 30), // This will grow to take available space
HorizontalExpand = true
};

buttonContainer.AddChild(copyButton);
hBox.AddChild(spacer); // Spacer to push the button to the right
hBox.AddChild(copyButton);

grid.AddChild(buttonContainer);
vBox.AddChild(hBox); // Add the horizontal box to the vertical box
}

popup.Contents.AddChild(grid);
popup.Contents.AddChild(vBox); // Add the vertical box to the popup

popup.OpenCentered();
}
Expand Down

0 comments on commit 8da6dac

Please sign in to comment.