summaryrefslogtreecommitdiffstats
path: root/scene/gui/color_picker.cpp
diff options
context:
space:
mode:
authorHugo Locurcio <hugo.locurcio@hugo.pro>2023-04-10 21:06:02 +0200
committerHugo Locurcio <hugo.locurcio@hugo.pro>2023-04-10 23:59:07 +0200
commit517dc3654a80e30021b8468ef87d0327200963db (patch)
treed051865c1870a7bbc98dade2d025a02f794d7f2a /scene/gui/color_picker.cpp
parentc3ed7af12347aa04a3d3bb91bc726170e894758e (diff)
downloadredot-engine-517dc3654a80e30021b8468ef87d0327200963db.tar.gz
Allow entering named colors in ColorPicker's hex field
This also makes the hex field wider to allow displaying 9-character hex code (`#rrggbbaa`) in full, even when using a custom font.
Diffstat (limited to 'scene/gui/color_picker.cpp')
-rw-r--r--scene/gui/color_picker.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp
index 23b5bb2c7b..7f9095c2a2 100644
--- a/scene/gui/color_picker.cpp
+++ b/scene/gui/color_picker.cpp
@@ -543,8 +543,9 @@ void ColorPicker::_html_submitted(const String &p_html) {
return;
}
- Color previous_color = color;
- color = Color::html(p_html);
+ const Color previous_color = color;
+ color = Color::from_string(p_html, previous_color);
+
if (!is_editing_alpha()) {
color.a = previous_color.a;
}
@@ -644,13 +645,13 @@ void ColorPicker::_text_type_toggled() {
text_type->set_icon(get_theme_icon(SNAME("Script"), SNAME("EditorIcons")));
c_text->set_editable(false);
- c_text->set_h_size_flags(SIZE_EXPAND_FILL);
+ c_text->set_tooltip_text(RTR("Copy this constructor in a script."));
} else {
text_type->set_text("#");
text_type->set_icon(nullptr);
c_text->set_editable(true);
- c_text->set_h_size_flags(SIZE_FILL);
+ c_text->set_tooltip_text(RTR("Enter a hex code (\"#ff0000\") or named color (\"red\")."));
}
_update_color();
}
@@ -1793,7 +1794,10 @@ ColorPicker::ColorPicker() {
c_text = memnew(LineEdit);
hex_hbc->add_child(c_text);
+ c_text->set_h_size_flags(SIZE_EXPAND_FILL);
c_text->set_select_all_on_focus(true);
+ c_text->set_tooltip_text(RTR("Enter a hex code (\"#ff0000\") or named color (\"red\")."));
+ c_text->set_placeholder(RTR("Hex code or named color"));
c_text->connect("text_submitted", callable_mp(this, &ColorPicker::_html_submitted));
c_text->connect("text_changed", callable_mp(this, &ColorPicker::_text_changed));
c_text->connect("focus_exited", callable_mp(this, &ColorPicker::_html_focus_exit));