From f41eda63ddf472a089b405345ee1c2f53284ab30 Mon Sep 17 00:00:00 2001 From: Rebornim Date: Thu, 5 Nov 2026 01:05:40 +0000 Subject: [PATCH 1/5] UI: mode buttons at the right end of the top bar, tool controls scroll when they don't fit The Painting, Bake and Render buttons move from the left tool shelf to the right end of the top bar, which now shows in every mode. The view and mode buttons keep their place; the tool controls scroll in their own strip with arrow buttons and the horizontal wheel instead of drawing over them. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/toolbar.rs | 243 ++++++++++++++++++++------------- crates/ui-egui/src/viewport.rs | 2 +- crates/ui-egui/src/widgets.rs | 14 +- 3 files changed, 160 insertions(+), 99 deletions(-) diff --git a/crates/ui-egui/src/toolbar.rs b/crates/ui-egui/src/toolbar.rs index 2c900ed3..49553015 100644 --- a/crates/ui-egui/src/toolbar.rs +++ b/crates/ui-egui/src/toolbar.rs @@ -1,5 +1,5 @@ //! The context tool bar (brush size, flow, stroke opacity, spacing, lazy mouse, symmetry, view -//! toggles), the vertical tool shelf, the right icon rail and the status bar. +//! toggles, mode buttons), the vertical tool shelf, the right icon rail and the status bar. use egui::{RichText, vec2}; use egui_phosphor::regular as ic; @@ -12,7 +12,7 @@ use crate::i18n::{tr, trf}; use crate::keymap::tip; use crate::state::{Mode, ViewLayout}; use crate::theme::{GUTTER, Tokens, card}; -use crate::widgets::{bar_slider, icon_button}; +use crate::widgets::{bar_slider, icon_button, icon_button_without_tooltip}; pub fn tool_icon(t: Tool) -> &'static str { match t { @@ -34,84 +34,15 @@ pub fn paint_bar(app: &mut TextureCraftApp, ui: &mut egui::Ui) { card(ui, &tokens, egui::Margin { bottom: GUTTER, ..Default::default() }, egui::Margin::symmetric(8, 0), |ui| { ui.horizontal_centered(|ui| { ui.spacing_mut().item_spacing.x = 10.0; - let tool = app.session.tool.tool; - ui.label(RichText::new(tool_icon(tool)).size(15.0).color(tokens.text_strong)).on_hover_text(tool.label()); - let brush = &mut app.session.tool.brush; - match tool { - Tool::Paint | Tool::Eraser | Tool::Projection | Tool::Smudge | Tool::Clone | Tool::Path => { - let mut size = brush.size / 0.25 * 100.0; - if bar_slider(ui, tr("Size"), &mut size, 0.05..=100.0, 110.0).changed() { - brush.size = (size / 100.0 * 0.25).clamp(0.0005, 0.25); - } - let mut flow = brush.flow * 100.0; - if bar_slider(ui, tr("Flow"), &mut flow, 0.0..=100.0, 100.0).changed() { - brush.flow = flow / 100.0; - } - let mut opacity = brush.opacity * 100.0; - if bar_slider(ui, tr("Stroke opacity"), &mut opacity, 0.0..=100.0, 110.0).changed() { - brush.opacity = opacity / 100.0; - } - let mut spacing = brush.spacing * 100.0; - if bar_slider(ui, tr("Spacing"), &mut spacing, 1.0..=200.0, 100.0).changed() { - brush.spacing = spacing / 100.0; - } - ui.separator(); - let lazy_on = brush.lazy > 0.0; - if icon_button(ui, ic::SCRIBBLE, tr("Lazy mouse"), lazy_on, 24.0).clicked() { - brush.lazy = if lazy_on { 0.0 } else { 20.0 }; - } - if lazy_on { - let mut distance = brush.lazy; - if bar_slider(ui, tr("Distance"), &mut distance, 1.0..=200.0, 90.0).changed() { - brush.lazy = distance; - } - } - ui.separator(); - if icon_button(ui, ic::FLIP_HORIZONTAL, tr("Symmetry (X)"), brush.symmetry.x, 24.0).clicked() { - brush.symmetry.x = !brush.symmetry.x; - } - if icon_button(ui, ic::FLIP_VERTICAL, tr("Symmetry (Y)"), brush.symmetry.y, 24.0).clicked() { - brush.symmetry.y = !brush.symmetry.y; - } - if icon_button(ui, ic::CLOUD_RAIN, tr("Particle brush: particles slide down the surface"), brush.particles.enabled, 24.0).clicked() { - brush.particles.enabled = !brush.particles.enabled; - } - if tool == Tool::Smudge { - ui.separator(); - let mut strength = app.session.tool.smudge_strength * 100.0; - if bar_slider(ui, tr("Strength"), &mut strength, 0.0..=100.0, 100.0).changed() { - app.session.tool.smudge_strength = (strength / 100.0).clamp(0.0, 1.0); - } - } - if tool == Tool::Clone && app.session.tool.clone_source.is_none() { - ui.separator(); - ui.label(RichText::new(tr("Hold V and click the mesh to set the clone source")).color(tokens.text_dim)); - } - if tool == Tool::Path { - ui.separator(); - path_controls(app, ui); - } - } - Tool::PolygonFill => { - use texturecraft_engine::FillMode; - for (fill_mode, icon, tip) in [ - (FillMode::Triangle, ic::POLYGON, tr("Triangle fill")), - (FillMode::UvIsland, ic::SHAPES, tr("UV island fill")), - (FillMode::Mesh, ic::CUBE, tr("Mesh fill")), - ] { - if icon_button(ui, icon, tip, app.session.tool.fill_mode == fill_mode, 24.0).clicked() { - app.session.tool.fill_mode = fill_mode; - } - } - } - Tool::ColorPicker => { - ui.label(RichText::new(tr("Click the mesh to pick its material into the brush")).color(tokens.text_dim)); - } - Tool::GeometryMask => { - ui.label(RichText::new(tr("Click a mesh part to show or hide the selected layer on it.")).color(tokens.text_dim)); - } - } ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { + mode_buttons(app, ui); + + // Bake and Render modes have no brush, so their bar holds only the mode buttons + if app.ui.mode != Mode::Painting { + return; + } + + ui.separator(); if icon_button(ui, ic::CAMERA, tr("Screenshot of the viewport"), false, 24.0).clicked() { app.toast(tr("Use the control channel or `texturecraft-cli render` for screenshots"), false); } @@ -131,12 +62,153 @@ pub fn paint_bar(app: &mut TextureCraftApp, ui: &mut egui::Ui) { let mode = if checker { "material" } else { "uvChecker" }; app.run("viewport.view", json!({"mode": mode})); } + ui.separator(); + ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| scrolling_tool_controls(app, ui, &tokens)); }); }); }); }); } +/// The tool's controls, in a strip with scroll arrows when they don't fit +fn scrolling_tool_controls(app: &mut TextureCraftApp, ui: &mut egui::Ui, tokens: &Tokens) { + let strip_width = ui.available_width(); + let overflow_id = egui::Id::unique("tool_controls_overflow"); + let overflowing = ui.data(|data| data.get_temp::(overflow_id)).unwrap_or(false); + + // A positive delta moves the content right, revealing its start + let arrow_scroll_step = strip_width / 2.0; + let mut scroll_delta = 0.0; + if overflowing && icon_button_without_tooltip(ui, ic::CARET_DOUBLE_LEFT, "Scroll left", false, 24.0).clicked() { + scroll_delta = arrow_scroll_step; + } + + ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { + if overflowing && icon_button_without_tooltip(ui, ic::CARET_DOUBLE_RIGHT, "Scroll right", false, 24.0).clicked() { + scroll_delta = -arrow_scroll_step; + } + + let scroll_area = egui::ScrollArea::horizontal().id_salt("tool_controls").scroll_bar_visibility(egui::scroll_area::ScrollBarVisibility::AlwaysHidden); + let output = ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| { + scroll_area.show(ui, |ui| { + ui.scroll_with_delta(vec2(scroll_delta, 0.0)); + ui.horizontal_centered(|ui| tool_controls(app, ui, tokens)); + }) + }); + + // The arrows take room from the strip, so measure the overflow against its full width + let overflows_now = output.inner.content_size.x > strip_width; + if overflows_now != overflowing { + ui.data_mut(|data| data.insert_temp(overflow_id, overflows_now)); + ui.ctx().request_repaint(); + } + }); +} + +/// The selected tool's icon and its settings +fn tool_controls(app: &mut TextureCraftApp, ui: &mut egui::Ui, tokens: &Tokens) { + // Brush radius limits as a fraction of the mesh diagonal; the slider shows the maximum as 100 + const MAX_BRUSH_SIZE: f32 = 0.25; + const MIN_BRUSH_SIZE: f32 = 0.0005; + const DEFAULT_LAZY_DISTANCE: f32 = 20.0; + const TOOL_ICON_SIZE: f32 = 15.0; + + let tool = app.session.tool.tool; + ui.label(RichText::new(tool_icon(tool)).size(TOOL_ICON_SIZE).color(tokens.text_strong)).on_hover_text(tr(tool.label())); + + let brush = &mut app.session.tool.brush; + match tool { + Tool::Paint | Tool::Eraser | Tool::Projection | Tool::Smudge | Tool::Clone | Tool::Path => { + let mut size = brush.size / MAX_BRUSH_SIZE * 100.0; + if bar_slider(ui, tr("Size"), &mut size, 0.05..=100.0, 110.0).changed() { + brush.size = (size / 100.0 * MAX_BRUSH_SIZE).clamp(MIN_BRUSH_SIZE, MAX_BRUSH_SIZE); + } + let mut flow = brush.flow * 100.0; + if bar_slider(ui, tr("Flow"), &mut flow, 0.0..=100.0, 100.0).changed() { + brush.flow = flow / 100.0; + } + let mut opacity = brush.opacity * 100.0; + if bar_slider(ui, tr("Stroke opacity"), &mut opacity, 0.0..=100.0, 110.0).changed() { + brush.opacity = opacity / 100.0; + } + let mut spacing = brush.spacing * 100.0; + if bar_slider(ui, tr("Spacing"), &mut spacing, 1.0..=200.0, 100.0).changed() { + brush.spacing = spacing / 100.0; + } + + ui.separator(); + let lazy_on = brush.lazy > 0.0; + if icon_button(ui, ic::SCRIBBLE, tr("Lazy mouse"), lazy_on, 24.0).clicked() { + brush.lazy = if lazy_on { 0.0 } else { DEFAULT_LAZY_DISTANCE }; + } + if lazy_on { + let mut distance = brush.lazy; + if bar_slider(ui, tr("Distance"), &mut distance, 1.0..=200.0, 90.0).changed() { + brush.lazy = distance; + } + } + + ui.separator(); + if icon_button(ui, ic::FLIP_HORIZONTAL, tr("Symmetry (X)"), brush.symmetry.x, 24.0).clicked() { + brush.symmetry.x = !brush.symmetry.x; + } + if icon_button(ui, ic::FLIP_VERTICAL, tr("Symmetry (Y)"), brush.symmetry.y, 24.0).clicked() { + brush.symmetry.y = !brush.symmetry.y; + } + if icon_button(ui, ic::CLOUD_RAIN, tr("Particle brush: particles slide down the surface"), brush.particles.enabled, 24.0).clicked() { + brush.particles.enabled = !brush.particles.enabled; + } + + if tool == Tool::Smudge { + ui.separator(); + let mut strength = app.session.tool.smudge_strength * 100.0; + if bar_slider(ui, tr("Strength"), &mut strength, 0.0..=100.0, 100.0).changed() { + app.session.tool.smudge_strength = (strength / 100.0).clamp(0.0, 1.0); + } + } + if tool == Tool::Clone && app.session.tool.clone_source.is_none() { + ui.separator(); + ui.label(RichText::new(tr("Hold V and click the mesh to set the clone source")).color(tokens.text_dim)); + } + if tool == Tool::Path { + ui.separator(); + path_controls(app, ui); + } + } + Tool::PolygonFill => { + use texturecraft_engine::FillMode; + for (fill_mode, icon, tooltip) in [ + (FillMode::Triangle, ic::POLYGON, tr("Triangle fill")), + (FillMode::UvIsland, ic::SHAPES, tr("UV island fill")), + (FillMode::Mesh, ic::CUBE, tr("Mesh fill")), + ] { + if icon_button(ui, icon, tooltip, app.session.tool.fill_mode == fill_mode, 24.0).clicked() { + app.session.tool.fill_mode = fill_mode; + } + } + } + Tool::ColorPicker => { + ui.label(RichText::new(tr("Click the mesh to pick its material into the brush")).color(tokens.text_dim)); + } + Tool::GeometryMask => { + ui.label(RichText::new(tr("Click a mesh part to show or hide the selected layer on it.")).color(tokens.text_dim)); + } + } +} + +/// Bake, Painting and Rendering mode buttons for a right-to-left layout, so Rendering is added first +fn mode_buttons(app: &mut TextureCraftApp, ui: &mut egui::Ui) { + for (mode, icon, label, command) in [ + (Mode::Rendering, ic::APERTURE, tr("Rendering (path traced)"), "ui.mode.render"), + (Mode::Painting, ic::PALETTE, tr("Painting"), "ui.mode.paint"), + (Mode::Baking, ic::ATOM, tr("Bake Mesh Maps"), "ui.mode.bake"), + ] { + if icon_button(ui, icon, &tip(&app.ui.keymap, label, command), app.ui.mode == mode, 24.0).clicked() { + crate::menus::invoke(app, &ui.ctx().clone(), command); + } + } +} + /// Path tool options and actions (top bar and properties). pub fn path_controls(app: &mut TextureCraftApp, ui: &mut egui::Ui) { let path = &mut app.session.tool.path; @@ -165,19 +237,6 @@ pub fn tool_shelf(app: &mut TextureCraftApp, ui: &mut egui::Ui) { egui::Panel::left("tool_shelf").resizable(false).exact_size(40.0).show_separator_line(false).frame(egui::Frame::NONE).show(ui, |ui| { card(ui, &tokens, egui::Margin { left: GUTTER, right: 0, top: GUTTER, bottom: GUTTER }, egui::Margin::symmetric(3, 6), |ui| { ui.spacing_mut().item_spacing.y = 3.0; - for (mode, icon, label, command) in [ - (Mode::Painting, ic::PALETTE, tr("Painting"), "ui.mode.paint"), - (Mode::Baking, ic::ATOM, tr("Bake Mesh Maps"), "ui.mode.bake"), - (Mode::Rendering, ic::APERTURE, tr("Rendering (path traced)"), "ui.mode.render"), - ] { - if icon_button(ui, icon, &tip(&app.ui.keymap, label, command), app.ui.mode == mode, 28.0).clicked() { - crate::menus::invoke(app, &ui.ctx().clone(), command); - } - } - - ui.add_space(6.0); - ui.separator(); - ui.add_space(6.0); ui.add_enabled_ui(app.ui.mode == Mode::Painting, |ui| { for tool in Tool::ALL { let selected = app.ui.mode == Mode::Painting && app.session.tool.tool == tool; diff --git a/crates/ui-egui/src/viewport.rs b/crates/ui-egui/src/viewport.rs index db50b2db..da60a42d 100644 --- a/crates/ui-egui/src/viewport.rs +++ b/crates/ui-egui/src/viewport.rs @@ -43,7 +43,7 @@ pub fn central(app: &mut TextureCraftApp, ui: &mut Ui) { !texture_set.bake.high_poly.use_low_as_high && texture_set.bake.cage.kind == texturecraft_engine::core::CageType::DistanceBased }); app.ui.bake_paint_brush.on = bake_painting; - if mode == crate::state::Mode::Painting && !app.ui.hide_ui { + if !app.ui.hide_ui { crate::toolbar::paint_bar(app, ui); } diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rs index eb3a8eb4..1dd4046e 100644 --- a/crates/ui-egui/src/widgets.rs +++ b/crates/ui-egui/src/widgets.rs @@ -177,6 +177,11 @@ pub fn elided(painter: &egui::Painter, text: impl Into, size: f32, color /// A square icon button (Phosphor glyph) in a rounded tool well: `selected` sits in the accent /// tinted well (the shared Craft icon button, `craft_ui::buttons`). pub fn icon_button(ui: &mut Ui, icon: &str, tooltip: &str, selected: bool, size: f32) -> Response { + icon_button_without_tooltip(ui, icon, tooltip, selected, size).on_hover_text(tooltip) +} + +/// An `icon_button` with no tooltip, whose `label` still names it for screen readers +pub fn icon_button_without_tooltip(ui: &mut Ui, icon: &str, label: &str, selected: bool, size: f32) -> Response { let tk = Tokens::get(ui.ctx()); let well = |fill, icon| ButtonVisuals { fill, stroke: Stroke::NONE, icon }; let style = IconButtonStyle { @@ -187,12 +192,9 @@ pub fn icon_button(ui: &mut Ui, icon: &str, tooltip: &str, selected: bool, size: corner_radius: CornerRadius::same(6), focus_stroke: Stroke::new(1.0, tk.accent), }; - IconButton::new(tooltip, vec2(size, size), &style) - .selected(selected) - .show(ui, |ui, rect, color| { - ui.painter().text(rect.center(), egui::Align2::CENTER_CENTER, icon, egui::FontId::proportional(size * 0.62), color); - }) - .on_hover_text(tooltip) + IconButton::new(label, vec2(size, size), &style).selected(selected).show(ui, |ui, rect, color| { + ui.painter().text(rect.center(), egui::Align2::CENTER_CENTER, icon, egui::FontId::proportional(size * 0.62), color); + }) } /// A flat button filled with the accent, white lettering (a dialog's main action). From e072a6a5465552378a2b71c22973c4601160ca5a Mon Sep 17 00:00:00 2001 From: Rebornim Date: Thu, 5 Nov 2026 01:22:59 +0000 Subject: [PATCH 2/5] Document the top bar function Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/toolbar.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/ui-egui/src/toolbar.rs b/crates/ui-egui/src/toolbar.rs index 49553015..9f04df4c 100644 --- a/crates/ui-egui/src/toolbar.rs +++ b/crates/ui-egui/src/toolbar.rs @@ -28,6 +28,7 @@ pub fn tool_icon(t: Tool) -> &'static str { } } +/// The top bar: the tool's controls, the view buttons and the mode buttons (only the mode buttons outside Painting) pub fn paint_bar(app: &mut TextureCraftApp, ui: &mut egui::Ui) { let tokens = Tokens::get(ui.ctx()); egui::Panel::top("paint_bar").exact_size(40.0).show_separator_line(false).frame(egui::Frame::NONE).show(ui, |ui| { From 70b7029b662b7b2debeed93c6a6a0ec8d5d39226 Mon Sep 17 00:00:00 2001 From: chasse20 Date: Wed, 4 Nov 2026 21:06:18 -0500 Subject: [PATCH 3/5] Fix toolbar overflow in narrow viewports Keep mode buttons accessible while view controls join the scrolling strip when space is tight. Respect the remaining clip width, simplify the layout, translate view hints, and add toolbar interaction and visual checks. --- crates/ui-egui/src/toolbar.rs | 123 +++++++++++++++-------- crates/ui-egui/src/widgets.rs | 16 +-- crates/ui-egui/tests/toolbar.rs | 171 ++++++++++++++++++++++++++++++++ 3 files changed, 260 insertions(+), 50 deletions(-) create mode 100644 crates/ui-egui/tests/toolbar.rs diff --git a/crates/ui-egui/src/toolbar.rs b/crates/ui-egui/src/toolbar.rs index 9f04df4c..a075840d 100644 --- a/crates/ui-egui/src/toolbar.rs +++ b/crates/ui-egui/src/toolbar.rs @@ -1,5 +1,4 @@ -//! The context tool bar (brush size, flow, stroke opacity, spacing, lazy mouse, symmetry, view -//! toggles, mode buttons), the vertical tool shelf, the right icon rail and the status bar. +//! Context controls, view and mode buttons, tool shelf, icon rail and status bar use egui::{RichText, vec2}; use egui_phosphor::regular as ic; @@ -14,6 +13,11 @@ use crate::state::{Mode, ViewLayout}; use crate::theme::{GUTTER, Tokens, card}; use crate::widgets::{bar_slider, icon_button, icon_button_without_tooltip}; +const BAR_BUTTON_SIZE: f32 = 24.0; +const BAR_SPACING: f32 = 10.0; +const COMPACT_BAR_SPACING: f32 = 4.0; +const BAR_SEPARATOR_WIDTH: f32 = 6.0; + pub fn tool_icon(t: Tool) -> &'static str { match t { Tool::Paint => ic::PAINT_BRUSH, @@ -28,51 +32,70 @@ pub fn tool_icon(t: Tool) -> &'static str { } } -/// The top bar: the tool's controls, the view buttons and the mode buttons (only the mode buttons outside Painting) +/// Keep mode buttons visible, with painting controls scrolling as space runs out pub fn paint_bar(app: &mut TextureCraftApp, ui: &mut egui::Ui) { let tokens = Tokens::get(ui.ctx()); egui::Panel::top("paint_bar").exact_size(40.0).show_separator_line(false).frame(egui::Frame::NONE).show(ui, |ui| { card(ui, &tokens, egui::Margin { bottom: GUTTER, ..Default::default() }, egui::Margin::symmetric(8, 0), |ui| { - ui.horizontal_centered(|ui| { - ui.spacing_mut().item_spacing.x = 10.0; - ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { - mode_buttons(app, ui); + ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { + let mode_width = 3.0 * BAR_BUTTON_SIZE + 2.0 * BAR_SPACING; + let separator_width = BAR_SEPARATOR_WIDTH + 2.0 * BAR_SPACING; + // Leave room for both scroll arrows and at least one button of content + let minimum_strip_width = 3.0 * BAR_BUTTON_SIZE + 2.0 * BAR_SPACING; + let scroll_views = ui.available_width() < mode_width + view_buttons_width(BAR_SPACING) + 2.0 * separator_width + minimum_strip_width; + ui.spacing_mut().item_spacing.x = if scroll_views { COMPACT_BAR_SPACING } else { BAR_SPACING }; + mode_buttons(app, ui); - // Bake and Render modes have no brush, so their bar holds only the mode buttons - if app.ui.mode != Mode::Painting { - return; - } + if app.ui.mode != Mode::Painting { + return; + } - ui.separator(); - if icon_button(ui, ic::CAMERA, tr("Screenshot of the viewport"), false, 24.0).clicked() { - app.toast(tr("Use the control channel or `texturecraft-cli render` for screenshots"), false); - } - ui.separator(); - for (layout, icon, label, id) in [ - (ViewLayout::Only2D, ic::SQUARE, "2D view only", "ui.layout.2d"), - (ViewLayout::Only3D, ic::CUBE, "3D view only", "ui.layout.3d"), - (ViewLayout::Split, ic::COLUMNS, "3D/2D views", "ui.layout.split"), - ] { - if icon_button(ui, icon, &tip(&app.ui.keymap, label, id), app.ui.layout == layout, 24.0).clicked() { - app.ui.layout = layout; - } - } - ui.separator(); - let checker = app.session.view == texturecraft_engine::ViewMode::UvChecker; - if icon_button(ui, ic::CHECKERBOARD, &tip(&app.ui.keymap, tr("UV checker"), "ui.uvChecker"), checker, 24.0).clicked() { - let mode = if checker { "material" } else { "uvChecker" }; - app.run("viewport.view", json!({"mode": mode})); - } - ui.separator(); - ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| scrolling_tool_controls(app, ui, &tokens)); + ui.add(egui::Separator::default().spacing(BAR_SEPARATOR_WIDTH)); + if !scroll_views { + view_buttons(app, ui); + ui.add(egui::Separator::default().spacing(BAR_SEPARATOR_WIDTH)); + } + + ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| { + scrolling_tool_controls(app, ui, &tokens, scroll_views); }); }); }); }); } -/// The tool's controls, in a strip with scroll arrows when they don't fit -fn scrolling_tool_controls(app: &mut TextureCraftApp, ui: &mut egui::Ui, tokens: &Tokens) { +fn view_buttons_width(spacing: f32) -> f32 { + // Five icons, two separators and the six gaps between them + 5.0 * BAR_BUTTON_SIZE + 2.0 * BAR_SEPARATOR_WIDTH + 6.0 * spacing +} + +/// View buttons in a right-to-left layout, with the screenshot button at the end +fn view_buttons(app: &mut TextureCraftApp, ui: &mut egui::Ui) { + if icon_button(ui, ic::CAMERA, tr("Screenshot of the viewport"), false, BAR_BUTTON_SIZE).clicked() { + app.toast(tr("Use the control channel or `texturecraft-cli render` for screenshots"), false); + } + + ui.add(egui::Separator::default().spacing(BAR_SEPARATOR_WIDTH)); + for (layout, icon, label, command) in [ + (ViewLayout::Only2D, ic::SQUARE, "2D view only", "ui.layout.2d"), + (ViewLayout::Only3D, ic::CUBE, "3D view only", "ui.layout.3d"), + (ViewLayout::Split, ic::COLUMNS, "3D/2D views", "ui.layout.split"), + ] { + if icon_button(ui, icon, &tip(&app.ui.keymap, tr(label), command), app.ui.layout == layout, BAR_BUTTON_SIZE).clicked() { + crate::menus::invoke(app, &ui.ctx().clone(), command); + } + } + + ui.add(egui::Separator::default().spacing(BAR_SEPARATOR_WIDTH)); + let checker = app.session.view == texturecraft_engine::ViewMode::UvChecker; + if icon_button(ui, ic::CHECKERBOARD, &tip(&app.ui.keymap, tr("UV checker"), "ui.uvChecker"), checker, BAR_BUTTON_SIZE).clicked() { + let mode = if checker { "material" } else { "uvChecker" }; + app.run("viewport.view", json!({"mode": mode})); + } +} + +/// Scroll tool controls and, in narrow viewports, the view buttons +fn scrolling_tool_controls(app: &mut TextureCraftApp, ui: &mut egui::Ui, tokens: &Tokens, scroll_views: bool) { let strip_width = ui.available_width(); let overflow_id = egui::Id::unique("tool_controls_overflow"); let overflowing = ui.data(|data| data.get_temp::(overflow_id)).unwrap_or(false); @@ -80,20 +103,30 @@ fn scrolling_tool_controls(app: &mut TextureCraftApp, ui: &mut egui::Ui, tokens: // A positive delta moves the content right, revealing its start let arrow_scroll_step = strip_width / 2.0; let mut scroll_delta = 0.0; - if overflowing && icon_button_without_tooltip(ui, ic::CARET_DOUBLE_LEFT, "Scroll left", false, 24.0).clicked() { + if overflowing && icon_button_without_tooltip(ui, ic::CARET_DOUBLE_LEFT, "Scroll left", false, BAR_BUTTON_SIZE).clicked() { scroll_delta = arrow_scroll_step; } ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { - if overflowing && icon_button_without_tooltip(ui, ic::CARET_DOUBLE_RIGHT, "Scroll right", false, 24.0).clicked() { + if overflowing && icon_button_without_tooltip(ui, ic::CARET_DOUBLE_RIGHT, "Scroll right", false, BAR_BUTTON_SIZE).clicked() { scroll_delta = -arrow_scroll_step; } - let scroll_area = egui::ScrollArea::horizontal().id_salt("tool_controls").scroll_bar_visibility(egui::scroll_area::ScrollBarVisibility::AlwaysHidden); + let scroll_area = egui::ScrollArea::horizontal() + .id_salt("tool_controls") + .min_scrolled_width(0.0) + .scroll_bar_visibility(egui::scroll_area::ScrollBarVisibility::AlwaysHidden); let output = ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| { scroll_area.show(ui, |ui| { ui.scroll_with_delta(vec2(scroll_delta, 0.0)); - ui.horizontal_centered(|ui| tool_controls(app, ui, tokens)); + ui.horizontal_centered(|ui| { + tool_controls(app, ui, tokens); + if scroll_views { + ui.add(egui::Separator::default().spacing(BAR_SEPARATOR_WIDTH)); + let size = vec2(view_buttons_width(ui.spacing().item_spacing.x), ui.available_height()); + ui.allocate_ui_with_layout(size, egui::Layout::right_to_left(egui::Align::Center), |ui| view_buttons(app, ui)); + } + }); }) }); @@ -111,7 +144,7 @@ fn tool_controls(app: &mut TextureCraftApp, ui: &mut egui::Ui, tokens: &Tokens) // Brush radius limits as a fraction of the mesh diagonal; the slider shows the maximum as 100 const MAX_BRUSH_SIZE: f32 = 0.25; const MIN_BRUSH_SIZE: f32 = 0.0005; - const DEFAULT_LAZY_DISTANCE: f32 = 20.0; + const DEFAULT_LAZY_DISTANCE_PX: f32 = 20.0; const TOOL_ICON_SIZE: f32 = 15.0; let tool = app.session.tool.tool; @@ -124,14 +157,17 @@ fn tool_controls(app: &mut TextureCraftApp, ui: &mut egui::Ui, tokens: &Tokens) if bar_slider(ui, tr("Size"), &mut size, 0.05..=100.0, 110.0).changed() { brush.size = (size / 100.0 * MAX_BRUSH_SIZE).clamp(MIN_BRUSH_SIZE, MAX_BRUSH_SIZE); } + let mut flow = brush.flow * 100.0; if bar_slider(ui, tr("Flow"), &mut flow, 0.0..=100.0, 100.0).changed() { brush.flow = flow / 100.0; } + let mut opacity = brush.opacity * 100.0; if bar_slider(ui, tr("Stroke opacity"), &mut opacity, 0.0..=100.0, 110.0).changed() { brush.opacity = opacity / 100.0; } + let mut spacing = brush.spacing * 100.0; if bar_slider(ui, tr("Spacing"), &mut spacing, 1.0..=200.0, 100.0).changed() { brush.spacing = spacing / 100.0; @@ -140,7 +176,7 @@ fn tool_controls(app: &mut TextureCraftApp, ui: &mut egui::Ui, tokens: &Tokens) ui.separator(); let lazy_on = brush.lazy > 0.0; if icon_button(ui, ic::SCRIBBLE, tr("Lazy mouse"), lazy_on, 24.0).clicked() { - brush.lazy = if lazy_on { 0.0 } else { DEFAULT_LAZY_DISTANCE }; + brush.lazy = if lazy_on { 0.0 } else { DEFAULT_LAZY_DISTANCE_PX }; } if lazy_on { let mut distance = brush.lazy; @@ -167,10 +203,12 @@ fn tool_controls(app: &mut TextureCraftApp, ui: &mut egui::Ui, tokens: &Tokens) app.session.tool.smudge_strength = (strength / 100.0).clamp(0.0, 1.0); } } + if tool == Tool::Clone && app.session.tool.clone_source.is_none() { ui.separator(); ui.label(RichText::new(tr("Hold V and click the mesh to set the clone source")).color(tokens.text_dim)); } + if tool == Tool::Path { ui.separator(); path_controls(app, ui); @@ -178,6 +216,7 @@ fn tool_controls(app: &mut TextureCraftApp, ui: &mut egui::Ui, tokens: &Tokens) } Tool::PolygonFill => { use texturecraft_engine::FillMode; + for (fill_mode, icon, tooltip) in [ (FillMode::Triangle, ic::POLYGON, tr("Triangle fill")), (FillMode::UvIsland, ic::SHAPES, tr("UV island fill")), @@ -204,7 +243,7 @@ fn mode_buttons(app: &mut TextureCraftApp, ui: &mut egui::Ui) { (Mode::Painting, ic::PALETTE, tr("Painting"), "ui.mode.paint"), (Mode::Baking, ic::ATOM, tr("Bake Mesh Maps"), "ui.mode.bake"), ] { - if icon_button(ui, icon, &tip(&app.ui.keymap, label, command), app.ui.mode == mode, 24.0).clicked() { + if icon_button(ui, icon, &tip(&app.ui.keymap, label, command), app.ui.mode == mode, BAR_BUTTON_SIZE).clicked() { crate::menus::invoke(app, &ui.ctx().clone(), command); } } diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rs index 1dd4046e..72853550 100644 --- a/crates/ui-egui/src/widgets.rs +++ b/crates/ui-egui/src/widgets.rs @@ -174,24 +174,24 @@ pub fn elided(painter: &egui::Painter, text: impl Into, size: f32, color painter.layout_job(job) } -/// A square icon button (Phosphor glyph) in a rounded tool well: `selected` sits in the accent -/// tinted well (the shared Craft icon button, `craft_ui::buttons`). +/// A square Phosphor icon button with a tooltip and an accent well when selected pub fn icon_button(ui: &mut Ui, icon: &str, tooltip: &str, selected: bool, size: f32) -> Response { icon_button_without_tooltip(ui, icon, tooltip, selected, size).on_hover_text(tooltip) } /// An `icon_button` with no tooltip, whose `label` still names it for screen readers pub fn icon_button_without_tooltip(ui: &mut Ui, icon: &str, label: &str, selected: bool, size: f32) -> Response { - let tk = Tokens::get(ui.ctx()); + let tokens = Tokens::get(ui.ctx()); let well = |fill, icon| ButtonVisuals { fill, stroke: Stroke::NONE, icon }; let style = IconButtonStyle { - normal: well(Color32::TRANSPARENT, tk.text), - hovered: well(tk.row_hover, tk.text_strong), - pressed: Some(well(tk.tool_active, tk.text_strong)), - selected: well(tk.tool_active, tk.text_strong), + normal: well(Color32::TRANSPARENT, tokens.text), + hovered: well(tokens.row_hover, tokens.text_strong), + pressed: Some(well(tokens.tool_active, tokens.text_strong)), + selected: well(tokens.tool_active, tokens.text_strong), corner_radius: CornerRadius::same(6), - focus_stroke: Stroke::new(1.0, tk.accent), + focus_stroke: Stroke::new(1.0, tokens.accent), }; + IconButton::new(label, vec2(size, size), &style).selected(selected).show(ui, |ui, rect, color| { ui.painter().text(rect.center(), egui::Align2::CENTER_CENTER, icon, egui::FontId::proportional(size * 0.62), color); }) diff --git a/crates/ui-egui/tests/toolbar.rs b/crates/ui-egui/tests/toolbar.rs new file mode 100644 index 00000000..fc5c295a --- /dev/null +++ b/crates/ui-egui/tests/toolbar.rs @@ -0,0 +1,171 @@ +//! Toolbar layout and input coverage + +use egui_kittest::Harness; +use egui_kittest::kittest::Queryable; +use texturecraft_engine::{Session, Tool}; +use texturecraft_ui_egui::state::Mode; +use texturecraft_ui_egui::{TextureCraftApp, theme, toolbar}; + +fn toolbar_harness(width: f32, tool: Tool) -> Harness<'static, TextureCraftApp> { + let session = Session::new_project("Toolbar", texturecraft_engine::geom::primitives::cube(1.0), "builtin:cube", None, 128).unwrap(); + let context = eframe::CreationContext::_new_kittest(egui::Context::default()); + let mut app = TextureCraftApp::new(&context, session); + app.session.tool.tool = tool; + app.session.tool.brush.lazy = 20.0; + let mut harness = + Harness::builder().with_size(egui::vec2(width, 200.0)).with_context_setup(theme::install).build_ui_state(|ui, app| toolbar::paint_bar(app, ui), app); + harness.run_steps(4); + harness +} + +fn size_label(harness: &Harness<'_, TextureCraftApp>) -> (egui::Pos2, egui::Rect) { + harness + .output() + .shapes + .iter() + .find_map(|shape| match &shape.shape { + egui::Shape::Text(text) if text.galley.text() == "Size" => Some((text.pos, shape.clip_rect)), + _ => None, + }) + .unwrap() +} + +#[test] +fn narrow_toolbars_keep_scroll_arrows_and_mode_buttons_separate() { + let mut harness = toolbar_harness(700.0, Tool::Path); + for width in [500.0, 450.0, 400.0, 350.0, 240.0, 200.0] { + harness.set_size(egui::vec2(width, 200.0)); + harness.run_steps(4); + let left = harness.get_by_label("Scroll left").rect(); + let right = harness.get_by_label("Scroll right").rect(); + let bake = harness.get_by_label("Bake Mesh Maps (F8)").rect(); + let (_, clip) = size_label(&harness); + assert!(left.right() <= right.left(), "arrows overlap at width {width}: {left:?}, {right:?}"); + assert!(right.right() < bake.left(), "scrolling overlaps the mode buttons at width {width}"); + assert!(clip.left() >= left.right() && clip.right() <= right.left(), "content covers an arrow at width {width}: {clip:?}"); + assert!(harness.ctx.content_rect().contains_rect(left) && harness.ctx.content_rect().contains_rect(bake)); + } +} + +#[test] +fn arrows_and_wheel_scroll_without_changing_the_brush() { + let mut harness = toolbar_harness(700.0, Tool::Path); + let brush = harness.state().session.tool.brush.clone(); + let start = size_label(&harness).0.x; + harness.get_by_label("Scroll right").click(); + harness.run_steps(30); + let scrolled = size_label(&harness).0.x; + assert!(scrolled < start - 50.0); + + harness.get_by_label("Scroll left").click(); + harness.run_steps(30); + assert!((size_label(&harness).0.x - start).abs() < 1.0); + + let (_, clip) = size_label(&harness); + harness.hover_at(clip.center()); + harness.event(egui::Event::MouseWheel { + unit: egui::MouseWheelUnit::Point, + delta: egui::vec2(-100.0, 0.0), + phase: egui::TouchPhase::Move, + source: egui::MouseWheelSource::Unknown, + modifiers: egui::Modifiers::NONE, + }); + harness.run_steps(30); + assert!(size_label(&harness).0.x < start - 50.0); + assert_eq!(harness.state().session.tool.brush, brush); +} + +#[test] +fn shorter_tools_and_wider_windows_remove_the_arrows() { + let mut harness = toolbar_harness(700.0, Tool::Path); + harness.get_by_label("Scroll right").click(); + harness.run_steps(30); + harness.state_mut().session.tool.tool = Tool::PolygonFill; + harness.state_mut().session.tool.fill_mode = texturecraft_engine::FillMode::Mesh; + harness.run_steps(4); + assert!(harness.query_by_label("Scroll right").is_none()); + let triangle = harness.get_by_label("Triangle fill").rect(); + harness.get_by_label("Triangle fill").click(); + harness.run_steps(2); + assert!(harness.ctx.content_rect().contains_rect(triangle)); + assert_eq!(harness.state().session.tool.fill_mode, texturecraft_engine::FillMode::Triangle); + + harness.state_mut().session.tool.tool = Tool::Path; + harness.set_size(egui::vec2(1600.0, 200.0)); + harness.run_steps(4); + assert!(harness.query_by_label("Scroll right").is_none()); + let (position, clip) = size_label(&harness); + assert!(clip.contains(position)); +} + +#[test] +fn compact_view_buttons_can_be_scrolled_into_view_and_clicked() { + let mut harness = toolbar_harness(400.0, Tool::Path); + for _ in 0..20 { + let left = harness.get_by_label("Scroll left").rect(); + let right = harness.get_by_label("Scroll right").rect(); + let visible = harness.query_by_label("UV checker").is_some_and(|node| node.rect().left() > left.right() && node.rect().right() < right.left()); + if visible { + harness.get_by_label("UV checker").click(); + harness.run_steps(3); + assert_eq!(harness.state().session.view, texturecraft_engine::ViewMode::UvChecker); + return; + } + + harness.get_by_label("Scroll right").click(); + harness.run_steps(30); + } + + panic!("the view buttons never became accessible"); +} + +#[test] +fn mode_buttons_keep_their_order_and_dispatch_commands() { + let mut harness = toolbar_harness(700.0, Tool::Paint); + for (label, mode) in [("Bake Mesh Maps (F8)", Mode::Baking), ("Rendering (path traced) (F10)", Mode::Rendering), ("Painting (F9)", Mode::Painting)] { + let bake = harness.get_by_label("Bake Mesh Maps (F8)").rect(); + let paint = harness.get_by_label("Painting (F9)").rect(); + let render = harness.get_by_label("Rendering (path traced) (F10)").rect(); + assert!(bake.right() < paint.left() && paint.right() < render.left()); + harness.get_by_label(label).click(); + harness.run_steps(3); + assert_eq!(harness.state().ui.mode, mode); + } +} + +#[test] +#[ignore] +fn toolbar_frame_timing() { + for width in [1600.0, 1000.0, 400.0] { + let mut harness = toolbar_harness(width, Tool::Path); + harness.run_steps(100); + let mut timings = [0.0_f64; 5]; + for timing in &mut timings { + let start = std::time::Instant::now(); + harness.run_steps(1000); + *timing = start.elapsed().as_secs_f64() * 1000.0; + } + timings.sort_by(f64::total_cmp); + eprintln!("Path + lazy mouse, width {width}: {:.2} us/frame median, batches {timings:?}", timings[2]); + } +} + +#[test] +#[ignore] +fn toolbar_window_snapshots() { + let Some(directory) = std::env::var_os("TC_UI_SNAPSHOTS").map(std::path::PathBuf::from) else { + return; + }; + + std::fs::create_dir_all(&directory).unwrap(); + let session = texturecraft_engine::sample_session(256, 64).unwrap(); + let mut harness = Harness::builder().with_size(egui::vec2(1600.0, 960.0)).wgpu().build_eframe(|context| TextureCraftApp::new(context, session)); + harness.state_mut().session.tool.tool = Tool::Path; + harness.state_mut().session.tool.brush.lazy = 20.0; + for (width, scale) in [(1600.0, 1.0), (960.0, 1.0), (960.0, 1.5)] { + harness.set_size(egui::vec2(width, 960.0)); + harness.state_mut().ui.prefs.ui_scale = scale; + harness.run_steps(6); + harness.render().unwrap().save(directory.join(format!("toolbar-{width}-{scale}.png"))).unwrap(); + } +} From 97880c7f05ef86e07e62a1c42106511b4bd25958 Mon Sep 17 00:00:00 2001 From: chasse20 Date: Wed, 4 Nov 2026 21:22:46 -0500 Subject: [PATCH 4/5] Derive standard control sizes from the active theme Use theme control heights for toolbar, path, asset, property, bake and browser export controls. Keep width calculations in sync with the rendered controls and verify narrow toolbars at three theme sizes. --- .../ui-egui/src/bake_mode/common_settings.rs | 22 ++++++--- crates/ui-egui/src/dock.rs | 40 ++++++++------- crates/ui-egui/src/shelf.rs | 15 ++++-- crates/ui-egui/src/toolbar.rs | 49 +++++++++++-------- crates/ui-egui/src/windows.rs | 15 +++--- crates/ui-egui/tests/toolbar.rs | 39 ++++++++++----- 6 files changed, 110 insertions(+), 70 deletions(-) diff --git a/crates/ui-egui/src/bake_mode/common_settings.rs b/crates/ui-egui/src/bake_mode/common_settings.rs index d96fdc85..7680903b 100644 --- a/crates/ui-egui/src/bake_mode/common_settings.rs +++ b/crates/ui-egui/src/bake_mode/common_settings.rs @@ -9,6 +9,8 @@ use texturecraft_engine::core::{ BakeAntialiasing, BakePaintTarget, BakeResolution, BakeSettings, CageType, CommonBakeSettings, MeshMatchMode, SkewCorrectionMethod, }; +const FILE_BUTTON_SIZE: f32 = 20.0; + pub(super) fn show(app: &mut TextureCraftApp, ui: &mut Ui, settings: &mut BakeSettings) { ui.push_id("common", |ui| { let is_enabled = settings.common.is_enabled; @@ -104,7 +106,8 @@ pub(super) fn show(app: &mut TextureCraftApp, ui: &mut Ui, settings: &mut BakeSe fn output_size(ui: &mut Ui, settings: &mut CommonBakeSettings) { ui.label(tr("Output Size")); ui.horizontal(|ui| { - let dropdown_width = ((ui.available_width() - 24.0 - ui.spacing().item_spacing.x * 2.0) / 2.0).max(40.0); + let button_size = ui.spacing().interact_size.y; + let dropdown_width = ((ui.available_width() - button_size - ui.spacing().item_spacing.x * 2.0) / 2.0).max(40.0); let resolution = |ui: &mut Ui, id: &str, value: &mut BakeResolution| { egui::ComboBox::from_id_salt(id).width(dropdown_width).selected_text(value.pixels().to_string()).show_ui(ui, |ui| { for resolution in BakeResolution::ALL { @@ -112,6 +115,7 @@ fn output_size(ui: &mut Ui, settings: &mut CommonBakeSettings) { } }); }; + resolution(ui, "output_width", &mut settings.resolution); let locked = settings.resolution_height.is_none(); let mut height = settings.resolution_height.unwrap_or(settings.resolution); @@ -119,7 +123,8 @@ fn output_size(ui: &mut Ui, settings: &mut CommonBakeSettings) { if !locked { settings.resolution_height = Some(height); } - if icon_button(ui, if locked { icon::LOCK_SIMPLE } else { icon::LOCK_SIMPLE_OPEN }, tr("Lock Output Size"), locked, 24.0).clicked() { + + if icon_button(ui, if locked { icon::LOCK_SIMPLE } else { icon::LOCK_SIMPLE_OPEN }, tr("Lock Output Size"), locked, button_size).clicked() { settings.resolution_height = if locked { Some(settings.resolution) } else { None }; } }); @@ -131,12 +136,14 @@ fn high_poly_files(app: &mut TextureCraftApp, ui: &mut Ui) { let mut remove = None; for (index, name) in meshes.iter().enumerate() { ui.horizontal(|ui| { - ui.add_sized([ui.available_width() - 24.0, 24.0], egui::Label::new(name).truncate()).on_hover_text(name); - if icon_button(ui, icon::TRASH, tr("Remove"), false, 20.0).clicked() { + let label_width = (ui.available_width() - FILE_BUTTON_SIZE - ui.spacing().item_spacing.x).max(0.0); + ui.add_sized([label_width, ui.spacing().interact_size.y], egui::Label::new(name).truncate()).on_hover_text(name); + if icon_button(ui, icon::TRASH, tr("Remove"), false, FILE_BUTTON_SIZE).clicked() { remove = Some(index); } }); } + if meshes.is_empty() { hint(ui, tr("No High-Poly Meshes")); } @@ -152,11 +159,12 @@ fn cage_file(app: &mut TextureCraftApp, ui: &mut Ui) { ui.label(tr("Cage Scene")); let cage = app.session.bake_meshes.cage.as_ref().map(|mesh| mesh.name.clone()); ui.horizontal(|ui| { - ui.add_sized([ui.available_width() - 52.0, 24.0], egui::Label::new(cage.as_deref().unwrap_or("")).truncate()); - if icon_button(ui, icon::FOLDER_OPEN, tr("Load Cage"), false, 20.0).clicked() { + let label_width = (ui.available_width() - 2.0 * (FILE_BUTTON_SIZE + ui.spacing().item_spacing.x)).max(0.0); + ui.add_sized([label_width, ui.spacing().interact_size.y], egui::Label::new(cage.as_deref().unwrap_or("")).truncate()); + if icon_button(ui, icon::FOLDER_OPEN, tr("Load Cage"), false, FILE_BUTTON_SIZE).clicked() { crate::web_files::import_bake_mesh(app, &ui.ctx().clone(), true); } - if cage.is_some() && icon_button(ui, icon::TRASH, tr("Remove Cage"), false, 20.0).clicked() { + if cage.is_some() && icon_button(ui, icon::TRASH, tr("Remove Cage"), false, FILE_BUTTON_SIZE).clicked() { app.run("bake.cage.clear", json!({})); } }); diff --git a/crates/ui-egui/src/dock.rs b/crates/ui-egui/src/dock.rs index 3a74a80b..4d5a1d06 100644 --- a/crates/ui-egui/src/dock.rs +++ b/crates/ui-egui/src/dock.rs @@ -990,38 +990,43 @@ fn height_mask_section(app: &mut TextureCraftApp, ui: &mut Ui, layer: &Layer) { } fn tool_properties(app: &mut TextureCraftApp, ui: &mut Ui) { - let tk = Tokens::get(ui.ctx()); - // Brush preview: a stroke and a sphere with the tool's material. + let tokens = Tokens::get(ui.ctx()); + // Brush preview: a stroke and a sphere with the tool's material let (rect, _) = ui.allocate_exact_size(vec2(ui.available_width(), 88.0), Sense::hover()); - let p = ui.painter(); - p.rect_filled(rect, 2.0, tk.viewport); - let half = rect.width() * 0.5; - let b = &app.session.tool.brush; - let mut pts = Vec::new(); - for k in 0..=40 { - let t = k as f32 / 40.0; - pts.push(pos2(rect.left() + 14.0 + t * (half - 28.0), rect.center().y + (t * 9.0).sin() * 18.0)); + let painter = ui.painter(); + painter.rect_filled(rect, 2.0, tokens.viewport); + let half_width = rect.width() * 0.5; + let brush = &app.session.tool.brush; + let mut points = Vec::new(); + for step in 0..=40 { + let fraction = step as f32 / 40.0; + points.push(pos2(rect.left() + 14.0 + fraction * (half_width - 28.0), rect.center().y + (fraction * 9.0).sin() * 18.0)); } - let w = (b.size / 0.25 * 60.0).clamp(2.0, 30.0); - let a = (b.flow * b.opacity * 255.0) as u8; - p.add(egui::Shape::line(pts, Stroke::new(w, Color32::from_white_alpha(a.max(30))))); - let base = app.session.tool.values.get(&Channel::BaseColor).copied().unwrap_or([0.8; 3]); - crate::thumbs::paint_sphere(p, pos2(rect.left() + half * 1.5, rect.center().y), 36.0, base); + + let stroke_width = (brush.size / 0.25 * 60.0).clamp(2.0, 30.0); + let alpha = (brush.flow * brush.opacity * 255.0) as u8; + painter.add(egui::Shape::line(points, Stroke::new(stroke_width, Color32::from_white_alpha(alpha.max(30))))); + let base_color = app.session.tool.values.get(&Channel::BaseColor).copied().unwrap_or([0.8; 3]); + crate::thumbs::paint_sphere(painter, pos2(rect.left() + half_width * 1.5, rect.center().y), 36.0, base_color); ui.add_space(4.0); + ui.horizontal(|ui| { + let button_size = ui.spacing().interact_size.y; for (tab, icon, tip) in [(PropsTab::Brush, ic::PAINT_BRUSH, tr("Brush")), (PropsTab::Alpha, ic::CIRCLE_HALF, tr("Alpha")), (PropsTab::Material, ic::SPHERE, tr("Material"))] { - if icon_button(ui, icon, tip, app.ui.props_tab == tab, 24.0).clicked() { + if icon_button(ui, icon, tip, app.ui.props_tab == tab, button_size).clicked() { app.ui.props_tab = tab; } } }); ui.separator(); + if app.session.quick_mask.editing { - ui.label(RichText::new(tr("Editing the quick mask: strokes paint where painting is allowed. Press U to finish.")).color(tk.text_dim)); + ui.label(RichText::new(tr("Editing the quick mask: strokes paint where painting is allowed. Press U to finish.")).color(tokens.text_dim)); ui.separator(); } + let tool_section: Option = match app.session.tool.tool { Tool::Projection => Some(stencil_section), Tool::Clone => Some(clone_section), @@ -1034,6 +1039,7 @@ fn tool_properties(app: &mut TextureCraftApp, ui: &mut Ui) { section(app, ui); ui.separator(); } + match app.ui.props_tab { PropsTab::Brush => brush_section(app, ui), PropsTab::Alpha => alpha_section(app, ui), diff --git a/crates/ui-egui/src/shelf.rs b/crates/ui-egui/src/shelf.rs index f2aaeb65..351219b9 100644 --- a/crates/ui-egui/src/shelf.rs +++ b/crates/ui-egui/src/shelf.rs @@ -156,34 +156,39 @@ pub fn drop_target(app: &mut TextureCraftApp, ui: &Ui, response: &egui::Response } } -/// The Assets panel body (a dock tab). +/// The Assets panel body (a dock tab) pub fn body(app: &mut TextureCraftApp, ui: &mut Ui) { - let tk = Tokens::get(ui.ctx()); + let tokens = Tokens::get(ui.ctx()); let ctx = ui.ctx().clone(); let mut tab = app.ui.shelf_tab.min(TABS.len() - 1); let searching = !app.ui.shelf_filter.is_empty(); + ui.horizontal_wrapped(|ui| { + let button_size = ui.spacing().interact_size.y; ui.spacing_mut().item_spacing = vec2(2.0, 2.0); for (i, (_, icon, label)) in TABS.iter().enumerate() { - if icon_button(ui, icon, tr(label), i == tab && !searching, 24.0).clicked() { + if icon_button(ui, icon, tr(label), i == tab && !searching, button_size).clicked() { tab = i; app.ui.shelf_filter.clear(); } } }); app.ui.shelf_tab = tab; + ui.horizontal(|ui| { - ui.label(RichText::new(ic::MAGNIFYING_GLASS).color(tk.text_dim)); + ui.label(RichText::new(ic::MAGNIFYING_GLASS).color(tokens.text_dim)); ui.add(egui::TextEdit::singleline(&mut app.ui.shelf_filter).hint_text(tr("Search all assets")).desired_width(f32::INFINITY)); }); ui.add_space(4.0); + let filter = app.ui.shelf_filter.to_lowercase(); egui::ScrollArea::vertical().id_salt("shelf_scroll").auto_shrink([false, false]).show(ui, |ui| { - // Searching shows matches from every tab, each under its tab's name. + // Searching shows matches from every tab, each under its tab's name for (i, (t, _, title)) in TABS.iter().enumerate() { if filter.is_empty() && i != tab { continue; } + let title = tr(title); match t { Tab::Materials => materials(app, ui, &ctx, &filter, false, title), diff --git a/crates/ui-egui/src/toolbar.rs b/crates/ui-egui/src/toolbar.rs index a075840d..b2e4d83e 100644 --- a/crates/ui-egui/src/toolbar.rs +++ b/crates/ui-egui/src/toolbar.rs @@ -13,7 +13,6 @@ use crate::state::{Mode, ViewLayout}; use crate::theme::{GUTTER, Tokens, card}; use crate::widgets::{bar_slider, icon_button, icon_button_without_tooltip}; -const BAR_BUTTON_SIZE: f32 = 24.0; const BAR_SPACING: f32 = 10.0; const COMPACT_BAR_SPACING: f32 = 4.0; const BAR_SEPARATOR_WIDTH: f32 = 6.0; @@ -38,11 +37,13 @@ pub fn paint_bar(app: &mut TextureCraftApp, ui: &mut egui::Ui) { egui::Panel::top("paint_bar").exact_size(40.0).show_separator_line(false).frame(egui::Frame::NONE).show(ui, |ui| { card(ui, &tokens, egui::Margin { bottom: GUTTER, ..Default::default() }, egui::Margin::symmetric(8, 0), |ui| { ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { - let mode_width = 3.0 * BAR_BUTTON_SIZE + 2.0 * BAR_SPACING; + let button_size = ui.spacing().interact_size.y; + let mode_width = 3.0 * button_size + 2.0 * BAR_SPACING; let separator_width = BAR_SEPARATOR_WIDTH + 2.0 * BAR_SPACING; // Leave room for both scroll arrows and at least one button of content - let minimum_strip_width = 3.0 * BAR_BUTTON_SIZE + 2.0 * BAR_SPACING; - let scroll_views = ui.available_width() < mode_width + view_buttons_width(BAR_SPACING) + 2.0 * separator_width + minimum_strip_width; + let minimum_strip_width = 3.0 * button_size + 2.0 * BAR_SPACING; + let scroll_views = + ui.available_width() < mode_width + view_buttons_width(button_size, BAR_SPACING) + 2.0 * separator_width + minimum_strip_width; ui.spacing_mut().item_spacing.x = if scroll_views { COMPACT_BAR_SPACING } else { BAR_SPACING }; mode_buttons(app, ui); @@ -64,14 +65,15 @@ pub fn paint_bar(app: &mut TextureCraftApp, ui: &mut egui::Ui) { }); } -fn view_buttons_width(spacing: f32) -> f32 { +fn view_buttons_width(button_size: f32, spacing: f32) -> f32 { // Five icons, two separators and the six gaps between them - 5.0 * BAR_BUTTON_SIZE + 2.0 * BAR_SEPARATOR_WIDTH + 6.0 * spacing + 5.0 * button_size + 2.0 * BAR_SEPARATOR_WIDTH + 6.0 * spacing } /// View buttons in a right-to-left layout, with the screenshot button at the end fn view_buttons(app: &mut TextureCraftApp, ui: &mut egui::Ui) { - if icon_button(ui, ic::CAMERA, tr("Screenshot of the viewport"), false, BAR_BUTTON_SIZE).clicked() { + let button_size = ui.spacing().interact_size.y; + if icon_button(ui, ic::CAMERA, tr("Screenshot of the viewport"), false, button_size).clicked() { app.toast(tr("Use the control channel or `texturecraft-cli render` for screenshots"), false); } @@ -81,14 +83,14 @@ fn view_buttons(app: &mut TextureCraftApp, ui: &mut egui::Ui) { (ViewLayout::Only3D, ic::CUBE, "3D view only", "ui.layout.3d"), (ViewLayout::Split, ic::COLUMNS, "3D/2D views", "ui.layout.split"), ] { - if icon_button(ui, icon, &tip(&app.ui.keymap, tr(label), command), app.ui.layout == layout, BAR_BUTTON_SIZE).clicked() { + if icon_button(ui, icon, &tip(&app.ui.keymap, tr(label), command), app.ui.layout == layout, button_size).clicked() { crate::menus::invoke(app, &ui.ctx().clone(), command); } } ui.add(egui::Separator::default().spacing(BAR_SEPARATOR_WIDTH)); let checker = app.session.view == texturecraft_engine::ViewMode::UvChecker; - if icon_button(ui, ic::CHECKERBOARD, &tip(&app.ui.keymap, tr("UV checker"), "ui.uvChecker"), checker, BAR_BUTTON_SIZE).clicked() { + if icon_button(ui, ic::CHECKERBOARD, &tip(&app.ui.keymap, tr("UV checker"), "ui.uvChecker"), checker, button_size).clicked() { let mode = if checker { "material" } else { "uvChecker" }; app.run("viewport.view", json!({"mode": mode})); } @@ -96,6 +98,7 @@ fn view_buttons(app: &mut TextureCraftApp, ui: &mut egui::Ui) { /// Scroll tool controls and, in narrow viewports, the view buttons fn scrolling_tool_controls(app: &mut TextureCraftApp, ui: &mut egui::Ui, tokens: &Tokens, scroll_views: bool) { + let button_size = ui.spacing().interact_size.y; let strip_width = ui.available_width(); let overflow_id = egui::Id::unique("tool_controls_overflow"); let overflowing = ui.data(|data| data.get_temp::(overflow_id)).unwrap_or(false); @@ -103,12 +106,12 @@ fn scrolling_tool_controls(app: &mut TextureCraftApp, ui: &mut egui::Ui, tokens: // A positive delta moves the content right, revealing its start let arrow_scroll_step = strip_width / 2.0; let mut scroll_delta = 0.0; - if overflowing && icon_button_without_tooltip(ui, ic::CARET_DOUBLE_LEFT, "Scroll left", false, BAR_BUTTON_SIZE).clicked() { + if overflowing && icon_button_without_tooltip(ui, ic::CARET_DOUBLE_LEFT, "Scroll left", false, button_size).clicked() { scroll_delta = arrow_scroll_step; } ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { - if overflowing && icon_button_without_tooltip(ui, ic::CARET_DOUBLE_RIGHT, "Scroll right", false, BAR_BUTTON_SIZE).clicked() { + if overflowing && icon_button_without_tooltip(ui, ic::CARET_DOUBLE_RIGHT, "Scroll right", false, button_size).clicked() { scroll_delta = -arrow_scroll_step; } @@ -123,7 +126,7 @@ fn scrolling_tool_controls(app: &mut TextureCraftApp, ui: &mut egui::Ui, tokens: tool_controls(app, ui, tokens); if scroll_views { ui.add(egui::Separator::default().spacing(BAR_SEPARATOR_WIDTH)); - let size = vec2(view_buttons_width(ui.spacing().item_spacing.x), ui.available_height()); + let size = vec2(view_buttons_width(button_size, ui.spacing().item_spacing.x), ui.available_height()); ui.allocate_ui_with_layout(size, egui::Layout::right_to_left(egui::Align::Center), |ui| view_buttons(app, ui)); } }); @@ -147,6 +150,7 @@ fn tool_controls(app: &mut TextureCraftApp, ui: &mut egui::Ui, tokens: &Tokens) const DEFAULT_LAZY_DISTANCE_PX: f32 = 20.0; const TOOL_ICON_SIZE: f32 = 15.0; + let button_size = ui.spacing().interact_size.y; let tool = app.session.tool.tool; ui.label(RichText::new(tool_icon(tool)).size(TOOL_ICON_SIZE).color(tokens.text_strong)).on_hover_text(tr(tool.label())); @@ -175,7 +179,7 @@ fn tool_controls(app: &mut TextureCraftApp, ui: &mut egui::Ui, tokens: &Tokens) ui.separator(); let lazy_on = brush.lazy > 0.0; - if icon_button(ui, ic::SCRIBBLE, tr("Lazy mouse"), lazy_on, 24.0).clicked() { + if icon_button(ui, ic::SCRIBBLE, tr("Lazy mouse"), lazy_on, button_size).clicked() { brush.lazy = if lazy_on { 0.0 } else { DEFAULT_LAZY_DISTANCE_PX }; } if lazy_on { @@ -186,13 +190,13 @@ fn tool_controls(app: &mut TextureCraftApp, ui: &mut egui::Ui, tokens: &Tokens) } ui.separator(); - if icon_button(ui, ic::FLIP_HORIZONTAL, tr("Symmetry (X)"), brush.symmetry.x, 24.0).clicked() { + if icon_button(ui, ic::FLIP_HORIZONTAL, tr("Symmetry (X)"), brush.symmetry.x, button_size).clicked() { brush.symmetry.x = !brush.symmetry.x; } - if icon_button(ui, ic::FLIP_VERTICAL, tr("Symmetry (Y)"), brush.symmetry.y, 24.0).clicked() { + if icon_button(ui, ic::FLIP_VERTICAL, tr("Symmetry (Y)"), brush.symmetry.y, button_size).clicked() { brush.symmetry.y = !brush.symmetry.y; } - if icon_button(ui, ic::CLOUD_RAIN, tr("Particle brush: particles slide down the surface"), brush.particles.enabled, 24.0).clicked() { + if icon_button(ui, ic::CLOUD_RAIN, tr("Particle brush: particles slide down the surface"), brush.particles.enabled, button_size).clicked() { brush.particles.enabled = !brush.particles.enabled; } @@ -222,7 +226,7 @@ fn tool_controls(app: &mut TextureCraftApp, ui: &mut egui::Ui, tokens: &Tokens) (FillMode::UvIsland, ic::SHAPES, tr("UV island fill")), (FillMode::Mesh, ic::CUBE, tr("Mesh fill")), ] { - if icon_button(ui, icon, tooltip, app.session.tool.fill_mode == fill_mode, 24.0).clicked() { + if icon_button(ui, icon, tooltip, app.session.tool.fill_mode == fill_mode, button_size).clicked() { app.session.tool.fill_mode = fill_mode; } } @@ -238,27 +242,30 @@ fn tool_controls(app: &mut TextureCraftApp, ui: &mut egui::Ui, tokens: &Tokens) /// Bake, Painting and Rendering mode buttons for a right-to-left layout, so Rendering is added first fn mode_buttons(app: &mut TextureCraftApp, ui: &mut egui::Ui) { + let button_size = ui.spacing().interact_size.y; for (mode, icon, label, command) in [ (Mode::Rendering, ic::APERTURE, tr("Rendering (path traced)"), "ui.mode.render"), (Mode::Painting, ic::PALETTE, tr("Painting"), "ui.mode.paint"), (Mode::Baking, ic::ATOM, tr("Bake Mesh Maps"), "ui.mode.bake"), ] { - if icon_button(ui, icon, &tip(&app.ui.keymap, label, command), app.ui.mode == mode, BAR_BUTTON_SIZE).clicked() { + if icon_button(ui, icon, &tip(&app.ui.keymap, label, command), app.ui.mode == mode, button_size).clicked() { crate::menus::invoke(app, &ui.ctx().clone(), command); } } } -/// Path tool options and actions (top bar and properties). +/// Path tool options and actions (top bar and properties) pub fn path_controls(app: &mut TextureCraftApp, ui: &mut egui::Ui) { + let button_size = ui.spacing().interact_size.y; let path = &mut app.session.tool.path; - if icon_button(ui, ic::POLYGON, tr("Closed path"), path.closed, 24.0).clicked() { + if icon_button(ui, ic::POLYGON, tr("Closed path"), path.closed, button_size).clicked() { path.closed = !path.closed; } let fill_tip = if path.closed { tr("Fill the closed path (lasso)") } else { tr("Fill the path (close it first)") }; - if icon_button(ui, ic::PAINT_BUCKET, fill_tip, path.fill, 24.0).clicked() { + if icon_button(ui, ic::PAINT_BUCKET, fill_tip, path.fill, button_size).clicked() { path.fill = !path.fill; } + let has_points = !path.points.is_empty(); if ui .add_enabled(has_points, egui::Button::new(format!("{} {}", ic::CHECK, tr("Apply")))) diff --git a/crates/ui-egui/src/windows.rs b/crates/ui-egui/src/windows.rs index c8bd72c5..3672ad45 100644 --- a/crates/ui-egui/src/windows.rs +++ b/crates/ui-egui/src/windows.rs @@ -615,8 +615,7 @@ fn settings(app: &mut TextureCraftApp, ctx: &egui::Context) { app.ui.windows.settings = open; } -/// Browser File › Export Mesh: pick the download format (the desktop picks it in the save -/// dialog). +/// Browser File › Export Mesh: pick the download format #[cfg(target_arch = "wasm32")] fn export_mesh(app: &mut TextureCraftApp, ctx: &egui::Context) { let formats = [ @@ -627,18 +626,20 @@ fn export_mesh(app: &mut TextureCraftApp, ctx: &egui::Context) { if !app.ui.windows.export_mesh { return; } + let mut open = true; let mut picked = None; dialog("export_mesh", tr("Export mesh"), &mut open).show(ctx, |ui| { ui.label(caption(tr("Download as"))); - for (ext, label, hint) in formats { - if ui.add_sized(vec2(220.0, 24.0), egui::Button::new(label)).on_hover_text(hint).clicked() { - picked = Some(ext); + for (extension, label, hint) in formats { + if ui.add_sized(vec2(220.0, ui.spacing().interact_size.y), egui::Button::new(label)).on_hover_text(hint).clicked() { + picked = Some(extension); } } }); - if let Some(ext) = picked { - crate::web_files::export_mesh(app, ext); + + if let Some(extension) = picked { + crate::web_files::export_mesh(app, extension); open = false; } app.ui.windows.export_mesh = open; diff --git a/crates/ui-egui/tests/toolbar.rs b/crates/ui-egui/tests/toolbar.rs index fc5c295a..76b0053d 100644 --- a/crates/ui-egui/tests/toolbar.rs +++ b/crates/ui-egui/tests/toolbar.rs @@ -12,8 +12,13 @@ fn toolbar_harness(width: f32, tool: Tool) -> Harness<'static, TextureCraftApp> let mut app = TextureCraftApp::new(&context, session); app.session.tool.tool = tool; app.session.tool.brush.lazy = 20.0; - let mut harness = - Harness::builder().with_size(egui::vec2(width, 200.0)).with_context_setup(theme::install).build_ui_state(|ui, app| toolbar::paint_bar(app, ui), app); + let mut harness = Harness::builder() + .with_size(egui::vec2(width, 200.0)) + .with_context_setup(|context| { + theme::install(context); + theme::apply(context, theme::Brightness::default(), theme::Accent::default()); + }) + .build_ui_state(|ui, app| toolbar::paint_bar(app, ui), app); harness.run_steps(4); harness } @@ -33,17 +38,25 @@ fn size_label(harness: &Harness<'_, TextureCraftApp>) -> (egui::Pos2, egui::Rect #[test] fn narrow_toolbars_keep_scroll_arrows_and_mode_buttons_separate() { let mut harness = toolbar_harness(700.0, Tool::Path); - for width in [500.0, 450.0, 400.0, 350.0, 240.0, 200.0] { - harness.set_size(egui::vec2(width, 200.0)); - harness.run_steps(4); - let left = harness.get_by_label("Scroll left").rect(); - let right = harness.get_by_label("Scroll right").rect(); - let bake = harness.get_by_label("Bake Mesh Maps (F8)").rect(); - let (_, clip) = size_label(&harness); - assert!(left.right() <= right.left(), "arrows overlap at width {width}: {left:?}, {right:?}"); - assert!(right.right() < bake.left(), "scrolling overlaps the mode buttons at width {width}"); - assert!(clip.left() >= left.right() && clip.right() <= right.left(), "content covers an arrow at width {width}: {clip:?}"); - assert!(harness.ctx.content_rect().contains_rect(left) && harness.ctx.content_rect().contains_rect(bake)); + for button_size in [20.0, 24.0, 28.0] { + harness.ctx.all_styles_mut(|style| style.spacing.interact_size = egui::Vec2::splat(button_size)); + for width in [500.0, 450.0, 400.0, 350.0, 240.0, 200.0] { + let width = width * button_size / 24.0; + harness.set_size(egui::vec2(width, 200.0)); + harness.run_steps(4); + let left = harness.get_by_label("Scroll left").rect(); + let right = harness.get_by_label("Scroll right").rect(); + let bake = harness.get_by_label("Bake Mesh Maps (F8)").rect(); + let (_, clip) = size_label(&harness); + for button in [left, right, bake] { + assert_eq!(button.size(), egui::Vec2::splat(button_size)); + } + + assert!(left.right() <= right.left(), "arrows overlap at width {width}: {left:?}, {right:?}"); + assert!(right.right() < bake.left(), "scrolling overlaps the mode buttons at width {width}"); + assert!(clip.left() >= left.right() && clip.right() <= right.left(), "content covers an arrow at width {width}: {clip:?}"); + assert!(harness.ctx.content_rect().contains_rect(left) && harness.ctx.content_rect().contains_rect(bake)); + } } } From 6b31b9e376b519c18fabad32efec2cbc98d26b8b Mon Sep 17 00:00:00 2001 From: chasse20 Date: Wed, 4 Nov 2026 21:49:36 -0500 Subject: [PATCH 5/5] Derive bake file button sizes from the active UI Use the UI control height for high-poly and cage file buttons and their row-width reservations. Cover smaller and larger control sizes in the bake UI regression test. --- crates/ui-egui/src/bake_mode/common_settings.rs | 14 +++++++------- crates/ui-egui/tests/bake_mode.rs | 10 ++++++++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/crates/ui-egui/src/bake_mode/common_settings.rs b/crates/ui-egui/src/bake_mode/common_settings.rs index 7680903b..d6710290 100644 --- a/crates/ui-egui/src/bake_mode/common_settings.rs +++ b/crates/ui-egui/src/bake_mode/common_settings.rs @@ -9,8 +9,6 @@ use texturecraft_engine::core::{ BakeAntialiasing, BakePaintTarget, BakeResolution, BakeSettings, CageType, CommonBakeSettings, MeshMatchMode, SkewCorrectionMethod, }; -const FILE_BUTTON_SIZE: f32 = 20.0; - pub(super) fn show(app: &mut TextureCraftApp, ui: &mut Ui, settings: &mut BakeSettings) { ui.push_id("common", |ui| { let is_enabled = settings.common.is_enabled; @@ -136,9 +134,10 @@ fn high_poly_files(app: &mut TextureCraftApp, ui: &mut Ui) { let mut remove = None; for (index, name) in meshes.iter().enumerate() { ui.horizontal(|ui| { - let label_width = (ui.available_width() - FILE_BUTTON_SIZE - ui.spacing().item_spacing.x).max(0.0); + let button_size = ui.spacing().interact_size.y; + let label_width = (ui.available_width() - button_size - ui.spacing().item_spacing.x).max(0.0); ui.add_sized([label_width, ui.spacing().interact_size.y], egui::Label::new(name).truncate()).on_hover_text(name); - if icon_button(ui, icon::TRASH, tr("Remove"), false, FILE_BUTTON_SIZE).clicked() { + if icon_button(ui, icon::TRASH, tr("Remove"), false, button_size).clicked() { remove = Some(index); } }); @@ -159,12 +158,13 @@ fn cage_file(app: &mut TextureCraftApp, ui: &mut Ui) { ui.label(tr("Cage Scene")); let cage = app.session.bake_meshes.cage.as_ref().map(|mesh| mesh.name.clone()); ui.horizontal(|ui| { - let label_width = (ui.available_width() - 2.0 * (FILE_BUTTON_SIZE + ui.spacing().item_spacing.x)).max(0.0); + let button_size = ui.spacing().interact_size.y; + let label_width = (ui.available_width() - 2.0 * (button_size + ui.spacing().item_spacing.x)).max(0.0); ui.add_sized([label_width, ui.spacing().interact_size.y], egui::Label::new(cage.as_deref().unwrap_or("")).truncate()); - if icon_button(ui, icon::FOLDER_OPEN, tr("Load Cage"), false, FILE_BUTTON_SIZE).clicked() { + if icon_button(ui, icon::FOLDER_OPEN, tr("Load Cage"), false, button_size).clicked() { crate::web_files::import_bake_mesh(app, &ui.ctx().clone(), true); } - if cage.is_some() && icon_button(ui, icon::TRASH, tr("Remove Cage"), false, FILE_BUTTON_SIZE).clicked() { + if cage.is_some() && icon_button(ui, icon::TRASH, tr("Remove Cage"), false, button_size).clicked() { app.run("bake.cage.clear", json!({})); } }); diff --git a/crates/ui-egui/tests/bake_mode.rs b/crates/ui-egui/tests/bake_mode.rs index 409966c6..acd1135c 100644 --- a/crates/ui-egui/tests/bake_mode.rs +++ b/crates/ui-egui/tests/bake_mode.rs @@ -106,14 +106,24 @@ fn cage_and_skew_controls_require_a_high_poly_and_follow_cage_type() { harness.run_steps(3); assert!(harness.query_by_label("Cage Type").is_none()); assert!(harness.query_by_label("Skew Correction").is_none()); + harness.state_mut().session.add_high_poly_bytes("High.obj", b"v 0 0 0\nv 1 0 0\nv 0 1 0\nf 1 2 3\n".to_vec()).unwrap(); harness.run_steps(3); harness.get_by_label("Max Frontal Distance"); harness.get_by_label("Skew Correction"); + click(&mut harness, "Cage Type"); click(&mut harness, "Custom File"); assert_eq!(harness.state().session.doc.project.texture_sets[0].bake.cage.kind, CageType::CustomFile); harness.get_by_label("Cage Scene"); assert!(harness.query_by_label("Max Frontal Distance").is_none()); assert!(harness.query_by_label("Skew Correction").is_none()); + + for button_size in [20.0, 28.0] { + harness.ctx.all_styles_mut(|style| style.spacing.interact_size = egui::Vec2::splat(button_size)); + harness.run_steps(3); + for label in ["Remove", "Load Cage"] { + assert_eq!(harness.get_by_label(label).rect().size(), egui::Vec2::splat(button_size)); + } + } }