summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-02-26 10:48:54 +0100
committerRémi Verschelde <rverschelde@gmail.com>2024-02-26 10:48:54 +0100
commit7e567c4777db1dc6d24c15e9c20d339448eae05a (patch)
tree4115cf4f29bba2c85f942b3b9edd4fe3f5955c88
parente7bf883068996168e692d0383c190bbc2808bcf6 (diff)
parent5de496d3b08c23ef9cf8ae97055204815087bcfb (diff)
downloadredot-engine-7e567c4777db1dc6d24c15e9c20d339448eae05a.tar.gz
Merge pull request #88615 from Rindbee/add-h_separation-between-icons-in-CheckButton-and-CheckBox
Add a `h_separation` between icons in `CheckButton`/`CheckBox`
-rw-r--r--scene/gui/button.cpp16
-rw-r--r--scene/gui/button.h3
-rw-r--r--scene/gui/check_box.cpp16
-rw-r--r--scene/gui/check_button.cpp16
-rw-r--r--scene/gui/option_button.cpp2
5 files changed, 27 insertions, 26 deletions
diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp
index 978fb56f78..b1870eea55 100644
--- a/scene/gui/button.cpp
+++ b/scene/gui/button.cpp
@@ -50,10 +50,6 @@ void Button::_set_internal_margin(Side p_side, float p_value) {
void Button::_queue_update_size_cache() {
}
-void Button::_set_h_separation_is_valid_when_no_text(bool p_h_separation_is_valid_when_no_text) {
- h_separation_is_valid_when_no_text = p_h_separation_is_valid_when_no_text;
-}
-
Ref<StyleBox> Button::_get_current_stylebox() const {
Ref<StyleBox> stylebox = theme_cache.normal;
const bool rtl = is_layout_rtl();
@@ -180,14 +176,12 @@ void Button::_notification(int p_what) {
float right_internal_margin_with_h_separation = _internal_margin[SIDE_RIGHT];
{ // The width reserved for internal element in derived classes (and h_separation if need).
- if (!xl_text.is_empty() || h_separation_is_valid_when_no_text) {
- if (_internal_margin[SIDE_LEFT] > 0.0f) {
- left_internal_margin_with_h_separation += h_separation;
- }
+ if (_internal_margin[SIDE_LEFT] > 0.0f) {
+ left_internal_margin_with_h_separation += h_separation;
+ }
- if (_internal_margin[SIDE_RIGHT] > 0.0f) {
- right_internal_margin_with_h_separation += h_separation;
- }
+ if (_internal_margin[SIDE_RIGHT] > 0.0f) {
+ right_internal_margin_with_h_separation += h_separation;
}
drawable_size_remained.width -= left_internal_margin_with_h_separation + right_internal_margin_with_h_separation; // The size after the internal element is stripped.
diff --git a/scene/gui/button.h b/scene/gui/button.h
index 6efbafe0ad..86fdbd35d5 100644
--- a/scene/gui/button.h
+++ b/scene/gui/button.h
@@ -56,8 +56,6 @@ private:
VerticalAlignment vertical_icon_alignment = VERTICAL_ALIGNMENT_CENTER;
float _internal_margin[4] = {};
- bool h_separation_is_valid_when_no_text = false;
-
struct ThemeCache {
Ref<StyleBox> normal;
Ref<StyleBox> normal_mirrored;
@@ -105,7 +103,6 @@ protected:
void _set_internal_margin(Side p_side, float p_value);
virtual void _queue_update_size_cache();
- void _set_h_separation_is_valid_when_no_text(bool p_h_separation_is_valid_when_no_text);
Ref<StyleBox> _get_current_stylebox() const;
void _notification(int p_what);
static void _bind_methods();
diff --git a/scene/gui/check_box.cpp b/scene/gui/check_box.cpp
index 6c02ba1a86..46c20e4a1c 100644
--- a/scene/gui/check_box.cpp
+++ b/scene/gui/check_box.cpp
@@ -64,12 +64,18 @@ Size2 CheckBox::get_icon_size() const {
Size2 CheckBox::get_minimum_size() const {
Size2 minsize = Button::get_minimum_size();
- Size2 tex_size = get_icon_size();
- minsize.width += tex_size.width;
- if (get_text().length() > 0) {
- minsize.width += MAX(0, theme_cache.h_separation);
+ const Size2 tex_size = get_icon_size();
+ if (tex_size.width > 0 || tex_size.height > 0) {
+ const Size2 padding = _get_current_stylebox()->get_minimum_size();
+ Size2 content_size = minsize - padding;
+ if (content_size.width > 0 && tex_size.width > 0) {
+ content_size.width += MAX(0, theme_cache.h_separation);
+ }
+ content_size.width += tex_size.width;
+ content_size.height = MAX(content_size.height, tex_size.height);
+
+ minsize = content_size + padding;
}
- minsize.height = MAX(minsize.height, tex_size.height + theme_cache.normal_style->get_margin(SIDE_TOP) + theme_cache.normal_style->get_margin(SIDE_BOTTOM));
return minsize;
}
diff --git a/scene/gui/check_button.cpp b/scene/gui/check_button.cpp
index d9fabc5459..ca2ef220fd 100644
--- a/scene/gui/check_button.cpp
+++ b/scene/gui/check_button.cpp
@@ -68,12 +68,18 @@ Size2 CheckButton::get_icon_size() const {
Size2 CheckButton::get_minimum_size() const {
Size2 minsize = Button::get_minimum_size();
- Size2 tex_size = get_icon_size();
- minsize.width += tex_size.width;
- if (get_text().length() > 0) {
- minsize.width += MAX(0, theme_cache.h_separation);
+ const Size2 tex_size = get_icon_size();
+ if (tex_size.width > 0 || tex_size.height > 0) {
+ const Size2 padding = _get_current_stylebox()->get_minimum_size();
+ Size2 content_size = minsize - padding;
+ if (content_size.width > 0 && tex_size.width > 0) {
+ content_size.width += MAX(0, theme_cache.h_separation);
+ }
+ content_size.width += tex_size.width;
+ content_size.height = MAX(content_size.height, tex_size.height);
+
+ minsize = content_size + padding;
}
- minsize.height = MAX(minsize.height, tex_size.height + theme_cache.normal_style->get_margin(SIDE_TOP) + theme_cache.normal_style->get_margin(SIDE_BOTTOM));
return minsize;
}
diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp
index 6613f25b4c..0e10652f07 100644
--- a/scene/gui/option_button.cpp
+++ b/scene/gui/option_button.cpp
@@ -614,8 +614,6 @@ void OptionButton::set_disable_shortcuts(bool p_disabled) {
OptionButton::OptionButton(const String &p_text) :
Button(p_text) {
- _set_h_separation_is_valid_when_no_text(true);
-
set_toggle_mode(true);
set_process_shortcut_input(true);
set_text_alignment(HORIZONTAL_ALIGNMENT_LEFT);