Skip to content

Craft Anything: understand how any software works, and craft your own.

Rust

Keep macOS's own window buttons and frame (#994)

BFlat5a65542b88d1
diff --git a/apps/craft-anything/src/main.rs b/apps/craft-anything/src/main.rs
index b5bca9b6..a9c1b937 100644
--- a/apps/craft-anything/src/main.rs
+++ b/apps/craft-anything/src/main.rs
@@ -56,10 +56,15 @@ fn main() -> eframe::Result {
.with_app_id("ai.storyteller.craft-anything")
.with_inner_size([1360.0, 860.0])
.with_min_inner_size([760.0, 520.0])
- // Our own title bar draws the window controls, moves and resizes the window.
- .with_decorations(false)
.with_resizable(true)
.with_drag_and_drop(true);
+ // Our own title bar draws the window controls, moves and resizes the window. macOS keeps its
+ // own buttons and frame instead, with the content reaching under a see-through title bar (#20).
+ let viewport = if cfg!(target_os = "macos") {
+ viewport.with_fullsize_content_view(true).with_titlebar_shown(false).with_title_shown(false)
+ } else {
+ viewport.with_decorations(false)
+ };
// On macOS a window icon replaces the Dock icon, and the bundle's own icon is the one padded to
// Apple's icon grid (the full tile looked bigger than other apps', #102). An empty icon keeps
// the bundle's; no icon at all would bring eframe's own.
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index fad42a4b..6df4028e 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -1764,9 +1764,7 @@ impl CraftApp {
menu::update(self, &ctx);
let t = theme::Tokens::get(&ctx);
// The title bar is on every screen: it is how the window moves, resizes and closes.
- egui::Panel::top("titlebar").exact_size(titlebar::HEIGHT).frame(egui::Frame::new().fill(t.chrome)).show(ui, |ui| {
- guard_ui(ui, "title bar", |ui| titlebar::show(self, ui));
- });
+ titlebar::bar(self, ui);
self.stuck_banner(ui, &ctx);
if !self.settings.first_run_done {
egui::CentralPanel::default().frame(egui::Frame::new().fill(t.canvas)).show(ui, |ui| guard_ui(ui, "first run", |ui| first_run::show(self, ui)));
diff --git a/crates/ui-egui/src/titlebar.rs b/crates/ui-egui/src/titlebar.rs
index 8cb453e2..2cb15865 100644
--- a/crates/ui-egui/src/titlebar.rs
+++ b/crates/ui-egui/src/titlebar.rs
@@ -1,6 +1,7 @@
-//! The custom title bar (the native frame is off): app mark, what's open, Clean room / Deep, AI
-//! backend, Simple · Advanced, settings and the window buttons. Empty parts drag the window; the
-//! window edges resize it.
+//! The custom title bar: app mark, what's open, Clean room / Deep, AI backend, Simple · Advanced,
+//! settings and the window buttons. Empty parts drag the window. On Windows and Linux the native
+//! frame is off, so we draw the window buttons and the window edges resize it; macOS keeps its own
+//! frame and buttons, drawn over the bar's left end.
use crate::i18n::tr;
use crate::state::Screen;
@@ -10,10 +11,39 @@ use craft_anything_engine::Mode;
use egui::viewport::ResizeDirection;
use egui::{RichText, Ui, Vec2};
-/// Height of the custom title bar.
-pub const HEIGHT: f32 = 40.0;
+/// macOS draws its own window buttons, frame and resize edges (#20).
+pub const NATIVE_FRAME: bool = cfg!(target_os = "macos");
+/// Height of the custom title bar. On macOS it matches the system's title bar, so its window
+/// buttons sit centred in it.
+const HEIGHT: f32 = if NATIVE_FRAME { 32.0 } else { 40.0 };
+/// Height of the switches and buttons in the bar.
+const CONTROL: f32 = if NATIVE_FRAME { 26.0 } else { 30.0 };
/// How close to the window edge the pointer must be to resize.
const EDGE: f32 = 5.0;
+/// Room left of the app mark for macOS's window buttons.
+const NATIVE_BUTTONS_WIDTH: f32 = 84.0;
+
+/// How much the bar's sizes are scaled: on macOS it keeps its size when the app is zoomed
+/// (Cmd − / Cmd =), like the system's window buttons beside it, so every size in it is divided by
+/// the zoom and only the rest of the window zooms. Sizes, not a scaled layer, keep text sharp.
+fn scale(ctx: &egui::Context) -> f32 {
+ if NATIVE_FRAME { 1.0 / ctx.zoom_factor() } else { 1.0 }
+}
+
+/// A size for `label_text` / `label_galley` that comes out as `size` scaled by `s`: they add a
+/// fixed 1.5 pt to the size they're given.
+fn label(size: f32, s: f32) -> f32 {
+ (size + 1.5) * s - 1.5
+}
+
+/// The title bar across the top of the window.
+pub fn bar(app: &mut CraftApp, ui: &mut Ui) {
+ let t = Tokens::get(ui.ctx());
+ let height = HEIGHT * scale(ui.ctx());
+ egui::Panel::top("titlebar").exact_size(height).frame(egui::Frame::new().fill(t.chrome)).show(ui, |ui| {
+ crate::guard_ui(ui, "title bar", |ui| show(app, ui));
+ });
+}
fn maximized(ctx: &egui::Context) -> bool {
ctx.input(|i| i.viewport().maximized.unwrap_or(false) || i.viewport().fullscreen.unwrap_or(false))
@@ -21,7 +51,7 @@ fn maximized(ctx: &egui::Context) -> bool {
/// The window edge (or corner) under the pointer, when the window can be resized from there.
pub fn edge_at(ctx: &egui::Context) -> Option<ResizeDirection> {
- if maximized(ctx) {
+ if NATIVE_FRAME || maximized(ctx) {
return None;
}
let pos = ctx.input(|i| i.pointer.hover_pos())?;
@@ -42,7 +72,7 @@ pub fn edge_at(ctx: &egui::Context) -> Option<ResizeDirection> {
/// A 1 px edge around the window (the native frame is off), so it doesn't melt into the desktop.
pub fn window_edge(ctx: &egui::Context) {
- if maximized(ctx) {
+ if NATIVE_FRAME || maximized(ctx) {
return;
}
let t = Tokens::get(ctx);
@@ -75,8 +105,9 @@ pub fn resize_edges(ctx: &egui::Context) {
/// A thin vertical rule between title bar cells.
fn rule(ui: &mut Ui) {
let t = Tokens::get(ui.ctx());
- let (r, _) = ui.allocate_exact_size(Vec2::new(1.0, HEIGHT), egui::Sense::hover());
- ui.painter().vline(r.center().x, r.y_range(), egui::Stroke::new(1.0, t.separator));
+ let s = scale(ui.ctx());
+ let (r, _) = ui.allocate_exact_size(Vec2::new(s, HEIGHT * s), egui::Sense::hover());
+ ui.painter().vline(r.center().x, r.y_range(), egui::Stroke::new(s, t.separator));
}
/// One of the window buttons (minimise, maximise, close): a full-height cell.
@@ -94,9 +125,12 @@ fn window_button(ui: &mut Ui, icon: &str, tip: &str, close: bool) -> egui::Respo
resp.on_hover_text(tr(tip))
}
+/// Draws the bar: the app mark and what's open on the left, the switches, settings and (off
+/// macOS) the window buttons on the right. Empty parts move the window; a double-click zooms it.
pub fn show(app: &mut CraftApp, ui: &mut Ui) {
let t = Tokens::get(ui.ctx());
let ctx = ui.ctx().clone();
+ let s = scale(&ctx);
let bar = ui.max_rect();
// Empty parts of the bar move the window and double-click maximises. This is registered
// before the controls, so they get their own clicks.
@@ -107,20 +141,22 @@ pub fn show(app: &mut CraftApp, ui: &mut Ui) {
if drag.double_clicked() {
ctx.send_viewport_cmd(egui::ViewportCommand::Maximized(!maximized(&ctx)));
}
- ui.painter().hline(bar.x_range(), bar.bottom() - 0.5, egui::Stroke::new(1.0, t.separator));
+ ui.painter().hline(bar.x_range(), bar.bottom() - 0.5 * s, egui::Stroke::new(s, t.separator));
// A download anywhere in the app fills the bottom edge of the bar, on every screen.
let download = crate::engine_ui::global_download(app);
if let Some((_, Some(f), _)) = &download {
let x = bar.left() + bar.width() * f.clamp(0.0, 1.0);
- ui.painter().line_segment([egui::pos2(bar.left(), bar.bottom() - 1.0), egui::pos2(x, bar.bottom() - 1.0)], egui::Stroke::new(2.0, t.accent));
+ ui.painter().line_segment([egui::pos2(bar.left(), bar.bottom() - s), egui::pos2(x, bar.bottom() - s)], egui::Stroke::new(2.0 * s, t.accent));
}
ui.horizontal_centered(|ui| {
- ui.spacing_mut().item_spacing.x = 10.0;
- ui.add_space(12.0);
- if ui.add(crate::app_icon(22.0).sense(egui::Sense::click())).on_hover_text(tr("Home")).clicked() {
+ ui.spacing_mut().item_spacing.x = 10.0 * s;
+ // Room for macOS's buttons, kept in full screen too: they slide back in when the pointer
+ // reaches the top of the screen, and land there instead of over the app mark.
+ ui.add_space(if NATIVE_FRAME { NATIVE_BUTTONS_WIDTH } else { 12.0 } * s);
+ if ui.add(crate::app_icon(22.0 * s).sense(egui::Sense::click())).on_hover_text(tr("Home")).clicked() {
app.state.screen = Screen::Home;
}
- ui.label(theme::label_text("Craft Anything", 12.0).color(t.text).strong());
+ ui.label(theme::label_text("Craft Anything", label(12.0, s)).color(t.text).strong());
let in_project = app.state.screen == Screen::Project;
let project = if in_project { app.workspace.as_ref().map(|w| w.manifest.name.clone()) } else { app.view.project.clone() };
let target = if in_project { None } else { app.view.active_target().map(|t| (t.name.clone(), t.kind)) };
@@ -128,30 +164,33 @@ pub fn show(app: &mut CraftApp, ui: &mut Ui) {
rule(ui);
}
if let Some(p) = project {
- ui.label(theme::label_text(&p, 12.0).color(t.text_dim));
+ ui.label(theme::label_text(&p, label(12.0, s)).color(t.text_dim));
if target.is_some() {
ui.label(RichText::new("/").color(t.text_faint));
}
}
if let Some((name, kind)) = target {
- icons::show(ui, crate::kind_icon(kind), 14.0, t.icon);
- ui.add(egui::Label::new(RichText::new(name).font(theme::mono(theme::CAPTION)).color(t.text)).truncate()).on_hover_text(tr(kind.plain()));
+ icons::show(ui, crate::kind_icon(kind), 14.0 * s, t.icon);
+ ui.add(egui::Label::new(RichText::new(name).font(theme::mono(theme::CAPTION * s)).color(t.text)).truncate()).on_hover_text(tr(kind.plain()));
}
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
ui.spacing_mut().item_spacing.x = 0.0;
- if window_button(ui, "x", "Close", true).clicked() {
- ctx.send_viewport_cmd(egui::ViewportCommand::Close);
- }
- let max = maximized(&ctx);
- if window_button(ui, if max { "layers" } else { "square" }, if max { "Restore" } else { "Maximise" }, false).clicked() {
- ctx.send_viewport_cmd(egui::ViewportCommand::Maximized(!max));
- }
- if window_button(ui, "minus", "Minimise", false).clicked() {
- ctx.send_viewport_cmd(egui::ViewportCommand::Minimized(true));
+ if !NATIVE_FRAME {
+ if window_button(ui, "x", "Close", true).clicked() {
+ ctx.send_viewport_cmd(egui::ViewportCommand::Close);
+ }
+ let max = maximized(&ctx);
+ if window_button(ui, if max { "layers" } else { "square" }, if max { "Restore" } else { "Maximise" }, false).clicked() {
+ ctx.send_viewport_cmd(egui::ViewportCommand::Maximized(!max));
+ }
+ if window_button(ui, "minus", "Minimise", false).clicked() {
+ ctx.send_viewport_cmd(egui::ViewportCommand::Minimized(true));
+ }
+ rule(ui);
}
- rule(ui);
- ui.spacing_mut().item_spacing.x = 10.0;
- ui.add_space(4.0);
+ ui.spacing_mut().item_spacing.x = 10.0 * s;
+ // Without window buttons on the right, keep the controls off the window's rounded corner.
+ ui.add_space(if NATIVE_FRAME { 12.0 } else { 4.0 } * s);
if let Some((title, fraction, message)) = download {
if download_pill(ui, &title, fraction).on_hover_text(message).clicked() {
app.state.modal = Some(match app.engine_flow.job {
@@ -172,12 +211,12 @@ pub fn show(app: &mut CraftApp, ui: &mut Ui) {
usage_pill(app, ui);
return;
}
- if icons::button(ui, "settings", 30.0, app.state.settings_open, "Settings").clicked() {
+ if icons::button(ui, "settings", CONTROL * s, app.state.settings_open, "Settings").clicked() {
app.state.settings_open = !app.state.settings_open;
}
rule(ui);
let sel = usize::from(app.mode() == Mode::Experienced);
- if let Some(i) = widgets::segmented(ui, &["Simple", "Advanced"], sel, 28.0) {
+ if let Some(i) = widgets::segmented_scaled(ui, &["Simple", "Advanced"], sel, CONTROL - 2.0, 12.0, s) {
app.set_mode(if i == 0 { Mode::Beginner } else { Mode::Experienced });
}
rule(ui);
@@ -186,7 +225,7 @@ pub fn show(app: &mut CraftApp, ui: &mut Ui) {
usage_pill(app, ui);
if app.jobs.busy() {
let n = app.jobs.running().filter(|j| j.visible).count();
- ui.add(crate::widgets::Spinner::new().size(14.0).color(t.accent))
+ ui.add(crate::widgets::Spinner::new().size(14.0 * s).color(t.accent))
.on_hover_text(crate::i18n::trf("{n} job(s) running", &[("n", &n.to_string())]));
}
});
@@ -202,7 +241,7 @@ fn usage_pill(app: &CraftApp, ui: &mut Ui) {
}
let t = Tokens::get(ui.ctx());
let text = if u.priced { crate::usage::cost_short(u) } else { crate::usage::tokens_words(u.tokens()) };
- let r = widgets::pill(ui, &text, t.text_dim, t.raised);
+ let r = widgets::pill_sized(ui, &text, t.text_dim, t.raised, label(11.0, scale(ui.ctx())));
r.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Label, true, &text));
r.on_hover_ui(|ui| {
ui.label(RichText::new(tr("AI use this session")).font(theme::semibold(theme::SMALL)));
@@ -217,17 +256,18 @@ fn download_pill(ui: &mut Ui, title: &str, fraction: Option<f32>) -> egui::Respo
Some(f) => format!("{title} · {:.0}%", f * 100.0),
None => title.to_string(),
};
- let g = widgets::label_galley(ui, &text, 12.0, t.text);
- let size = Vec2::new(g.size().x + 26.0 + 52.0, 26.0);
+ let s = scale(ui.ctx());
+ let g = widgets::label_galley(ui, &text, label(12.0, s), t.text);
+ let size = Vec2::new(g.size().x + (26.0 + 52.0) * s, 26.0 * s);
let (rect, resp) = ui.allocate_exact_size(size, egui::Sense::click());
let h = widgets::hover_t(ui, &resp);
- ui.painter().rect(rect, t.radius, crate::theme::mix(t.raised, t.hover, h), egui::Stroke::new(1.0, t.card_border), egui::StrokeKind::Inside);
- icons::paint(ui, egui::Rect::from_center_size(egui::pos2(rect.left() + 14.0, rect.center().y), Vec2::splat(14.0)), "download", 14.0, t.accent);
- ui.painter().galley_with_override_text_color(egui::pos2(rect.left() + 26.0, rect.center().y - g.size().y / 2.0), g, t.text);
- let track = egui::Rect::from_min_size(egui::pos2(rect.right() - 48.0, rect.center().y - 1.5), Vec2::new(38.0, 3.0));
- ui.painter().rect_filled(track, 1.5, t.separator);
+ ui.painter().rect(rect, t.radius, crate::theme::mix(t.raised, t.hover, h), egui::Stroke::new(s, t.card_border), egui::StrokeKind::Inside);
+ icons::paint(ui, egui::Rect::from_center_size(egui::pos2(rect.left() + 14.0 * s, rect.center().y), Vec2::splat(14.0 * s)), "download", 14.0 * s, t.accent);
+ ui.painter().galley_with_override_text_color(egui::pos2(rect.left() + 26.0 * s, rect.center().y - g.size().y / 2.0), g, t.text);
+ let track = egui::Rect::from_min_size(egui::pos2(rect.right() - 48.0 * s, rect.center().y - 1.5 * s), Vec2::new(38.0, 3.0) * s);
+ ui.painter().rect_filled(track, 1.5 * s, t.separator);
let f = fraction.unwrap_or_else(|| (ui.input(|i| i.time) * 0.6).fract() as f32).clamp(0.0, 1.0);
- ui.painter().rect_filled(egui::Rect::from_min_size(track.min, Vec2::new(track.width() * f, track.height())), 1.5, t.accent);
+ ui.painter().rect_filled(egui::Rect::from_min_size(track.min, Vec2::new(track.width() * f, track.height())), 1.5 * s, t.accent);
widgets::focus_ring(ui, &resp, rect);
widgets::animate(ui, std::time::Duration::from_millis(250));
resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, text.clone()));
@@ -240,21 +280,22 @@ fn deep_toggle(app: &mut CraftApp, ui: &mut Ui) {
let deep = app.settings.deep_mode;
let missing = app.ghidra_missing();
let label = tr(if deep { "Deep" } else { "Clean room" });
- let g = widgets::label_galley(ui, &label, 12.0, t.text);
- let size = Vec2::new(g.size().x + 64.0, 30.0);
+ let s = scale(ui.ctx());
+ let g = widgets::label_galley(ui, &label, self::label(12.0, s), t.text);
+ let size = Vec2::new(g.size().x + 64.0 * s, CONTROL * s);
let (rect, resp) = ui.allocate_exact_size(size, egui::Sense::click());
let fill = if resp.hovered() { t.hover } else { egui::Color32::TRANSPARENT };
- ui.painter().rect(rect, t.radius, fill, egui::Stroke::new(1.0, t.card_border), egui::StrokeKind::Inside);
- let icon_rect = egui::Rect::from_center_size(egui::pos2(rect.left() + 16.0, rect.center().y), Vec2::splat(16.0));
+ ui.painter().rect(rect, t.radius, fill, egui::Stroke::new(s, t.card_border), egui::StrokeKind::Inside);
+ let icon_rect = egui::Rect::from_center_size(egui::pos2(rect.left() + 16.0 * s, rect.center().y), Vec2::splat(16.0 * s));
let (icon, col) = if deep { ("microscope", t.accent) } else { ("shield-check", t.success) };
- icons::paint(ui, icon_rect, icon, 15.0, col);
- ui.painter().galley_with_override_text_color(egui::pos2(rect.left() + 30.0, rect.center().y - g.size().y / 2.0), g, t.text);
+ icons::paint(ui, icon_rect, icon, 15.0 * s, col);
+ ui.painter().galley_with_override_text_color(egui::pos2(rect.left() + 30.0 * s, rect.center().y - g.size().y / 2.0), g, t.text);
// The little switch.
- let sw = egui::Rect::from_center_size(egui::pos2(rect.right() - 18.0, rect.center().y), Vec2::new(22.0, 12.0));
+ let sw = egui::Rect::from_center_size(egui::pos2(rect.right() - 18.0 * s, rect.center().y), Vec2::new(22.0, 12.0) * s);
let how = ui.ctx().animate_bool(resp.id, deep);
- ui.painter().rect_filled(sw, 6.0, if deep { t.accent } else { t.pressed });
- let knob_x = egui::lerp(sw.left() + 6.0..=sw.right() - 6.0, how);
- ui.painter().circle_filled(egui::pos2(knob_x, sw.center().y), 4.5, egui::Color32::WHITE);
+ ui.painter().rect_filled(sw, 6.0 * s, if deep { t.accent } else { t.pressed });
+ let knob_x = egui::lerp(sw.left() + 6.0 * s..=sw.right() - 6.0 * s, how);
+ ui.painter().circle_filled(egui::pos2(knob_x, sw.center().y), 4.5 * s, egui::Color32::WHITE);
widgets::focus_ring(ui, &resp, rect);
resp.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::Checkbox, true, !deep, tr("Clean room")));
let resp = resp.on_hover_ui(|ui| {
@@ -279,11 +320,17 @@ fn backend_picker(app: &mut CraftApp, ui: &mut Ui) {
let mut choice: Option<Option<String>> = None;
let mut setup = false;
ui.scope(|ui| {
- ui.spacing_mut().interact_size.y = 30.0;
+ let s = scale(ui.ctx());
+ let spacing = ui.spacing_mut();
+ spacing.interact_size.y = CONTROL * s;
+ // The box takes its padding from the style, which zooms; keep it the bar's size too.
+ spacing.button_padding *= s;
+ spacing.icon_width *= s;
+ spacing.icon_spacing *= s;
egui::ComboBox::from_id_salt("backend-picker")
- .selected_text(theme::label_text(&current, 12.0).color(if app.state.backend.is_some() { t.text } else { t.text_dim }))
- .icon(widgets::combo_icon)
- .width(190.0)
+ .selected_text(theme::label_text(&current, label(12.0, s)).color(if app.state.backend.is_some() { t.text } else { t.text_dim }))
+ .icon(move |ui, rect, _, _| icons::paint(ui, rect.expand(2.0 * s), "chevron-down", 14.0 * s, Tokens::get(ui.ctx()).icon))
+ .width(190.0 * s)
.show_ui(ui, |ui| {
for b in &app.backends {
let on = app.state.backend.as_ref() == Some(&b.name);
diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rs
index 6c078d33..08b854ee 100644
--- a/crates/ui-egui/src/widgets.rs
+++ b/crates/ui-egui/src/widgets.rs
@@ -236,21 +236,30 @@ pub fn segmented(ui: &mut Ui, options: &[&str], selected: usize, height: f32) ->
/// [`segmented`] with a given label size (in the [`label_galley`] style), for a bigger switch.
pub fn segmented_sized(ui: &mut Ui, options: &[&str], selected: usize, height: f32, text: f32) -> Option<usize> {
+ segmented_scaled(ui, options, selected, height, text, 1.0)
+}
+
+/// [`segmented_sized`] with every size in it, padding too, multiplied by `scale` (the macOS
+/// title bar's, which keeps its size when the app zooms).
+pub fn segmented_scaled(ui: &mut Ui, options: &[&str], selected: usize, height: f32, text: f32, scale: f32) -> Option<usize> {
let t = Tokens::get(ui.ctx());
- let galleys: Vec<_> = options.iter().map(|o| label_galley(ui, &tr(o), text, t.text)).collect();
- let widths: Vec<f32> = galleys.iter().map(|g| segment_width(g.size().x, text)).collect();
- let total: f32 = widths.iter().sum::<f32>() + 4.0;
+ // label_text adds a fixed 1.5 pt to the size it's given; scale that too.
+ let label = (text + 1.5) * scale - 1.5;
+ let (height, pad) = (height * scale, 2.0 * scale);
+ let galleys: Vec<_> = options.iter().map(|o| label_galley(ui, &tr(o), label, t.text)).collect();
+ let widths: Vec<f32> = galleys.iter().map(|g| g.size().x + (text * 2.0 + 2.0) * scale).collect();
+ let total: f32 = widths.iter().sum::<f32>() + 2.0 * pad;
let (rect, _) = ui.allocate_exact_size(Vec2::new(total, height), Sense::hover());
- ui.painter().rect(rect, t.radius, t.raised, Stroke::new(1.0, t.card_border), egui::StrokeKind::Inside);
- let mut x = rect.left() + 2.0;
+ ui.painter().rect(rect, t.radius, t.raised, Stroke::new(scale, t.card_border), egui::StrokeKind::Inside);
+ let mut x = rect.left() + pad;
let mut picked = None;
for (i, (g, w)) in galleys.into_iter().zip(widths).enumerate() {
- let seg = egui::Rect::from_min_size(egui::pos2(x, rect.top() + 2.0), Vec2::new(w, height - 4.0));
+ let seg = egui::Rect::from_min_size(egui::pos2(x, rect.top() + pad), Vec2::new(w, height - 2.0 * pad));
let resp = ui.interact(seg, ui.id().with(("seg", options.get(i).copied().unwrap_or_default())), Sense::click());
let on = i == selected;
resp.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::SelectableLabel, true, on, tr(options.get(i).copied().unwrap_or_default())));
if on {
- ui.painter().rect(seg, t.radius_sm, t.card, Stroke::new(1.0, t.card_border), egui::StrokeKind::Inside);
+ ui.painter().rect(seg, t.radius_sm, t.card, Stroke::new(scale, t.card_border), egui::StrokeKind::Inside);
} else {
ui.painter().rect_filled(seg, t.radius_sm, theme::mix(Color32::TRANSPARENT, t.hover, hover_t(ui, &resp)));
}
@@ -278,10 +287,15 @@ pub fn segmented_width(ui: &Ui, options: &[&str]) -> f32 {
/// A small status label on a tint.
pub fn pill(ui: &mut Ui, text: &str, fg: Color32, bg: Color32) -> Response {
+ pill_sized(ui, text, fg, bg, 11.0)
+}
+
+/// [`pill`] with a given label size, its padding scaled to match.
+pub fn pill_sized(ui: &mut Ui, text: &str, fg: Color32, bg: Color32, text_size: f32) -> Response {
let t = Tokens::get(ui.ctx());
let label = tr(text);
- let g = label_galley(ui, &label, 11.0, fg);
- let size = Vec2::new(g.size().x + 14.0, g.size().y + 8.0);
+ let g = label_galley(ui, &label, text_size, fg);
+ let size = Vec2::new(g.size().x + text_size * 14.0 / 11.0, g.size().y + text_size * 8.0 / 11.0);
let (rect, resp) = ui.allocate_exact_size(size, Sense::hover());
ui.painter().rect_filled(rect, t.r_sm(), bg);
ui.painter().galley_with_override_text_color(rect.center() - g.size() / 2.0, g, fg);
diff --git a/crates/ui-egui/tests/smoke.rs b/crates/ui-egui/tests/smoke.rs
index 1ee96819..f8bc2ae3 100644
--- a/crates/ui-egui/tests/smoke.rs
+++ b/crates/ui-egui/tests/smoke.rs
@@ -31,12 +31,15 @@ fn wait(h: &mut Harness<'static, CraftApp>, done: impl Fn(&CraftApp) -> bool) ->
false
}
+/// First run goes from the welcome to the AI step, with the window controls there throughout.
#[test]
fn first_run_walks_through_four_screens() {
let mut h = harness(|| demo::app(demo::engine(Mode::Beginner, false)));
h.run_steps(3);
- // The window controls are there from the first screen (the native frame is off).
- h.get_by_label("Close");
+ // The window controls are there from the first screen (the native frame is off; macOS draws its own).
+ if !craft_anything_ui_egui::titlebar::NATIVE_FRAME {
+ h.get_by_label("Close");
+ }
h.get_by_label("I'm new to this").click();
h.run_steps(3);
assert_eq!(h.state().state.first_run, FirstRunStep::Brain);
@@ -1447,6 +1450,37 @@ fn zoom_stays_between_half_and_double() {
assert_eq!(craft_anything_ui_egui::bounded_zoom(f32::NAN), 1.0);
}
+/// macOS keeps its own window buttons beside the title bar, and they don't zoom, so the bar
+/// doesn't either: at 50%, 100% and 150% its controls keep their size and place on screen (zoomed
+/// points times the zoom), while the body below does zoom.
+#[cfg(target_os = "macos")]
+#[test]
+fn title_bar_keeps_its_size_when_zoomed() {
+ let on_screen = |zoom: f32| {
+ let mut h = harness_sized(egui::vec2(1360.0, 600.0), || demo::app(demo::engine(Mode::Experienced, true)));
+ h.ctx.set_zoom_factor(zoom);
+ h.run_steps(4);
+ // The topmost node with the label: Settings and Advanced appear in the bar first.
+ let rect = |label: &str| {
+ let r = h.get_all_by_label(label).map(|n| n.rect()).min_by(|a, b| a.top().total_cmp(&b.top())).unwrap();
+ egui::Rect::from_min_max(r.min * zoom, r.max * zoom)
+ };
+ (rect("Settings"), rect("Advanced"), rect("Filter"))
+ };
+ let (settings, advanced, filter) = on_screen(1.0);
+ // The bar is the system title bar's height, and its controls sit centred in it.
+ assert!((settings.center().y - 16.0).abs() <= 1.0, "settings button at {settings:?}");
+ for zoom in [0.5, 1.5] {
+ let (s, a, f) = on_screen(zoom);
+ for (name, at_100, now) in [("Settings", settings, s), ("Advanced", advanced, a)] {
+ let moved = (now.min - at_100.min).length().max((now.max - at_100.max).length());
+ assert!(moved <= 1.0, "{name} moved {moved} pt at {zoom}x: {at_100:?} → {now:?}");
+ }
+ let grew = f.height() / filter.height();
+ assert!((grew - zoom).abs() < 0.15, "the body should zoom: Filter grew {grew}x at {zoom}x");
+ }
+}
+
#[test]
fn settings_window_tabs_draw() {
let mut h = harness(|| {
diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md
index 4c5b81c3..2e0d6c64 100644
--- a/docs/ROADMAP.md
+++ b/docs/ROADMAP.md
@@ -773,8 +773,11 @@ Gaps found while using the app for real projects.
open, so the command doesn't return until it closes (#207). Every fix found needs `unsafe` or
an unstable API: an exception to rule 9, or a limit we document. Meanwhile a reproducing test
marked `#[ignore]` and a line in the CLI docs are welcome
-- [ ] macOS: the window draws Windows-style controls at the top right, since the app turns off the
- system's title bar (`with_decorations(false)`), and its icon is bigger than the system's (#20)
+- [x] macOS: the window drew Windows-style controls at the top right, since the app turned off the
+ system's title bar (`with_decorations(false)`); it now keeps the system's buttons, frame and
+ resize edges under a see-through title bar, which is 32 pt there so the buttons sit centred
+ in it (#20)
+- [ ] macOS: the app's icon is bigger than the system's (#20)
- [ ] Show a command's output while it runs: Claude Code reports a tool's result only when it
ends, so a long `cargo build` is one quiet line until then. Watching the agent's child
processes from outside could say what's running and for how long