-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow adding buttons to the TabContainer
header
#80301
base: master
Are you sure you want to change the base?
Conversation
Besides that, it seems fine. However, the way it currently works (adding already created full-fledged |
I agree that the current implementation seems extra. It would be better to mimic existing examples and add a method that takes a string, a icon, and an id. Then the Other than that, feature looks great. If it's not too much work, would make sense to make use of it in scene tabs in the same PR. |
For my use-case1 I need to add
The scene tabs are using Footnotes |
Ah, right. Well, I was hoping we could remove the hackish code that we have to add buttons there, but I'm not sure if it fits the |
If that's the case, then maybe this should be generalized to allow to add any Also, the separation between the clip buttons and the first custom one is different from the separation between each custom button: |
I'd be fine with that too. I didn't need other types of Controls, but if that's what the GUI team prefers I'll change it.
I have changed the If I draw a red outline for each icon rect, and a green outline for each button rect. This shows that there is some separation caused by the button margin that I don't think we can get rid of, so the custom buttons will always look more separated. This margin seems to be determined by the button styleboxes, but since we don't create the button it's up to the user to remove this margin by setting a Drawing codediff --git a/scene/gui/button.cpp b/scene/gui/button.cpp
index 430569432ab..8438f702091 100644
--- a/scene/gui/button.cpp
+++ b/scene/gui/button.cpp
@@ -228,6 +228,8 @@ void Button::_notification(int p_what) {
style2->draw(ci, Rect2(Point2(), size));
}
+ draw_rect(Rect2(Point2(), size), Color::named("GREEN"), false, 2.0);
+
Ref<Texture2D> _icon;
if (icon.is_null() && has_theme_icon(SNAME("icon"))) {
_icon = theme_cache.icon;
@@ -319,6 +321,8 @@ void Button::_notification(int p_what) {
if (icon_region.size.width > 0) {
Rect2 icon_region_rounded = Rect2(icon_region.position.round(), icon_region.size.round());
draw_texture_rect(_icon, icon_region_rounded, false, color_icon);
+
+ draw_rect(icon_region_rounded, Color::named("RED"), false, 2.0);
}
}
diff --git a/scene/gui/tab_bar.cpp b/scene/gui/tab_bar.cpp
index 959a51eff91..d0ec7153bc3 100644
--- a/scene/gui/tab_bar.cpp
+++ b/scene/gui/tab_bar.cpp
@@ -435,11 +435,15 @@ void TabBar::_notification(int p_what) {
draw_texture(theme_cache.decrement_icon, Point2(0, vofs), Color(1, 1, 1, 0.5));
}
+ draw_rect(Rect2(Point2(0, vofs), theme_cache.decrement_icon->get_size()), Color::named("RED"), false, 2.0);
+
if (offset > 0) {
draw_texture(highlight_arrow == 0 ? theme_cache.increment_hl_icon : theme_cache.increment_icon, Point2(theme_cache.increment_icon->get_size().width, vofs));
} else {
draw_texture(theme_cache.increment_icon, Point2(theme_cache.increment_icon->get_size().width, vofs), Color(1, 1, 1, 0.5));
}
+
+ draw_rect(Rect2(Point2(theme_cache.increment_icon->get_size().width, vofs), theme_cache.increment_icon->get_size()), Color::named("RED"), false, 2.0);
} else {
if (offset > 0) {
draw_texture(highlight_arrow == 0 ? theme_cache.decrement_hl_icon : theme_cache.decrement_icon, Point2(limit_minus_buttons, vofs));
@@ -447,11 +451,15 @@ void TabBar::_notification(int p_what) {
draw_texture(theme_cache.decrement_icon, Point2(limit_minus_buttons, vofs), Color(1, 1, 1, 0.5));
}
+ draw_rect(Rect2(Point2(limit_minus_buttons, vofs), theme_cache.decrement_icon->get_size()), Color::named("RED"), false, 2.0);
+
if (missing_right) {
draw_texture(highlight_arrow == 1 ? theme_cache.increment_hl_icon : theme_cache.increment_icon, Point2(limit_minus_buttons + theme_cache.decrement_icon->get_size().width, vofs));
} else {
draw_texture(theme_cache.increment_icon, Point2(limit_minus_buttons + theme_cache.decrement_icon->get_size().width, vofs), Color(1, 1, 1, 0.5));
}
+
+ draw_rect(Rect2(Point2(limit_minus_buttons + theme_cache.decrement_icon->get_size().width, vofs), theme_cache.increment_icon->get_size()), Color::named("RED"), false, 2.0);
}
}
diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp
index e34e7d648c2..4a6aaf4e02c 100644
--- a/scene/gui/tab_container.cpp
+++ b/scene/gui/tab_container.cpp
@@ -208,8 +208,10 @@ void TabContainer::_notification(int p_what) {
if (menu_hovered) {
theme_cache.menu_hl_icon->draw(get_canvas_item(), Point2(x, (header_height - theme_cache.menu_hl_icon->get_height()) / 2));
+ draw_rect(Rect2(Point2(x, (header_height - theme_cache.menu_hl_icon->get_height()) / 2), theme_cache.menu_hl_icon->get_size()), Color::named("RED"), false, 2.0);
} else {
theme_cache.menu_icon->draw(get_canvas_item(), Point2(x, (header_height - theme_cache.menu_icon->get_height()) / 2));
+ draw_rect(Rect2(Point2(x, (header_height - theme_cache.menu_icon->get_height()) / 2), theme_cache.menu_icon->get_size()), Color::named("RED"), false, 2.0);
}
}
|
dff853b
to
a2ccdbe
Compare
My idea was more having the separation distance be the same as the container's separation. |
I'm not sure I understand, the container's separation is 0 now. We can increase the container's separation and use the same value to add separation between the container and the clip buttons and popup button, but the custom buttons will still have more separation because of the button stylebox. |
I think in the end that should be case. Also, the separation constant should be it's own theme item (that defaults to the HBox's value), since having to rely on a constant of another unrelated node (from the user's view at least) isn't great for discoverability. |
63dc767
to
fc09a28
Compare
I feel the name is as clear as it can get. 👍
Hum, I see that the default size is too much, I think |
Just to be clear, the default is |
Yeah, let's try |
fc09a28
to
c490354
Compare
c490354
to
4b14b55
Compare
However, I still think that it should be generalized to allow adding any |
IMO unless you have a signal like |
4b14b55
to
47d0072
Compare
47d0072
to
5c4a414
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method names and docs should be updated to reflect the changes.
related: godotengine/godot-proposals#2250 |
Implements methods to add/remove buttons to the
TabContainer
header, as suggested by @YeldhamDev in #80227 (comment).Preview
Example project
TabContainerButtons.zip