diff options
Diffstat (limited to 'gui/ThemeLayout.h')
-rw-r--r-- | gui/ThemeLayout.h | 86 |
1 files changed, 52 insertions, 34 deletions
diff --git a/gui/ThemeLayout.h b/gui/ThemeLayout.h index e738002aa6..a99de5a99c 100644 --- a/gui/ThemeLayout.h +++ b/gui/ThemeLayout.h @@ -35,6 +35,8 @@ struct Surface; namespace GUI { +class Widget; + class ThemeLayout { friend class ThemeLayoutMain; friend class ThemeLayoutStacked; @@ -46,12 +48,13 @@ public: kLayoutVertical, kLayoutHorizontal, kLayoutWidget, - kLayoutTabWidget + kLayoutTabWidget, + kLayoutSpace }; ThemeLayout(ThemeLayout *p) : _parent(p), _x(0), _y(0), _w(-1), _h(-1), - _centered(false), _defaultW(-1), _defaultH(-1), + _defaultW(-1), _defaultH(-1), _textHAlign(Graphics::kTextAlignInvalid) {} virtual ~ThemeLayout() { @@ -59,9 +62,8 @@ public: delete _children[i]; } - virtual void reflowLayout() = 0; - - virtual void resetLayout() { _x = 0; _y = 0; _w = _defaultW; _h = _defaultH; } + virtual void reflowLayout(Widget *widgetChain) = 0; + virtual void resetLayout(); void addChild(ThemeLayout *child) { _children.push_back(child); } @@ -92,7 +94,14 @@ protected: void setHeight(int16 height) { _h = height; } void setTextHAlign(Graphics::TextAlign align) { _textHAlign = align; } - virtual LayoutType getLayoutType() = 0; + /** + * Checks if the layout element is attached to a GUI widget + * + * Layout elements that are not bound do not take space. + */ + virtual bool isBound(Widget *widgetChain) const { return true; } + + virtual LayoutType getLayoutType() const = 0; virtual ThemeLayout *makeClone(ThemeLayout *newParent) = 0; @@ -116,20 +125,24 @@ protected: int16 _x, _y, _w, _h; Common::Rect _padding; Common::Array<ThemeLayout *> _children; - bool _centered; int16 _defaultW, _defaultH; Graphics::TextAlign _textHAlign; }; class ThemeLayoutMain : public ThemeLayout { public: - ThemeLayoutMain(int16 x, int16 y, int16 w, int16 h) : ThemeLayout(0) { - _w = _defaultW = w; - _h = _defaultH = h; - _x = _defaultX = x; - _y = _defaultY = y; + ThemeLayoutMain(const Common::String &name, const Common::String &overlays, bool enabled, int inset) : + ThemeLayout(nullptr), + _name(name), + _overlays(overlays), + _enabled(enabled), + _inset(inset) { + _w = _defaultW = -1; + _h = _defaultH = -1; + _x = _defaultX = -1; + _y = _defaultY = -1; } - void reflowLayout(); + void reflowLayout(Widget *widgetChain) override; void resetLayout() { ThemeLayout::resetLayout(); @@ -137,35 +150,39 @@ public: _y = _defaultY; } -#ifdef LAYOUT_DEBUG_DIALOG - const char *getName() const { return "Global Layout"; } -#endif + const char *getName() const { return _name.c_str(); } protected: - LayoutType getLayoutType() { return kLayoutMain; } + LayoutType getLayoutType() const override { return kLayoutMain; } ThemeLayout *makeClone(ThemeLayout *newParent) { assert(!"Do not copy Main Layouts!"); return 0; } int16 _defaultX; int16 _defaultY; + + Common::String _name; + Common::String _overlays; + bool _enabled; + int _inset; }; class ThemeLayoutStacked : public ThemeLayout { public: ThemeLayoutStacked(ThemeLayout *p, LayoutType type, int spacing, bool center) : - ThemeLayout(p), _type(type) { + ThemeLayout(p), _type(type), _centered(center) { assert((type == kLayoutVertical) || (type == kLayoutHorizontal)); _spacing = spacing; _centered = center; } - void reflowLayout() { + void reflowLayout(Widget *widgetChain) override { if (_type == kLayoutVertical) - reflowLayoutVertical(); + reflowLayoutVertical(widgetChain); else - reflowLayoutHorizontal(); + reflowLayoutHorizontal(widgetChain); } - void reflowLayoutHorizontal(); - void reflowLayoutVertical(); + + void reflowLayoutHorizontal(Widget *widgetChain); + void reflowLayoutVertical(Widget *widgetChain); #ifdef LAYOUT_DEBUG_DIALOG const char *getName() const { @@ -178,7 +195,7 @@ protected: int16 getParentWidth(); int16 getParentHeight(); - LayoutType getLayoutType() { return _type; } + LayoutType getLayoutType() const override { return _type; } ThemeLayout *makeClone(ThemeLayout *newParent) { ThemeLayoutStacked *n = new ThemeLayoutStacked(*this); @@ -191,6 +208,7 @@ protected: } const LayoutType _type; + bool _centered; int8 _spacing; }; @@ -206,14 +224,15 @@ public: bool getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h); Graphics::TextAlign getWidgetTextHAlign(const Common::String &name); - void reflowLayout() {} + void reflowLayout(Widget *widgetChain) override; -#ifdef LAYOUT_DEBUG_DIALOG virtual const char *getName() const { return _name.c_str(); } -#endif protected: - LayoutType getLayoutType() { return kLayoutWidget; } + LayoutType getLayoutType() const override { return kLayoutWidget; } + + bool isBound(Widget *widgetChain) const override; + Widget *getWidget(Widget *widgetChain) const; ThemeLayout *makeClone(ThemeLayout *newParent) { ThemeLayout *n = new ThemeLayoutWidget(*this); @@ -233,10 +252,9 @@ public: _tabHeight = tabHeight; } - void reflowLayout() { + void reflowLayout(Widget *widgetChain) override { for (uint i = 0; i < _children.size(); ++i) { - _children[i]->resetLayout(); - _children[i]->reflowLayout(); + _children[i]->reflowLayout(widgetChain); } } @@ -250,7 +268,7 @@ public: } protected: - LayoutType getLayoutType() { return kLayoutTabWidget; } + LayoutType getLayoutType() const override { return kLayoutTabWidget; } ThemeLayout *makeClone(ThemeLayout *newParent) { ThemeLayoutTabWidget *n = new ThemeLayoutTabWidget(*this); @@ -272,13 +290,13 @@ public: } bool getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h) { return false; } - void reflowLayout() {} + void reflowLayout(Widget *widgetChain) override {} #ifdef LAYOUT_DEBUG_DIALOG const char *getName() const { return "SPACE"; } #endif protected: - LayoutType getLayoutType() { return kLayoutWidget; } + LayoutType getLayoutType() const override { return kLayoutSpace; } ThemeLayout *makeClone(ThemeLayout *newParent) { ThemeLayout *n = new ThemeLayoutSpacing(*this); |