DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge #253: Integrate Windows window controls into the menu bar
aiongg7f940dc4f8e9
diff --cc apps/designcraft/src/main.rsindex 50fdc3589,d1ed4a154..5d29bb9a4--- a/apps/designcraft/src/main.rs+++ b/apps/designcraft/src/main.rs@@@ -437,106 -300,64 +438,107 @@@ fn main() -> std::process::ExitCodeb.with_x11();}));}- // AppKit Dock Quit otherwise terminates before egui can cancel the close. Route it through- // ordinary CloseRequested events, preserving the same transactional Save/Don't Save flow.+ // Registered before the event loop starts, so it catches the Finder event that launched the app+ // as well as later ones. Lives until the event loop returns; the app creator only borrows it.#[cfg(target_os = "macos")]- {- options.event_loop_builder = Some(Box::new(|builder| {- use winit::platform::macos::EventLoopBuilderExtMacOS;- builder.with_close_requested_on_terminate(true);- }));- }- eframe::run_native(- "DesignCraft",- options,- Box::new(move |cc| {- let mut gpu = gpu;- if let Some(rs) = &cc.wgpu_render_state {- // What a bug report needs to know about the graphics driver.- let info = rs.adapter.get_info();- log::info!("graphics: {} on {:?} ({:?}; driver {} {})", info.name, info.backend, info.device_type, info.driver, info.driver_info);- if let (Some(s), Some(backend)) = (gpu.as_mut(), gpu::Backend::of(info.backend)) {- s.started_with(backend);+ let apple_events = apple_events::AppleEvents::install();+ #[cfg(target_os = "macos")]+ let events = &apple_events;+ let created = startup.clone();+ // A panic that ends the window (egui-wgpu's own) is caught here: never a crash.+ let run = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {+ eframe::run_native(+ "DesignCraft",+ options,+ Box::new(move |cc| {+ let mut restarted = None;+ let mut device = None;+ if let Some(rs) = &cc.wgpu_render_state {+ device = Some(rs.device.clone());+ // What a bug report needs to know about the graphics driver.+ let info = rs.adapter.get_info();+ log::info!(+ "graphics: {} on {:?} ({:?}; driver {} {}; power preference {power:?})",+ info.name,+ info.backend,+ info.device_type,+ info.driver,+ info.driver_info+ );+ created.started_with(info.backend);+ created.created(&cc.egui_ctx);+ if !skip.is_empty() {+ // A processor chosen by `WGPU_POWER_PREF` can be the one that can't show the window.+ let hint = if chosen_gpu { " (without WGPU_POWER_PREF it uses the one that drives your display)" } else { "" };+ restarted = Some(format!(+ "The graphics processor tried first couldn't show the window, so DesignCraft started again on {} ({:?}, {:?}){hint}.",+ info.name.trim(),+ info.backend,+ info.device_type+ ));+ }}- }- let mut session = Session::new();- // Crash recovery: reopen what a previous run left unsaved, then keep it current.- session.recovery_dir = profile::recovery_dir();- let recovered = session.execute("file.recovery.open", &serde_json::json!({})).ok();- let mut app = DesignApp::new(session, services());- if let Some(line) = gpu.as_ref().and_then(gpu::Startup::status_line) {- app.status(line);- }- // Recovered documents matter more than the graphics note; both are in the log.- if let Some(n) = recovered.as_ref().and_then(|r| r["opened"].as_array()).map(Vec::len).filter(|n| *n > 0) {- app.status(format!("Recovered {n} unsaved document{} from the last session.", if n == 1 { "" } else { "s" }));- }- load_prefs(&mut app);- app.integrated_titlebar = cfg!(target_os = "macos");- app.custom_titlebar = cfg!(target_os = "windows");- if let Some(port) = control_port {- let rx = control_server::start(port, cc.egui_ctx.clone());- app = app.with_control(rx);- }- if sample {- let _ = app.run("file.newSample", serde_json::json!({}));- }- for f in files {- if let Err(e) = app.open_file("file.open", serde_json::json!({"path": f})) {- eprintln!("designcraft: {f}: {e}");+ let mut session = Session::new();+ // Crash recovery: reopen what a previous run left unsaved, then keep it current.+ session.recovery_dir = profile::recovery_dir();+ let recovered = session.execute("file.recovery.open", &serde_json::json!({})).ok();+ let mut app = DesignApp::new(session, services());+ if let Some(line) = restarted.or_else(|| created.status_line()) {+ app.status(line);}- }- Ok(Box::new(App {- app,- #[cfg(target_os = "macos")]- menu: None,- startup: gpu,- frames: 0,- }))- }),- )+ // Recovered documents matter more than the graphics note; both are in the log.+ if let Some(n) = recovered.as_ref().and_then(|r| r["opened"].as_array()).map(Vec::len).filter(|n| *n > 0) {+ app.status(format!("Recovered {n} unsaved document{} from the last session.", if n == 1 { "" } else { "s" }));+ }+ load_prefs(&mut app);+ // After `load_prefs`, which replaces the UI state and with it the status line.+ if let Some(note) = portable_note {+ app.status(note);+ }+ app.integrated_titlebar = cfg!(target_os = "macos");++ app.custom_titlebar = cfg!(target_os = "windows");+ if let Some(port) = control_port {+ let rx = control_server::start(port, cc.egui_ctx.clone());+ app = app.with_control(rx);+ }+ if sample {+ let _ = app.run("file.newSample", serde_json::json!({}));+ }+ for f in files {+ if let Err(e) = app.open_file("file.open", serde_json::json!({"path": f})) {+ log::warn!("{f}: {e}");+ }+ }+ // The first frame is due from now (`gpu::watch_first_frame`).+ created.ready();+ Ok(Box::new(App {+ app,+ #[cfg(target_os = "macos")]+ menu: None,+ startup: created,+ #[cfg(target_os = "macos")]+ apple_events: events.connect(&cc.egui_ctx),+ #[cfg(target_os = "macos")]+ movable: None,+ frames: 0,+ log_errors_after_startup: device,+ }))+ }),+ )+ }))+ .map_err(|payload| designcraft_engine::guard::panic_message(payload.as_ref()));+ // The window's end, or a graphics failure that starts the app again. A failure is logged:+ // standard error and the log file, since a Windows start has no console to show it.+ // Documents that arrived after the last frame, for a start again to open too.+ #[cfg(target_os = "macos")]+ startup.opening(apple_events.queued());+ match gpu::finish(run, &startup) {+ Ok(()) => std::process::ExitCode::SUCCESS,+ Err(e) => {+ log::error!("DesignCraft stopped: {e}");+ std::process::ExitCode::FAILURE+ }+ }}#[cfg(test)]diff --cc crates/ui-egui/src/chrome.rsindex 68de574f7,fdfb383ea..750bc7a92--- a/crates/ui-egui/src/chrome.rs+++ b/crates/ui-egui/src/chrome.rs@@@ -10,302 -10,176 +10,347 @@@ use crate::theme::{Tokens, semibold}use crate::widgets::{caption, measure, number};use crate::{DesignApp, icons};+/// Height of the application bar (InDesign 2026), then a 7 pt lower band and a 1 pt border. The+/// band covers the panel's 1 pt separator line, so the frame's bottom margin is 1 pt short of it.+const APP_BAR: f32 = 36.0;+const APP_BAR_BAND: f32 = 7.0;+const SEPARATOR: f32 = 1.0;+/// Height of the application bar on macOS, where it is the window's title bar (#333). AppKit draws+/// the traffic lights itself, centred in the standard 28 pt title-bar band at the top of the+/// window; moving them would take AppKit calls (`unsafe`, which the workspace forbids). So the bar+/// is that band: the lights sit vertically centred in it, with the bar's controls beside them.+pub const MAC_APP_BAR: f32 = 28.0;+/// The traffic lights as AppKit lays them out: button diameter, centre-to-centre pitch and the+/// first button's left edge (8–10 pt depending on the macOS version; the larger value keeps the+/// gap after them from shrinking).+const MAC_LIGHT: f32 = 12.0;+const MAC_LIGHT_PITCH: f32 = 20.0;+const MAC_LIGHTS_LEFT: f32 = 10.0;+/// Where the bar's content starts to the right of the traffic lights: the end of the three lights+/// plus the same gap the lights keep from the top of the window.+pub const MAC_CONTENT_LEFT: f32 = MAC_LIGHTS_LEFT + 2.0 * MAC_LIGHT_PITCH + MAC_LIGHT + (MAC_APP_BAR - MAC_LIGHT) / 2.0;++fn search_id() -> egui::Id {+ egui::Id::new("app_bar_search")+}++/// Whether the application bar's search field had the keyboard last frame. Escape takes egui's+/// focus away before any widget runs, so that press must not reach the global shortcuts.+pub fn search_had_focus(ctx: &egui::Context) -> bool {+ ctx.memory(|m| m.had_focus_last_frame(search_id()))+}++/// The search field's state between frames: the query, the highlighted match, whether the matches+/// are shown, and the widget that had the keyboard before the field took it.+#[derive(Clone, Default)]+struct SearchState {+ query: String,+ highlight: usize,+ open: bool,+ previous_focus: Option<egui::Id>,+}++/// The application bar's search field: finds menu commands by their labels in the interface+/// language. ↑/↓ move through the matches; Return or a click runs one as its menu item would.+/// Running one or pressing Escape clears the field and gives the keyboard back to the widget that+/// had it. While the field has the keyboard, no key reaches the shortcuts or the document.+fn search_field(app: &mut DesignApp, ui: &mut egui::Ui) {+ let t = Tokens::get(ui.ctx());+ let id = search_id();+ let state_id = id.with("state");+ let mut st: SearchState = ui.data(|d| d.get_temp(state_id)).unwrap_or_default();+ let (r, _) = ui.allocate_exact_size(vec2(125.0, 18.0), Sense::hover());+ ui.painter().rect(r, 1.0, t.input, Stroke::new(1.0, t.field_border), egui::StrokeKind::Inside);+ icons::paint(ui.painter(), egui::Rect::from_min_size(r.min + vec2(3.0, 2.0), vec2(14.0, 14.0)), "search", t.icon);+ let focused = ui.memory(|m| m.has_focus(id));+ let had_focus = search_had_focus(ui.ctx());+ if !focused && !had_focus {+ st.previous_focus = ui.memory(|m| m.focused());+ }+ let none = egui::Modifiers::NONE;+ let (down, up, enter, escape) = if focused || had_focus {+ ui.input_mut(|i| {+ (+ i.consume_key(none, egui::Key::ArrowDown),+ i.consume_key(none, egui::Key::ArrowUp),+ i.consume_key(none, egui::Key::Enter),+ i.consume_key(none, egui::Key::Escape),+ )+ })+ } else {+ (false, false, false, false)+ };+ let lang = app.ui.language.clone();+ let hint = crate::rtl::widget(ui, egui::RichText::new(crate::i18n::tr(&lang, "Search")).color(t.text_dim));+ let field = egui::Rect::from_min_max(r.min + vec2(19.0, 0.0), r.max - vec2(3.0, 0.0));+ let resp = ui+ .put(+ field,+ egui::TextEdit::singleline(&mut st.query)+ .id(id)+ .frame(egui::Frame::NONE)+ .margin(egui::Margin::ZERO)+ .font(egui::FontId::proportional(11.0))+ .text_color(t.text)+ .hint_text(hint)+ .desired_width(field.width())+ .vertical_align(egui::Align::Center)+ // Return runs the highlighted match instead of leaving the field.+ .return_key(None),+ )+ .on_hover_text(crate::i18n::tr(&lang, "Search commands"));+ if resp.changed() {+ st.highlight = 0;+ st.open = true;+ }+ if resp.gained_focus() {+ st.open = true;+ }+ let items = if st.open { crate::menus::command_search(app, &st.query) } else { Vec::new() };+ let last = items.len().saturating_sub(1);+ if down {+ st.highlight = st.highlight.saturating_add(1);+ }+ if up {+ st.highlight = st.highlight.saturating_sub(1);+ }+ st.highlight = st.highlight.min(last);+ let mut run = None;+ if enter && let Some(it) = items.get(st.highlight).filter(|it| crate::menus::menu_enabled(app, &it.id)) {+ run = Some(it.id.clone());+ }+ let mut over_matches = false;+ if st.open && !st.query.trim().is_empty() {+ let shown = egui::Area::new(id.with("matches"))+ .order(egui::Order::Foreground)+ .pivot(egui::Align2::RIGHT_TOP)+ .fixed_pos(r.right_bottom() + vec2(0.0, 2.0))+ .show(ui.ctx(), |ui| {+ egui::Frame::menu(ui.style()).show(ui, |ui| {+ let size = vec2(300.0, 22.0);+ ui.set_width(size.x);+ if items.is_empty() {+ crate::rtl::label(ui, egui::RichText::new(crate::i18n::tr(&lang, "No matching commands")).color(t.text_dim));+ }+ for (k, it) in items.iter().enumerate() {+ let mut b = egui::Button::new(crate::rtl::widget(ui, it.label.as_str())).frame(false).min_size(size);+ if let Some(sc) = &it.shortcut {+ b = b.shortcut_text(crate::menus::shortcut_text(sc));+ }+ if k == st.highlight {+ ui.painter().rect_filled(egui::Rect::from_min_size(ui.cursor().min, size), 2.0, t.hover);+ }+ let enabled = crate::menus::menu_enabled(app, &it.id);+ // The button aligns its label by the layout it's in: left, like the menus.+ let row = ui.allocate_ui_with_layout(+ size,+ egui::Layout::left_to_right(egui::Align::Center).with_main_align(egui::Align::Min),+ |ui| ui.add_enabled(enabled, b),+ );+ if row.inner.clicked() {+ run = Some(it.id.clone());+ }+ }+ });+ });+ over_matches = shown.response.contains_pointer();+ }+ if escape || run.is_some() {+ st.query.clear();+ st.open = false;+ let previous = st.previous_focus.take();+ ui.memory_mut(|m| match previous {+ Some(p) => m.request_focus(p),+ None => m.surrender_focus(id),+ });+ } else if !resp.has_focus() && !over_matches {+ // A click elsewhere or Tab took the keyboard: the matches close, the query stays.+ st.open = false;+ }+ ui.data_mut(|d| d.insert_temp(state_id, st));+ if let Some(cmd) = run {+ crate::menus::activate(app, &cmd, &serde_json::Value::Null);+ }+}++/// Width of the app bar's right-hand slot: what is left of the row, minus a pixel of slack so+/// that rounding at fractional scales (115%) never makes the row a hair wider than the scroll+/// area and shows a needless scroll bar. Never narrower than the controls themselves.+fn tools_slot_width(available: f32, tools_w: f32) -> f32 {+ (available - 1.0).max(tools_w)+}+pub fn app_bar(app: &mut DesignApp, ui: &mut egui::Ui) {let t = Tokens::get(ui.ctx());- let left = if app.integrated_titlebar { 78 } else { 8 };- // 36 pt bar + 7 pt lower band (InDesign 2026), then a 1 pt border.+ let mac = app.integrated_titlebar;+ let left = if mac { MAC_CONTENT_LEFT as i8 } else { 8 };+ let bar = if mac { MAC_APP_BAR } else { APP_BAR };+ // The tallest control keeps a margin above and below it in the shorter macOS bar.+ let home = if mac { 22.0 } else { 24.0 };let resp = egui::Panel::top("app_bar")- .exact_size(43.0)+ .exact_size(bar + APP_BAR_BAND)- .frame(egui::Frame::NONE.fill(t.app_bar).inner_margin(egui::Margin { left, right: 10, top: 0, bottom: (APP_BAR_BAND - SEPARATOR) as i8 }))+ .frame(egui::Frame::NONE.fill(t.app_bar).inner_margin(egui::Margin {+ left,+ right: if app.custom_titlebar { 0 } else { 10 },+ top: 0,- bottom: 7,++ bottom: (APP_BAR_BAND - SEPARATOR) as i8,+ })).show(ui, |ui| {let full = ui.max_rect();+ if mac {+ // The whole title-bar band, margins included; the controls drawn below take+ // their own clicks.+ let band = egui::Rect::from_min_max(+ egui::pos2(full.min.x - f32::from(left), full.min.y),+ egui::pos2(full.max.x + 10.0, full.min.y + MAC_APP_BAR),+ );+ crate::title_bar::empty_area(ui, band);+ }let mut menus_end = full.min.x;let mut tools_start = full.max.x;- // The right-hand controls' width, measured last frame: in a window too narrow for them- // and the menus they follow the menus, and the bar scrolls sideways.- let tools_w_id = ui.id().with("tools_width");- let tools_w: f32 = ui.data(|d| d.get_temp(tools_w_id)).unwrap_or(0.0);- crate::widgets::overflow_scrolling(ui);- egui::ScrollArea::horizontal().id_salt("app_bar_scroll").auto_shrink([false, false]).show(ui, |ui| {- ui.horizontal_centered(|ui| {- if icons::button(ui, "home", home, app.session.active().is_none(), crate::i18n::tr(&app.ui.language, "Home")).clicked() {- app.session_home();- }- ui.add_space(6.0);- if !app.native_menu {- ui.style_mut().visuals.widgets.inactive.weak_bg_fill = Color32::TRANSPARENT;- ui.style_mut().visuals.widgets.inactive.bg_stroke = Stroke::NONE;- ui.style_mut().visuals.widgets.hovered.bg_stroke = Stroke::NONE;- ui.style_mut().spacing.button_padding = vec2(7.0, 3.0);- crate::menus::menu_bar(app, ui);- }- menus_end = ui.min_rect().max.x;- let size = vec2(tools_slot_width(ui.available_width(), tools_w), ui.available_height());- let tools = ui.allocate_ui_with_layout(size, egui::Layout::right_to_left(egui::Align::Center), |ui| {- ui.add_space(4.0);- search_field(app, ui);- ui.add_space(8.0);- let current = app.ui.workspace.clone();- let shown = crate::i18n::workspace_name(&app.ui.language, ¤t);- crate::menus::menu_button(- ui,- crate::rtl::widget(ui, egui::RichText::new(format!("{shown} ▾")).font(semibold(11.5)).color(t.text)),- |ui| {- let customs: Vec<String> = app.ui.custom_workspaces.iter().map(|w| w.name.clone()).collect();- for w in [- "Essentials",- "Advanced",- "Book",- "Digital Publishing",- "Interactive for PDF",- "Printing and Proofing",- "Typography",- ]- .into_iter()- .map(str::to_string)- .chain(customs.iter().cloned())- {+ // Windows caption buttons stay at the right edge; the rest of the bar scrolls.+ let caption_w = if app.custom_titlebar { CAPTION_W } else { 0.0 };+ // Undecorated window: the bar moves it. The drag area is the whole bar but the caption+ // buttons, lower band included, registered before the menus and tools so they stay on+ // top of it: any gap drags, and the lower band is always there, however narrow the+ // window (the menus and tools scroll).+ if app.custom_titlebar {+ let drag = egui::Rect::from_min_max(+ egui::pos2(full.min.x - left as f32, full.min.y),- egui::pos2(full.max.x - caption_w, full.min.y + BAR_H + LOWER_BAND),++ egui::pos2(full.max.x - caption_w, full.min.y + bar + APP_BAR_BAND),+ );+ let response = ui.interact(drag, egui::Id::new("window_title_drag"), Sense::click_and_drag());+ // Only from an empty part of the bar: the lower band, or the gap between the menus+ // and the tools (as they were last frame). A menu title pressed and dragged doesn't+ // move the window, as with native title bars.+ let (gap0, gap1) =+ ui.data(|d| (d.get_temp::<f32>(egui::Id::new("app_bar_menus_end")), d.get_temp::<f32>(egui::Id::new("app_bar_tools_start"))));- let empty = |p: egui::Pos2| p.y >= full.min.y + BAR_H || matches!((gap0, gap1), (Some(a), Some(b)) if p.x >= a && p.x <= b);++ let empty = |p: egui::Pos2| p.y >= full.min.y + bar || matches!((gap0, gap1), (Some(a), Some(b)) if p.x >= a && p.x <= b);+ let from_empty = ui.input(|i| i.pointer.press_origin().or(i.pointer.interact_pos())).is_some_and(empty);+ if response.double_clicked() && from_empty {+ let on = !ui.input(|i| i.viewport().maximized.unwrap_or(false));+ let _ = app.run("window.maximize", json!({"on": on}));+ } else if response.drag_started_by(egui::PointerButton::Primary) && from_empty {+ let _ = app.run("window.drag", json!({}));+ }+ app.flush_window_commands(ui.ctx());+ }+ if app.custom_titlebar {+ let caption = egui::Rect::from_min_max(egui::pos2(full.max.x - caption_w, full.min.y), full.max);+ ui.scope_builder(egui::UiBuilder::new().max_rect(caption).layout(egui::Layout::right_to_left(egui::Align::Center)), |ui| {+ caption_buttons(app, ui);+ });+ }+ let scrolled = egui::Rect::from_min_max(full.min, egui::pos2(full.max.x - caption_w, full.max.y));+ ui.scope_builder(egui::UiBuilder::new().max_rect(scrolled), |ui| {+ // The right-hand controls' width, measured last frame: in a window too narrow for them+ // and the menus they follow the menus, and the bar scrolls sideways.+ let tools_w_id = ui.id().with("tools_width");+ let tools_w: f32 = ui.data(|d| d.get_temp(tools_w_id)).unwrap_or(0.0);+ crate::widgets::overflow_scrolling(ui);+ // (Drag-scrolling is touch-only by default, so a mouse drag on the bar moves the window.)+ egui::ScrollArea::horizontal().id_salt("app_bar_scroll").auto_shrink([false, false]).show(ui, |ui| {+ ui.horizontal_centered(|ui| {- if icons::button(ui, "home", 24.0, app.session.active().is_none(), crate::i18n::tr(&app.ui.language, "Home")).clicked() {++ if icons::button(ui, "home", home, app.session.active().is_none(), crate::i18n::tr(&app.ui.language, "Home")).clicked() {+ app.session_home();+ }+ ui.add_space(6.0);+ if !app.native_menu {+ ui.style_mut().visuals.widgets.inactive.weak_bg_fill = Color32::TRANSPARENT;+ ui.style_mut().visuals.widgets.inactive.bg_stroke = Stroke::NONE;+ ui.style_mut().visuals.widgets.hovered.bg_stroke = Stroke::NONE;+ ui.style_mut().spacing.button_padding = vec2(7.0, 3.0);+ crate::menus::menu_bar(app, ui);+ }+ menus_end = ui.min_rect().max.x;+ // Where the menus end on screen (moves as a narrow bar scrolls).+ ui.data_mut(|d| d.insert_temp(egui::Id::new("app_bar_menus_end"), menus_end));- let size = vec2(ui.available_width().max(tools_w), ui.available_height());++ let size = vec2(tools_slot_width(ui.available_width(), tools_w), ui.available_height());+ let tools = ui.allocate_ui_with_layout(size, egui::Layout::right_to_left(egui::Align::Center), |ui| {+ ui.add_space(4.0);- // Search field.- let (r, _) = ui.allocate_exact_size(vec2(125.0, 18.0), Sense::click());- ui.painter().rect(r, 1.0, t.input, Stroke::new(1.0, t.field_border), egui::StrokeKind::Inside);- icons::paint(ui.painter(), egui::Rect::from_min_size(r.min + vec2(3.0, 2.0), vec2(14.0, 14.0)), "search", t.icon);- crate::rtl::paint(- ui.painter(),- r.min + vec2(20.0, 9.0),- egui::Align2::LEFT_CENTER,- crate::i18n::tr(&app.ui.language, "Search"),- egui::FontId::proportional(11.0),- t.text_dim,- );++ search_field(app, ui);+ ui.add_space(8.0);+ let current = app.ui.workspace.clone();+ let shown = crate::i18n::workspace_name(&app.ui.language, ¤t);+ crate::menus::menu_button(+ ui,+ crate::rtl::widget(ui, egui::RichText::new(format!("{shown} ▾")).font(semibold(11.5)).color(t.text)),+ |ui| {+ let customs: Vec<String> = app.ui.custom_workspaces.iter().map(|w| w.name.clone()).collect();+ for w in [+ "Essentials",+ "Advanced",+ "Book",+ "Digital Publishing",+ "Interactive for PDF",+ "Printing and Proofing",+ "Typography",+ ]+ .into_iter()+ .map(str::to_string)+ .chain(customs.iter().cloned())+ {+ if ui+ .selectable_label(w == current, crate::rtl::widget(ui, crate::i18n::workspace_name(&app.ui.language, &w)))+ .clicked()+ {+ let _ = app.run("window.workspace", json!({"name": w}));+ ui.close();+ }+ }+ ui.separator();if ui- .selectable_label(w == current, crate::rtl::widget(ui, crate::i18n::workspace_name(&app.ui.language, &w)))+ .button(crate::rtl::widget(+ ui,+ format!(+ "{} {}",+ crate::i18n::tr(&app.ui.language, "Reset"),+ crate::i18n::workspace_name(&app.ui.language, ¤t)+ ),+ )).clicked(){- let _ = app.run("window.workspace", json!({"name": w}));+ let _ = app.run("window.resetWorkspace", json!({}));+ ui.close();+ }+ if ui.button(crate::rtl::widget(ui, crate::i18n::tr(&app.ui.language, "New Workspace…"))).clicked() {+ let _ = app.run("window.newWorkspace", json!({}));ui.close();}- }- ui.separator();- if ui- .button(crate::rtl::widget(- ui,- format!(- "{} {}",- crate::i18n::tr(&app.ui.language, "Reset"),- crate::i18n::workspace_name(&app.ui.language, ¤t)- ),- ))- .clicked()- {- let _ = app.run("window.resetWorkspace", json!({}));- ui.close();- }- if ui.button(crate::rtl::widget(ui, crate::i18n::tr(&app.ui.language, "New Workspace…"))).clicked() {- let _ = app.run("window.newWorkspace", json!({}));- ui.close();- }- if !customs.is_empty() {- crate::menus::menu_button(- ui,- crate::rtl::widget(ui, crate::i18n::tr(&app.ui.language, "Delete Workspace")),- |ui| {- for w in &customs {- if ui.button(w).clicked() {- let _ = app.run("window.deleteWorkspace", json!({"name": w}));- ui.close();+ if !customs.is_empty() {+ crate::menus::menu_button(+ ui,+ crate::rtl::widget(ui, crate::i18n::tr(&app.ui.language, "Delete Workspace")),+ |ui| {+ for w in &customs {+ if ui.button(w).clicked() {+ let _ = app.run("window.deleteWorkspace", json!({"name": w}));+ ui.close();+ }}- }- },- );- }- },- );- ui.add_space(6.0);- if icons::button(ui, "share", 22.0, false, crate::i18n::tr(&app.ui.language, "Share")).clicked() {- app.status(crate::i18n::tr(&app.ui.language, "Export a PDF, IDML or package to share — no cloud account needed."));- }- ui.add_space(8.0);- // Always one click away: the ArtCraft community Discord.- if crate::about::discord_button(ui, "Discord", vec2(78.0, 22.0)) {- let _ = app.run("help.discord", json!({}));+ },+ );+ }+ },+ );+ ui.add_space(6.0);+ if icons::button(ui, "share", 22.0, false, crate::i18n::tr(&app.ui.language, "Share")).clicked() {- app.status("Export a PDF, IDML or package to share — no cloud account needed.");++ app.status(crate::i18n::tr(&app.ui.language, "Export a PDF, IDML or package to share — no cloud account needed."));+ }+ ui.add_space(8.0);+ // Always one click away: the ArtCraft community Discord.+ if crate::about::discord_button(ui, "Discord", vec2(78.0, 22.0)) {+ let _ = app.run("help.discord", json!({}));+ }+ tools_start = ui.min_rect().min.x;+ ui.data_mut(|d| d.insert_temp(egui::Id::new("app_bar_tools_start"), tools_start));+ ui.min_rect().width()+ });+ if (tools.inner - tools_w).abs() > 0.5 {+ ui.data_mut(|d| d.insert_temp(tools_w_id, tools.inner));+ ui.ctx().request_discard("app bar: the right-hand controls changed width");}- tools_start = ui.min_rect().min.x;- ui.min_rect().width()});- if (tools.inner - tools_w).abs() > 0.5 {- ui.data_mut(|d| d.insert_temp(tools_w_id, tools.inner));- ui.ctx().request_discard("app bar: the right-hand controls changed width");- }});});// Centred title.@@@ -326,9 -200,91 +371,88 @@@ui.painter().line_segment([egui::pos2(r.min.x, r.max.y), egui::pos2(r.max.x, r.max.y)], Stroke::new(1.0, t.border));}-/// The app bar: its 36 pt row and the 7 pt lower band under it (InDesign 2026).-const BAR_H: f32 = 36.0;-const LOWER_BAND: f32 = 7.0;+ const CAPTION_BUTTON_W: f32 = 46.0;+ /// Minimize, maximize and close, and the space after them.+ const CAPTION_W: f32 = 3.0 * CAPTION_BUTTON_W + 8.0;++ /// Windows caption buttons. The macOS traffic lights remain native.+ fn caption_buttons(app: &mut DesignApp, ui: &mut egui::Ui) {+ let t = Tokens::get(ui.ctx());+ let maximized = ui.input(|i| i.viewport().maximized.unwrap_or(false));+ let spacing = ui.spacing().item_spacing.x;+ ui.spacing_mut().item_spacing.x = 0.0;+ for (command, label) in+ [("window.close", "Close"), ("window.maximize", if maximized { "Restore" } else { "Maximize" }), ("window.minimize", "Minimize")]+ {- let (rect, _) = ui.allocate_exact_size(vec2(CAPTION_BUTTON_W, BAR_H), Sense::hover());++ let (rect, _) = ui.allocate_exact_size(vec2(CAPTION_BUTTON_W, APP_BAR), Sense::hover());+ let response = ui.interact(rect, egui::Id::new(command), Sense::click());+ response.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, ui.is_enabled(), label));+ let hovered = response.hovered();+ if hovered {+ ui.painter().rect_filled(rect, 0.0, if command == "window.close" { t.caption_close } else { t.hover });+ }+ let color = if hovered && command == "window.close" { t.caption_close_text } else { t.text };+ let stroke = Stroke::new(1.0, color);+ let icon = egui::Rect::from_center_size(rect.center(), vec2(10.0, 10.0));+ match command {+ "window.close" => {+ ui.painter().line_segment([icon.left_top(), icon.right_bottom()], stroke);+ ui.painter().line_segment([icon.right_top(), icon.left_bottom()], stroke);+ }+ "window.maximize" if maximized => {+ let back = icon.translate(vec2(2.0, -2.0));+ ui.painter().line_segment([back.left_top(), back.right_top()], stroke);+ ui.painter().line_segment([back.right_top(), back.right_bottom()], stroke);+ ui.painter().rect_stroke(icon, 0.0, stroke, egui::StrokeKind::Inside);+ }+ "window.maximize" => {+ ui.painter().rect_stroke(icon, 0.0, stroke, egui::StrokeKind::Inside);+ }+ _ => {+ ui.painter().line_segment([icon.left_center(), icon.right_center()], stroke);+ }+ }+ if response.clicked() {+ let params = if command == "window.maximize" { json!({"on": !maximized}) } else { json!({}) };+ let _ = app.run(command, params);+ app.flush_window_commands(ui.ctx());+ }+ response.on_hover_text(crate::i18n::tr(&app.ui.language, label));+ }+ ui.spacing_mut().item_spacing.x = spacing;+ ui.add_space(8.0);+ }++ /// Undecorated Windows windows need resize grips as well as caption controls.+ pub(crate) fn resize_borders(app: &mut DesignApp, ui: &mut egui::Ui) {+ if ui.input(|i| i.viewport().maximized.unwrap_or(false) || i.viewport().fullscreen.unwrap_or(false)) {+ return;+ }+ let r = ui.ctx().content_rect();+ let edge = 4.0;+ let corner = 10.0;+ let rect = |x0, y0, x1, y1| egui::Rect::from_min_max(egui::pos2(x0, y0), egui::pos2(x1, y1));+ for (name, region, cursor) in [+ ("northWest", rect(r.left(), r.top(), r.left() + corner, r.top() + corner), egui::CursorIcon::ResizeNwSe),+ ("northEast", rect(r.right() - corner, r.top(), r.right(), r.top() + corner), egui::CursorIcon::ResizeNeSw),+ ("southWest", rect(r.left(), r.bottom() - corner, r.left() + corner, r.bottom()), egui::CursorIcon::ResizeNeSw),+ ("southEast", rect(r.right() - corner, r.bottom() - corner, r.right(), r.bottom()), egui::CursorIcon::ResizeNwSe),+ ("north", rect(r.left() + corner, r.top(), r.right() - corner, r.top() + edge), egui::CursorIcon::ResizeVertical),+ ("south", rect(r.left() + corner, r.bottom() - edge, r.right() - corner, r.bottom()), egui::CursorIcon::ResizeVertical),+ ("west", rect(r.left(), r.top() + corner, r.left() + edge, r.bottom() - corner), egui::CursorIcon::ResizeHorizontal),+ ("east", rect(r.right() - edge, r.top() + corner, r.right(), r.bottom() - corner), egui::CursorIcon::ResizeHorizontal),+ ] {+ let response = ui.interact(region, egui::Id::new(("window_resize", name)), Sense::drag()).on_hover_cursor(cursor);+ if response.drag_started_by(egui::PointerButton::Primary) {+ let _ = app.run("window.resize", json!({"edge": name}));+ app.flush_window_commands(ui.ctx());+ }+ }+ }+impl DesignApp {fn session_home(&mut self) {- self.ui.status = "Home".into();+ self.ui.status = crate::i18n::tr(&self.ui.language, "Home").into();}}@@@ -770,12 -918,13 +894,13 @@@ fn community_card(app: &mut DesignApp,#[cfg(test)]mod tests {use egui::{pos2, vec2};- use egui_kittest::kittest::Queryable;+ use egui_kittest::kittest::{NodeT, Queryable};+ use super::*;use crate::test_window::{self, wheel};- /// The Control panel's last control with nothing selected.- const LAST_CONTROL: &str = "Jump to Next Column";+ /// The Control panel's last control with no text frame selected.+ const LAST_CONTROL: &str = "Align bottom edges";const FIRST_CONTROL: &str = "Rotate 90° Counterclockwise";fn app() -> crate::DesignApp {@@@ -1110,8 -1014,192 +1235,192 @@@let mut h = test_window::open(app, vec2(700.0, 600.0));let bar = test_window::panel_rect(&h, "control_bar").center();wheel(&mut h, bar, vec2(0.0, -3000.0));- // The text frame's last group: its caption gets only what is left of the row.- let columns = h.get_by_label("Columns").rect();- assert!(columns.height() < 20.0 && columns.width() > columns.height(), "Columns wraps: {columns:?}");+ // The text frame's last group keeps its full size, not only what is left of the row.+ let columns = group(&h, "columns");+ assert!(columns.width() >= 48.0 && columns.max.x <= 700.0, "Columns group squeezed or off screen: {columns:?}");}++ struct WindowHarness {+ ctx: egui::Context,+ app: DesignApp,+ time: f64,+ maximized: bool,+ size: egui::Vec2,+ }++ impl WindowHarness {+ fn new() -> Self {+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());+ app.custom_titlebar = true;+ let ctx = egui::Context::default();+ crate::theme::install_fonts(&ctx, "");+ let mut harness = Self { ctx, app, time: 0.0, maximized: false, size: vec2(1440.0, 900.0) };+ harness.frame(vec![]);+ harness.frame(vec![]);+ harness+ }++ fn frame(&mut self, events: Vec<egui::Event>) -> Vec<egui::ViewportCommand> {+ self.time += 0.1;+ let mut input = egui::RawInput {+ screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, self.size)),+ time: Some(self.time),+ events,+ ..Default::default()+ };+ input.viewports.entry(egui::ViewportId::ROOT).or_default().maximized = Some(self.maximized);+ let mut output = self.ctx.run_ui(input, |ui| {+ app_bar(&mut self.app, ui);+ resize_borders(&mut self.app, ui);+ });+ output.textures_delta.clear();+ output.viewport_output.get(&egui::ViewportId::ROOT).map(|v| v.commands.clone()).unwrap_or_default()+ }++ fn press(&mut self, pos: egui::Pos2) -> Vec<egui::ViewportCommand> {+ self.frame(vec![+ egui::Event::PointerMoved(pos),+ egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() },+ ])+ }++ fn click(&mut self, pos: egui::Pos2) -> Vec<egui::ViewportCommand> {+ let mut commands = self.press(pos);+ commands.extend(self.frame(vec![egui::Event::PointerButton {+ pos,+ button: egui::PointerButton::Primary,+ pressed: false,+ modifiers: Default::default(),+ }]));+ commands+ }++ fn caption_center(&self, id: &str) -> egui::Pos2 {+ self.ctx.read_response(egui::Id::new(id)).unwrap().rect.center()+ }+ }++ #[test]+ fn caption_buttons_minimize_maximize_restore_and_close() {+ let mut h = WindowHarness::new();+ for (id, command) in+ [("window.minimize", egui::ViewportCommand::Minimized(true)), ("window.maximize", egui::ViewportCommand::Maximized(true))]+ {+ let p = h.caption_center(id);+ assert!(h.click(p).contains(&command), "{id}");+ }+ h.maximized = true;+ h.frame(vec![]);+ let p = h.caption_center("window.maximize");+ assert!(h.click(p).contains(&egui::ViewportCommand::Maximized(false)));+ let p = h.caption_center("window.close");+ assert!(h.click(p).contains(&egui::ViewportCommand::Close));+ }++ #[test]+ fn title_area_drags_and_double_clicks_but_menus_do_not_drag() {+ let mut h = WindowHarness::new();+ let title = h.ctx.read_response(egui::Id::new("window_title_drag")).unwrap().rect;+ assert!(title.width() > 0.0, "there is a drag region between menus and tools");+ let p = title.center();+ let mut commands = h.press(p);+ commands.extend(h.frame(vec![egui::Event::PointerMoved(p + vec2(20.0, 0.0))]));+ assert!(commands.contains(&egui::ViewportCommand::StartDrag));++ let mut h = WindowHarness::new();+ h.click(p);+ assert!(h.click(p).contains(&egui::ViewportCommand::Maximized(true)));++ let mut h = WindowHarness::new();+ let p = egui::pos2(70.0, 18.0); // File menu, outside the title's drag region.+ let mut commands = h.press(p);+ commands.extend(h.frame(vec![egui::Event::PointerMoved(title.center())]));+ assert!(!commands.contains(&egui::ViewportCommand::StartDrag));+ }++ #[test]+ fn edges_resize_only_when_the_window_is_restored() {+ let mut h = WindowHarness::new();+ let p = egui::pos2(1438.0, 400.0);+ let mut commands = h.press(p);+ commands.extend(h.frame(vec![egui::Event::PointerMoved(p + vec2(-20.0, 0.0))]));+ assert!(commands.contains(&egui::ViewportCommand::BeginResize(egui::ResizeDirection::East)));+ let mut h = WindowHarness::new();+ h.maximized = true;+ h.frame(vec![]);+ let mut commands = h.press(p);+ commands.extend(h.frame(vec![egui::Event::PointerMoved(p + vec2(-20.0, 0.0))]));+ assert!(!commands.iter().any(|c| matches!(c, egui::ViewportCommand::BeginResize(_))));+ }++ #[test]+ fn native_window_actions_are_unavailable_without_custom_chrome() {+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());+ assert!(!crate::menus::enabled(&app, "window.close"));+ assert!(app.run("window.close", json!({})).is_err());+ assert!(app.pending_window_commands.is_empty());+ app.custom_titlebar = true;+ assert!(app.run("window.resize", json!({"edge": "invalid"})).is_err());+ assert!(app.pending_window_commands.is_empty());+ }++ #[test]+ fn caption_buttons_stay_put_while_a_narrow_app_bar_scrolls() {+ let mut h = WindowHarness::new();+ h.size = vec2(640.0, 560.0);+ h.frame(vec![]);+ h.frame(vec![]);+ let rect = |h: &WindowHarness, id: &str| h.ctx.read_response(egui::Id::new(id)).unwrap().rect;+ let menus_end = |h: &WindowHarness| h.ctx.data(|d| d.get_temp::<f32>(egui::Id::new("app_bar_menus_end"))).unwrap();+ let (close, menus0) = (rect(&h, "window.close"), menus_end(&h));+ assert!(close.left() >= 0.0 && close.right() <= h.size.x, "{close:?}");+ let p = egui::pos2(200.0, 18.0);+ h.frame(vec![+ egui::Event::PointerMoved(p),+ egui::Event::MouseWheel {+ unit: egui::MouseWheelUnit::Point,+ delta: vec2(0.0, -3000.0),+ phase: egui::TouchPhase::Move,+ modifiers: egui::Modifiers::NONE,+ },+ ]);+ for _ in 0..10 {+ h.frame(vec![]);+ }+ assert!(menus_end(&h) < menus0, "the menus scrolled");+ assert_eq!(rect(&h, "window.close"), close, "the caption buttons did not");+ assert!(h.click(close.center()).contains(&egui::ViewportCommand::Close));+ }++ #[test]+ fn the_window_drags_from_its_lower_band_at_the_minimum_width() {+ // At 900 px the menus and tools fill the bar's row; its lower band still moves the window,+ // and it isn't drawn over the caption buttons.+ let mut h = WindowHarness::new();+ h.size = vec2(900.0, 560.0);+ h.frame(vec![]);+ h.frame(vec![]);+ let drag = h.ctx.read_response(egui::Id::new("window_title_drag")).unwrap().rect;+ let close = h.ctx.read_response(egui::Id::new("window.close")).unwrap().rect;+ assert!(drag.right() <= close.left() + 0.5, "{drag:?} {close:?}");- let p = egui::pos2(450.0, BAR_H + LOWER_BAND / 2.0);++ let p = egui::pos2(450.0, APP_BAR + APP_BAR_BAND / 2.0);+ assert!(drag.contains(p), "{drag:?}");+ let mut commands = h.press(p);+ commands.extend(h.frame(vec![egui::Event::PointerMoved(p + vec2(20.0, 0.0))]));+ assert!(commands.contains(&egui::ViewportCommand::StartDrag));+ }++ #[test]+ fn caption_buttons_fit_the_minimum_window_width() {+ let mut h = WindowHarness::new();+ h.size = vec2(900.0, 560.0);+ h.frame(vec![]);+ h.frame(vec![]);+ for id in ["window.minimize", "window.maximize", "window.close"] {+ let rect = h.ctx.read_response(egui::Id::new(id)).unwrap().rect;+ assert!(rect.left() >= 0.0 && rect.right() <= h.size.x, "{id}: {rect:?}");+ let p = rect.center();+ assert!(!h.click(p).is_empty(), "{id} remains clickable");+ }+ }}diff --cc crates/ui-egui/src/lib.rsindex 3b5e44b4c,00efede01..b4c9458c0--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@@ -543,15 -505,13 +543,19 @@@ pub struct DesignAppstyled: bool,/// The interface language the UI fonts were installed for (it orders the CJK fallbacks).fonts_lang: String,+ /// The installed CJK faces are among the UI fonts (false while the system fonts are still+ /// being cataloged: the fonts are installed again when they are).+ fonts_system: bool,pub restyle: bool,fonts_ready: bool,+ /// Files the operating system asked to open (macOS Finder, Dock, Open With), opened once the+ /// window is ready; see [`DesignApp::open_documents_later`].+ os_documents: Vec<String>,pub integrated_titlebar: bool,+ /// The desktop host uses our caption controls and window drag/resize regions (Windows).+ pub custom_titlebar: bool,+ pub(crate) window_maximized: bool,+ pub(crate) pending_window_commands: Vec<egui::ViewportCommand>,/// The host installed a native menu bar (macOS): don't draw menus in the window.pub native_menu: bool,/// Shortcuts the native menu handles (skip them in the egui shortcut handler).@@@ -620,11 -561,12 +624,14 @@@ impl DesignAppshot_token: 0,styled: false,fonts_lang: String::new(),+ fonts_system: false,restyle: false,fonts_ready: false,+ os_documents: Vec::new(),integrated_titlebar: false,+ custom_titlebar: false,+ window_maximized: false,+ pending_window_commands: vec![],native_menu: false,native_shortcuts: Default::default(),last_time: 0.0,@@@ -1020,9 -768,7 +1027,10 @@@/// Per-frame logic before layout.pub fn logic(&mut self, ctx: &egui::Context) {+ if self.egui_ctx.is_none() {+ self.egui_ctx = Some(ctx.clone());+ }+ self.window_maximized = ctx.input(|i| i.viewport().maximized.unwrap_or(false));if !self.color_applied {self.color_applied = true;if let Some(cs) = self.ui.color_settings.clone() {diff --cc crates/ui-egui/src/menus.rsindex 9919d7216,aee673927..866a82d09--- a/crates/ui-egui/src/menus.rs+++ b/crates/ui-egui/src/menus.rs@@@ -821,19 -755,11 +826,22 @@@ pub fn ui_label(id: &str) -> Option<(&'UI_COMMANDS.iter().find(|c| c.0 == id).map(|c| (c.1, c.2))}+/// Type › Tabs: float the Tabs panel (placed above the selected text frame) or close it.+fn toggle_tabs_panel(app: &mut DesignApp) {+ if app.ui.floating.iter().any(|(p, _)| p == "tabs") {+ crate::dock::dock_panel(app, "tabs");+ } else {+ let at = app.canvas_rect.map_or(egui::pos2(300.0, 140.0), |r| r.min + egui::vec2(80.0, 60.0));+ crate::dock::float_panel(app, "tabs", at);+ app.ui.tabs_panel.snap_request = 2;+ }+}+/// Run a UI command; `None` if `id` isn't one.pub fn run_ui(app: &mut DesignApp, id: &str, p: &Value) -> Option<Result<Value, String>> {+ if matches!(id, "window.minimize" | "window.maximize" | "window.close" | "window.drag" | "window.resize") && !app.custom_titlebar {+ return Some(Err("custom window controls are not available in this host".into()));+ }if let Some(result) = crate::panel_docking::command(app, id, p) {return Some(result);}@@@ -1817,22 -1673,11 +1857,25 @@@ pub(crate) fn export_pdf(app: &mut Desi}}+/// Commands that act on the text being typed wait while an IME composes at the caret (its marked+/// text isn't typed yet): Undo and Redo (the native menu takes ⌘Z ahead of the IME), the clipboard+/// and the selection.+pub(crate) fn waits_for_ime(app: &DesignApp, id: &str) -> bool {+ app.session.tool_composing()+ && (matches!(+ id,+ "edit.undo" | "edit.redo" | "edit.cut" | "edit.copy" | "edit.clear" | "edit.duplicate" | "edit.selectAll" | "edit.deselectAll"+ ) || id.starts_with("edit.paste"))+}+/// Is a command enabled (for menu greying)?pub fn enabled(app: &DesignApp, id: &str) -> bool {+ if waits_for_ime(app, id) {+ return false;+ }+ if matches!(id, "window.minimize" | "window.maximize" | "window.close" | "window.drag" | "window.resize") {+ return app.custom_titlebar;+ }match designcraft_engine::find_command(id) {Some(c) => (c.enabled)(&app.session).is_ok(),None => true,@@@ -2126,14 -1899,11 +2169,17 @@@ pub fn checked(app: &DesignApp, id: &st/// Enablement for menu display (UI commands need a document unless they're app/window-level).pub fn menu_enabled(app: &DesignApp, id: &str) -> bool {+ if waits_for_ime(app, id) {+ return false;+ }+ if matches!(id, "window.minimize" | "window.maximize" | "window.close" | "window.drag" | "window.resize") {+ return app.custom_titlebar;+ }+ if id == "app.justificationDialog" {+ return enabled(app, "type.para");+ }if ui_label(id).is_some() {- return app.session.active().is_some() || id.starts_with("app.") || id.starts_with("window.");+ return app.session.active().is_some() || id.starts_with("app.") || id.starts_with("window.") || id.starts_with("help.");}enabled(app, id)}diff --cc crates/ui-egui/src/theme.rsindex 45a0afafa,3a86d3fa1..7b2364ffe--- a/crates/ui-egui/src/theme.rs+++ b/crates/ui-egui/src/theme.rs@@@ -83,8 -83,9 +83,11 @@@ pub struct Tokens/// Measurement labels on the canvas (smart dimensions, gaps).pub measure_bg: Color32,pub measure_text: Color32,+ /// Live-corner widget and corner diamonds.+ pub live_corner: Color32,+ /// The Windows caption Close button when hovered, and its glyph.+ pub caption_close: Color32,+ pub caption_close_text: Color32,}fn hex(s: u32) -> Color32 {@@@ -127,7 -128,8 +130,9 @@@ impl Tokenssmart_guide: hex(0x00c853),measure_bg: Color32::from_rgba_unmultiplied(70, 70, 70, 230),measure_text: Color32::WHITE,+ live_corner: hex(0xffe500),+ caption_close: hex(0xc42b1c),+ caption_close_text: Color32::WHITE,};match b {Brightness::Dark => dark,