mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-21 12:09:43 +00:00
Use string_view in Layout and remove dead code
This commit is contained in:
parent
a814d11a39
commit
81ec7e80bb
4 changed files with 34 additions and 34 deletions
|
@ -8,29 +8,24 @@
|
|||
|
||||
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;
|
||||
|
||||
if (mLayoutName.empty())
|
||||
mMainWidget = _parent;
|
||||
else
|
||||
mPrefix = MyGUI::utility::toString(this, "_");
|
||||
mListWindowRoot = MyGUI::LayoutManager::getInstance().loadLayout(mLayoutName, mPrefix);
|
||||
|
||||
const std::string main_name = mPrefix + MAIN_WINDOW;
|
||||
for (MyGUI::Widget* widget : mListWindowRoot)
|
||||
{
|
||||
mPrefix = MyGUI::utility::toString(this, "_");
|
||||
mListWindowRoot = MyGUI::LayoutManager::getInstance().loadLayout(mLayoutName, mPrefix, _parent);
|
||||
if (widget->getName() == main_name)
|
||||
mMainWidget = widget;
|
||||
|
||||
const std::string main_name = mPrefix + MAIN_WINDOW;
|
||||
for (MyGUI::Widget* widget : mListWindowRoot)
|
||||
{
|
||||
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.");
|
||||
// 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.");
|
||||
}
|
||||
|
||||
void Layout::shutdown()
|
||||
|
@ -50,7 +45,7 @@ namespace MWGui
|
|||
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;
|
||||
getWidget(pt, name);
|
||||
|
@ -65,11 +60,13 @@ namespace MWGui
|
|||
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)
|
||||
{
|
||||
MyGUI::Widget* find = widget->findWidget(mPrefix + _name);
|
||||
MyGUI::Widget* find = widget->findWidget(target);
|
||||
if (nullptr != find)
|
||||
{
|
||||
return find;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define OPENMW_MWGUI_LAYOUT_H
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include <MyGUI_Widget.h>
|
||||
|
||||
|
@ -15,9 +16,12 @@ namespace MWGui
|
|||
class Layout
|
||||
{
|
||||
public:
|
||||
Layout(const std::string & _layout, MyGUI::Widget* _parent = nullptr)
|
||||
: mMainWidget(nullptr)
|
||||
{ initialise(_layout, _parent); }
|
||||
Layout(std::string_view layout) : mMainWidget(nullptr)
|
||||
{
|
||||
initialise(layout);
|
||||
assert(mMainWidget);
|
||||
}
|
||||
|
||||
virtual ~Layout()
|
||||
{
|
||||
try
|
||||
|
@ -30,10 +34,10 @@ namespace MWGui
|
|||
}
|
||||
}
|
||||
|
||||
MyGUI::Widget* getWidget(const std::string& _name);
|
||||
MyGUI::Widget* getWidget(std::string_view name);
|
||||
|
||||
template <typename T>
|
||||
void getWidget(T * & _widget, const std::string & _name)
|
||||
void getWidget(T * & _widget, std::string_view _name)
|
||||
{
|
||||
MyGUI::Widget* w = getWidget(_name);
|
||||
T* cast = w->castType<T>(false);
|
||||
|
@ -48,8 +52,7 @@ namespace MWGui
|
|||
}
|
||||
|
||||
private:
|
||||
void initialise(const std::string & _layout,
|
||||
MyGUI::Widget* _parent = nullptr);
|
||||
void initialise(std::string_view layout);
|
||||
|
||||
void shutdown();
|
||||
|
||||
|
@ -58,7 +61,7 @@ namespace MWGui
|
|||
|
||||
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.
|
||||
void setTitle(const std::string& title);
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
using namespace MWGui;
|
||||
|
||||
WindowBase::WindowBase(const std::string& parLayout)
|
||||
WindowBase::WindowBase(std::string_view parLayout)
|
||||
: Layout(parLayout)
|
||||
{
|
||||
mMainWidget->setVisible(false);
|
||||
|
@ -139,12 +139,12 @@ void NoDrop::setAlpha(float alpha)
|
|||
mWidget->setAlpha(alpha);
|
||||
}
|
||||
|
||||
BookWindowBase::BookWindowBase(const std::string& parLayout)
|
||||
BookWindowBase::BookWindowBase(std::string_view parLayout)
|
||||
: WindowBase(parLayout)
|
||||
{
|
||||
}
|
||||
|
||||
float BookWindowBase::adjustButton (char const * name)
|
||||
float BookWindowBase::adjustButton(std::string_view name)
|
||||
{
|
||||
Gui::ImageButton* button;
|
||||
WindowBase::getWidget (button, name);
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace MWGui
|
|||
class WindowBase: public Layout
|
||||
{
|
||||
public:
|
||||
WindowBase(const std::string& parLayout);
|
||||
WindowBase(std::string_view parLayout);
|
||||
|
||||
virtual MyGUI::Widget* getDefaultKeyFocus() { return nullptr; }
|
||||
|
||||
|
@ -88,10 +88,10 @@ namespace MWGui
|
|||
class BookWindowBase : public WindowBase
|
||||
{
|
||||
public:
|
||||
BookWindowBase(const std::string& parLayout);
|
||||
BookWindowBase(std::string_view parLayout);
|
||||
|
||||
protected:
|
||||
float adjustButton (char const * name);
|
||||
float adjustButton(std::string_view name);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue