Skip to content

Make the position and the size of FileSystem controls more precise #105560

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions editor/filesystem_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,30 +107,34 @@ bool FileSystemList::edit_selected() {
Rect2 popup_rect;
Vector2 ofs;

Vector2 icon_size = get_item_icon(s)->get_size();
Vector2 icon_size = get_fixed_icon_size() * get_icon_scale();

// Handles the different icon modes (TOP/LEFT).
switch (get_icon_mode()) {
case ItemList::ICON_MODE_LEFT:
rect = get_item_rect(s, true);
ofs = Vector2(0, Math::floor((MAX(line_editor->get_minimum_size().height, rect.size.height) - rect.size.height) / 2));
popup_rect.position = get_screen_position() + rect.position - ofs;
popup_rect.position = rect.position - ofs;
popup_rect.size = rect.size;

// Adjust for icon position and size.
popup_rect.size.x -= icon_size.x;
popup_rect.position.x += icon_size.x;
popup_rect.size.x -= MAX(theme_cache.h_separation, 0) / 2 + icon_size.x;
popup_rect.position.x += MAX(theme_cache.h_separation, 0) / 2 + icon_size.x;
break;
case ItemList::ICON_MODE_TOP:
rect = get_item_rect(s, false);
popup_rect.position = get_screen_position() + rect.position;
popup_rect.position = rect.position;
popup_rect.size = rect.size;

// Adjust for icon position and size.
popup_rect.size.y -= icon_size.y;
popup_rect.position.y += icon_size.y;
popup_rect.size.y -= MAX(theme_cache.v_separation, 0) / 2 + theme_cache.icon_margin + icon_size.y;
popup_rect.position.y += MAX(theme_cache.v_separation, 0) / 2 + theme_cache.icon_margin + icon_size.y;
break;
}
if (is_layout_rtl()) {
popup_rect.position.x = get_size().width - popup_rect.position.x - popup_rect.size.x;
}
popup_rect.position += get_screen_position();

popup_editor->set_position(popup_rect.position);
popup_editor->set_size(popup_rect.size);
Expand Down
19 changes: 10 additions & 9 deletions scene/gui/item_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,14 @@ Rect2 ItemList::get_item_rect(int p_idx, bool p_expand) const {
ERR_FAIL_INDEX_V(p_idx, items.size(), Rect2());

Rect2 ret = items[p_idx].rect_cache;
ret.position += theme_cache.panel_style->get_offset();

if (p_expand && p_idx % current_columns == current_columns - 1) {
ret.size.width = get_size().width - ret.position.x;
int width = get_size().width - theme_cache.panel_style->get_minimum_size().width;
if (scroll_bar_v->is_visible()) {
width -= scroll_bar_v->get_combined_minimum_size().width;
}
ret.size.width = width - ret.position.x;
}
ret.position += theme_cache.panel_style->get_offset();
return ret;
}

Expand Down Expand Up @@ -1485,9 +1488,7 @@ void ItemList::_notification(int p_what) {
icon_size = items[i].get_icon_size() * icon_scale;
}

Vector2 icon_ofs;

Point2 pos = items[i].rect_cache.position + icon_ofs + base_ofs;
Point2 pos = items[i].rect_cache.position + base_ofs;

if (icon_mode == ICON_MODE_TOP) {
pos.y += MAX(theme_cache.v_separation, 0) / 2;
Expand Down Expand Up @@ -1540,14 +1541,14 @@ void ItemList::_notification(int p_what) {
tag_icon_size = items[i].tag_icon->get_size();
}

Point2 draw_pos = items[i].rect_cache.position;
Point2 draw_pos = items[i].rect_cache.position + base_ofs;
draw_pos.x += MAX(theme_cache.h_separation, 0) / 2;
draw_pos.y += MAX(theme_cache.v_separation, 0) / 2;
if (rtl) {
draw_pos.x = size.width - draw_pos.x - tag_icon_size.x;
}

draw_texture_rect(items[i].tag_icon, Rect2(draw_pos + base_ofs, tag_icon_size));
draw_texture_rect(items[i].tag_icon, Rect2(draw_pos, tag_icon_size));
}

if (!items[i].text.is_empty()) {
Expand Down Expand Up @@ -1610,7 +1611,7 @@ void ItemList::_notification(int p_what) {
text_ofs += base_ofs;
text_ofs += items[i].rect_cache.position;

float text_w = items[i].rect_cache.size.width - icon_size.x - MAX(theme_cache.h_separation, 0);
float text_w = items[i].rect_cache.size.width - icon_size.x - MAX(theme_cache.h_separation, 0) / 2 - theme_cache.icon_margin;
if (wraparound_items && items[i].rect_cache.size.width > width) {
text_w -= items[i].rect_cache.size.width - width;
}
Expand Down
14 changes: 7 additions & 7 deletions scene/gui/item_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ class ItemList : public Control {

bool do_autoscroll_to_bottom = false;

void _scroll_changed(double);
void _shape_text(int p_idx);
void _mouse_exited();

String _atr(int p_idx, const String &p_text) const;

protected:
struct ThemeCache {
int h_separation = 0;
int v_separation = 0;
Expand Down Expand Up @@ -170,13 +177,6 @@ class ItemList : public Control {
Color guide_color;
} theme_cache;

void _scroll_changed(double);
void _shape_text(int p_idx);
void _mouse_exited();

String _atr(int p_idx, const String &p_text) const;

protected:
void _notification(int p_what);
bool _set(const StringName &p_name, const Variant &p_value);
bool _get(const StringName &p_name, Variant &r_ret) const { return property_helper.property_get_value(p_name, r_ret); }
Expand Down