Load GUI from XML
This commit is contained in:
28
Widget.hh
28
Widget.hh
@@ -15,6 +15,9 @@ static const int WRAP_CONTENT = -1;
|
||||
WRAP_CONTENT */
|
||||
static const int MATCH_PARENT = -2;
|
||||
|
||||
/* Size the widget to wrap the content size, expanding to fill parent when
|
||||
parent is larger */
|
||||
static const int WRAP_CONTENT_FILL = -3;
|
||||
|
||||
static const int ALIGN_TOP = 0;
|
||||
static const int ALIGN_BOTTOM = 1;
|
||||
@@ -56,8 +59,16 @@ public:
|
||||
the background is applied to the entire dstRect, and the content is
|
||||
rendered with padding*/
|
||||
void setPadding(int left, int top, int right, int bottom);
|
||||
int getLeftPadding() const { return padLeft_; }
|
||||
int getTopPadding() const { return padTop_; }
|
||||
int getRightPadding() const { return padRight_; }
|
||||
int getBottomPadding() const { return padBottom_; }
|
||||
|
||||
virtual void setAlignment(int horiz, int vert);
|
||||
|
||||
void setContainerAlignment(int horiz, int vert);
|
||||
int getContainerAlignmentHoriz() const { return alignContHoriz_; }
|
||||
int getContainerAlignmentVert() const { return alignContVert_; }
|
||||
|
||||
void setGLRenderPos(int left, int top);
|
||||
|
||||
@@ -66,23 +77,29 @@ public:
|
||||
|
||||
protected:
|
||||
/* Update realWidth_ and realHeight_ where necessary
|
||||
(width_ or height_ == WRAP_CONTENT) */
|
||||
virtual void layout() = 0;
|
||||
(width_ or height_ == WRAP_CONTENT). Check caller to prevent recursion */
|
||||
virtual void layout(Widget *caller = nullptr) = 0;
|
||||
|
||||
/* Inform the renderToGL() code that any cached presentations are now invalid */
|
||||
void invalidateGL() { renderTexValid_ = false; }
|
||||
void invalidateGL();
|
||||
|
||||
/* Helper to calculate the SDL_Rect with which to render the content,
|
||||
respecting alignment and padding */
|
||||
SDL_Rect calcContentRect(SDL_Surface *dst, SDL_Rect *dstRect, SDL_Rect contentRect) const;
|
||||
|
||||
/* Helper to calculate layout height, width constraints
|
||||
Returns width, height tuple with with width/height > 0 if fixed or
|
||||
determined by parent layout, 0 if it should be based on widget contents.
|
||||
Checks caller to prevent recursion */
|
||||
std::tuple<int, int> baseLayout(Widget *caller);
|
||||
|
||||
void setParent(Widget *parent);
|
||||
|
||||
/* Helpers to allow Views to access protected methods of other Widgets */
|
||||
void _setParent(Widget& child) { child.setParent(this); }
|
||||
void _clearParent(Widget& child) { child.setParent(nullptr); }
|
||||
void _layout(Widget& child) { child.layout(); }
|
||||
|
||||
void _layout(Widget& child) { child.layout(this); }
|
||||
|
||||
std::string name_;
|
||||
|
||||
int width_, height_;
|
||||
@@ -94,6 +111,7 @@ protected:
|
||||
int padLeft_, padTop_, padRight_, padBottom_;
|
||||
|
||||
int alignHoriz_, alignVert_;
|
||||
int alignContHoriz_, alignContVert_;
|
||||
|
||||
Widget *parent_;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user