summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2019-09-20 23:15:40 +0200
committerGitHub <noreply@github.com>2019-09-20 23:15:40 +0200
commitd249bb37e5b7c90bb901247760311d1afc787605 (patch)
treea3449dcf57d4fe7f2d8098467a8b376155a248cc
parentf7cd50e900593e1e904a30124d4c6b622b878c22 (diff)
parent9e5f1d664165ad218c7d6c2248db7b5dd69a750d (diff)
Merge pull request #32112 from Calinou/project-manager-add-hover-style
Add an "hover" style to items in the project manager
-rw-r--r--editor/editor_themes.cpp5
-rw-r--r--editor/project_manager.cpp22
2 files changed, 27 insertions, 0 deletions
diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp
index 31b21a6273..42c55681ae 100644
--- a/editor/editor_themes.cpp
+++ b/editor/editor_themes.cpp
@@ -714,6 +714,11 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
style_tree_btn->set_border_width_all(0);
theme->set_stylebox("button_pressed", "Tree", style_tree_btn);
+ Ref<StyleBoxFlat> style_tree_hover = style_default->duplicate();
+ style_tree_hover->set_bg_color(highlight_color * Color(1, 1, 1, 0.4));
+ style_tree_hover->set_border_width_all(0);
+ theme->set_stylebox("hover", "Tree", style_tree_hover);
+
Ref<StyleBoxFlat> style_tree_focus = style_default->duplicate();
style_tree_focus->set_bg_color(highlight_color);
style_tree_focus->set_border_width_all(0);
diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp
index c6e3dc1e32..701676a7f8 100644
--- a/editor/project_manager.cpp
+++ b/editor/project_manager.cpp
@@ -928,16 +928,36 @@ public:
TextureButton *favorite_button;
TextureRect *icon;
bool icon_needs_reload;
+ bool hover;
ProjectListItemControl() {
favorite_button = NULL;
icon = NULL;
icon_needs_reload = true;
+ hover = false;
}
void set_is_favorite(bool fav) {
favorite_button->set_modulate(fav ? Color(1, 1, 1, 1) : Color(1, 1, 1, 0.2));
}
+
+ void _notification(int p_what) {
+ switch (p_what) {
+ case NOTIFICATION_MOUSE_ENTER: {
+ hover = true;
+ update();
+ } break;
+ case NOTIFICATION_MOUSE_EXIT: {
+ hover = false;
+ update();
+ } break;
+ case NOTIFICATION_DRAW: {
+ if (hover) {
+ draw_style_box(get_stylebox("hover", "Tree"), Rect2(Point2(), get_size() - Size2(10, 0) * EDSCALE));
+ }
+ } break;
+ }
+ }
};
class ProjectList : public ScrollContainer {
@@ -1260,6 +1280,8 @@ void ProjectList::create_project_item_control(int p_index) {
TextureButton *favorite = memnew(TextureButton);
favorite->set_name("FavoriteButton");
favorite->set_normal_texture(favorite_icon);
+ // This makes the project's "hover" style display correctly when hovering the favorite icon
+ favorite->set_mouse_filter(MOUSE_FILTER_PASS);
favorite->connect("pressed", this, "_favorite_pressed", varray(hb));
favorite_box->add_child(favorite);
favorite_box->set_alignment(BoxContainer::ALIGN_CENTER);