https://github.com/libsdl-org/Maelstrom/commit/7b4e9add0b24e173547259cef9fa1cdf82da8cef
From 7b4e9add0b24e173547259cef9fa1cdf82da8cef Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 23 Nov 2011 15:47:58 -0500
Subject: [PATCH] Added support for containers with borders
---
game/MaelstromUI.cpp | 2 ++
screenlib/UIContainer.cpp | 18 ++++++++++++++++--
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/game/MaelstromUI.cpp b/game/MaelstromUI.cpp
index 050a34ad..38ab3348 100644
--- a/game/MaelstromUI.cpp
+++ b/game/MaelstromUI.cpp
@@ -214,6 +214,8 @@ MaelstromUI::CreateElement(UIBaseElement *parent, const char *type, const char *
element = new UIElementControlButton(parent, name, new UIDrawEngine());
} else if (strcasecmp(type, "DialogLabel") == 0) {
element = new UIElement(parent, name, new MacDialogDrawEngine());
+ } else if (strcasecmp(type, "DialogContainer") == 0) {
+ element = new UIContainer(parent, name, new MacDialogDrawEngine());
} else if (strcasecmp(type, "DialogButton") == 0) {
element = new UIDialogButton(parent, name, new MacDialogButton());
} else if (strcasecmp(type, "DialogCheckbox") == 0) {
diff --git a/screenlib/UIContainer.cpp b/screenlib/UIContainer.cpp
index 04ff16fa..eb113c0e 100644
--- a/screenlib/UIContainer.cpp
+++ b/screenlib/UIContainer.cpp
@@ -73,7 +73,9 @@ UIContainer::LayoutChildren()
anchor = NULL;
for (i = 0; i < m_elements.length(); ++i) {
if (m_elements[i]->IsShown()) {
- m_elements[i]->SetAnchor(TOPLEFT, TOPLEFT, this);
+ m_elements[i]->SetAnchor(TOPLEFT, TOPLEFT, this,
+ HasBorder() ? 1 : 0,
+ HasBorder() ? 1 : 0);
anchor = m_elements[i];
break;
}
@@ -105,8 +107,14 @@ UIContainer::LayoutChildren()
}
}
}
+ if (HasBorder()) {
+ h += 2;
+ }
if (anchor) {
w = (anchor->X() - X()) + anchor->Width();
+ if (HasBorder()) {
+ w += 1;
+ }
}
} else {
// Width is the max of children, height is the sum of children
@@ -117,11 +125,17 @@ UIContainer::LayoutChildren()
}
}
}
+ if (HasBorder()) {
+ w += 2;
+ }
if (anchor) {
h = (anchor->Y() - Y()) + anchor->Height();
+ if (HasBorder()) {
+ h += 1;
+ }
}
}
- SetSize(w, h, true);
+ AutoSize(w, h);
m_layoutInProgress = false;
}