Insert design: file names get the dialog's width (#8097) (#8122)

* claim: #8097

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Insert design: file names get the width the size and actions leave (#8097)

The web app's "Files in this browser" window listed stored files in an egui
Grid sized from cell content: the wide action buttons took most of the fixed
window width, the name and size columns were cut, and the rest was empty.

Add ui_kit::name_list on the kit's table grid: the name column takes the
width the other columns leave, the other columns are as wide as their widest
cell (measured as drawn, a changed measurement discards the frame), and a
name is cut with an ellipsis and its full text on hover only when it does
not fit. The window is a little wider (still capped at the browser width).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
PaddleStrokeandClaude Opus 5.5 authored and GitHub committed 2026-10-28 14:23:31 +00:00
1 parent 67d5051792
commit 8be7bb0201
6 files changed
+224 -50

No files matched your search

+52 -50
View File
@@ -353,7 +353,8 @@ mod web {
}
let mut act: Option<(&'static str, String)> = None;
let closed = solidcraft_ui_egui::ui_kit::Window::new(egui::Id::new("sc_browser_files"), "folder", "Files in this browser")
.cards(3.0)
// Room for long names; the kit still caps the window at the browser's width.
.cards(4.0)
.show_body(ctx, |ui| {
ui.horizontal(|ui| {
if ui_kit::button(ui, "Open from computer…", ui_kit::Button::Normal).clicked() {
@@ -381,61 +382,62 @@ mod web {
return;
}
let entries = self.files.entries.borrow().clone();
if entries.is_empty() {
ui.label("Designs you save appear here. They stay in this browser.");
}
egui::ScrollArea::vertical().max_height(360.0).show(ui, |ui| {
egui::Grid::new("opfs_files").num_columns(3).spacing([12.0, 6.0]).show(ui, |ui| {
// The name takes the width the size and the actions leave (#8097).
let empty = "Designs you save appear here. They stay in this browser.";
ui_kit::name_list(ui, "opfs_files", &["Name", "Size", "Actions"], empty, |list| {
for e in &entries {
match &mut self.renaming {
Some((from, to)) if *from == e.name => {
let r = ui_kit::cell_editor(ui, ui.make_persistent_id(("stored_file_name", from.as_str())), to, "", false);
if std::mem::take(&mut self.rename_focus) {
r.request_focus();
}
if r.lost_focus() {
act = Some(if ui.input(|i| i.key_pressed(egui::Key::Enter)) {
("rename", to.clone())
} else {
("rename_cancel", String::new())
});
list.row(&e.name, |row| {
match &mut self.renaming {
Some((from, to)) if *from == e.name => row.cell(|ui| {
let r =
ui_kit::cell_editor(ui, ui.make_persistent_id(("stored_file_name", from.as_str())), to, "", false);
if std::mem::take(&mut self.rename_focus) {
r.request_focus();
}
if r.lost_focus() {
act = Some(if ui.input(|i| i.key_pressed(egui::Key::Enter)) {
("rename", to.clone())
} else {
("rename_cancel", String::new())
});
}
}),
_ => {
row.name(&e.name);
}
}
_ => {
ui.label(&e.name);
}
}
ui.label(format!("{:.1} KB", e.size as f64 / 1024.0));
ui.horizontal(|ui| {
if ui_kit::button(ui, "Open", ui_kit::Button::Small).clicked() {
act = Some(("open", e.name.clone()));
}
let design = solidcraft_engine::io::is_design_path(&e.name);
if !design
&& ui_kit::button(ui, "Insert", ui_kit::Button::Small)
.on_hover_text(solidcraft_ui_egui::i18n::tr("web.files.insert_stored_drawings_hint"))
row.cell(|ui| ui.label(format!("{:.1} KB", e.size as f64 / 1024.0)));
row.cell(|ui| {
if ui_kit::button(ui, "Open", ui_kit::Button::Small).clicked() {
act = Some(("open", e.name.clone()));
}
let design = solidcraft_engine::io::is_design_path(&e.name);
if !design
&& ui_kit::button(ui, "Insert", ui_kit::Button::Small)
.on_hover_text(solidcraft_ui_egui::i18n::tr("web.files.insert_stored_drawings_hint"))
.clicked()
{
act = Some(("insert", e.name.clone()));
}
if ui_kit::button(ui, "Rename", ui_kit::Button::Small).clicked() {
self.renaming = Some((e.name.clone(), e.name.clone()));
self.rename_focus = true;
}
if ui_kit::button(ui, "Save to computer…", ui_kit::Button::Small)
.on_hover_text("A copy in a file you choose; the stored design stays here")
.clicked()
{
act = Some(("insert", e.name.clone()));
}
if ui_kit::button(ui, "Rename", ui_kit::Button::Small).clicked() {
self.renaming = Some((e.name.clone(), e.name.clone()));
self.rename_focus = true;
}
if ui_kit::button(ui, "Save to computer…", ui_kit::Button::Small)
.on_hover_text("A copy in a file you choose; the stored design stays here")
.clicked()
{
act = Some(("save_copy", e.name.clone()));
}
if ui_kit::button(ui, "Download", ui_kit::Button::Small).clicked() {
act = Some(("download", e.name.clone()));
}
if ui_kit::button(ui, "Delete", ui_kit::Button::Small).clicked() {
act = Some(("delete", e.name.clone()));
}
{
act = Some(("save_copy", e.name.clone()));
}
if ui_kit::button(ui, "Download", ui_kit::Button::Small).clicked() {
act = Some(("download", e.name.clone()));
}
if ui_kit::button(ui, "Delete", ui_kit::Button::Small).clicked() {
act = Some(("delete", e.name.clone()));
}
});
});
ui.end_row();
}
});
});
+9
View File
@@ -866,6 +866,15 @@ const ELEMENTS: &[Element] = &[
});
});
}),
element!("name_list", "dialog:table:gallery_names:Bracket.solidcraft", None, |ui, _| {
name_list(ui, "gallery_names", &["Name", "Size", "Actions"], "No files", |list| {
list.row("Bracket.solidcraft", |row| {
row.name("Bracket.solidcraft");
row.cell(|ui| text(ui, "12.3 KB", Text::Inline));
row.cell(|ui| button(ui, "Open", Button::Small));
});
});
}),
element!("list_picker", "dialog:list:gallery", Some("dialog:list:gallery"), |ui, _| {
list_picker(ui, "gallery", "Preset", true);
}),
+2
View File
@@ -20,6 +20,7 @@ mod layout;
mod look_chain;
mod menu;
mod metrics;
mod name_list;
mod navigation;
mod navigation_menu;
mod navigation_settings;
@@ -62,6 +63,7 @@ pub(crate) use layout::*;
pub use look_chain::{LookStep, look_chain};
pub(crate) use menu::{Menu, MenuItem, rename_menu, workspace_menu};
pub(crate) use metrics::{ContentWidth, header_height, row_height, table_row_height};
pub use name_list::{NameList, NameRow, name_list};
pub(crate) use navigation::*;
pub(crate) use navigation_menu::*;
pub(crate) use navigation_settings::*;
+116
View File
@@ -0,0 +1,116 @@
//! A list of named rows, such as the web app's stored files: the name takes the width the other
//! cells leave. Built on the kit's table grid; see `docs/ui-kit.md` for tokens and usage.
use super::metrics::dimension;
use super::table::{Column, Table, TableRow, table_custom};
use crate::{scenario, theme::Tokens};
use egui::{Response, Ui, vec2};
/// Columns past this are ignored: a list of named rows has a handful of cells.
const MAX_COLUMNS: usize = 16;
/// Widest a cell past the name is laid out and measured, in points.
const MEASURE_WIDTH: f32 = 4096.0;
/// Draw a list whose first column, the name, takes every point the other columns leave. A name
/// is only cut, with an ellipsis and the full name on hover, when even that width is too narrow.
/// The other columns are as wide as their widest cell, measured as the rows are drawn: a frame
/// whose measurement changed is discarded and drawn again, so a new row never overlaps.
/// `columns` names the columns for automation (`dialog:table:{id}:{key}:cell:{column}`); no
/// header is drawn. Tokens: form_label_width, font_label, form_ink, space_8, table_row_height.
pub fn name_list(ui: &mut Ui, id: &str, columns: &[&str], empty: &str, add: impl FnOnce(&mut NameList<'_, '_>)) {
let t = Tokens::get();
let columns = columns.get(..columns.len().min(MAX_COLUMNS)).unwrap_or_default();
let key = ui.id().with(("name_list", id));
let measured: Vec<f32> = ui.data(|d| d.get_temp(key)).unwrap_or_default();
let grid: Vec<Column<'_>> = columns
.iter()
.enumerate()
.map(|(i, label)| {
if i == 0 {
Column::new(label, 1.0).flex().min_content_width(t.form_label_width)
} else {
Column::new(label, 0.0).min_content_width(measured.get(i).copied().unwrap_or(0.0))
}
})
.collect();
let mut widest = vec![0.0; columns.len()];
table_custom(ui, id, &grid, empty, |ui, table| add(&mut NameList { ui, table, widest: &mut widest }));
let settled = widest.len() == measured.len() && widest.iter().zip(&measured).all(|(a, b)| (a - b).abs() <= 0.5);
if !settled {
ui.data_mut(|d| d.insert_temp(key, widest));
ui.ctx().request_discard("name list measured its cells");
}
}
/// The rows of a [`name_list`].
pub struct NameList<'a, 'b> {
ui: &'a mut Ui,
table: &'a mut Table<'b>,
widest: &'a mut Vec<f32>,
}
impl NameList<'_, '_> {
/// One row; `key` (the name, say) identifies it for automation. Cells go left to right.
pub fn row(&mut self, key: &str, add: impl FnOnce(&mut NameRow<'_, '_>)) -> Response {
let widest = &mut *self.widest;
self.table.row(self.ui, key, false, |row| add(&mut NameRow { row, widest, column: 0 }))
}
}
/// The cells of one [`NameList`] row.
pub struct NameRow<'a, 'b> {
row: &'a mut TableRow<'b>,
widest: &'a mut Vec<f32>,
column: usize,
}
impl NameRow<'_, '_> {
/// The name, in the next cell (the first, normally).
pub fn name(&mut self, name: &str) -> Response {
self.cell(|ui| name_text(ui, name))
}
/// Any content in the next cell, such as a name editor, a size or row actions. Past the name,
/// the content's own width sets the column's width.
pub fn cell<R>(&mut self, add: impl FnOnce(&mut Ui) -> R) -> R {
let column = self.column;
self.column += 1;
let widest = &mut *self.widest;
self.row.cell(|ui| {
if column == 0 {
return add(ui);
}
// Lay the content out at its own width (no eliding, wrapping or shrinking to the
// current column), so the measurement can grow the column; the cell still clips.
let rect = egui::Rect::from_min_size(ui.max_rect().min, vec2(MEASURE_WIDTH, ui.max_rect().height()));
let inner = ui.scope_builder(egui::UiBuilder::new().max_rect(rect).layout(egui::Layout::left_to_right(egui::Align::Center)), |ui| {
ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Extend);
let result = add(ui);
(result, ui.min_rect().width())
});
let (result, used) = inner.inner;
if let Some(width) = widest.get_mut(column) {
*width = width.max(dimension(used).min(MEASURE_WIDTH).ceil());
}
result
})
}
}
/// One line of name text across the cell. Only a name that does not fit is cut with an ellipsis
/// and given its full text on hover. Tokens: font_label, form_ink, control_height.
fn name_text(ui: &mut Ui, name: &str) -> Response {
let t = Tokens::get();
let font = egui::FontId::proportional(t.font_label);
let (rect, response) = ui.allocate_exact_size(vec2(dimension(ui.available_width()), super::row_height()), egui::Sense::hover());
let mut job = egui::text::LayoutJob::single_section(name.to_owned(), egui::TextFormat::simple(font.clone(), t.form_ink));
job.wrap.max_width = rect.width();
job.wrap.max_rows = 1;
let cut = ui.fonts_mut(|fonts| fonts.layout_job(job)).elided;
super::text::paint_text(ui, rect, name, font, t.form_ink, false);
response.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Label, ui.is_enabled(), name));
let id = format!("dialog:name:{name}");
scenario::publish_rect(&id, rect);
scenario::publish_count(&format!("{id}:cut"), f64::from(u8::from(cut)));
if cut { response.on_hover_text(name) } else { response }
}
+44
View File
@@ -304,3 +304,47 @@ fn horizontal_bar_is_painted_only_for_actual_table_overflow() {
}
}
}
/// #8097: a stored file's long name takes the width the size and actions leave (no empty band
/// on the right), and is only cut, with the full name on hover, when even that is too narrow.
#[test]
fn name_list_gives_the_name_the_width_the_other_cells_leave() {
let long = "a-rather-long-stored-design-name-for-the-bracket-v12.solidcraft";
for (width, cut) in [(900.0, false), (420.0, true)] {
let ctx = crate::fonts::test_context();
for _ in 0..4 {
harness::frame(&ctx, vec![], |ui| {
ui.set_width(width);
ui_kit::name_list(ui, "files", &["Name", "Size", "Actions"], "Empty", |list| {
for name in [long, "b.step"] {
list.row(name, |row| {
row.name(name);
row.cell(|ui| ui.label("12.3 KB"));
row.cell(|ui| {
ui_kit::button(ui, "Open", ui_kit::Button::Small);
ui_kit::button(ui, "Save to computer…", ui_kit::Button::Small);
ui_kit::button(ui, "Delete", ui_kit::Button::Small);
});
});
}
});
});
}
let t = Tokens::get();
let row = scenario::rect_of(&format!("dialog:table:files:{long}")).unwrap();
let name = scenario::rect_of(&format!("dialog:table:files:{long}:cell:Name")).unwrap();
let size = scenario::rect_of(&format!("dialog:table:files:{long}:cell:Size")).unwrap();
let actions = scenario::rect_of(&format!("dialog:table:files:{long}:cell:Actions")).unwrap();
// The actions end at the row's inset: nothing is left over on the right.
assert!((row.right() - actions.right() - t.space_8).abs() <= 1.0, "{width}: row {row:?} actions {actions:?}");
// The size and actions are as wide as their content, not wider; the name has the rest.
assert!(size.width() < 80.0 && actions.width() < 320.0, "{width}: size {size:?} actions {actions:?}");
// ...and never narrower: the size is not cut and every action button keeps its label.
let ctx_label = |text: &str| ctx.fonts_mut(|f| f.layout_no_wrap(text.into(), egui::FontId::proportional(t.font_label), t.form_ink).size().x);
assert!(size.width() >= ctx_label("12.3 KB") * 0.8, "{width}: size {size:?}");
assert!(actions.width() >= ctx_label("OpenSave to computer…Delete"), "{width}: actions {actions:?}");
assert!((size.left() - name.right() - t.space_8).abs() <= 1.0);
assert_eq!(scenario::count_of(&format!("dialog:name:{long}:cut")), Some(f64::from(u8::from(cut))), "{width}: name {name:?}");
assert_eq!(scenario::count_of("dialog:name:b.step:cut"), Some(0.0));
}
}
+1
View File
@@ -176,6 +176,7 @@ table. Panel/Window/Confirm compositions also have dedicated geometry and intera
| `keyboard` | Esc cancels, unowned Enter submits when valid | none |
| `action_menu`, `command_menu_button` | Nested dense action menu or ribbon overflow action retaining its icon, shortcut and enabled state | form control/font tokens, `space_16`, icon palette |
| table: `table`, `table_custom`, `Column`, `Table::headers`, `Table::row`, `TableRow::cell`, `Table::add_prompt` | Left-aligned headers/cells, horizontal overflow, selected/hover rows and empty state. `table_custom` supplies header actions through `headers`. `Column::flex` shares remaining width by weight, freezing columns at their control minimums before redistributing the remaining space; `Column::icon_only` hides the heading while retaining its automation identity. `add_prompt` is the final slim dashed line and requests a regular draft row from its owner; `Column::new(label, width)` uses label-column multiples, `min_content_width(points)` reserves measured control content; `ContentWidth::name` measures strong configuration names | label-column tokens, `control_height`, `dialog_rule/footer`, `selected_bg`, spacing |
| `name_list`, `NameList::row`, `NameRow::name`, `NameRow::cell` | A list of named rows on the table grid (the web app's stored files): the name column takes the width the other columns leave; the other columns are as wide as their widest cell, measured as drawn (a changed measurement discards the frame). A name is cut with an ellipsis, and given its full text on hover, only when it does not fit; `dialog:name:NAME:cut` reports it | `form_label_width`, `font_label`, `form_ink`, `space_8`, `table_row_height` |
| `removable_header`, `plus_header`, `bin_button`, `active_pill` | Hover-only column removal, anchored Add Column menu with insertion brackets, icon-only immediate deletion and active-row status. Bins preserve `dialog:button:Actions:Delete` and `:×`; header removal preserves `dialog:button:LABEL:×`. | `control_*`, `form_*`, `selected_bg`, spacing |
| `compact_button`, `summary_row` | Borderless stars and chevrons with enabled/selected states; named two-line rule summary beside an enable checkbox and compact actions. | `form_close_size`, `control_*`, `form_*`, typography and spacing |
| `label_actions` | Clipped row name beside compact actions | `control_height`, form font/spacing tokens |