app: draw the title bar without a native frame

The window kept Windows' native caption above the app's own title bar:
two title bars, and nothing in the frame said the app was drawing its
own.

Setting `.titlebar(Titlebar::new(app::TITLEBAR_HEIGHT))` hands the
frame to Rune. The native caption goes; Windows keeps its resize edges,
snap layouts and window menu, and Rune draws the minimize, maximize and
close buttons over the bar's right edge in the ink the view gives with
`Cx::caption_color`. The bar pads itself by `Cx::chrome_insets`, so its
own buttons keep clear of those on either platform (macOS keeps its
traffic lights at the leading edge). The window now refuses to shrink
past the width where both rows fit.
This commit is contained in:
vhaudiquet committed 2026-11-23 21:58:04 +01:00
1 parent 7213c119da
commit b9d97d0724
2 files changed
+20 -5

No files matched your search

+14 -5
View File
@@ -5,7 +5,7 @@ use std::sync::mpsc::{Receiver, TryRecvError, channel};
use std::time::Duration;
use rune::tok::type_;
use rune::{Cx, El, Key, KeyEvent, Tx, col, el, row, text};
use rune::{ChromeInsets, Cx, El, Key, KeyEvent, Tx, col, el, row, text};
use crate::export::{self, Clip};
use crate::history::{self, QueueCategory, Summary, Timeline};
@@ -17,6 +17,9 @@ use crate::screens;
use crate::settings::{AudioSource, AudioSourceType, Settings};
use crate::ui::{self, Paint, body, heading};
/// The band the app draws its own title bar in, which the window's controls sit over.
pub const TITLEBAR_HEIGHT: f32 = 48.0;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Screen {
Settings,
@@ -1224,7 +1227,7 @@ fn back_label(screen: Screen) -> &'static str {
}
}
fn titlebar(p: Paint, app: &App) -> El {
fn titlebar(p: Paint, app: &App, insets: ChromeInsets) -> El {
// Leaving a screen is on the left, where a window's back arrow lives; the app's own
// actions stay on the right.
let mut leading = row().key("leading").gap(8.0).center_y();
@@ -1284,9 +1287,12 @@ fn titlebar(p: Paint, app: &App) -> El {
}
row()
.key("titlebar")
.h(48.0)
.h(TITLEBAR_HEIGHT)
.w_full()
.px(16.0)
// What the window's controls take: the traffic lights on macOS, the caption buttons on
// Windows, which are drawn over this band.
.pl(16.0 + insets.leading)
.pr(16.0 + insets.trailing)
.gap(8.0)
.center_y()
.justify_between()
@@ -1330,6 +1336,9 @@ fn notice(p: Paint, notice: &Notice) -> El {
pub fn view(app: &App, cx: &mut Cx<App>) -> El {
let p = Paint::new(app.dark, cx.env().scale);
// The window's own controls sit over the title bar and take its ink: the caption buttons
// on Windows, the traffic lights on macOS.
cx.caption_color(p.t.text);
// Menus and dialogs cover the whole window, title bar and status bar included: the
// history row menus, the add-application form and the delete confirmation.
let mut overlays = Vec::new();
@@ -1350,7 +1359,7 @@ pub fn view(app: &App, cx: &mut Cx<App>) -> El {
.w_full()
.h_full()
.fill(p.t.bg)
.child(titlebar(p, app))
.child(titlebar(p, app, cx.chrome_insets()))
.child(main)
.child(statusbar(p, app));
let content = match app.screen {
+6
View File
@@ -163,9 +163,15 @@ fn main() {
setup: Some(app::setup),
poll: Some(app::poll),
on_key: Some(app::on_key),
// Narrower than this, the title bar's own buttons would run under the window's
// caption buttons.
min_size: Some((640.0, 480.0)),
..AppSpec::new("League Recorder", (1200.0, 800.0), app::App::new, app::view)
})
.args(args)
// The app draws the title bar itself, so the window keeps no native caption: Rune draws the
// caption buttons over the bar's right edge and keeps Windows' resize edges and snap.
.titlebar(rune::Titlebar::new(app::TITLEBAR_HEIGHT))
.keep_running()
.on_close(app::window_closed)
.on_quit(app::window_closed)