mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-25 03:24:46 +00:00
Add getPreferredTextSize to calculate unconstrained text width
Introduces (CButton|CText).getPreferredTextSize, a new method for estimating the natural width of a caption if the object had no width constraints. Unlike .getTextSize, which reports the size after applying current layout constraints (e.g., fixed width or anchors), getPreferredTextSize answers the question: "How wide would this object need to be to display the caption on a single line?" This is particularly useful for modders and layout logic that wants to dynamically size elements *before* assigning a fixed width or anchoring.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2024 Wildfire Games.
|
||||
/* Copyright (C) 2025 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -44,6 +44,7 @@ DECLARE_GUIPROXY(IGUIObject);
|
||||
template<> void JSI_GUIProxy<CButton>::CreateFunctions(const ScriptRequest& rq, GUIProxyProps* cache)
|
||||
{
|
||||
CreateFunction<&CButton::GetTextSize>(rq, cache, "getTextSize");
|
||||
CreateFunction<&CButton::GetPreferredTextSize>(rq, cache, "getPreferredTextSize");
|
||||
}
|
||||
DECLARE_GUIPROXY(CButton);
|
||||
|
||||
@@ -51,6 +52,7 @@ DECLARE_GUIPROXY(CButton);
|
||||
template<> void JSI_GUIProxy<CText>::CreateFunctions(const ScriptRequest& rq, GUIProxyProps* cache)
|
||||
{
|
||||
CreateFunction<&CText::GetTextSize>(rq, cache, "getTextSize");
|
||||
CreateFunction<&CText::GetPreferredTextSize>(rq, cache, "getPreferredTextSize");
|
||||
}
|
||||
DECLARE_GUIPROXY(CText);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user