1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-17 14:11:06 +00:00

Add dock dragging area and highlight

This commit is contained in:
Logan Detrick
2025-05-23 15:42:54 -07:00
parent 5dd76968d8
commit 0413297f7f
4 changed files with 252 additions and 37 deletions

View File

@@ -572,48 +572,54 @@ void TabBar::_notification(int p_what) {
}
if (dragging_valid_tab) {
int x;
int closest_tab = get_closest_tab_idx_to_point(get_local_mouse_position());
if (closest_tab != -1) {
Rect2 tab_rect = get_tab_rect(closest_tab);
x = tab_rect.position.x;
// Only add the tab_separation if closest tab is not on the edge.
bool not_leftmost_tab = -1 != (rtl ? get_next_available(closest_tab) : get_previous_available(closest_tab));
bool not_rightmost_tab = -1 != (rtl ? get_previous_available(closest_tab) : get_next_available(closest_tab));
// Calculate midpoint between tabs.
if (get_local_mouse_position().x > tab_rect.get_center().x) {
x += tab_rect.size.x;
if (not_rightmost_tab) {
x += Math::ceil(0.5f * theme_cache.tab_separation);
}
} else if (not_leftmost_tab) {
x -= Math::floor(0.5f * theme_cache.tab_separation);
}
} else {
if (rtl ^ (get_local_mouse_position().x < get_tab_rect(0).position.x)) {
x = get_tab_rect(0).position.x;
if (rtl) {
x += get_tab_rect(0).size.width;
}
} else {
Rect2 tab_rect = get_tab_rect(get_tab_count() - 1);
x = tab_rect.position.x;
if (!rtl) {
x += tab_rect.size.width;
}
}
}
theme_cache.drop_mark_icon->draw(get_canvas_item(), Point2(x - theme_cache.drop_mark_icon->get_width() / 2, (size.height - theme_cache.drop_mark_icon->get_height()) / 2), theme_cache.drop_mark_color);
_draw_tab_drop(get_canvas_item());
}
} break;
}
}
void TabBar::_draw_tab_drop(RID p_canvas_item) {
Vector2 size = get_size();
int x;
bool rtl = is_layout_rtl();
int closest_tab = get_closest_tab_idx_to_point(get_local_mouse_position());
if (closest_tab != -1) {
Rect2 tab_rect = get_tab_rect(closest_tab);
x = tab_rect.position.x;
// Only add the tab_separation if closest tab is not on the edge.
bool not_leftmost_tab = -1 != (rtl ? get_next_available(closest_tab) : get_previous_available(closest_tab));
bool not_rightmost_tab = -1 != (rtl ? get_previous_available(closest_tab) : get_next_available(closest_tab));
// Calculate midpoint between tabs.
if (get_local_mouse_position().x > tab_rect.get_center().x) {
x += tab_rect.size.x;
if (not_rightmost_tab) {
x += Math::ceil(0.5f * theme_cache.tab_separation);
}
} else if (not_leftmost_tab) {
x -= Math::floor(0.5f * theme_cache.tab_separation);
}
} else {
if (rtl ^ (get_local_mouse_position().x < get_tab_rect(0).position.x)) {
x = get_tab_rect(0).position.x;
if (rtl) {
x += get_tab_rect(0).size.width;
}
} else {
Rect2 tab_rect = get_tab_rect(get_tab_count() - 1);
x = tab_rect.position.x;
if (!rtl) {
x += tab_rect.size.width;
}
}
}
theme_cache.drop_mark_icon->draw(p_canvas_item, Point2(x - theme_cache.drop_mark_icon->get_width() / 2, (size.height - theme_cache.drop_mark_icon->get_height()) / 2), theme_cache.drop_mark_color);
}
void TabBar::_draw_tab(Ref<StyleBox> &p_tab_style, Color &p_font_color, int p_index, float p_x, bool p_focus) {
RID ci = get_canvas_item();
bool rtl = is_layout_rtl();