1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-10 09:32:29 +01:00

Move title height helper functions to WindowBase and fix FlexUI plugins

This commit is contained in:
Aaron van Geffen
2025-04-11 23:26:34 +02:00
parent 883845bcf9
commit a8267412c2
14 changed files with 94 additions and 46 deletions

View File

@@ -840,7 +840,7 @@ public:
std::unique_ptr<WindowBase>&& wp, WindowClass cls, ScreenCoordsXY pos, int32_t width, int32_t height,
uint32_t flags) override
{
height += getTitleHeightDiff();
height += wp->getTitleBarDiffTarget();
if (flags & WF_AUTO_POSITION)
{
@@ -854,7 +854,7 @@ public:
}
}
height -= getTitleHeightDiff();
height -= wp->getTitleBarDiffTarget();
// Check if there are any window slots left
// include kWindowLimitReserved for items such as the main viewport and toolbars to not appear to be counted.

View File

@@ -984,8 +984,18 @@ namespace OpenRCT2::Ui::Windows
if (Config::Get().interface.EnlargedUi)
{
w.min_height += getTitleHeightDiff();
w.max_height += getTitleHeightDiff();
// Not sure why plugin windows have to be treated differently,
// but they currently show a deviation if we don't.
if (w.classification == WindowClass::Custom)
{
w.min_height += w.getTitleBarDiffTarget();
w.max_height += w.getTitleBarDiffTarget();
}
else
{
w.min_height += w.getTitleBarDiffNormal();
w.max_height += w.getTitleBarDiffNormal();
}
}
// Clamp width and height to minimum and maximum

View File

@@ -439,6 +439,16 @@ namespace OpenRCT2::Ui::Windows
void OnResize() override
{
if (width < min_width)
{
Invalidate();
width = min_width;
}
if (height < min_height)
{
Invalidate();
height = min_height;
}
UpdateViewport();
}
@@ -747,6 +757,9 @@ namespace OpenRCT2::Ui::Windows
void ChangeTab(size_t tabIndex)
{
if (page == static_cast<int16_t>(tabIndex) && !widgets.empty())
return;
page = static_cast<int16_t>(tabIndex);
frame_no = 0;
RefreshWidgets();

View File

@@ -167,7 +167,8 @@ namespace OpenRCT2::Scripting
auto widget = GetWidget();
if (widget != nullptr)
{
return widget->top - getTitleHeightDiff();
auto w = GetWindow();
return widget->top - w->getTitleBarDiffNormal();
}
return 0;
}
@@ -176,7 +177,8 @@ namespace OpenRCT2::Scripting
auto widget = GetWidget();
if (widget != nullptr)
{
value += getTitleHeightDiff();
auto w = GetWindow();
value += w->getTitleBarDiffNormal();
auto delta = value - widget->top;
Invalidate();

View File

@@ -97,8 +97,14 @@ namespace OpenRCT2::Scripting
auto w = GetWindow();
if (w != nullptr)
{
w->width = value;
WindowSetResize(*w, { w->min_width, w->min_height }, { w->max_width, w->max_height });
if (WindowCanResize(*w))
{
WindowResizeByDelta(*w, value - w->width, 0);
}
else
{
WindowSetResize(*w, { value, w->min_height }, { value, w->max_height });
}
}
}
int32_t height_get() const
@@ -106,7 +112,7 @@ namespace OpenRCT2::Scripting
auto w = GetWindow();
if (w != nullptr)
{
return w->height - getTitleHeightDiff();
return w->height - w->getTitleBarDiffNormal();
}
return 0;
}
@@ -115,8 +121,15 @@ namespace OpenRCT2::Scripting
auto w = GetWindow();
if (w != nullptr)
{
w->height = value + getTitleHeightDiff();
WindowSetResize(*w, { w->min_width, w->min_height }, { w->max_width, w->max_height });
value += w->getTitleBarDiffNormal();
if (WindowCanResize(*w))
{
WindowResizeByDelta(*w, 0, value - w->height);
}
else
{
WindowSetResize(*w, { w->min_width, value }, { w->max_width, value });
}
}
}
int32_t minWidth_get() const
@@ -158,7 +171,7 @@ namespace OpenRCT2::Scripting
auto w = GetWindow();
if (w != nullptr)
{
return w->min_height;
return w->min_height - w->getTitleBarDiffNormal();
}
return 0;
}
@@ -167,6 +180,7 @@ namespace OpenRCT2::Scripting
auto w = GetWindow();
if (w != nullptr)
{
value += w->getTitleBarDiffNormal();
WindowSetResize(*w, { w->min_width, value }, { w->max_width, w->max_height });
}
}
@@ -175,7 +189,7 @@ namespace OpenRCT2::Scripting
auto w = GetWindow();
if (w != nullptr)
{
return w->max_height;
return w->max_height - w->getTitleBarDiffNormal();
}
return 0;
}
@@ -184,6 +198,7 @@ namespace OpenRCT2::Scripting
auto w = GetWindow();
if (w != nullptr)
{
value += w->getTitleBarDiffNormal();
WindowSetResize(*w, { w->min_width, w->min_height }, { w->max_width, value });
}
}

