mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-03-13 07:14:31 +00:00
Merge branch 'assert' into 'master'
Use string_view in Layout and remove dead code See merge request OpenMW/openmw!2060
This commit is contained in:
commit
776cae4c95
@ -8,29 +8,24 @@
|
|||||||
|
|
||||||
namespace MWGui
|
namespace MWGui
|
||||||
{
|
{
|
||||||
void Layout::initialise(const std::string& _layout, MyGUI::Widget* _parent)
|
void Layout::initialise(std::string_view _layout)
|
||||||
{
|
{
|
||||||
const std::string MAIN_WINDOW = "_Main";
|
const auto MAIN_WINDOW = "_Main";
|
||||||
mLayoutName = _layout;
|
mLayoutName = _layout;
|
||||||
|
|
||||||
if (mLayoutName.empty())
|
mPrefix = MyGUI::utility::toString(this, "_");
|
||||||
mMainWidget = _parent;
|
mListWindowRoot = MyGUI::LayoutManager::getInstance().loadLayout(mLayoutName, mPrefix);
|
||||||
else
|
|
||||||
|
const std::string main_name = mPrefix + MAIN_WINDOW;
|
||||||
|
for (MyGUI::Widget* widget : mListWindowRoot)
|
||||||
{
|
{
|
||||||
mPrefix = MyGUI::utility::toString(this, "_");
|
if (widget->getName() == main_name)
|
||||||
mListWindowRoot = MyGUI::LayoutManager::getInstance().loadLayout(mLayoutName, mPrefix, _parent);
|
mMainWidget = widget;
|
||||||
|
|
||||||
const std::string main_name = mPrefix + MAIN_WINDOW;
|
// Force the alignment to update immediately
|
||||||
for (MyGUI::Widget* widget : mListWindowRoot)
|
widget->_setAlign(widget->getSize(), widget->getParentSize());
|
||||||
{
|
|
||||||
if (widget->getName() == main_name)
|
|
||||||
mMainWidget = widget;
|
|
||||||
|
|
||||||
// Force the alignment to update immediately
|
|
||||||
widget->_setAlign(widget->getSize(), widget->getParentSize());
|
|
||||||
}
|
|
||||||
MYGUI_ASSERT(mMainWidget, "root widget name '" << MAIN_WINDOW << "' in layout '" << mLayoutName << "' not found.");
|
|
||||||
}
|
}
|
||||||
|
MYGUI_ASSERT(mMainWidget, "root widget name '" << MAIN_WINDOW << "' in layout '" << mLayoutName << "' not found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layout::shutdown()
|
void Layout::shutdown()
|
||||||
@ -50,7 +45,7 @@ namespace MWGui
|
|||||||
mMainWidget->setVisible(b);
|
mMainWidget->setVisible(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layout::setText(const std::string &name, const std::string &caption)
|
void Layout::setText(std::string_view name, const std::string &caption)
|
||||||
{
|
{
|
||||||
MyGUI::Widget* pt;
|
MyGUI::Widget* pt;
|
||||||
getWidget(pt, name);
|
getWidget(pt, name);
|
||||||
@ -65,11 +60,13 @@ namespace MWGui
|
|||||||
window->setCaptionWithReplacing(title);
|
window->setCaptionWithReplacing(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
MyGUI::Widget* Layout::getWidget(const std::string &_name)
|
MyGUI::Widget* Layout::getWidget(std::string_view _name)
|
||||||
{
|
{
|
||||||
|
std::string target = mPrefix;
|
||||||
|
target += _name;
|
||||||
for (MyGUI::Widget* widget : mListWindowRoot)
|
for (MyGUI::Widget* widget : mListWindowRoot)
|
||||||
{
|
{
|
||||||
MyGUI::Widget* find = widget->findWidget(mPrefix + _name);
|
MyGUI::Widget* find = widget->findWidget(target);
|
||||||
if (nullptr != find)
|
if (nullptr != find)
|
||||||
{
|
{
|
||||||
return find;
|
return find;
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define OPENMW_MWGUI_LAYOUT_H
|
#define OPENMW_MWGUI_LAYOUT_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
#include <MyGUI_Widget.h>
|
#include <MyGUI_Widget.h>
|
||||||
|
|
||||||
@ -15,9 +16,12 @@ namespace MWGui
|
|||||||
class Layout
|
class Layout
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Layout(const std::string & _layout, MyGUI::Widget* _parent = nullptr)
|
Layout(std::string_view layout) : mMainWidget(nullptr)
|
||||||
: mMainWidget(nullptr)
|
{
|
||||||
{ initialise(_layout, _parent); }
|
initialise(layout);
|
||||||
|
assert(mMainWidget);
|
||||||
|
}
|
||||||
|
|
||||||
virtual ~Layout()
|
virtual ~Layout()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -30,10 +34,10 @@ namespace MWGui
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MyGUI::Widget* getWidget(const std::string& _name);
|
MyGUI::Widget* getWidget(std::string_view name);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void getWidget(T * & _widget, const std::string & _name)
|
void getWidget(T * & _widget, std::string_view _name)
|
||||||
{
|
{
|
||||||
MyGUI::Widget* w = getWidget(_name);
|
MyGUI::Widget* w = getWidget(_name);
|
||||||
T* cast = w->castType<T>(false);
|
T* cast = w->castType<T>(false);
|
||||||
@ -48,8 +52,7 @@ namespace MWGui
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initialise(const std::string & _layout,
|
void initialise(std::string_view layout);
|
||||||
MyGUI::Widget* _parent = nullptr);
|
|
||||||
|
|
||||||
void shutdown();
|
void shutdown();
|
||||||
|
|
||||||
@ -58,7 +61,7 @@ namespace MWGui
|
|||||||
|
|
||||||
virtual void setVisible(bool b);
|
virtual void setVisible(bool b);
|
||||||
|
|
||||||
void setText(const std::string& name, const std::string& caption);
|
void setText(std::string_view name, const std::string& caption);
|
||||||
|
|
||||||
// NOTE: this assume that mMainWidget is of type Window.
|
// NOTE: this assume that mMainWidget is of type Window.
|
||||||
void setTitle(const std::string& title);
|
void setTitle(const std::string& title);
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
using namespace MWGui;
|
using namespace MWGui;
|
||||||
|
|
||||||
WindowBase::WindowBase(const std::string& parLayout)
|
WindowBase::WindowBase(std::string_view parLayout)
|
||||||
: Layout(parLayout)
|
: Layout(parLayout)
|
||||||
{
|
{
|
||||||
mMainWidget->setVisible(false);
|
mMainWidget->setVisible(false);
|
||||||
@ -139,12 +139,12 @@ void NoDrop::setAlpha(float alpha)
|
|||||||
mWidget->setAlpha(alpha);
|
mWidget->setAlpha(alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
BookWindowBase::BookWindowBase(const std::string& parLayout)
|
BookWindowBase::BookWindowBase(std::string_view parLayout)
|
||||||
: WindowBase(parLayout)
|
: WindowBase(parLayout)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
float BookWindowBase::adjustButton (char const * name)
|
float BookWindowBase::adjustButton(std::string_view name)
|
||||||
{
|
{
|
||||||
Gui::ImageButton* button;
|
Gui::ImageButton* button;
|
||||||
WindowBase::getWidget (button, name);
|
WindowBase::getWidget (button, name);
|
||||||
|
@ -15,7 +15,7 @@ namespace MWGui
|
|||||||
class WindowBase: public Layout
|
class WindowBase: public Layout
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WindowBase(const std::string& parLayout);
|
WindowBase(std::string_view parLayout);
|
||||||
|
|
||||||
virtual MyGUI::Widget* getDefaultKeyFocus() { return nullptr; }
|
virtual MyGUI::Widget* getDefaultKeyFocus() { return nullptr; }
|
||||||
|
|
||||||
@ -88,10 +88,10 @@ namespace MWGui
|
|||||||
class BookWindowBase : public WindowBase
|
class BookWindowBase : public WindowBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BookWindowBase(const std::string& parLayout);
|
BookWindowBase(std::string_view parLayout);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
float adjustButton (char const * name);
|
float adjustButton(std::string_view name);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user