From 039b4548675c0ad986f688b6b87379907c05db29 Mon Sep 17 00:00:00 2001 From: FredApps Date: Tue, 24 Nov 2026 11:03:23 +0100 Subject: [PATCH] Keep the resizable Export window from widening itself every frame The Output templates and List of exports tabs size their columns from the window's width, and some of their rows are a little wider than the column. In the fixed-size window that overflow was clipped; in the resizable one it widened the window, the next frame's columns took the new width, and the window grew each frame until it ran off the screen, so clicks and hovers missed their controls (nine export tests failed). - The tab body lays out in a child area fixed to the body's rect, so an overflow is clipped as before and cannot widen the window. - Each output map card takes the column's width; it took the width the card before it left, so every card was 9 points wider than the last. - The input maps column is 210 points, wide enough for its naming-pattern row; at 170 its info icon was outside the window. - The Save template and Load UI Layout pickers keep the reference titles the tests check ("Save template", "Select a UI layout file."). Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/export_templates.rs | 15 ++++++++++----- crates/ui-egui/src/export_window.rs | 19 +++++++++++++------ crates/ui-egui/src/windows.rs | 4 ++-- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/crates/ui-egui/src/export_templates.rs b/crates/ui-egui/src/export_templates.rs index 061c31cf..250de679 100644 --- a/crates/ui-egui/src/export_templates.rs +++ b/crates/ui-egui/src/export_templates.rs @@ -18,7 +18,10 @@ use crate::widgets::{chip, icon_button}; const ICON: f32 = 20.0; const LIST_WIDTH: f32 = 190.0; -const INPUTS_WIDTH: f32 = 170.0; +/// Width of the input maps column; its naming-pattern row (label, dropdown, info icon) needs about 210 +const INPUTS_WIDTH: f32 = 210.0; +/// Inner margin of an output map's card +const CARD_MARGIN: f32 = 6.0; const RENAME_ID: &str = "exp_rename"; /// The name "+" gives a new template, as in the reference const NEW_PRESET: &str = "new_export_preset"; @@ -629,9 +632,11 @@ fn outputs(app: &mut TextureCraftApp, ui: &mut Ui) { ui.label(RichText::new(tr("No outputs yet: add one above, then drag input maps onto its channels.")).color(tokens.text_dim)); } ui.add_enabled_ui(editable, |ui| { + // Every card takes the column's width, not the width a wider card before it left + let card_width = ui.available_width(); for (map_index, map) in preset.maps.iter_mut().enumerate() { let file = preview.as_ref().ok().and_then(|names| names.get(map_index).cloned().flatten()); - changed |= output_card(ui, map_index, map_count, map, file.as_deref(), &mut action); + changed |= output_card(ui, card_width, map_index, map_count, map, file.as_deref(), &mut action); ui.add_space(4.0); } }); @@ -712,11 +717,11 @@ fn preview_names(app: &mut TextureCraftApp, preset: &ExportPreset) -> Result, action: &mut Option) -> bool { +fn output_card(ui: &mut Ui, card_width: f32, mi: usize, n: usize, map: &mut MapSpec, file: Option<&str>, action: &mut Option) -> bool { let tk = Tokens::get(ui.ctx()); let mut changed = false; - egui::Frame::new().fill(tk.row).corner_radius(tk.radius).inner_margin(6.0).show(ui, |ui| { - ui.set_width(ui.available_width()); + egui::Frame::new().fill(tk.row).corner_radius(tk.radius).inner_margin(CARD_MARGIN).show(ui, |ui| { + ui.set_width((card_width - 2.0 * CARD_MARGIN).max(0.0)); ui.horizontal(|ui| { let width = ui.available_width() - 4.0 * (ICON + ui.spacing().item_spacing.x); changed |= ui diff --git a/crates/ui-egui/src/export_window.rs b/crates/ui-egui/src/export_window.rs index fc9e2f62..5c7f6780 100644 --- a/crates/ui-egui/src/export_window.rs +++ b/crates/ui-egui/src/export_window.rs @@ -1355,17 +1355,24 @@ pub fn show(app: &mut TextureCraftApp, ctx: &egui::Context) { }); }); ui.separator(); - let body_height = ui.available_height().max(0.0); - ui.allocate_ui_with_layout(vec2(ui.available_width(), body_height), egui::Layout::left_to_right(egui::Align::Min), |ui| { - ui.set_height(body_height); + let body = egui::Rect::from_min_size(ui.cursor().min, vec2(ui.available_width(), ui.available_height().max(0.0))); + + // The tabs size their columns from the body's width. A child that cannot widen the + // resizable window holds them, so an overflow is clipped instead of growing the window each frame + let mut body_ui = ui.new_child(egui::UiBuilder::new().max_rect(body).layout(egui::Layout::left_to_right(egui::Align::Min))); + body_ui.shrink_clip_rect(body); + ui.advance_cursor_after_rect(body); + let ui = &mut body_ui; + 'tab: { + ui.set_height(body.height()); match app.ui.export.tab { 1 => { crate::export_templates::tab(app, ui, &presets); - return; + break 'tab; } 2 => { list_tab(app, ui); - return; + break 'tab; } _ => {} } @@ -1385,7 +1392,7 @@ pub fn show(app: &mut TextureCraftApp, ctx: &egui::Context) { _ => global_page(app, ui, &presets), }); }); - }); + } }); }); }); diff --git a/crates/ui-egui/src/windows.rs b/crates/ui-egui/src/windows.rs index d3e7d119..f9e8fa5c 100644 --- a/crates/ui-egui/src/windows.rs +++ b/crates/ui-egui/src/windows.rs @@ -452,7 +452,7 @@ pub fn save_layout(app: &mut TextureCraftApp, mode: crate::state::Mode) { #[cfg(not(target_arch = "wasm32"))] pub fn load_layout(app: &mut TextureCraftApp) { let dir = crate::user_dir("layouts"); - let dialog = FileDialog::open().title(tr("Load UI Layout")).filter(tr("UI layout"), &["json"]).directory(dir); + let dialog = FileDialog::open().title(tr("Select a UI layout file.")).filter(tr("UI layout"), &["json"]).directory(dir); app.ask_file(dialog, Bound::App, move |app, paths| { let Some(path) = paths.first() else { return }; let result = std::fs::read(path).map_err(|e| e.to_string()).and_then(|bytes| crate::mode_layout::ModeLayout::read(&bytes)).map(|layout| { @@ -481,7 +481,7 @@ pub(crate) fn template_name_of(file_name: &str) -> &str { #[cfg(not(target_arch = "wasm32"))] pub fn save_as_template(app: &mut TextureCraftApp) { let dir = app.session.templates.dir.clone().unwrap_or_else(|| crate::user_dir("templates")); - let dialog = in_save_folder(app, FileDialog::save().title(tr("Save As Template")).filter(tr("Project template"), &["json"]), dir); + let dialog = in_save_folder(app, FileDialog::save().title(tr("Save template")).filter(tr("Project template"), &["json"]), dir); app.ask_file(dialog, Bound::Project, |app, paths| { let Some(path) = paths.first() else { return };