fix(launcher): fill window width and add Windows title bar

Keep page content and pixel art responsive, align navigation left, and use native Windows control hit regions in themed chrome.

Co-Authored-By: OpenAI Codex (GPT-6.1 Sol) <noreply@openai.com>
This commit is contained in:
RobertTGreat
2026-10-24 18:30:36 +01:00
parent 7fca3c2f97
commit 4ebba25280
8 changed files with 250 additions and 45 deletions
+4
View File
@@ -97,6 +97,10 @@ page `servers.json` (the list), `servers/<name>/` (the servers created there) an
Long pages, dialogs, the server console and data previews have a visible scrollbar when
their content overflows. Drag the thumb or click the track to navigate without a mouse wheel.
Pages and Home's landscape fill the window as it resizes. Windows uses a matching title
bar with native dragging, resizing, Snap,
minimize, maximize/restore and close; macOS and Linux keep their system title bars.
## Updates
The launcher looks for a newer Horizon release when it starts and every 30 minutes while it
Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 KiB

+59 -10
View File
@@ -2,7 +2,7 @@
//! and the landscape behind Home (the vanilla grass block is `browser::images::grass_block`).
//! GPUI samples images smoothly, so every image is baked at the window's scale with each texel a
//! whole block of device pixels, and drawn at exactly its size: the edges stay sharp. Each image
//! is made once per appearance and scale, then reused.
//! is reused until its appearance, scale or landscape width changes.
use gpui::RenderImage;
use horizon_theme as tokens;
use std::collections::HashMap;
@@ -11,8 +11,15 @@ use std::sync::Arc;
/// What an image is, to find it again.
#[derive(Clone, PartialEq, Eq, Hash)]
enum Key {
Stone { dark: bool, scale: u32 },
Scene { dark: bool, scale: u32 },
Stone {
dark: bool,
scale: u32,
},
Scene {
dark: bool,
scale: u32,
width: usize,
},
}
#[derive(Default)]
@@ -24,7 +31,8 @@ pub struct Art {
pub const STONE: f32 = tokens::TILE_TEXEL * (tokens::TILE_TEXELS * 4) as f32;
/// Home's landscape: texels of this many logical pixels, and its size in texels.
pub const SCENE_TEXEL: f32 = 6.;
pub const SCENE_SIZE: (usize, usize) = (220, 56);
pub const SCENE_HEIGHT: usize = 56;
const MIN_SCENE_WIDTH: f32 = 10.;
impl Art {
/// The page's stone texture, for a window at `scale`.
@@ -42,20 +50,33 @@ impl Art {
.clone()
}
/// Home's landscape: a sunset in the dark appearance, a dawn in the light one.
pub fn scene(&mut self, dark: bool, scale: f32) -> Arc<RenderImage> {
/// Home's landscape at the banner's width, without stretching its square texels.
/// Only the current size is retained, so resizing cannot accumulate large images.
pub fn scene(&mut self, dark: bool, scale: f32, width: f32) -> (Arc<RenderImage>, f32) {
let width = (width / SCENE_TEXEL).ceil().max(MIN_SCENE_WIDTH) as usize;
let key = Key::Scene {
dark,
scale: scale_key(scale),
width,
};
self.made
if !self.made.contains_key(&key) {
self.made.retain(|key, _| matches!(key, Key::Stone { .. }));
}
let image = self
.made
.entry(key)
.or_insert_with(|| {
let (w, h) = SCENE_SIZE;
let palette = if dark { &SUNSET } else { &DAWN };
bake(&opaque(&scene(palette, 3, w, h)), w, h, SCENE_TEXEL, scale)
bake(
&opaque(&scene(palette, 3, width, SCENE_HEIGHT)),
width,
SCENE_HEIGHT,
SCENE_TEXEL,
scale,
)
})
.clone()
.clone();
(image, width as f32 * SCENE_TEXEL)
}
}
@@ -320,4 +341,32 @@ mod tests {
let size = image.size(0);
assert_eq!((size.width.0, size.height.0), (16, 16));
}
#[test]
fn landscape_fills_the_banner_at_narrow_and_wide_window_sizes() {
let mut art = Art::default();
for banner_width in [696., 916., 1633.] {
let (image, drawn_width) = art.scene(true, 2., banner_width);
assert!(drawn_width >= banner_width);
assert!(drawn_width - banner_width < SCENE_TEXEL);
assert_eq!(image.size(0).width.0, (drawn_width * 2.) as i32);
assert_eq!(
image.size(0).height.0,
(SCENE_HEIGHT as f32 * SCENE_TEXEL * 2.) as i32
);
}
}
#[test]
fn resizing_replaces_the_landscape_and_preserves_the_stone_cache() {
let mut art = Art::default();
let stone = art.stone(0x0f0d17, true, 1.);
let (first, _) = art.scene(true, 1., 900.);
let (reused, _) = art.scene(true, 1., 900.);
assert!(Arc::ptr_eq(&first, &reused));
let (resized, _) = art.scene(true, 1., 1500.);
assert!(!Arc::ptr_eq(&first, &resized));
assert_eq!(art.made.len(), 2);
assert!(Arc::ptr_eq(&stone, &art.stone(0x0f0d17, true, 1.)));
}
}
+29 -34
View File
@@ -19,12 +19,13 @@ mod perf;
mod scrollbar;
mod servers_page;
mod theme;
mod titlebar;
use gpui::{
actions, div, ease_out_quint, prelude::*, px, relative, size, Animation, AnimationExt,
AnyElement, App, Application, Bounds, ClickEvent, Context, Div, ElementId, FocusHandle,
FontWeight, Hsla, KeyBinding, KeyDownEvent, Menu, MenuItem, PathPromptOptions, SharedString,
Stateful, Subscription, TitlebarOptions, Window, WindowBounds, WindowOptions,
Stateful, Subscription, Window, WindowBounds, WindowOptions,
};
use horizon_launcher::account::{self, Accounts, SignIn, SignInState};
use horizon_launcher::backend::{self, Job, Msg, Release, Running, Settings, Updates};
@@ -1313,11 +1314,10 @@ fn megabytes(bytes: u64) -> String {
// ----- Pages -------------------------------------------------------------------------------------
impl Launcher {
/// The top bar: the mark and the name over the sidebar, the pages with their icons, then
/// the account playing and the Settings button.
/// The top bar: the pages with their icons, then the account and Settings.
fn topbar(&mut self, cx: &mut Context<Self>) -> Div {
let t = self.theme;
let mut nav = div().flex().h_full().gap(px(2.));
let mut nav = div().flex().flex_none().h_full().gap(px(2.));
for (page, label, icon) in Page::ALL {
if page == Page::Settings {
continue;
@@ -1372,6 +1372,8 @@ impl Launcher {
let account = keyboard(div().id("account"), &t)
.relative()
.flex()
.min_w_0()
.max_w(px(180.))
.items_center()
.gap(px(10.))
.h(px(40.))
@@ -1395,8 +1397,10 @@ impl Launcher {
div()
.flex()
.flex_col()
.min_w_0()
.child(
blocks::pixel(14., FontWeight::MEDIUM)
.truncate()
.text_color(t.ink)
.child(name),
)
@@ -1448,25 +1452,12 @@ impl Launcher {
.bg(t.side)
.border_b_2()
.border_color(t.outline)
.child(
div()
.flex()
.flex_none()
.items_center()
.gap(px(10.))
.w(px(theme::SIDEBAR - 18.))
.child(mark(24., &t))
.child(
blocks::pixel(20., FontWeight::SEMIBOLD)
.text_color(t.ink)
.child("HORIZON"),
),
)
.child(nav)
.child(
div()
.ml_auto()
.flex()
.flex_none()
.items_center()
.gap(px(8.))
.child(account)
@@ -1835,7 +1826,7 @@ impl Launcher {
wrap
}
fn play_page(&mut self, cx: &mut Context<Self>) -> Div {
fn play_page(&mut self, banner_width: f32, cx: &mut Context<Self>) -> Div {
let t = self.theme;
let Some(tag) = self.selected().cloned() else {
// No hero without a version: the page starts below the top bar like the others.
@@ -1994,7 +1985,7 @@ impl Launcher {
// The banner: Horizon's landscape (`art.rs`) under a veil of the page colour, the hero and
// the Play row over it. It reaches the content's edges and the top bar.
let scene = self.art.scene(t.dark, self.scale);
let (scene, scene_width) = self.art.scene(t.dark, self.scale, banner_width);
let veil = |angle: f32, from: f32, to: f32, at: f32| {
div()
.absolute()
@@ -2007,15 +1998,14 @@ impl Launcher {
gpui::linear_color_stop(t.page.opacity(to), at),
))
};
let (w, h) = art::SCENE_SIZE;
let banner = div()
.relative()
.flex()
.flex_col()
.justify_end()
.min_h(px(340.))
.mx(px(-32.))
.px(px(32.))
.mx(px(-theme::PAGE_GUTTER))
.px(px(theme::PAGE_GUTTER))
.pb(px(28.))
.gap(px(24.))
.overflow_hidden()
@@ -2027,8 +2017,8 @@ impl Launcher {
.absolute()
.bottom_0()
.left_0()
.w(px(w as f32 * art::SCENE_TEXEL))
.h(px(h as f32 * art::SCENE_TEXEL)),
.w(px(scene_width))
.h(px(art::SCENE_HEIGHT as f32 * art::SCENE_TEXEL)),
)
.child(veil(90., 0.82, 0., 0.62))
.child(veil(180., 0., 0.75, 1.))
@@ -3251,8 +3241,10 @@ impl Render for Launcher {
self.friend_focused = self.friend_focus.is_focused(window);
self.mods.note_focus(window);
self.args_focused = self.args_focus.is_focused(window);
let size = window.viewport_size();
let banner_width = f32::from(size.width) - theme::SIDEBAR - scrollbar::GUTTER;
let content = match self.page {
Page::Play => self.play_page(cx),
Page::Play => self.play_page(banner_width, cx),
Page::Versions => self.versions_page(cx),
Page::Mods => self.mods_page(cx),
Page::Servers => self.servers_page(cx),
@@ -3265,7 +3257,6 @@ impl Render for Launcher {
.w_full()
// Let the page shrink inside the padded flex row so long notices can wrap.
.min_w_0()
.max_w(px(1152.))
.child(content)
.with_animation(
ElementId::named_usize("page", self.switches),
@@ -3277,7 +3268,6 @@ impl Render for Launcher {
if self.opening.is_none() && window.focused(cx).is_none() {
window.focus(&self.root_focus);
}
let size = window.viewport_size();
let stone = self.art.stone(t.page_rgb, t.dark, window.scale_factor());
let topbar = self.topbar(cx);
let sidebar = self.sidebar(cx);
@@ -3333,7 +3323,9 @@ impl Render for Launcher {
.child(
div()
.flex()
.px(px(32.))
.w_full()
.min_w_0()
.px(px(theme::PAGE_GUTTER))
.pt(px(if self.page == Page::Play {
0.
} else {
@@ -3411,7 +3403,13 @@ impl Render for Launcher {
}),
);
}
root
div()
.flex()
.flex_col()
.size_full()
.bg(t.side)
.children(titlebar::render(&t, window))
.child(root.flex_1().min_h_0())
}
}
@@ -3533,10 +3531,7 @@ fn main() {
WindowOptions {
window_bounds: Some(WindowBounds::Windowed(bounds)),
window_min_size: Some(size(px(960.), px(600.))),
titlebar: Some(TitlebarOptions {
title: Some("Horizon".into()),
..Default::default()
}),
titlebar: Some(titlebar::options()),
app_id: Some("horizon-launcher".into()),
..Default::default()
},
+4 -1
View File
@@ -6,6 +6,9 @@ use gpui::{
};
use std::{cell::Cell, rc::Rc};
/// Space reserved beside scroll content for the track and its padding.
pub const GUTTER: f32 = 16.;
#[derive(Clone, Default)]
pub(crate) struct Scrollbar {
pub handle: ScrollHandle,
@@ -60,7 +63,7 @@ impl Scrollbar {
.child(
content
.track_scroll(&self.handle)
.mr(px(16.))
.mr(px(GUTTER))
// Nested scroll areas must not also move the page behind them.
.on_scroll_wheel(|_, _, cx| cx.stop_propagation()),
)
+1
View File
@@ -24,6 +24,7 @@ pub const CONTROL: f32 = 34.;
/// The top bar, and the sidebar of instances and servers.
pub const TOPBAR: f32 = 56.;
pub const SIDEBAR: f32 = 248.;
pub const PAGE_GUTTER: f32 = 32.;
/// Motion: short and eased out, never bouncy.
pub const QUICK: Duration = tokens::QUICK.duration();
+153
View File
@@ -0,0 +1,153 @@
//! Custom Windows chrome. Other platforms keep their native window decorations.
use crate::theme::Theme;
use gpui::{Div, TitlebarOptions, Window};
pub fn options() -> TitlebarOptions {
TitlebarOptions {
title: Some("Horizon".into()),
appears_transparent: cfg!(target_os = "windows"),
..Default::default()
}
}
#[cfg(not(target_os = "windows"))]
pub fn render(_theme: &Theme, _window: &Window) -> Option<Div> {
None
}
#[cfg(target_os = "windows")]
mod windows {
use super::*;
use crate::{blocks, mark};
use gpui::{div, prelude::*, px, FontWeight, Stateful, WindowControlArea};
const HEIGHT: f32 = 32.;
const BUTTON_WIDTH: f32 = 46.;
const RESIZE_INSET: f32 = 5.;
#[derive(Clone, Copy)]
enum Control {
Minimize,
Maximize,
Close,
}
impl Control {
fn area(self) -> WindowControlArea {
match self {
Self::Minimize => WindowControlArea::Min,
Self::Maximize => WindowControlArea::Max,
Self::Close => WindowControlArea::Close,
}
}
fn name(self) -> &'static str {
match self {
Self::Minimize => "window-minimize",
Self::Maximize => "window-maximize",
Self::Close => "window-close",
}
}
}
fn control_icon(control: Control, maximized: bool, theme: &Theme) -> Div {
let square = || {
div()
.absolute()
.size(px(10.))
.border_1()
.border_color(theme.ink_soft)
};
let icon = div().relative().size(px(14.));
match control {
Control::Minimize => icon.child(
div()
.absolute()
.left(px(2.))
.top(px(7.))
.w(px(10.))
.h(px(1.))
.bg(theme.ink_soft),
),
Control::Maximize if maximized => icon
.child(
div()
.absolute()
.left(px(4.))
.top_0()
.size(px(10.))
.border_t_1()
.border_r_1()
.border_color(theme.ink_soft),
)
.child(square().left(px(1.)).top(px(3.))),
Control::Maximize => icon.child(square().left(px(2.)).top(px(2.))),
Control::Close => {
let hover_color = theme.page;
icon.child(
blocks::icon("close", 14., theme.ink_soft)
.group_hover("window-close", move |style| style.text_color(hover_color)),
)
}
}
}
fn control_button(control: Control, theme: &Theme, maximized: bool) -> Stateful<Div> {
let theme = *theme;
div()
.id(control.name())
.group(control.name())
.flex()
.flex_none()
.items_center()
.justify_center()
.w(px(BUTTON_WIDTH))
.h_full()
.text_color(theme.ink_soft)
// GPUI maps these to native non-client hit tests, retaining Snap Layouts,
// Alt+Space and close handling. Click callbacks would run the action twice.
.window_control_area(control.area())
.hover(move |style| match control {
Control::Close => style.bg(theme.danger).text_color(theme.page),
_ => style.bg(theme.raised),
})
.child(control_icon(control, maximized, &theme))
}
pub fn render(theme: &Theme, window: &Window) -> Option<Div> {
let drag = div()
.id("window-drag")
.flex()
.flex_1()
.h_full()
.items_center()
.gap(px(8.))
.px(px(12.))
.window_control_area(WindowControlArea::Drag)
.child(mark(16., theme))
.child(blocks::pixel(13., FontWeight::MEDIUM).child("Horizon"));
Some(
div()
.flex()
.flex_none()
.items_center()
.h(px(HEIGHT))
// Control hit tests run before native edge resizing in GPUI 0.2.2.
.when(!window.is_maximized(), |bar| {
bar.pt(px(RESIZE_INSET)).px(px(RESIZE_INSET))
})
.bg(theme.side)
.text_color(theme.muted)
.border_b_1()
.border_color(theme.outline)
.child(drag)
.children(
[Control::Minimize, Control::Maximize, Control::Close]
.map(|control| control_button(control, theme, window.is_maximized())),
),
)
}
}
#[cfg(target_os = "windows")]
pub use windows::render;