Skip to content
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

Fix LineEdit minimum width #45923

Merged
merged 1 commit into from
Feb 12, 2021
Merged
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
2 changes: 1 addition & 1 deletion editor/scene_tree_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2841,7 +2841,7 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel
filter->set_h_size_flags(SIZE_EXPAND_FILL);
filter->set_placeholder(TTR("Filter nodes"));
filter_hbc->add_child(filter);
filter->add_theme_constant_override("minimum_spaces", 0);
filter->add_theme_constant_override("minimum_character_width", 0);
filter->connect("text_changed", callable_mp(this, &SceneTreeDock::_filter_changed));

button_create_script = memnew(Button);
Expand Down
2 changes: 1 addition & 1 deletion editor/scene_tree_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,7 @@ SceneTreeDialog::SceneTreeDialog() {
filter = memnew(LineEdit);
filter->set_h_size_flags(Control::SIZE_EXPAND_FILL);
filter->set_placeholder(TTR("Filter nodes"));
filter->add_theme_constant_override("minimum_spaces", 0);
filter->add_theme_constant_override("minimum_character_width", 0);
filter->connect("text_changed", callable_mp(this, &SceneTreeDialog::_filter_changed));
vbc->add_child(filter);

Expand Down
2 changes: 1 addition & 1 deletion modules/gridmap/grid_map_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,7 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
floor->set_min(-32767);
floor->set_max(32767);
floor->set_step(1);
floor->get_line_edit()->add_theme_constant_override("minimum_spaces", 16);
floor->get_line_edit()->add_theme_constant_override("minimum_character_width", 16);

spatial_editor_hb->add_child(floor);
floor->connect("value_changed", callable_mp(this, &GridMapEditor::_floor_changed));
Expand Down
6 changes: 3 additions & 3 deletions scene/gui/line_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1568,12 +1568,12 @@ Size2 LineEdit::get_minimum_size() const {
Size2 min_size;

// Minimum size of text.
int space_size = font->get_char_size(' ', 0, font_size).x;
min_size.width = get_theme_constant("minimum_spaces") * space_size;
int em_space_size = font->get_char_size('M', 0, font_size).x;
min_size.width = get_theme_constant("minimum_character_width'") * em_space_size;

if (expand_to_text_length) {
// Add a space because some fonts are too exact, and because cursor needs a bit more when at the end.
min_size.width = MAX(min_size.width, full_width + space_size);
min_size.width = MAX(min_size.width, full_width + em_space_size);
}

min_size.height = MAX(TS->shaped_text_get_size(text_rid).y + font->get_spacing(Font::SPACING_TOP) + font->get_spacing(Font::SPACING_BOTTOM), font->get_height(font_size));
Expand Down
2 changes: 1 addition & 1 deletion scene/gui/text_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,7 @@ void TextEdit::_notification(int p_what) {
l_caret.size.y = h;
}
l_caret.position += Vector2(char_margin + ofs_x, ofs_y);
l_caret.size.x = cache.font->get_char_size('m', 0, cache.font_size).x;
l_caret.size.x = cache.font->get_char_size('M', 0, cache.font_size).x;

draw_rect(l_caret, cache.caret_color, false);
}
Expand Down
2 changes: 1 addition & 1 deletion scene/resources/default_theme/default_theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
theme->set_color("clear_button_color", "LineEdit", control_font_color);
theme->set_color("clear_button_color_pressed", "LineEdit", control_font_pressed_color);

theme->set_constant("minimum_spaces", "LineEdit", 12 * scale);
theme->set_constant("minimum_character_width", "LineEdit", 4);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference, this is multiplied by the font, which is usually multiplied by the editor (or theme) scale, so multiplication for scale here was not needed.


theme->set_icon("clear", "LineEdit", make_icon(line_edit_clear_png));

Expand Down