https://github.com/libsdl-org/Maelstrom/commit/efb114d7b4650fe5037fee03b70f61c9e2e3e9a8
From efb114d7b4650fe5037fee03b70f61c9e2e3e9a8 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 31 Oct 2011 19:34:35 -0400
Subject: [PATCH] Moved the label expanding behavior to the checkbox class
since it's useful to be able to click on the label for that as well.
---
MacDialogCheckbox.cpp | 12 ++++++------
MacDialogRadioButton.cpp | 2 +-
screenlib/UIElementCheckbox.cpp | 15 +++++++++++++++
screenlib/UIElementCheckbox.h | 1 +
screenlib/UIElementRadio.cpp | 15 ---------------
screenlib/UIElementRadio.h | 1 -
6 files changed, 23 insertions(+), 23 deletions(-)
diff --git a/MacDialogCheckbox.cpp b/MacDialogCheckbox.cpp
index 66d1fd14..4b9a44c7 100644
--- a/MacDialogCheckbox.cpp
+++ b/MacDialogCheckbox.cpp
@@ -46,20 +46,20 @@ MacDialogCheckbox::CreateLabel()
label = new MacDialogLabel(this, "label");
label->SetTextColor(m_color);
- label->SetAnchor(TOPLEFT, TOPRIGHT, this, 3, -2);
+ label->SetAnchor(TOPLEFT, TOPLEFT, this, CHECKBOX_SIZE+3, -2);
return label;
}
void
MacDialogCheckbox::Draw()
{
- m_screen->DrawRect(X(), Y(), Width(), Height(), m_color);
+ m_screen->DrawRect(X(), Y(), CHECKBOX_SIZE, CHECKBOX_SIZE, m_color);
if ( IsChecked() ) {
- m_screen->DrawLine(X(), Y(),
- X()+Width()-1, Y()+Height()-1, m_color);
- m_screen->DrawLine(X(), Y()+Height()-1,
- X()+Width()-1, Y(), m_color);
+ m_screen->DrawLine(X(), Y(), X()+CHECKBOX_SIZE-1,
+ Y()+CHECKBOX_SIZE-1, m_color);
+ m_screen->DrawLine(X(), Y()+CHECKBOX_SIZE-1,
+ X()+CHECKBOX_SIZE-1, Y(), m_color);
}
UIElementButton::Draw();
diff --git a/MacDialogRadioButton.cpp b/MacDialogRadioButton.cpp
index a040e35f..20b66520 100644
--- a/MacDialogRadioButton.cpp
+++ b/MacDialogRadioButton.cpp
@@ -45,7 +45,7 @@ MacDialogRadioButton::CreateLabel()
MacDialogLabel *label;
label = new MacDialogLabel(this, "label");
- label->SetAnchor(TOPLEFT, TOPLEFT, this, 21, 3);
+ label->SetAnchor(TOPLEFT, TOPLEFT, this, RADIOBUTTON_SIZE+1, 3);
return label;
}
diff --git a/screenlib/UIElementCheckbox.cpp b/screenlib/UIElementCheckbox.cpp
index 62a771ce..7e443676 100644
--- a/screenlib/UIElementCheckbox.cpp
+++ b/screenlib/UIElementCheckbox.cpp
@@ -20,6 +20,7 @@
*/
#include "UIElementCheckbox.h"
+#include "UIElementLabel.h"
UIElementType UIElementCheckbox::s_elementType;
@@ -46,6 +47,20 @@ UIElementCheckbox::Load(rapidxml::xml_node<> *node, const UITemplates *templates
return true;
}
+bool
+UIElementCheckbox::FinishLoading()
+{
+ if (m_label) {
+ // Extend the sensitive area to encompass the label
+ if (m_label->X() >= X()) {
+ SetWidth((m_label->X()+m_label->Width()) - X());
+ } else {
+ assert(!"Need code for labels on the left");
+ }
+ }
+ return true;
+}
+
void
UIElementCheckbox::OnClick()
{
diff --git a/screenlib/UIElementCheckbox.h b/screenlib/UIElementCheckbox.h
index 0e9f1aae..57343977 100644
--- a/screenlib/UIElementCheckbox.h
+++ b/screenlib/UIElementCheckbox.h
@@ -32,6 +32,7 @@ DECLARE_TYPESAFE_CLASS(UIElementButton)
UIElementCheckbox(UIBaseElement *parent, const char *name = "");
override bool Load(rapidxml::xml_node<> *node, const UITemplates *templates);
+ override bool FinishLoading();
void SetChecked(bool checked) {
if (checked != m_checked) {
diff --git a/screenlib/UIElementRadio.cpp b/screenlib/UIElementRadio.cpp
index 670b4ace..a274082a 100644
--- a/screenlib/UIElementRadio.cpp
+++ b/screenlib/UIElementRadio.cpp
@@ -20,7 +20,6 @@
*/
#include "UIElementRadio.h"
-#include "UIElementLabel.h"
UIElementType UIElementRadioGroup::s_elementType;
@@ -85,20 +84,6 @@ UIElementRadioButton::Load(rapidxml::xml_node<> *node, const UITemplates *templa
return true;
}
-bool
-UIElementRadioButton::FinishLoading()
-{
- if (m_label) {
- // Extend the sensitive area to encompass the label
- if (m_label->X() >= X()) {
- SetWidth((m_label->X()+m_label->Width()) - X());
- } else {
- assert(!"Need code for labels on the left");
- }
- }
- return true;
-}
-
void
UIElementRadioButton::OnClick()
{
diff --git a/screenlib/UIElementRadio.h b/screenlib/UIElementRadio.h
index 8b3dbe30..3145d3e4 100644
--- a/screenlib/UIElementRadio.h
+++ b/screenlib/UIElementRadio.h
@@ -64,7 +64,6 @@ DECLARE_TYPESAFE_CLASS(UIElementCheckbox)
}
override bool Load(rapidxml::xml_node<> *node, const UITemplates *templates);
- override bool FinishLoading();
override void OnClick();
override void OnChecked(bool checked);