GUI: Add ThemeLayoutTabWidget

This commit is contained in:
Alexander Tkachev 2016-06-24 23:26:25 +06:00 committed by Eugene Sandulenko
parent 24963ac97d
commit 0ae4409138
6 changed files with 58 additions and 13 deletions

View file

@ -91,10 +91,18 @@ void ThemeEval::addWidget(const Common::String &name, int w, int h, const Common
typeAlign = (Graphics::TextAlign)getVar("Globals." + type + ".Align", Graphics::kTextAlignInvalid); typeAlign = (Graphics::TextAlign)getVar("Globals." + type + ".Align", Graphics::kTextAlignInvalid);
} }
ThemeLayoutWidget *widget = new ThemeLayoutWidget(_curLayout.top(), name, ThemeLayoutWidget *widget;
typeW == -1 ? w : typeW, if (type == "TabWidget")
typeH == -1 ? h : typeH, widget = new ThemeLayoutTabWidget(_curLayout.top(), name,
typeAlign == Graphics::kTextAlignInvalid ? align : typeAlign); typeW == -1 ? w : typeW,
typeH == -1 ? h : typeH,
typeAlign == Graphics::kTextAlignInvalid ? align : typeAlign,
getVar("Globals.TabWidget.Tab.Height", 0));
else
widget = new ThemeLayoutWidget(_curLayout.top(), name,
typeW == -1 ? w : typeW,
typeH == -1 ? h : typeH,
typeAlign == Graphics::kTextAlignInvalid ? align : typeAlign);
_curLayout.top()->addChild(widget); _curLayout.top()->addChild(widget);
setVar(_curDialog + "." + name + ".Enabled", enabled ? 1 : 0); setVar(_curDialog + "." + name + ".Enabled", enabled ? 1 : 0);

View file

