Skip to content

macOS: centre the window buttons in the title bar (#170) - #323

Merged
h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
vangel76:fix/macos-title-bar
Oct 11, 2026
Merged

h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
vangel76:fix/macos-title-bar

Conversation

@vangel76

Copy link
Copy Markdown
Contributor

Fixes #170

Root cause

On macOS the window has no system title bar (with_fullsize_content_view, with_titlebar_shown(false) in apps/gridcraft/src/main.rs). AppKit still draws the traffic lights, centred in its standard 28 pt title-bar band at the top of the window. GridCraft's own title bar was 38 pt tall, so the lights sat about 5 pt above its centre line, and the content started 76 pt from the left. This is the same issue as storytold/wordcraft#225, fixed there by wordcraft#255; this PR uses the same analysis.

Neither winit 0.30 nor egui/eframe 0.36 can move the traffic lights, and doing it directly means AppKit calls (unsafe), which the workspace forbids. So the title bar now fits the lights instead.

What changed

crates/ui-egui/src/ribbon.rs, macOS only (cfg!(target_os = "macos"), as TITLE_LEFT_PAD already did). Linux, Windows and web are unchanged.

  • The title bar is 28 pt tall, so the lights are vertically centred in it.
  • Its icon buttons shrink from 26 to 22 pt high so they keep a margin above and below.
  • Content starts at MAC_CONTENT_LEFT: the end of the three lights (12 pt buttons, 20 pt pitch, the first at about 10 pt) plus the 8 pt gap the lights keep from the top. That is 70 pt instead of 76.
  • The geometry is in named constants. A unit test checks the gap after the lights, and a compile-time assertion checks the controls fit the bar.

Tests and commands run

  • cargo test -p gridcraft-ui-egui --lib title_bar, cargo test -p gridcraft-ui-egui --test interaction
  • cargo clippy -p gridcraft-ui-egui --all-targets -- -D warnings, cargo fmt -p gridcraft-ui-egui -- --check, cargo check --target wasm32-unknown-unknown -p gridcraft-ui-egui

Not done

Unverified assumptions (needs confirmation on macOS)

🤖 Generated with Claude Code

AppKit draws the traffic lights centred in its standard 28 pt title-bar
band, but GridCraft's title bar was 38 pt tall, so the lights sat above
its centre line. On macOS the title bar is now 28 pt with 22 pt controls,
and content starts after the lights with the same gap they keep from the
top. Other platforms are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@h-a-n-a-s-h-i
h-a-n-a-s-h-i merged commit 2f03239 into storytold:main Oct 11, 2026
@echelon

echelon commented Oct 11, 2026

Copy link
Copy Markdown
Member

Merged — thank you for the contribution! (I resolved a small conflict in the title bar: the Save button keeps #223's commit-edit fix and uses your ch height.)

If you haven't already, come join us on the ArtCraft Discord: https://discord.gg/artcraft

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Window controls misaligned on macOS

3 participants