paint: improve mesh rename

This commit is contained in:
luboslenco
2026-06-10 18:38:00 +02:00
parent ae0090b19c
commit e30e1df2da
3 changed files with 50 additions and 37 deletions
+1
View File
@@ -317,6 +317,7 @@ bool ui_box_click_to_hide = true;
i32 ui_box_modalw = 400;
i32 ui_box_modalh = 170;
ui_handle_t *tab_layers_layer_name_handle;
ui_handle_t *tab_meshes_mesh_name_handle;
slot_layer_t *tab_layers_l;
gpu_texture_t *util_uv_uvmap = NULL;
bool util_uv_uvmap_cached = false;
+3
View File
@@ -528,6 +528,9 @@ void _kickstart() {
tab_layers_layer_name_handle = ui_handle_create();
gc_root(tab_layers_layer_name_handle);
tab_meshes_mesh_name_handle = ui_handle_create();
gc_root(tab_meshes_mesh_name_handle);
render_path_raytrace_f32a = f32_array_create(24);
gc_root(render_path_raytrace_f32a);
render_path_raytrace_help_mat = mat4_identity();
+46 -37
View File
@@ -4,8 +4,9 @@
extern buffer_t *slot_material_default_canvas;
i32 _tab_meshes_draw_i;
any_map_t *tab_meshes_preview_map = NULL;
any_map_t *tab_meshes_override_map = NULL; // object uid -> overridden material index
i32 tab_meshes_mesh_name_edit = -1;
any_map_t *tab_meshes_preview_map = NULL;
any_map_t *tab_meshes_override_map = NULL; // object uid -> overridden material index
void tab_meshes_set_override(mesh_object_t *o, i32 mat_index) {
// Render an object with a chosen material instead of the painted layers
@@ -266,21 +267,6 @@ void tab_meshes_draw_context_menu() {
// script = string_copy(hscript->text);
// any_map_set(sim_object_script_map, g_context->selected_object, script);
f32_array_t *row = f32_array_create_from_raw(
(f32[]){
1 / 4.0,
3 / 4.0,
},
2);
ui_row(row);
ui_text("Name", UI_ALIGN_LEFT, 0x00000000);
h = ui_handle(__ID__);
h->text = string_copy(o->base->name);
char *new_name = string_copy(ui_text_input(h, "", UI_ALIGN_LEFT, true, false));
tab_stages_rename_object(o->base->name, new_name);
o->base->name = new_name;
o->data->name = string_copy(o->base->name);
// Material override
string_array_t *mat_combo = string_array_create(0);
string_array_push(mat_combo, ""); // Empty = use painted layers
@@ -701,30 +687,53 @@ void tab_meshes_draw_mesh_slot(mesh_object_t *o, i32 i) {
g_ui->_x = name_x;
g_ui->_y = uiy + center;
g_ui->_w = name_right - name_x;
ui_text(o->base->name, UI_ALIGN_LEFT, 0x00000000);
// Row interaction
f32 row_left = uix + uiw * 0.08;
bool hovered = g_ui->enabled && g_ui->input_enabled && g_ui->input_x > g_ui->_window_x + row_left && g_ui->input_x < g_ui->_window_x + uix + uiw &&
g_ui->input_y > g_ui->_window_y + uiy && g_ui->input_y < g_ui->_window_y + uiy + step * 2 * UI_SCALE();
if (hovered) {
ui_tooltip(o->base->name);
if (g_ui->input_started) {
g_context->paint_object = o;
bool over_name = g_ui->input_x > g_ui->_window_x + name_x && g_ui->input_x < g_ui->_window_x + name_right;
if (tab_meshes_mesh_name_edit == o->base->uid) {
tab_meshes_mesh_name_handle->text = string_copy(o->base->name);
char *new_name = string_copy(ui_text_input(tab_meshes_mesh_name_handle, "", UI_ALIGN_LEFT, true, false));
tab_stages_rename_object(o->base->name, new_name);
o->base->name = new_name;
o->data->name = string_copy(o->base->name);
if (g_ui->text_selected_handle != tab_meshes_mesh_name_handle) {
tab_meshes_mesh_name_edit = -1;
}
// Double click to show only this mesh
if (g_ui->input_released) {
if (sys_time() - g_context->select_time < 0.2) {
tab_layers_apply_filter(i + 1);
}
else {
ui_text(o->base->name, UI_ALIGN_LEFT, 0x00000000);
// Row interaction
f32 row_left = uix + uiw * 0.08;
bool hovered = g_ui->enabled && g_ui->input_enabled && g_ui->input_x > g_ui->_window_x + row_left && g_ui->input_x < g_ui->_window_x + uix + uiw &&
g_ui->input_y > g_ui->_window_y + uiy && g_ui->input_y < g_ui->_window_y + uiy + step * 2 * UI_SCALE();
if (hovered) {
ui_tooltip(o->base->name);
if (g_ui->input_started) {
g_context->paint_object = o;
}
if (sys_time() - g_context->select_time > 0.2) {
g_context->select_time = sys_time();
if (g_ui->input_released) {
if (sys_time() - g_context->select_time < 0.2) {
if (over_name) {
// Double click name to rename
tab_meshes_mesh_name_edit = o->base->uid;
tab_meshes_mesh_name_handle->text = string_copy(o->base->name);
ui_start_text_edit(tab_meshes_mesh_name_handle, UI_ALIGN_LEFT);
}
else {
// Double click to show only this mesh
tab_layers_apply_filter(i + 1);
}
}
if (sys_time() - g_context->select_time > 0.2) {
g_context->select_time = sys_time();
}
}
if (g_ui->input_released_r) {
g_context->paint_object = o;
_tab_meshes_draw_i = i;
ui_menu_draw(&tab_meshes_draw_context_menu, -1, -1);
}
}
if (g_ui->input_released_r) {
g_context->paint_object = o;
_tab_meshes_draw_i = i;
ui_menu_draw(&tab_meshes_draw_context_menu, -1, -1);
}
}