Merge pull request #51087 from Calinou/editor-viewport-highlight-context-menus-3.x

Highlight context menu items at the top of the 2D/3D viewports (3.x)
This commit is contained in:
Rémi Verschelde 2021-07-31 11:48:29 +02:00 committed by GitHub
commit 7c1ee0488e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 67 additions and 7 deletions

View file

@ -4137,7 +4137,10 @@ void CanvasItemEditor::_notification(int p_what) {
zoom_minus->set_icon(get_icon("ZoomLess", "EditorIcons")); zoom_minus->set_icon(get_icon("ZoomLess", "EditorIcons"));
zoom_plus->set_icon(get_icon("ZoomMore", "EditorIcons")); zoom_plus->set_icon(get_icon("ZoomMore", "EditorIcons"));
_update_context_menu_stylebox();
presets_menu->set_icon(get_icon("ControlLayout", "EditorIcons")); presets_menu->set_icon(get_icon("ControlLayout", "EditorIcons"));
PopupMenu *p = presets_menu->get_popup(); PopupMenu *p = presets_menu->get_popup();
p->clear(); p->clear();
@ -4284,6 +4287,18 @@ void CanvasItemEditor::_tree_changed(Node *) {
_queue_update_bone_list(); _queue_update_bone_list();
} }
void CanvasItemEditor::_update_context_menu_stylebox() {
// This must be called when the theme changes to follow the new accent color.
Ref<StyleBoxFlat> context_menu_stylebox = memnew(StyleBoxFlat);
const Color accent_color = EditorNode::get_singleton()->get_gui_base()->get_color("accent_color", "Editor");
context_menu_stylebox->set_bg_color(accent_color * Color(1, 1, 1, 0.1));
// Add an underline to the StyleBox, but prevent its minimum vertical size from changing.
context_menu_stylebox->set_border_color(accent_color);
context_menu_stylebox->set_border_width(MARGIN_BOTTOM, Math::round(2 * EDSCALE));
context_menu_stylebox->set_default_margin(MARGIN_BOTTOM, 0);
context_menu_container->add_style_override("panel", context_menu_stylebox);
}
void CanvasItemEditor::_update_scrollbars() { void CanvasItemEditor::_update_scrollbars() {
updating_scroll = true; updating_scroll = true;
@ -5619,11 +5634,11 @@ void CanvasItemEditor::remove_control_from_info_overlay(Control *p_control) {
void CanvasItemEditor::add_control_to_menu_panel(Control *p_control) { void CanvasItemEditor::add_control_to_menu_panel(Control *p_control) {
ERR_FAIL_COND(!p_control); ERR_FAIL_COND(!p_control);
hb->add_child(p_control); hbc_context_menu->add_child(p_control);
} }
void CanvasItemEditor::remove_control_from_menu_panel(Control *p_control) { void CanvasItemEditor::remove_control_from_menu_panel(Control *p_control) {
hb->remove_child(p_control); hbc_context_menu->remove_child(p_control);
} }
HSplitContainer *CanvasItemEditor::get_palette_split() { HSplitContainer *CanvasItemEditor::get_palette_split() {
@ -5992,9 +6007,20 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
p->add_separator(); p->add_separator();
p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/preview_canvas_scale", TTR("Preview Canvas Scale"), KEY_MASK_SHIFT | KEY_MASK_CMD | KEY_P), PREVIEW_CANVAS_SCALE); p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/preview_canvas_scale", TTR("Preview Canvas Scale"), KEY_MASK_SHIFT | KEY_MASK_CMD | KEY_P), PREVIEW_CANVAS_SCALE);
hb->add_child(memnew(VSeparator));
context_menu_container = memnew(PanelContainer);
hbc_context_menu = memnew(HBoxContainer);
context_menu_container->add_child(hbc_context_menu);
// Use a custom stylebox to make contextual menu items stand out from the rest.
// This helps with editor usability as contextual menu items change when selecting nodes,
// even though it may not be immediately obvious at first.
hb->add_child(context_menu_container);
_update_context_menu_stylebox();
presets_menu = memnew(MenuButton); presets_menu = memnew(MenuButton);
presets_menu->set_text(TTR("Layout")); presets_menu->set_text(TTR("Layout"));
hb->add_child(presets_menu); hbc_context_menu->add_child(presets_menu);
presets_menu->hide(); presets_menu->hide();
presets_menu->set_switch_on_hover(true); presets_menu->set_switch_on_hover(true);
@ -6007,13 +6033,13 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
anchors_popup->connect("id_pressed", this, "_popup_callback"); anchors_popup->connect("id_pressed", this, "_popup_callback");
anchor_mode_button = memnew(ToolButton); anchor_mode_button = memnew(ToolButton);
hb->add_child(anchor_mode_button); hbc_context_menu->add_child(anchor_mode_button);
anchor_mode_button->set_toggle_mode(true); anchor_mode_button->set_toggle_mode(true);
anchor_mode_button->hide(); anchor_mode_button->hide();
anchor_mode_button->connect("toggled", this, "_button_toggle_anchor_mode"); anchor_mode_button->connect("toggled", this, "_button_toggle_anchor_mode");
animation_hb = memnew(HBoxContainer); animation_hb = memnew(HBoxContainer);
hb->add_child(animation_hb); hbc_context_menu->add_child(animation_hb);
animation_hb->add_child(memnew(VSeparator)); animation_hb->add_child(memnew(VSeparator));
animation_hb->hide(); animation_hb->hide();

View file

@ -234,6 +234,10 @@ private:
HScrollBar *h_scroll; HScrollBar *h_scroll;
VScrollBar *v_scroll; VScrollBar *v_scroll;
HBoxContainer *hb; HBoxContainer *hb;
// Used for secondary menu items which are displayed depending on the currently selected node
// (such as MeshInstance's "Mesh" menu).
PanelContainer *context_menu_container;
HBoxContainer *hbc_context_menu;
ToolButton *zoom_minus; ToolButton *zoom_minus;
ToolButton *zoom_reset; ToolButton *zoom_reset;
@ -563,6 +567,7 @@ private:
void _update_bone_list(); void _update_bone_list();
void _tree_changed(Node *); void _tree_changed(Node *);
void _update_context_menu_stylebox();
void _popup_warning_temporarily(Control *p_control, const float p_duration); void _popup_warning_temporarily(Control *p_control, const float p_duration);
void _popup_warning_depop(Control *p_control); void _popup_warning_depop(Control *p_control);

View file

@ -5462,6 +5462,18 @@ void SpatialEditor::_init_indicators() {
_generate_selection_boxes(); _generate_selection_boxes();
} }
void SpatialEditor::_update_context_menu_stylebox() {
// This must be called when the theme changes to follow the new accent color.
Ref<StyleBoxFlat> context_menu_stylebox = memnew(StyleBoxFlat);
const Color accent_color = EditorNode::get_singleton()->get_gui_base()->get_color("accent_color", "Editor");
context_menu_stylebox->set_bg_color(accent_color * Color(1, 1, 1, 0.1));
// Add an underline to the StyleBox, but prevent its minimum vertical size from changing.
context_menu_stylebox->set_border_color(accent_color);
context_menu_stylebox->set_border_width(MARGIN_BOTTOM, Math::round(2 * EDSCALE));
context_menu_stylebox->set_default_margin(MARGIN_BOTTOM, 0);
context_menu_container->add_style_override("panel", context_menu_stylebox);
}
void SpatialEditor::_update_gizmos_menu() { void SpatialEditor::_update_gizmos_menu() {
gizmos_menu->clear(); gizmos_menu->clear();
@ -5926,6 +5938,7 @@ void SpatialEditor::_notification(int p_what) {
_init_indicators(); _init_indicators();
} else if (p_what == NOTIFICATION_THEME_CHANGED) { } else if (p_what == NOTIFICATION_THEME_CHANGED) {
_update_gizmos_menu_theme(); _update_gizmos_menu_theme();
_update_context_menu_stylebox();
} else if (p_what == NOTIFICATION_EXIT_TREE) { } else if (p_what == NOTIFICATION_EXIT_TREE) {
_finish_indicators(); _finish_indicators();
} else if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) { } else if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) {
@ -5963,11 +5976,11 @@ void SpatialEditor::_notification(int p_what) {
} }
void SpatialEditor::add_control_to_menu_panel(Control *p_control) { void SpatialEditor::add_control_to_menu_panel(Control *p_control) {
hbc_menu->add_child(p_control); hbc_context_menu->add_child(p_control);
} }
void SpatialEditor::remove_control_from_menu_panel(Control *p_control) { void SpatialEditor::remove_control_from_menu_panel(Control *p_control) {
hbc_menu->remove_child(p_control); hbc_context_menu->remove_child(p_control);
} }
void SpatialEditor::set_can_preview(Camera *p_preview) { void SpatialEditor::set_can_preview(Camera *p_preview) {
@ -6315,6 +6328,17 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) {
view_menu->set_switch_on_hover(true); view_menu->set_switch_on_hover(true);
hbc_menu->add_child(view_menu); hbc_menu->add_child(view_menu);
hbc_menu->add_child(memnew(VSeparator));
context_menu_container = memnew(PanelContainer);
hbc_context_menu = memnew(HBoxContainer);
context_menu_container->add_child(hbc_context_menu);
// Use a custom stylebox to make contextual menu items stand out from the rest.
// This helps with editor usability as contextual menu items change when selecting nodes,
// even though it may not be immediately obvious at first.
hbc_menu->add_child(context_menu_container);
_update_context_menu_stylebox();
p = view_menu->get_popup(); p = view_menu->get_popup();
accept = memnew(AcceptDialog); accept = memnew(AcceptDialog);

View file

@ -683,6 +683,10 @@ private:
void _update_camera_override_viewport(Object *p_viewport); void _update_camera_override_viewport(Object *p_viewport);
HBoxContainer *hbc_menu; HBoxContainer *hbc_menu;
// Used for secondary menu items which are displayed depending on the currently selected node
// (such as MeshInstance's "Mesh" menu).
PanelContainer *context_menu_container;
HBoxContainer *hbc_context_menu;
void _generate_selection_boxes(); void _generate_selection_boxes();
UndoRedo *undo_redo; UndoRedo *undo_redo;
@ -690,6 +694,7 @@ private:
int camera_override_viewport_id; int camera_override_viewport_id;
void _init_indicators(); void _init_indicators();
void _update_context_menu_stylebox();
void _update_gizmos_menu(); void _update_gizmos_menu();
void _update_gizmos_menu_theme(); void _update_gizmos_menu_theme();
void _init_grid(); void _init_grid();