Skip to content

Commit 728a8f7

Browse files
committed
Merge pull request #108718 from Koyper/split_container_touch_dragger_theme_colors
[SplitContainer] Fix inability to override touch dragger icon and add theme colors to touch dragger
2 parents 8c09004 + 2114440 commit 728a8f7

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

doc/classes/SplitContainer.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@
9494
</constant>
9595
</constants>
9696
<theme_items>
97+
<theme_item name="touch_dragger_color" data_type="color" type="Color" default="Color(1, 1, 1, 0.3)">
98+
The color of the touch dragger.
99+
</theme_item>
100+
<theme_item name="touch_dragger_hover_color" data_type="color" type="Color" default="Color(1, 1, 1, 0.6)">
101+
The color of the touch dragger when hovered.
102+
</theme_item>
103+
<theme_item name="touch_dragger_pressed_color" data_type="color" type="Color" default="Color(1, 1, 1, 1)">
104+
The color of the touch dragger when pressed.
105+
</theme_item>
97106
<theme_item name="autohide" data_type="constant" type="int" default="1">
98107
Boolean value. If [code]1[/code] ([code]true[/code]), the grabber will hide automatically when it isn't under the cursor. If [code]0[/code] ([code]false[/code]), it's always visible. The [member dragger_visibility] must be [constant DRAGGER_VISIBLE].
99108
</theme_item>

scene/gui/split_container.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,10 @@ void SplitContainer::_notification(int p_what) {
376376
} break;
377377
case NOTIFICATION_THEME_CHANGED: {
378378
update_minimum_size();
379+
if (touch_dragger) {
380+
touch_dragger->set_modulate(theme_cache.touch_dragger_color);
381+
touch_dragger->set_texture(_get_touch_dragger_icon());
382+
}
379383
} break;
380384
}
381385
}
@@ -542,7 +546,7 @@ void SplitContainer::set_touch_dragger_enabled(bool p_enabled) {
542546
touch_dragger->set_texture(_get_touch_dragger_icon());
543547
touch_dragger->set_anchors_and_offsets_preset(Control::PRESET_CENTER);
544548
touch_dragger->set_default_cursor_shape(vertical ? CURSOR_VSPLIT : CURSOR_HSPLIT);
545-
touch_dragger->set_modulate(Color(1, 1, 1, 0.3));
549+
touch_dragger->set_modulate(theme_cache.touch_dragger_color);
546550
touch_dragger->connect(SceneStringName(gui_input), callable_mp(this, &SplitContainer::_touch_dragger_gui_input));
547551
touch_dragger->connect(SceneStringName(mouse_exited), callable_mp(this, &SplitContainer::_touch_dragger_mouse_exited));
548552
dragging_area_control->add_child(touch_dragger, false, Node::INTERNAL_MODE_FRONT);
@@ -561,7 +565,7 @@ bool SplitContainer::is_touch_dragger_enabled() const {
561565

562566
void SplitContainer::_touch_dragger_mouse_exited() {
563567
if (!dragging_area_control->dragging) {
564-
touch_dragger->set_modulate(Color(1, 1, 1, 0.3));
568+
touch_dragger->set_modulate(theme_cache.touch_dragger_color);
565569
}
566570
}
567571

@@ -571,17 +575,16 @@ void SplitContainer::_touch_dragger_gui_input(const Ref<InputEvent> &p_event) {
571575
}
572576
Ref<InputEventMouseMotion> mm = p_event;
573577
Ref<InputEventMouseButton> mb = p_event;
574-
575578
if (mb.is_valid() && mb->get_button_index() == MouseButton::LEFT) {
576579
if (mb->is_pressed()) {
577-
touch_dragger->set_modulate(Color(1, 1, 1, 1));
580+
touch_dragger->set_modulate(theme_cache.touch_dragger_pressed_color);
578581
} else {
579-
touch_dragger->set_modulate(Color(1, 1, 1, 0.3));
582+
touch_dragger->set_modulate(theme_cache.touch_dragger_color);
580583
}
581584
}
582585

583586
if (mm.is_valid() && !dragging_area_control->dragging) {
584-
touch_dragger->set_modulate(Color(1, 1, 1, 0.6));
587+
touch_dragger->set_modulate(theme_cache.touch_dragger_hover_color);
585588
}
586589
}
587590

@@ -640,6 +643,9 @@ void SplitContainer::_bind_methods() {
640643
BIND_ENUM_CONSTANT(DRAGGER_HIDDEN);
641644
BIND_ENUM_CONSTANT(DRAGGER_HIDDEN_COLLAPSED);
642645

646+
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, SplitContainer, touch_dragger_color);
647+
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, SplitContainer, touch_dragger_pressed_color);
648+
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, SplitContainer, touch_dragger_hover_color);
643649
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, SplitContainer, separation);
644650
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, SplitContainer, minimum_grab_thickness);
645651
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, SplitContainer, autohide);

scene/gui/split_container.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ class SplitContainer : public Container {
8888
TextureRect *touch_dragger = nullptr;
8989

9090
struct ThemeCache {
91+
Color touch_dragger_color;
92+
Color touch_dragger_pressed_color;
93+
Color touch_dragger_hover_color;
9194
int separation = 0;
9295
int minimum_grab_thickness = 0;
9396
bool autohide = false;

scene/theme/default_theme.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,10 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
12041204

12051205
// Containers
12061206

1207+
theme->set_color("touch_dragger_color", "SplitContainer", Color(1, 1, 1, 0.3));
1208+
theme->set_color("touch_dragger_pressed_color", "SplitContainer", Color(1, 1, 1, 1));
1209+
theme->set_color("touch_dragger_hover_color", "SplitContainer", Color(1, 1, 1, 0.6));
1210+
12071211
theme->set_icon("h_touch_dragger", "SplitContainer", icons["h_dragger"]);
12081212
theme->set_icon("v_touch_dragger", "SplitContainer", icons["v_dragger"]);
12091213
theme->set_icon("touch_dragger", "VSplitContainer", icons["v_dragger"]);

0 commit comments

Comments
 (0)