forked from mirrors/0ad
Fix warnings on the charts tab of summary screen
Engine.GetTextWidth has been deprecated since e845da025a
Idea:
If you look at a dropdown as just a text field (its header) that can
change caption like any other, then getPreferredHeaderTextSize is the
equivalent to getPreferredTextSize (present on buttons and text fields).
Fixes #8493
This commit is contained in:
@@ -265,8 +265,8 @@ function initGUICharts()
|
||||
function resizeDropdown(dropdown)
|
||||
{
|
||||
dropdown.size.bottom = dropdown.size.top +
|
||||
(Engine.GetTextWidth(dropdown.font, dropdown.list[dropdown.selected]) >
|
||||
dropdown.size.right - dropdown.size.left - 28 &&
|
||||
(dropdown.getPreferredHeaderTextSize().width >
|
||||
dropdown.size.right - dropdown.size.left - dropdown.button_width &&
|
||||
dropdown.list[dropdown.selected].indexOf(" ") !== -1 ? 42 : 28);
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ void CGUI::AddObjectTypes()
|
||||
m_ProxyData.insert(JSI_GUIProxy<IGUIObject>::CreateData(*m_ScriptInterface));
|
||||
m_ProxyData.insert(JSI_GUIProxy<CText>::CreateData(*m_ScriptInterface));
|
||||
m_ProxyData.insert(JSI_GUIProxy<CList>::CreateData(*m_ScriptInterface));
|
||||
m_ProxyData.insert(JSI_GUIProxy<CDropDown>::CreateData(*m_ScriptInterface));
|
||||
m_ProxyData.insert(JSI_GUIProxy<CMiniMap>::CreateData(*m_ScriptInterface));
|
||||
m_ProxyData.insert(JSI_GUIProxy<CButton>::CreateData(*m_ScriptInterface));
|
||||
m_ProxyData.insert(JSI_GUIProxy<CScrollPanel>::CreateData(*m_ScriptInterface));
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <limits>
|
||||
#include <vector>
|
||||
|
||||
CDropDown::CDropDown(CGUI& pGUI)
|
||||
@@ -501,3 +502,11 @@ float CDropDown::GetBufferedZ() const
|
||||
else
|
||||
return bz;
|
||||
}
|
||||
|
||||
CSize2D CDropDown::GetPreferredHeaderTextSize() const
|
||||
{
|
||||
if (m_Selected == -1)
|
||||
return CSize2D{0.0f, 0.0f};
|
||||
|
||||
return CGUIText{m_pGUI, m_List->m_Items[m_Selected], m_Font, std::numeric_limits<float>::max(), m_BufferZone, m_TextAlign, this}.GetSize();
|
||||
}
|
||||
|
||||
@@ -74,6 +74,8 @@ public:
|
||||
*/
|
||||
virtual void Draw(CCanvas2D& canvas);
|
||||
|
||||
virtual void CreateJSObject() override;
|
||||
|
||||
// This is one of the few classes we actually need to redefine this function
|
||||
// this is because the size of the control changes whether it is open
|
||||
// or closed.
|
||||
@@ -81,6 +83,11 @@ public:
|
||||
|
||||
virtual float GetBufferedZ() const;
|
||||
|
||||
/**
|
||||
* Calculate the preferred text size of the currently selected item displayed in the header.
|
||||
*/
|
||||
virtual CSize2D GetPreferredHeaderTextSize() const;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* If the size changed, the texts have to be updated as
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include "gui/ObjectBases/IGUIObject.h"
|
||||
#include "gui/ObjectTypes/CButton.h"
|
||||
#include "gui/ObjectTypes/CDropDown.h"
|
||||
#include "gui/ObjectTypes/CList.h"
|
||||
#include "gui/ObjectTypes/CMiniMap.h"
|
||||
#include "gui/ObjectTypes/CScrollPanel.h"
|
||||
@@ -69,6 +70,13 @@ template<> void JSI_GUIProxy<CList>::CreateFunctions(const ScriptRequest& rq, GU
|
||||
}
|
||||
DECLARE_GUIPROXY(CList);
|
||||
|
||||
// CDropDown
|
||||
template<> void JSI_GUIProxy<CDropDown>::CreateFunctions(const ScriptRequest& rq, GUIProxyProps* cache)
|
||||
{
|
||||
CreateFunction<&CDropDown::GetPreferredHeaderTextSize>(rq, cache, "getPreferredHeaderTextSize");
|
||||
}
|
||||
DECLARE_GUIPROXY(CDropDown);
|
||||
|
||||
// CMiniMap
|
||||
template<> void JSI_GUIProxy<CMiniMap>::CreateFunctions(const ScriptRequest& rq, GUIProxyProps* cache)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user