Maelstrom: Expand the clickable area to include image area

https://github.com/libsdl-org/Maelstrom/commit/7e7b10133750539008bae39af279e4792307df11

From 7e7b10133750539008bae39af279e4792307df11 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sun, 6 Nov 2011 00:36:42 -0400
Subject: [PATCH] Expand the clickable area to include image area

---
 MacDialog.cpp                   |  4 ++--
 screenlib/UIArea.h              |  4 ++++
 screenlib/UIElementCheckbox.cpp | 22 ++++++++++++++++++----
 3 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/MacDialog.cpp b/MacDialog.cpp
index b75169bb..78b2dd04 100644
--- a/MacDialog.cpp
+++ b/MacDialog.cpp
@@ -288,7 +288,7 @@ MacDialogCheckbox::OnDraw()
 
 	color = m_element->GetCurrentColor();
 	x = m_element->X();
-	y = m_element->Y();
+	y = m_element->Y() + (m_element->Height() - CHECKBOX_SIZE)/2;
 
 	m_screen->DrawRect(x, y, CHECKBOX_SIZE, CHECKBOX_SIZE, color);
 
@@ -329,7 +329,7 @@ MacDialogRadioButton::OnDraw()
 
 	color = m_element->GetCurrentColor();
 	x = m_element->X() + 5;
-	y = m_element->Y() + 5;
+	y = m_element->Y() + 5 + (m_element->Height() - RADIOBUTTON_SIZE)/2;
 
 	/* Draw the circle */
 	m_screen->DrawLine(x+4, y, x+7, y, color);
diff --git a/screenlib/UIArea.h b/screenlib/UIArea.h
index 04bc3ffa..07f7be5e 100644
--- a/screenlib/UIArea.h
+++ b/screenlib/UIArea.h
@@ -89,6 +89,10 @@ class UIArea : public ErrorBase
 		return m_rect.h;
 	}
 
+	bool IsEmpty() const {
+		return !m_rect.w || !m_rect.h;
+	}
+
 	void AddAnchoredArea(UIArea *area) {
 		m_anchoredAreas.add(area);
 	}
diff --git a/screenlib/UIElementCheckbox.cpp b/screenlib/UIElementCheckbox.cpp
index a4b44189..c750b1dc 100644
--- a/screenlib/UIElementCheckbox.cpp
+++ b/screenlib/UIElementCheckbox.cpp
@@ -60,10 +60,24 @@ bool
 UIElementCheckbox::FinishLoading()
 {
 	// Extend the sensitive area to encompass the label
-	if (m_textArea.X() >= X()) {
-		SetWidth((m_textArea.X()+m_textArea.Width()) - X());
-	} else {
-		assert(!"Need code for labels on the left");
+	if (!m_textArea.IsEmpty()) {
+		if (m_textArea.X() >= X()) {
+printf("%p Setting width to encompass text (%d >= %d)\n", this, m_textArea.X(), X());
+			SetWidth((m_textArea.X()+m_textArea.Width()) - X());
+		} else {
+			assert(!"Need code for labels on the left");
+		}
+	}
+	if (!m_imageArea.IsEmpty()) {
+		if (m_imageArea.X() >= X()) {
+printf("%p Setting width to encompass image (%d >= %d)\n", this, m_imageArea.X(), X());
+			SetWidth((m_imageArea.X()+m_imageArea.Width()) - X());
+		} else {
+			assert(!"Need code for images on the left");
+		}
+		if (m_imageArea.Height() > Height()) {
+			SetHeight(m_imageArea.Height());
+		}
 	}
 	return UIElementButton::FinishLoading();
 }