@ -45,7 +45,8 @@ public:
kLayoutMain, kLayoutMain,
kLayoutVertical, kLayoutVertical,
kLayoutHorizontal, kLayoutHorizontal,
kLayoutWidget kLayoutWidget,
kLayoutTabWidget
}; };
ThemeLayout(ThemeLayout *p) : ThemeLayout(ThemeLayout *p) :
@ -223,6 +224,41 @@ protected:
Common::String _name; Common::String _name;
}; };
class ThemeLayoutTabWidget : public ThemeLayoutWidget {
int _tabHeight;
public:
ThemeLayoutTabWidget(ThemeLayout *p, const Common::String &name, int16 w, int16 h, Graphics::TextAlign align, int tabHeight):
ThemeLayoutWidget(p, name, w, h, align) {
_tabHeight = tabHeight;
}
void reflowLayout() {
for (uint i = 0; i < _children.size(); ++i) {
_children[i]->resetLayout();
_children[i]->reflowLayout();
}
}
virtual bool getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h) {
if (ThemeLayoutWidget::getWidgetData(name, x, y, w, h)) {
h -= _tabHeight;
return true;
}
return false;
}
protected:
LayoutType getLayoutType() { return kLayoutTabWidget; }
ThemeLayout *makeClone(ThemeLayout *newParent) {
ThemeLayoutTabWidget *n = new ThemeLayoutTabWidget(*this);
n->_parent = newParent;
return n;
}
};
class ThemeLayoutSpacing : public ThemeLayout { class ThemeLayoutSpacing : public ThemeLayout {
public: public:
ThemeLayoutSpacing(ThemeLayout *p, int size) : ThemeLayout(p) { ThemeLayoutSpacing(ThemeLayout *p, int size) : ThemeLayout(p) {

View file

@ -236,7 +236,7 @@
<dialog name = 'GlobalOptions' overlays = 'Dialog.Launcher.GameList' shading = 'dim'> <dialog name = 'GlobalOptions' overlays = 'Dialog.Launcher.GameList' shading = 'dim'>
<layout type = 'vertical' padding = '0, 0, 0, 0'> <layout type = 'vertical' padding = '0, 0, 0, 0'>
<widget name = 'TabWidget'/> <widget name = 'TabWidget' type = 'TabWidget'/>
<layout type = 'horizontal' padding = '16, 16, 16, 16'> <layout type = 'horizontal' padding = '16, 16, 16, 16'>
<space/> <space/>
<widget name = 'Cancel' <widget name = 'Cancel'

View file

@ -554,7 +554,7 @@
<dialog name = 'GameOptions' overlays = 'screen' inset = '16' shading = 'dim'> <dialog name = 'GameOptions' overlays = 'screen' inset = '16' shading = 'dim'>
<layout type = 'vertical' padding = '0, 0, 0, 0'> <layout type = 'vertical' padding = '0, 0, 0, 0'>
<widget name = 'TabWidget'/> <widget name = 'TabWidget' type = 'TabWidget'/>
<layout type = 'horizontal' padding = '8, 8, 8, 8'> <layout type = 'horizontal' padding = '8, 8, 8, 8'>
<space/> <space/>
<widget name = 'Cancel' <widget name = 'Cancel'

View file

@ -51,10 +51,7 @@ void ScrollContainerWidget::init() {
void ScrollContainerWidget::recalc() { void ScrollContainerWidget::recalc() {
int scrollbarWidth = g_gui.xmlEval()->getVar("Globals.Scrollbar.Width", 0); int scrollbarWidth = g_gui.xmlEval()->getVar("Globals.Scrollbar.Width", 0);
_limitH = _h;
//calculate _limitH - available height (boss's height - boss's "offset")
int d = _boss->getChildY() - _boss->getAbsY();
_limitH = _boss->getHeight() - d;
//calculate virtual height //calculate virtual height
const int spacing = g_gui.xmlEval()->getVar("Global.Font.Height", 16); //on the bottom const int spacing = g_gui.xmlEval()->getVar("Global.Font.Height", 16); //on the bottom

View file

@ -80,6 +80,8 @@ TabWidget::~TabWidget() {
} }
int16 TabWidget::getChildY() const { int16 TabWidget::getChildY() const {
// NOTE: if you change that, make sure to do the same
// changes in the ThemeLayoutTabWidget (gui/ThemeLayout.cpp)
return getAbsY() + _tabHeight; return getAbsY() + _tabHeight;
} }
@ -258,6 +260,8 @@ void TabWidget::adjustTabs(int value) {
void TabWidget::reflowLayout() { void TabWidget::reflowLayout() {
Widget::reflowLayout(); Widget::reflowLayout();
// NOTE: if you change that, make sure to do the same
// changes in the ThemeLayoutTabWidget (gui/ThemeLayout.cpp)
_tabHeight = g_gui.xmlEval()->getVar("Globals.TabWidget.Tab.Height"); _tabHeight = g_gui.xmlEval()->getVar("Globals.TabWidget.Tab.Height");
_tabWidth = g_gui.xmlEval()->getVar("Globals.TabWidget.Tab.Width"); _tabWidth = g_gui.xmlEval()->getVar("Globals.TabWidget.Tab.Width");
_titleVPad = g_gui.xmlEval()->getVar("Globals.TabWidget.Tab.Padding.Top"); _titleVPad = g_gui.xmlEval()->getVar("Globals.TabWidget.Tab.Padding.Top");
@ -304,7 +308,7 @@ void TabWidget::drawWidget() {
for (int i = _firstVisibleTab; i < (int)_tabs.size(); ++i) { for (int i = _firstVisibleTab; i < (int)_tabs.size(); ++i) {
tabs.push_back(_tabs[i].title); tabs.push_back(_tabs[i].title);
} }
g_gui.theme()->drawDialogBackground(Common::Rect(_x + _bodyLP, _y + _bodyTP, _x+_w-_bodyRP, _y+_h-_bodyBP), _bodyBackgroundType); g_gui.theme()->drawDialogBackground(Common::Rect(_x + _bodyLP, _y + _bodyTP, _x+_w-_bodyRP, _y+_h-_bodyBP+_tabHeight), _bodyBackgroundType);
g_gui.theme()->drawTab(Common::Rect(_x, _y, _x+_w, _y+_h), _tabHeight, _tabWidth, tabs, _activeTab - _firstVisibleTab, 0, _titleVPad); g_gui.theme()->drawTab(Common::Rect(_x, _y, _x+_w, _y+_h), _tabHeight, _tabWidth, tabs, _activeTab - _firstVisibleTab, 0, _titleVPad);
} }