Skip to content

Commit

Permalink
fix(Studio): Game info panel not resizing correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
psyGamer committed Sep 29, 2024
1 parent b20ac35 commit 722ee87
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions Studio/CelesteStudio/Editing/GameInfoPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,20 @@ protected override void OnPaint(PaintEventArgs e) {

public bool EditingTemplate => Content == editPanel;

// The StackLayouts don't fit the exact content size on their own..
public int ActualWidth => EditingTemplate
? Math.Max(infoTemplateArea.Width, buttonsPanel.Width)
: Math.Max(Math.Max(frameInfo.Width, gameStatus.Width), subpixelIndicator.Visible ? subpixelIndicator.Width : 0);
public int ActualHeight => EditingTemplate
? infoTemplateArea.Height + buttonsPanel.Height
: frameInfo.Height + gameStatus.Height + (subpixelIndicator.Visible ? subpixelIndicator.Height : 0);

private readonly Label frameInfo;
private readonly Label gameStatus;
private readonly SubpixelIndicator subpixelIndicator;

private readonly TextArea infoTemplateArea;
private readonly Panel buttonsPanel;

private readonly Panel showPanel;
private readonly Panel editPanel;
Expand Down Expand Up @@ -104,9 +113,10 @@ public GameInfo() {
Font = FontManager.StatusFont,
Wrap = false,
};

var doneButton = new Button { Text = "Done" };
var cancelButton = new Button { Text = "Cancel" };
var buttonsPanel = new StackLayout {
buttonsPanel = new StackLayout {
Padding = 5,
Spacing = 5,
Orientation = Orientation.Horizontal,
Expand Down Expand Up @@ -154,6 +164,14 @@ public GameInfo() {
subpixelIndicator.Invalidate();
};

// Manually forward size changes, since the StackLayouts won't do it..
frameInfo.SizeChanged += (_, _) => OnSizeChanged(EventArgs.Empty);
gameStatus.SizeChanged += (_, _) => OnSizeChanged(EventArgs.Empty);
subpixelIndicator.SizeChanged += (_, _) => OnSizeChanged(EventArgs.Empty);

infoTemplateArea.SizeChanged += (_, _) => OnSizeChanged(EventArgs.Empty);
buttonsPanel.SizeChanged += (_, _) => OnSizeChanged(EventArgs.Empty);

// React to settings changes
Settings.ThemeChanged += () => {
frameInfo.TextColor = Settings.Instance.Theme.StatusFg;
Expand Down Expand Up @@ -358,10 +376,11 @@ public GameInfoPanel() {
return;

void LimitSize() {
// Limit height to half the window
// Limit height to certain percentage of entire the window
scrollable.Size = new Size(
ClientSize.Width - Padding.Left - Padding.Right,
Math.Min(gameInfo.Height + Padding.Top + Padding.Bottom, (int)(Studio.Instance.Height * Settings.Instance.MaxGameInfoHeight)) - Padding.Top - Padding.Bottom);
Math.Min(gameInfo.ActualHeight + Padding.Top + Padding.Bottom, (int)(Studio.Instance.Height * Settings.Instance.MaxGameInfoHeight)) - Padding.Top - Padding.Bottom);
scrollable.ScrollSize = new Size(gameInfo.ActualWidth, gameInfo.ActualHeight);

// Account for scroll bar
bool scrollBarVisible = gameInfo.Height > scrollable.Height;
Expand Down Expand Up @@ -395,9 +414,6 @@ public GameInfoPopout() {
if (gameInfo.EditingTemplate) {
gameInfo.Width = ClientSize.Width - Padding.Left - Padding.Right;
}
scrollable.Size = new Size(
ClientSize.Width - Padding.Left - Padding.Right,
ClientSize.Height - Padding.Top - Padding.Bottom);
};

Load += (_, _) => Studio.Instance.WindowCreationCallback(this);
Expand Down

0 comments on commit 722ee87

Please sign in to comment.