|
32 | 32 |
|
33 | 33 | #include "core/config/project_settings.h" |
34 | 34 | #include "core/os/keyboard.h" |
| 35 | +#include "scene/gui/label.h" |
35 | 36 | #include "scene/main/window.h" |
36 | 37 |
|
37 | 38 | void BaseButton::_unpress_group() { |
@@ -390,16 +391,31 @@ void BaseButton::shortcut_input(const Ref<InputEvent> &p_event) { |
390 | 391 | } |
391 | 392 | } |
392 | 393 |
|
393 | | -String BaseButton::get_tooltip(const Point2 &p_pos) const { |
394 | | - String tooltip = Control::get_tooltip(p_pos); |
395 | | - if (shortcut_in_tooltip && shortcut.is_valid() && shortcut->has_valid_event()) { |
396 | | - String text = shortcut->get_name() + " (" + shortcut->get_as_text() + ")"; |
397 | | - if (!tooltip.is_empty() && shortcut->get_name().nocasecmp_to(tooltip) != 0) { |
398 | | - text += "\n" + atr(tooltip); |
399 | | - } |
400 | | - tooltip = text; |
| 394 | +Control *BaseButton::make_custom_tooltip(const String &p_text) const { |
| 395 | + Control *control = Control::make_custom_tooltip(p_text); |
| 396 | + if (control) { |
| 397 | + return control; |
| 398 | + } |
| 399 | + if (!shortcut_in_tooltip || shortcut.is_null() || !shortcut->has_valid_event()) { |
| 400 | + return nullptr; // Use the default tooltip label. |
401 | 401 | } |
402 | | - return tooltip; |
| 402 | + |
| 403 | + String text = atr(shortcut->get_name()) + " (" + shortcut->get_as_text() + ")"; |
| 404 | + if (!p_text.is_empty() && shortcut->get_name().nocasecmp_to(p_text) != 0) { |
| 405 | + text += "\n" + atr(p_text); |
| 406 | + } |
| 407 | + |
| 408 | + // Make a label similar to the default tooltip label. |
| 409 | + // Auto translation is disabled because we already did that manually above. |
| 410 | + // |
| 411 | + // We can't customize the tooltip text by overriding `get_tooltip()` |
| 412 | + // because otherwise user-defined `_make_custom_tooltip()` would receive |
| 413 | + // the translated and annotated text. |
| 414 | + Label *label = memnew(Label(text)); |
| 415 | + label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); |
| 416 | + label->set_theme_type_variation(SNAME("TooltipLabel")); |
| 417 | + |
| 418 | + return label; |
403 | 419 | } |
404 | 420 |
|
405 | 421 | void BaseButton::set_button_group(const Ref<ButtonGroup> &p_group) { |
|
0 commit comments