View File

@@ -508,7 +508,7 @@ namespace OpenRCT2::Ui::Windows
// We need to compensate for the enlarged title bar for windows that do not
// constrain the window height between tabs (e.g. chart tabs)
height -= getTitleHeightDiff();
height -= getTitleBarDiffNormal();
WindowSetResize(*this, { WW_OTHER_TABS, kHeightOtherTabs }, kMaxWindowSize);
}

View File

@@ -570,7 +570,7 @@ namespace OpenRCT2::Ui::Windows
auto& config = Config::Get().general;
config.FileBrowserWidth = width;
config.FileBrowserHeight = height - getTitleHeightDiff();
config.FileBrowserHeight = height - getTitleBarDiffNormal();
}
void OnUpdate() override

View File

@@ -1197,7 +1197,7 @@ namespace OpenRCT2::Ui::Windows
{
// We need to compensate for the enlarged title bar for windows that do not
// constrain the window height between tabs (e.g. chart tabs)
height -= getTitleHeightDiff();
height -= getTitleBarDiffNormal();
}
OnResize();

View File

@@ -71,8 +71,7 @@ namespace OpenRCT2::Ui::Windows
constexpr int32_t WINDOW_SCENERY_MIN_HEIGHT = 195 - kTitleHeightNormal;
constexpr int32_t SCENERY_BUTTON_WIDTH = 66;
constexpr int32_t SCENERY_BUTTON_HEIGHT = 80;
constexpr int32_t InitTabPosX = 3;
constexpr int32_t InitTabPosY = 17;
constexpr int32_t kTabMargin = 3;
constexpr int32_t TabWidth = 31;
constexpr int32_t TabHeight = 28;
constexpr int32_t ReservedTabCount = 2;
@@ -637,7 +636,7 @@ namespace OpenRCT2::Ui::Windows
void OnPrepareDraw() override
{
_actualMinHeight = WINDOW_SCENERY_MIN_HEIGHT + getTitleBarHeight();
_actualMinHeight = WINDOW_SCENERY_MIN_HEIGHT + getTitleBarTargetHeight();
// Set the window title
StringId titleStringId = STR_MISCELLANEOUS;
@@ -784,7 +783,7 @@ namespace OpenRCT2::Ui::Windows
const auto lastTabWidget = &widgets[WIDX_SCENERY_TAB_1 + lastTabIndex];
windowWidth = std::max<int32_t>(windowWidth, lastTabWidget->right + 3);
auto tabTop = widgets[WIDX_SCENERY_TITLE].bottom + 3;
auto tabTop = widgets[WIDX_SCENERY_TITLE].bottom + kTabMargin;
if (GetSceneryTabInfoForMisc() != nullptr)
{
auto miscTabWidget = &widgets[WIDX_SCENERY_TAB_1 + _tabEntries.size() - 2];
@@ -1376,7 +1375,7 @@ namespace OpenRCT2::Ui::Windows
// Add tabs
int32_t tabsInThisRow = 0;
ScreenCoordsXY pos = { InitTabPosX, InitTabPosY + getTitleHeightDiff() };
ScreenCoordsXY pos = { kTabMargin, widgets[WIDX_SCENERY_TITLE].bottom + kTabMargin };
for (const auto& tabInfo : _tabEntries)
{
auto widget = MakeTab(pos, STR_STRING_DEFINED_TOOLTIP);
@@ -1408,7 +1407,7 @@ namespace OpenRCT2::Ui::Windows
tabsInThisRow++;
if (tabsInThisRow >= maxTabsInThisRow)
{
pos.x = InitTabPosX;
pos.x = kTabMargin;
pos.y += TabHeight;
tabsInThisRow = 0;
_actualMinHeight += TabHeight;

View File

@@ -301,15 +301,14 @@ namespace OpenRCT2::Ui::Windows
Close();
}
static int32_t CalculateWindowHeight(std::string_view text)
int32_t CalculateWindowHeight(std::string_view text)
{
// String length needs to add 12 either side of box +13 for cursor when max length.
int32_t numLines{};
GfxWrapString(text, WW - (24 + 13), FontStyle::Medium, nullptr, &numLines);
const auto textHeight = numLines * 10;
const auto addedTitleHeight = getTitleBarHeight() - kTitleHeightNormal;
return WH + textHeight + addedTitleHeight;
return WH + textHeight + getTitleBarDiffNormal();
}
private:
@@ -371,8 +370,7 @@ namespace OpenRCT2::Ui::Windows
auto* windowMgr = GetWindowManager();
windowMgr->CloseByClass(WindowClass::Textinput);
auto height = TextInputWindow::CalculateWindowHeight(existing_text);
auto w = windowMgr->Create<TextInputWindow>(WindowClass::Textinput, WW, height, WF_CENTRE_SCREEN | WF_STICK_TO_FRONT);
auto w = windowMgr->Create<TextInputWindow>(WindowClass::Textinput, WW, WH + 10, WF_CENTRE_SCREEN | WF_STICK_TO_FRONT);
if (w != nullptr)
{
w->SetParentWindow(call_w, call_widget);
@@ -386,8 +384,7 @@ namespace OpenRCT2::Ui::Windows
std::function<void(std::string_view)> callback, std::function<void()> cancelCallback)
{
auto* windowMgr = GetWindowManager();
auto height = TextInputWindow::CalculateWindowHeight(initialValue);
auto w = windowMgr->Create<TextInputWindow>(WindowClass::Textinput, WW, height, WF_CENTRE_SCREEN | WF_STICK_TO_FRONT);
auto w = windowMgr->Create<TextInputWindow>(WindowClass::Textinput, WW, WH + 10, WF_CENTRE_SCREEN | WF_STICK_TO_FRONT);
if (w != nullptr)
{
w->SetTitle(title, description);

View File

@@ -975,19 +975,6 @@ static constexpr float kWindowScrollLocations[][2] = {
return w->viewport;
}
int16_t getTitleBarHeight()
{
return Config::Get().interface.EnlargedUi ? kTitleHeightLarge : kTitleHeightNormal;
}
int16_t getTitleHeightDiff()
{
if (Config::Get().interface.EnlargedUi)
return kTitleHeightLarge - kTitleHeightNormal;
else
return 0;
}
// TODO: declared in WindowManager.h; move when refactors continue
Ui::IWindowManager* Ui::GetWindowManager()
{

View File

@@ -348,7 +348,4 @@ namespace OpenRCT2
void WindowFollowSprite(WindowBase& w, EntityId spriteIndex);
void WindowUnfollowSprite(WindowBase& w);
int16_t getTitleBarHeight();
int16_t getTitleHeightDiff();
} // namespace OpenRCT2

View File

@@ -99,7 +99,7 @@ namespace OpenRCT2
}
// Figure out if we need to push the other widgets down to accommodate a resized title/caption
auto preferredHeight = getTitleBarHeight();
auto preferredHeight = getTitleBarTargetHeight();
auto currentHeight = titleWidget.height();
auto heightDifference = preferredHeight - currentHeight;
@@ -133,4 +133,27 @@ namespace OpenRCT2
if (viewport != nullptr)
viewport->pos.y += heightDifference;
}
int16_t WindowBase::getTitleBarTargetHeight() const
{
return Config::Get().interface.EnlargedUi ? kTitleHeightLarge : kTitleHeightNormal;
}
int16_t WindowBase::getTitleBarCurrentHeight() const
{
if (!(flags & WF_NO_TITLE_BAR) && widgets.size() > 2)
return widgets[1].height();
else
return 0;
}
int16_t WindowBase::getTitleBarDiffTarget() const
{
return getTitleBarTargetHeight() - getTitleBarCurrentHeight();
}
int16_t WindowBase::getTitleBarDiffNormal() const
{
return getTitleBarCurrentHeight() - kTitleHeightNormal;
}
} // namespace OpenRCT2

View File

@@ -115,6 +115,11 @@ namespace OpenRCT2
void SetWidgets(const std::span<const Widget> newWidgets);
void ResizeFrame();
int16_t getTitleBarTargetHeight() const;
int16_t getTitleBarCurrentHeight() const;
int16_t getTitleBarDiffTarget() const;
int16_t getTitleBarDiffNormal() const;
WindowBase() = default;
WindowBase(WindowBase&) = delete;
virtual ~WindowBase() = default;