Table Design: draw the Table Styles gallery in the ribbon (#2148)

This commit is contained in:
Francisco Herrera
2026-10-21 14:44:47 -05:00
parent 37e41424ed
commit a9223eabf8
+34 -5
View File
@@ -2268,10 +2268,10 @@ fn automate(app: &mut SheetApp, ui: &mut Ui) {
}
fn table_design(app: &mut SheetApp, ui: &mut Ui) {
let Some((tname, header, totals, banded, banded_c, first, last, filter)) = app.session.active().and_then(|d| {
let Some((tname, header, totals, banded, banded_c, first, last, filter, style)) = app.session.active().and_then(|d| {
let sh = d.wb.active()?;
let t = sh.table_at(d.selection.active)?;
Some((t.name.clone(), t.header_row, t.totals_row, t.banded_rows, t.banded_cols, t.first_col, t.last_col, t.filter_button))
Some((t.name.clone(), t.header_row, t.totals_row, t.banded_rows, t.banded_cols, t.first_col, t.last_col, t.filter_button, t.style.clone()))
}) else {
return;
};
@@ -2325,9 +2325,38 @@ fn table_design(app: &mut SheetApp, ui: &mut Ui) {
}
});
sep(ui);
let st = big_button(ui, Icon::FormatTable, "Table\nStyles", "Table Styles", true);
anchor_keytip(app, ui, &st, &["table.style"]);
egui::Popup::menu(&st).show(|ui| table_gallery(app, ui, "table.style"));
table_style_strip(app, ui, &tname, &style);
}
/// The first page of Excel's Table Styles gallery, drawn in the ribbon. The More arrow opens the
/// full gallery (Light, Medium, Dark) as a popup.
const RIBBON_TABLE_STYLES: [&str; 7] =
["TableStyleLight1", "TableStyleLight2", "TableStyleLight3", "TableStyleLight4", "TableStyleLight5", "TableStyleLight6", "TableStyleLight7"];
fn table_style_strip(app: &mut SheetApp, ui: &mut Ui, tname: &str, current: &str) {
let Some(wb) = app.session.active().map(|d| d.wb.clone()) else { return };
let t = Tokens::get(ui.ctx());
ui.add_space(12.0);
ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = 3.0;
for name in RIBBON_TABLE_STYLES {
let (r, resp) = ui.allocate_exact_size(vec2(52.0, 40.0), Sense::click());
paint_table_swatch(ui, r, &wb, name);
if resp.hovered() {
ui.painter().rect_stroke(r.expand(1.5), 2.0, Stroke::new(2.0, Color32::from_rgb(0xE8, 0x7D, 0x2B)), StrokeKind::Outside);
}
if name == current {
ui.painter().rect_stroke(r.expand(1.5), 2.0, Stroke::new(2.0, t.accent), StrokeKind::Outside);
}
let resp = resp.on_hover_text(name);
if resp.clicked() {
act(app, "table.style", json!({"table": tname, "style": name}));
}
}
let more = icon_button(ui, Icon::Chevron, t.text_dim, "More Table Styles", vec2(18.0, 40.0));
anchor_keytip(app, ui, &more, &["table.style"]);
egui::Popup::menu(&more).show(|ui| table_gallery(app, ui, "table.style"));
});
}
fn chart_design(app: &mut SheetApp, ui: &mut Ui) {