Skip to content

Commit 3fefbb0

Browse files
committed
Add class icons to script list
Draws icons representing the script's or doc page's class on the right side of the script editor. Supports custom icons and icons inherited from parent class.
1 parent 4788f54 commit 3fefbb0

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

editor/plugins/script_editor_plugin.cpp

+57
Original file line numberDiff line numberDiff line change
@@ -3340,6 +3340,62 @@ void ScriptEditor::_script_list_clicked(int p_item, Vector2 p_local_mouse_pos, M
33403340
}
33413341
}
33423342

3343+
void ScriptEditor::_draw_script_list() {
3344+
// Draw class icons on right side.
3345+
Size2 max_icon_size = EditorNode::get_singleton()->get_class_icon("Node")->get_size();
3346+
3347+
VScrollBar *scroll = script_list->get_v_scroll_bar();
3348+
real_t offset = -scroll->get_value();
3349+
3350+
real_t margin_right = script_list->get_theme_stylebox("panel")->get_margin(SIDE_RIGHT);
3351+
margin_right += script_list->get_theme_constant("h_separation") / 2;
3352+
if (scroll->is_visible()) {
3353+
margin_right += scroll->get_size().x;
3354+
}
3355+
3356+
for (int i = 0; i < script_list->get_item_count(); i++) {
3357+
Control *c = tab_container->get_tab_control(i);
3358+
if (!c) {
3359+
continue;
3360+
}
3361+
3362+
Ref<Texture2D> icon;
3363+
if (Object::cast_to<ScriptEditorBase>(c)) {
3364+
ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(c);
3365+
Ref<Script> scr = se->get_edited_resource();
3366+
3367+
icon = EditorNode::get_editor_data().get_script_icon(scr);
3368+
if (icon.is_null()) {
3369+
icon = EditorNode::get_singleton()->get_class_icon(scr->get_instance_base_type());
3370+
}
3371+
}
3372+
if (Object::cast_to<EditorHelp>(c)) {
3373+
EditorHelp *help = Object::cast_to<EditorHelp>(c);
3374+
icon = EditorNode::get_singleton()->get_class_icon(help->get_class());
3375+
}
3376+
3377+
if (icon.is_valid()) {
3378+
Size2 icon_size = icon->get_size();
3379+
if (icon_size.x > max_icon_size.x) {
3380+
icon_size.y = icon_size.y * (max_icon_size.x / icon_size.x);
3381+
icon_size.x = max_icon_size.x;
3382+
}
3383+
if (icon_size.y > max_icon_size.y) {
3384+
icon_size.x = icon_size.x * (max_icon_size.y / icon_size.y);
3385+
icon_size.y = max_icon_size.y;
3386+
}
3387+
Rect2 item_rect = script_list->get_item_rect(i);
3388+
real_t margin_top = (item_rect.size.y - icon_size.y) / 2;
3389+
real_t pos_from_right = max_icon_size.x - (max_icon_size.x - icon_size.x) / 2;
3390+
Rect2 icon_rect = Rect2(
3391+
item_rect.get_end().x - pos_from_right - margin_right,
3392+
item_rect.position.y + margin_top + offset,
3393+
icon_size.x, icon_size.y);
3394+
script_list->draw_texture_rect(icon, icon_rect);
3395+
}
3396+
}
3397+
}
3398+
33433399
void ScriptEditor::_make_script_list_context_menu() {
33443400
context_menu->clear();
33453401

@@ -4111,6 +4167,7 @@ ScriptEditor::ScriptEditor(WindowWrapper *p_wrapper) {
41114167
script_split->set_split_offset(70 * EDSCALE);
41124168
_sort_list_on_update = true;
41134169
script_list->connect("item_clicked", callable_mp(this, &ScriptEditor::_script_list_clicked), CONNECT_DEFERRED);
4170+
script_list->connect("draw", callable_mp(this, &ScriptEditor::_draw_script_list));
41144171
script_list->set_allow_rmb_select(true);
41154172
SET_DRAG_FORWARDING_GCD(script_list, ScriptEditor);
41164173

editor/plugins/script_editor_plugin.h

+1
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ class ScriptEditor : public PanelContainer {
469469
virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
470470

471471
void _script_list_clicked(int p_item, Vector2 p_local_mouse_pos, MouseButton p_mouse_button_index);
472+
void _draw_script_list();
472473
void _make_script_list_context_menu();
473474

474475
void _help_search(const String &p_text);

0 commit comments

Comments
 (0)