Skip to content

Commit

Permalink
Implement automatic translation for ItemList
Browse files Browse the repository at this point in the history
  • Loading branch information
DennisManaa committed Oct 23, 2023
1 parent 7f884b4 commit 1a1c542
Show file tree
Hide file tree
Showing 20 changed files with 40 additions and 2 deletions.
1 change: 1 addition & 0 deletions editor/create_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,7 @@ CreateDialog::CreateDialog() {
rec_vb->set_v_size_flags(Control::SIZE_EXPAND_FILL);

recent = memnew(ItemList);
recent->set_auto_translate(false);
rec_vb->add_margin_child(TTR("Recent:"), recent, true);
recent->set_allow_reselect(true);
recent->connect("item_selected", callable_mp(this, &CreateDialog::_history_selected));
Expand Down
1 change: 1 addition & 0 deletions editor/dependency_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ DependencyEditorOwners::DependencyEditorOwners() {
file_options->connect("id_pressed", callable_mp(this, &DependencyEditorOwners::_file_option));

owners = memnew(ItemList);
owners->set_auto_translate(false);
owners->set_select_mode(ItemList::SELECT_MULTI);
owners->connect("item_clicked", callable_mp(this, &DependencyEditorOwners::_list_rmb_clicked));
owners->connect("item_activated", callable_mp(this, &DependencyEditorOwners::_select_file));
Expand Down
1 change: 1 addition & 0 deletions editor/editor_about.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ ScrollContainer *EditorAbout::_populate_list(const String &p_name, const List<St
vbc->add_child(lbl);

ItemList *il = memnew(ItemList);
il->set_auto_translate(false);
il->set_h_size_flags(Control::SIZE_EXPAND_FILL);
il->set_same_column_width(true);
il->set_auto_height(true);
Expand Down
1 change: 1 addition & 0 deletions editor/editor_layouts_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ EditorLayoutsDialog::EditorLayoutsDialog() {
add_child(makevb);

layout_names = memnew(ItemList);
layout_names->set_auto_translate(false);
layout_names->set_auto_height(true);
layout_names->set_custom_minimum_size(Size2(300 * EDSCALE, 50 * EDSCALE));
layout_names->set_visible(true);
Expand Down
1 change: 1 addition & 0 deletions editor/export/project_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,7 @@ ProjectExportDialog::ProjectExportDialog() {
preset_vb->add_child(mc);
mc->set_v_size_flags(Control::SIZE_EXPAND_FILL);
presets = memnew(ItemList);
presets->set_auto_translate(false);
SET_DRAG_FORWARDING_GCD(presets, ProjectExportDialog);
mc->add_child(presets);
presets->connect("item_selected", callable_mp(this, &ProjectExportDialog::_edit_preset));
Expand Down
3 changes: 3 additions & 0 deletions editor/gui/editor_file_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1879,6 +1879,7 @@ EditorFileDialog::EditorFileDialog() {
fav_down->connect("pressed", callable_mp(this, &EditorFileDialog::_favorite_move_down));

favorites = memnew(ItemList);
favorites->set_auto_translate(false);
fav_vb->add_child(favorites);
favorites->set_v_size_flags(Control::SIZE_EXPAND_FILL);
favorites->connect("item_selected", callable_mp(this, &EditorFileDialog::_favorite_selected));
Expand All @@ -1888,6 +1889,7 @@ EditorFileDialog::EditorFileDialog() {
rec_vb->set_custom_minimum_size(Size2(150, 100) * EDSCALE);
rec_vb->set_v_size_flags(Control::SIZE_EXPAND_FILL);
recent = memnew(ItemList);
recent->set_auto_translate(false);
recent->set_allow_reselect(true);
rec_vb->add_margin_child(TTR("Recent:"), recent, true);
recent->connect("item_selected", callable_mp(this, &EditorFileDialog::_recent_selected));
Expand All @@ -1911,6 +1913,7 @@ EditorFileDialog::EditorFileDialog() {
// Item (files and folders) list with context menu.

item_list = memnew(ItemList);
item_list->set_auto_translate(false);
item_list->set_v_size_flags(Control::SIZE_EXPAND_FILL);
item_list->connect("item_clicked", callable_mp(this, &EditorFileDialog::_item_list_item_rmb_clicked));
item_list->connect("empty_clicked", callable_mp(this, &EditorFileDialog::_item_list_empty_clicked));
Expand Down
1 change: 1 addition & 0 deletions editor/history_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ HistoryDock::HistoryDock() {
global_history_checkbox->connect("toggled", callable_mp(this, &HistoryDock::refresh_history).unbind(1));

action_list = memnew(ItemList);
action_list->set_auto_translate(false);
add_child(action_list);
action_list->set_v_size_flags(Control::SIZE_EXPAND_FILL);
action_list->connect("item_selected", callable_mp(this, &HistoryDock::seek_history));
Expand Down
3 changes: 3 additions & 0 deletions editor/plugins/script_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3865,6 +3865,7 @@ ScriptEditor::ScriptEditor(WindowWrapper *p_wrapper) {
scripts_vbox->add_child(filter_scripts);

script_list = memnew(ItemList);
script_list->set_auto_translate(false);
scripts_vbox->add_child(script_list);
script_list->set_custom_minimum_size(Size2(150, 60) * EDSCALE); //need to give a bit of limit to avoid it from disappearing
script_list->set_v_size_flags(SIZE_EXPAND_FILL);
Expand Down Expand Up @@ -3909,6 +3910,7 @@ ScriptEditor::ScriptEditor(WindowWrapper *p_wrapper) {
overview_vbox->add_child(filter_methods);

members_overview = memnew(ItemList);
members_overview->set_auto_translate(false);
overview_vbox->add_child(members_overview);

members_overview->set_allow_reselect(true);
Expand All @@ -3917,6 +3919,7 @@ ScriptEditor::ScriptEditor(WindowWrapper *p_wrapper) {
members_overview->set_allow_rmb_select(true);

help_overview = memnew(ItemList);
help_overview->set_auto_translate(false);
overview_vbox->add_child(help_overview);
help_overview->set_allow_reselect(true);
help_overview->set_custom_minimum_size(Size2(0, 60) * EDSCALE); //need to give a bit of limit to avoid it from disappearing
Expand Down
1 change: 1 addition & 0 deletions editor/plugins/shader_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,7 @@ ShaderEditorPlugin::ShaderEditorPlugin() {
}

shader_list = memnew(ItemList);
shader_list->set_auto_translate(false);
shader_list->set_v_size_flags(Control::SIZE_EXPAND_FILL);
vb->add_child(shader_list);
shader_list->connect("item_selected", callable_mp(this, &ShaderEditorPlugin::_shader_selected));
Expand Down
1 change: 1 addition & 0 deletions editor/plugins/shader_file_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ ShaderFileEditor::ShaderFileEditor() {
add_child(main_hs);

versions = memnew(ItemList);
versions->set_auto_translate(false);
versions->connect("item_selected", callable_mp(this, &ShaderFileEditor::_version_selected));
versions->set_custom_minimum_size(Size2i(200 * EDSCALE, 0));
main_hs->add_child(versions);
Expand Down
1 change: 1 addition & 0 deletions editor/plugins/sprite_frames_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1879,6 +1879,7 @@ SpriteFramesEditor::SpriteFramesEditor() {
add_child(file);

frame_list = memnew(ItemList);
frame_list->set_auto_translate(false);
frame_list->set_v_size_flags(SIZE_EXPAND_FILL);
frame_list->set_icon_mode(ItemList::ICON_MODE_TOP);
frame_list->set_texture_filter(TEXTURE_FILTER_NEAREST_WITH_MIPMAPS);
Expand Down
1 change: 1 addition & 0 deletions editor/plugins/theme_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2247,6 +2247,7 @@ ThemeTypeDialog::ThemeTypeDialog() {
add_type_vb->add_child(add_type_options_label);

add_type_options = memnew(ItemList);
add_type_options->set_auto_translate(false);
add_type_options->set_v_size_flags(Control::SIZE_EXPAND_FILL);
add_type_vb->add_child(add_type_options);
add_type_options->connect("item_selected", callable_mp(this, &ThemeTypeDialog::_add_type_options_cbk));
Expand Down
1 change: 1 addition & 0 deletions editor/plugins/tiles/atlas_merging_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ AtlasMergingDialog::AtlasMergingDialog() {

// Atlas sources item list.
atlas_merging_atlases_list = memnew(ItemList);
atlas_merging_atlases_list->set_auto_translate(false);
atlas_merging_atlases_list->set_fixed_icon_size(Size2(60, 60) * EDSCALE);
atlas_merging_atlases_list->set_h_size_flags(Control::SIZE_EXPAND_FILL);
atlas_merging_atlases_list->set_v_size_flags(Control::SIZE_EXPAND_FILL);
Expand Down
4 changes: 4 additions & 0 deletions editor/plugins/tiles/tile_map_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2418,6 +2418,7 @@ TileMapEditorTilesPlugin::TileMapEditorTilesPlugin() {
sources_bottom_actions->add_child(source_sort_button);

sources_list = memnew(ItemList);
sources_list->set_auto_translate(false);
sources_list->set_fixed_icon_size(Size2(60, 60) * EDSCALE);
sources_list->set_h_size_flags(Control::SIZE_EXPAND_FILL);
sources_list->set_v_size_flags(Control::SIZE_EXPAND_FILL);
Expand Down Expand Up @@ -2457,6 +2458,7 @@ TileMapEditorTilesPlugin::TileMapEditorTilesPlugin() {

// Scenes collection source.
scene_tiles_list = memnew(ItemList);
scene_tiles_list->set_auto_translate(false);
scene_tiles_list->set_h_size_flags(Control::SIZE_EXPAND_FILL);
scene_tiles_list->set_v_size_flags(Control::SIZE_EXPAND_FILL);
scene_tiles_list->set_select_mode(ItemList::SELECT_MULTI);
Expand All @@ -2482,6 +2484,7 @@ TileMapEditorTilesPlugin::TileMapEditorTilesPlugin() {

int thumbnail_size = 64;
patterns_item_list = memnew(ItemList);
patterns_item_list->set_auto_translate(false);
patterns_item_list->set_max_columns(0);
patterns_item_list->set_icon_mode(ItemList::ICON_MODE_TOP);
patterns_item_list->set_fixed_column_width(thumbnail_size * 3 / 2);
Expand Down Expand Up @@ -3555,6 +3558,7 @@ TileMapEditorTerrainsPlugin::TileMapEditorTerrainsPlugin() {
tilemap_tab_terrains->add_child(terrains_tree);

terrains_tile_list = memnew(ItemList);
terrains_tile_list->set_auto_translate(false);
terrains_tile_list->set_h_size_flags(Control::SIZE_EXPAND_FILL);
terrains_tile_list->set_max_columns(0);
terrains_tile_list->set_same_column_width(true);
Expand Down
3 changes: 3 additions & 0 deletions editor/plugins/tiles/tile_proxies_manager_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ TileProxiesManagerDialog::TileProxiesManagerDialog() {
vbox_container->add_child(source_level_label);

source_level_list = memnew(ItemList);
source_level_list->set_auto_translate(false);
source_level_list->set_v_size_flags(Control::SIZE_EXPAND_FILL);
source_level_list->set_select_mode(ItemList::SELECT_MULTI);
source_level_list->set_allow_rmb_select(true);
Expand All @@ -356,6 +357,7 @@ TileProxiesManagerDialog::TileProxiesManagerDialog() {
vbox_container->add_child(coords_level_label);

coords_level_list = memnew(ItemList);
coords_level_list->set_auto_translate(false);
coords_level_list->set_v_size_flags(Control::SIZE_EXPAND_FILL);
coords_level_list->set_select_mode(ItemList::SELECT_MULTI);
coords_level_list->set_allow_rmb_select(true);
Expand All @@ -367,6 +369,7 @@ TileProxiesManagerDialog::TileProxiesManagerDialog() {
vbox_container->add_child(alternative_level_label);

alternative_level_list = memnew(ItemList);
alternative_level_list->set_auto_translate(false);
alternative_level_list->set_v_size_flags(Control::SIZE_EXPAND_FILL);
alternative_level_list->set_select_mode(ItemList::SELECT_MULTI);
alternative_level_list->set_allow_rmb_select(true);
Expand Down
2 changes: 2 additions & 0 deletions editor/plugins/tiles/tile_set_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,7 @@ TileSetEditor::TileSetEditor() {
p->set_item_checked(TilesEditorUtils::SOURCE_SORT_ID, true);

sources_list = memnew(ItemList);
sources_list->set_auto_translate(false);
sources_list->set_fixed_icon_size(Size2(60, 60) * EDSCALE);
sources_list->set_h_size_flags(SIZE_EXPAND_FILL);
sources_list->set_v_size_flags(SIZE_EXPAND_FILL);
Expand Down Expand Up @@ -934,6 +935,7 @@ TileSetEditor::TileSetEditor() {
//// Patterns ////
int thumbnail_size = 64;
patterns_item_list = memnew(ItemList);
patterns_item_list->set_auto_translate(false);
patterns_item_list->set_max_columns(0);
patterns_item_list->set_icon_mode(ItemList::ICON_MODE_TOP);
patterns_item_list->set_fixed_column_width(thumbnail_size * 3 / 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ TileSetScenesCollectionSourceEditor::TileSetScenesCollectionSourceEditor() {
split_container_right_side->add_child(right_vbox_container);

scene_tiles_list = memnew(ItemList);
scene_tiles_list->set_auto_translate(false);
scene_tiles_list->set_h_size_flags(SIZE_EXPAND_FILL);
scene_tiles_list->set_v_size_flags(SIZE_EXPAND_FILL);
SET_DRAG_FORWARDING_CDU(scene_tiles_list, TileSetScenesCollectionSourceEditor);
Expand Down
1 change: 1 addition & 0 deletions modules/gridmap/editor/grid_map_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,7 @@ GridMapEditor::GridMapEditor() {
EDITOR_DEF("editors/grid_map/preview_size", 64);

mesh_library_palette = memnew(ItemList);
mesh_library_palette->set_auto_translate(false);
add_child(mesh_library_palette);
mesh_library_palette->set_v_size_flags(SIZE_EXPAND_FILL);
mesh_library_palette->connect("gui_input", callable_mp(this, &GridMapEditor::_mesh_library_palette_input));
Expand Down
13 changes: 11 additions & 2 deletions scene/gui/item_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void ItemList::_shape_text(int p_idx) {
} else {
item.text_buf->set_direction((TextServer::Direction)item.text_direction);
}
item.text_buf->add_string(item.text, theme_cache.font, theme_cache.font_size, item.language);
item.text_buf->add_string(item.xl_text, theme_cache.font, theme_cache.font_size, item.language);
if (icon_mode == ICON_MODE_TOP && max_text_lines > 0) {
item.text_buf->set_break_flags(TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND | TextServer::BREAK_GRAPHEME_BOUND | TextServer::BREAK_TRIM_EDGE_SPACES);
} else {
Expand All @@ -58,6 +58,7 @@ int ItemList::add_item(const String &p_item, const Ref<Texture2D> &p_texture, bo
Item item;
item.icon = p_texture;
item.text = p_item;
item.xl_text = atr(p_item);
item.selectable = p_selectable;
items.push_back(item);
int item_id = items.size() - 1;
Expand Down Expand Up @@ -94,6 +95,7 @@ void ItemList::set_item_text(int p_idx, const String &p_text) {
}

items.write[p_idx].text = p_text;
items.write[p_idx].xl_text = atr(p_text);
_shape_text(p_idx);
queue_redraw();
shape_changed = true;
Expand Down Expand Up @@ -1001,14 +1003,21 @@ void ItemList::_notification(int p_what) {
} break;

case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
case NOTIFICATION_TRANSLATION_CHANGED:
case NOTIFICATION_THEME_CHANGED: {
for (int i = 0; i < items.size(); i++) {
_shape_text(i);
}
shape_changed = true;
queue_redraw();
} break;
case NOTIFICATION_TRANSLATION_CHANGED: {
for (int i = 0; i < items.size(); i++) {
items.write[i].xl_text = atr(items[i].text);
_shape_text(i);
}
shape_changed = true;
queue_redraw();
} break;

case NOTIFICATION_DRAW: {
force_update_list_size();
Expand Down
1 change: 1 addition & 0 deletions scene/gui/item_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class ItemList : public Control {
Color icon_modulate = Color(1, 1, 1, 1);
Ref<Texture2D> tag_icon;
String text;
String xl_text;
Ref<TextParagraph> text_buf;
String language;
TextDirection text_direction = TEXT_DIRECTION_AUTO;
Expand Down

0 comments on commit 1a1c542

Please sign in to comment.