Skip to content

Commit

Permalink
Center the vertical alignment of lobby options if less than the panel…
Browse files Browse the repository at this point in the history
… height.

This also enables an extra row to be shown before triggering the scroll bar.
  • Loading branch information
pchote committed Dec 12, 2017
1 parent c9c5517 commit 5086756
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
9 changes: 8 additions & 1 deletion OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyOptionsLogic.cs
Expand Up @@ -24,6 +24,7 @@ public class LobbyOptionsLogic : ChromeLogic
readonly Widget optionsContainer;
readonly Widget checkboxRowTemplate;
readonly Widget dropdownRowTemplate;
readonly int yMargin;

readonly Func<MapPreview> getMap;
readonly OrderManager orderManager;
Expand All @@ -40,6 +41,7 @@ internal LobbyOptionsLogic(Widget widget, OrderManager orderManager, Func<MapPre

panel = (ScrollPanelWidget)widget;
optionsContainer = widget.Get("LOBBY_OPTIONS");
yMargin = optionsContainer.Bounds.Y;
optionsContainer.IsVisible = () => validOptions;
checkboxRowTemplate = optionsContainer.Get("CHECKBOX_ROW_TEMPLATE");
dropdownRowTemplate = optionsContainer.Get("DROPDOWN_ROW_TEMPLATE");
Expand Down Expand Up @@ -173,7 +175,12 @@ void RebuildOptions()
}
}

panel.ContentHeight = optionsContainer.Bounds.Y + optionsContainer.Bounds.Height;
panel.ContentHeight = yMargin + optionsContainer.Bounds.Height;
optionsContainer.Bounds.Y = yMargin;
if (panel.ContentHeight < panel.Bounds.Height)
optionsContainer.Bounds.Y += (panel.Bounds.Height - panel.ContentHeight) / 2;

panel.ScrollToTop();
}
}
}
7 changes: 3 additions & 4 deletions mods/cnc/chrome/lobby-options.yaml
Expand Up @@ -16,12 +16,11 @@ Container@LOBBY_OPTIONS_BIN:
Children:
Container@LOBBY_OPTIONS:
X: 18
Y: 30
Y: 9
Width: PARENT_RIGHT - 24 - 18
Height: PARENT_BOTTOM - 75
Children:
Container@CHECKBOX_ROW_TEMPLATE:
Height: 35
Height: 34
Children:
Checkbox@A:
Width: 175
Expand All @@ -44,7 +43,7 @@ Container@LOBBY_OPTIONS_BIN:
Visible: False
TooltipContainer: TOOLTIP_CONTAINER
Container@DROPDOWN_ROW_TEMPLATE:
Height: 35
Height: 34
Width: PARENT_RIGHT
Children:
Label@A_DESC:
Expand Down
7 changes: 3 additions & 4 deletions mods/common/chrome/lobby-options.yaml
Expand Up @@ -16,12 +16,11 @@ Container@LOBBY_OPTIONS_BIN:
Children:
Container@LOBBY_OPTIONS:
X: 18
Y: 30
Y: 9
Width: PARENT_RIGHT - 18 - 24
Height: PARENT_BOTTOM - 75
Children:
Container@CHECKBOX_ROW_TEMPLATE:
Height: 35
Height: 34
Children:
Checkbox@A:
Width: 175
Expand All @@ -41,7 +40,7 @@ Container@LOBBY_OPTIONS_BIN:
Visible: False
TooltipContainer: TOOLTIP_CONTAINER
Container@DROPDOWN_ROW_TEMPLATE:
Height: 35
Height: 34
Width: PARENT_RIGHT
Children:
Label@A_DESC:
Expand Down

0 comments on commit 5086756

Please sign in to comment.