diff --git a/Cargo.lock b/Cargo.lock index 073a3a4..ee60562 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1060,6 +1060,20 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e9c71c2167ca323c882b99918929403426e2373ea17242ff5653e0d5e1058be" +[[package]] +name = "embed-resource" +version = "3.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbfdaacccebec3b28e4866b8973543c7647797db5ada1bdab552e48fe665fbbd" +dependencies = [ + "cc", + "memchr", + "rustc_version", + "toml", + "vswhom", + "winreg", +] + [[package]] name = "endi" version = "1.1.1" @@ -1655,6 +1669,7 @@ checksum = "b40ca9252762c466af32d0b1002e91e4e1bc5398f77455e55474deb466355ff5" name = "halation-app" version = "0.1.0" dependencies = [ + "embed-resource", "halation-core", "i-slint-backend-testing", "rfd", @@ -4928,6 +4943,26 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "vswhom" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be979b7f07507105799e854203b470ff7c78a1639e330a58f183b5fea574608b" +dependencies = [ + "libc", + "vswhom-sys", +] + +[[package]] +name = "vswhom-sys" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb067e4cbd1ff067d1df46c9194b5de0e98efd2810bbc95c5d5e5f25a3231150" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "vtable" version = "0.5.0" @@ -5754,6 +5789,16 @@ dependencies = [ "memchr", ] +[[package]] +name = "winreg" +version = "0.55.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb5a765337c50e9ec252c2069be9bf91c7df47afb103b642ba3a53bf8101be97" +dependencies = [ + "cfg-if", + "windows-sys 0.59.0", +] + [[package]] name = "wit-bindgen" version = "0.57.1" diff --git a/assets/README.md b/assets/README.md index 0c8cdff..c09b897 100644 --- a/assets/README.md +++ b/assets/README.md @@ -1,19 +1,16 @@ -# Asset provenance +# Asset provenance -`halation-mark.png` is the Halation logo (Java, 2026-10-22): a hand-drawn vector stroke, +`halation-mark.png` is the Halation logo (Java, 2026-10-22): a hand-drawn vector stroke (one continuous line: an arch, a dip and a hooked rise), `docs/media/brand/source/halation-mark.svg`, rendered at 512 px by `tools/render-brand.js` (an identity asset, drawn for this project). `halation-app-icon.png` is the window and taskbar icon from the same script: the mark on a flat `#111111` rounded square. The static Home reference image is kept outside the source tree under ignored `.tools/ui-rebuild-native/home-reference/`; it is composition guidance only and is not embedded in the application. `halation-wordmark.svg` is the HALATION wordmark (one path, identity asset): Bodoni Moda (SIL OFL 1.1) at weight 600, -optical size 60, tracked 0.20 em, converted to outlines (Java's choice, 2026-10-22). -`halation-wordmark-glow.png` is the wordmark's halation glow (960 x 428, the wordmark plus 180 px around it), drawn -from the wordmark by `tools/render-wordmark-glow.js` with Java's settings (2026-10-22). +drawn for this project. `halation-wordmark-glow.png` is its soft white bloom, rendered by `tools/render-wordmark-glow.js`. `drop-outline.svg` is the dashed outline of Home's drop zone, drawn for this crate. -`fonts/SchibstedGrotesk.ttf` (variable weight, © The Schibsted-Grotesk Project Authors) is the interface face and -`fonts/Italiana.ttf` (© Santiago Orozco, Reserved Font Name "Italiana", unmodified) the page-title face; both SIL Open -Font License 1.1, from the Google Fonts repository. +`fonts/Inter.ttf` is the Inter typeface (variable weight, Latin subset), SIL Open Font License 1.1, © The Inter +Project Authors (https://github.com/rsms/inter); the original app uses the same typeface. `drape-loop.mp4`, `drape-tint.bin` and `drape-still.jpg` are recordings of the original Halation's Drape background: a seamless two-minute loop of 1800 frames of 320 x 180 at 15 fps stored as lifted luma in H.264, the colour of each diff --git a/assets/halation-app-icon.ico b/assets/halation-app-icon.ico new file mode 100644 index 0000000..448c351 Binary files /dev/null and b/assets/halation-app-icon.ico differ diff --git a/assets/halation-app-icon.png b/assets/halation-app-icon.png index e5742f1..7278be5 100644 Binary files a/assets/halation-app-icon.png and b/assets/halation-app-icon.png differ diff --git a/assets/halation-mark.png b/assets/halation-mark.png index 3c9a534..703e7ba 100644 Binary files a/assets/halation-mark.png and b/assets/halation-mark.png differ diff --git a/crates/halation-app/Cargo.toml b/crates/halation-app/Cargo.toml index 10ce70c..6bfe8a2 100644 --- a/crates/halation-app/Cargo.toml +++ b/crates/halation-app/Cargo.toml @@ -60,6 +60,8 @@ diag-skia-vulkan = ["slint/renderer-skia-vulkan"] [build-dependencies] slint-build = { version = "=1.18.1", default-features = false, features = ["compat-1-18"] } +# The Windows executable's icon and version resources (build.rs); it finds rc.exe in the Windows SDK +embed-resource = "=3.0.11" [dev-dependencies] # Headless UI tests (layout bounds at small window sizes); test builds only, never part of the shipped binary. diff --git a/crates/halation-app/build.rs b/crates/halation-app/build.rs index ec3d7e8..02d8989 100644 --- a/crates/halation-app/build.rs +++ b/crates/halation-app/build.rs @@ -16,6 +16,7 @@ fn main() { } copy_assets(); + embed_windows_icon(); let sha = git_output(&["rev-parse", "--short=12", "HEAD"]) .filter(|sha| !sha.is_empty()) @@ -36,6 +37,34 @@ fn main() { .expect("the Slint UI must compile; fix the reported .slint diagnostics"); } +/// The window and taskbar icon (the mark on #111111, `tools/render-brand.js`) is also a resource of the executable: +/// Explorer and the taskbar read it before the window exists, and it is the icon of a shortcut or a pinned app. +fn embed_windows_icon() { + if std::env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("windows") { + return; + } + let icon = PathBuf::from(std::env::var_os("CARGO_MANIFEST_DIR").unwrap_or_default()) + .join("../../assets/halation-app-icon.ico"); + if !icon.is_file() { + println!( + "cargo:warning=assets/halation-app-icon.ico is missing; run node tools/render-brand.js" + ); + return; + } + println!("cargo:rerun-if-changed={}", icon.display()); + let script = PathBuf::from(std::env::var_os("OUT_DIR").unwrap_or_default()).join("halation.rc"); + // Forward slashes: rc.exe reads `\t` in a quoted path as an escape (and this tree lives under `\trrax`) + let source = format!( + "1 ICON \"{}\"\n", + icon.display().to_string().replace('\\', "/") + ); + std::fs::write(&script, source).expect("the icon resource script must be written"); + // Only the app binary carries the icon; test and benchmark executables do not need it. + embed_resource::compile_for(&script, ["halation-slint"], embed_resource::NONE) + .manifest_optional() + .expect("the icon resource must compile (rc.exe comes with the Windows SDK)"); +} + /// Development builds run from `target/`: put a copy of the workspace's `assets/` next to the executable there, /// as the installer does beside the installed one. Only changed files are copied. fn copy_assets() { diff --git a/crates/halation-app/src/screenshot.rs b/crates/halation-app/src/screenshot.rs index d6a5fa8..05805bc 100644 --- a/crates/halation-app/src/screenshot.rs +++ b/crates/halation-app/src/screenshot.rs @@ -196,6 +196,9 @@ pub fn run(spec: ScreenshotSpec) -> Result<(), Box> { let (page, mode, section) = match spec.page.as_str() { "home" => (0, 0, -1), "home-open" => (0, 2, -1), + "motion-home" => (0, 6, -1), + "motion-settings" => (3, 7, -1), + "motion-sidebar" => (0, 8, -1), "settings" => (3, 0, -1), "converter" => (4, 0, -1), "converter-open" => (4, 2, -1), @@ -209,12 +212,15 @@ pub fn run(spec: ScreenshotSpec) -> Result<(), Box> { Some(section) if (0..8).contains(§ion) => (3, 0, section), _ => { return Err(format!( - "unknown page '{other}'; expected home, home-open, settings, settings-<0..7>, converter, converter-open, converter-ready, converter-audio or converter-video" + "unknown page '{other}'; expected home, home-open, settings, settings-<0..7>, converter, converter-open, converter-ready, converter-audio, converter-video, motion-home, motion-settings or motion-sidebar" ) .into()); } }, }; + if (6..=8).contains(&mode) && (spec.width != 1440 || spec.height != 900) { + return Err("motion sequences use 1440x900 fixed pointer fixtures".into()); + } // Absolute, like a real profile: FFmpeg runs in its own folder let out_dir = std::path::absolute( spec.out @@ -330,8 +336,77 @@ pub fn run(spec: ScreenshotSpec) -> Result<(), Box> { pump(&queue, Duration::from_millis(300)); } + if (6..=8).contains(&mode) { + // Real headless pointer events; never set UI hover properties and never touch the desktop. Capture departure, + // detachment, rest, reversal, and exit, not just an attractive final frame. Times are wall-clock approximations. + // Hold the same decoded Drape frame in every capture: otherwise the ambient movie changes the pixels we + // compare for hover-only changes. This changes the diagnostic render only, not the production player. + let backdrop = ui.get_backdrop(); + let capture = |name: &str| -> Result<(), Box> { + ui.set_backdrop(backdrop.clone()); + let mut pixels = vec![Rgb8Pixel::new(0, 0, 0); (spec.width * spec.height) as usize]; + window.request_redraw(); + window.draw_if_needed(|renderer| { + renderer.render(&mut pixels, spec.width as usize); + }); + let stem = spec.out.file_stem().unwrap_or_default().to_string_lossy(); + write_png( + &spec.out.with_file_name(format!("{stem}-{name}.png")), + spec.width, + spec.height, + &pixels, + )?; + Ok(()) + }; + let point = |x, y| { + ui.window() + .dispatch_event(slint::platform::WindowEvent::PointerMoved { + position: slint::LogicalPosition::new(x, y), + }) + }; + capture("idle")?; + let (first, second) = match mode { + 6 => ((500.0, 390.0), (860.0, 390.0)), + 7 => ((195.0, 78.0), (300.0, 78.0)), + _ => ((30.0, 82.0), (30.0, 166.0)), + }; + point(first.0, first.1); + pump(&queue, Duration::from_millis(400)); + capture("entered")?; + point(second.0, second.1); + for (name, wait) in [ + ("move-016", 16), + ("move-048", 32), + ("move-096", 48), + ("move-160", 64), + ("settled", 300), + ] { + pump(&queue, Duration::from_millis(wait)); + capture(name)?; + } + point(first.0, first.1); + pump(&queue, Duration::from_millis(32)); + capture("reverse-032")?; + ui.window() + .dispatch_event(slint::platform::WindowEvent::PointerExited); + pump(&queue, Duration::from_millis(400)); + capture("exit")?; + if mode == 6 { + point(746.0, 680.0); + pump(&queue, Duration::from_millis(400)); + capture("drop-hover")?; + point(450.0, 680.0); + pump(&queue, Duration::from_millis(400)); + capture("drop-hover-left")?; + ui.window() + .dispatch_event(slint::platform::WindowEvent::PointerExited); + pump(&queue, Duration::from_millis(400)); + capture("drop-exit")?; + } + } let (w, h) = (spec.width as usize, spec.height as usize); let mut buffer = vec![Rgb8Pixel::new(0, 0, 0); w * h]; + window.request_redraw(); let drawn = window.draw_if_needed(|renderer| { renderer.render(&mut buffer, w); }); diff --git a/crates/halation-app/tests/ui_layout.rs b/crates/halation-app/tests/ui_layout.rs index 02a83c0..0d91188 100644 --- a/crates/halation-app/tests/ui_layout.rs +++ b/crates/halation-app/tests/ui_layout.rs @@ -371,6 +371,154 @@ fn advance(ms: u64) { slint::platform::update_timers_and_animations(); } +#[test] +fn home_dock_hover_is_aligned_and_clicks_still_reach_the_tool() { + i_slint_backend_testing::init_no_event_loop(); + let ui = AppWindow::new().unwrap(); + ui.show().unwrap(); + fill_home(&ui); + let activated = Rc::new(std::cell::RefCell::new(String::new())); + let result = activated.clone(); + ui.on_tool_activated(move |id| *result.borrow_mut() = id.to_string()); + for (w, h) in SIZES { + resize(&ui, w, h); + let tool = |label: &str| { + ElementHandle::find_by_accessible_label(&ui, label) + .find(|e| e.absolute_position().x > 62.0 && e.size().height > 0.0) + .expect("tool is on Home, not the sidebar") + }; + let first = tool("Converter"); + let second = tool("Grade"); + let at = |e: &ElementHandle| { + let (p, s) = (e.absolute_position(), e.size()); + slint::LogicalPosition::new(p.x + s.width / 2.0, p.y + s.height / 2.0) + }; + ui.window().dispatch_event(WindowEvent::PointerMoved { + position: at(&first), + }); + advance(1000); + let pill = || { + ElementHandle::find_by_element_id(&ui, "PillList::hover-pill") + .find(|e| e.absolute_position().x > 62.0) + .unwrap() + }; + let p = pill(); + assert!((p.absolute_position().x - first.absolute_position().x).abs() < 0.5); + assert!((p.size().width - first.size().width).abs() < 0.5); + assert!((p.absolute_position().y - first.absolute_position().y).abs() < 0.5); + ui.window().dispatch_event(WindowEvent::PointerMoved { + position: at(&second), + }); + advance(1); + advance(24); + assert!(pill().absolute_position().x > first.absolute_position().x); + assert!(pill().absolute_position().x < second.absolute_position().x); + advance(1000); + assert!((pill().absolute_position().x - second.absolute_position().x).abs() < 0.5); + let button = slint::platform::PointerEventButton::Left; + ui.window().dispatch_event(WindowEvent::PointerPressed { + position: at(&second), + button, + }); + ui.window().dispatch_event(WindowEvent::PointerReleased { + position: at(&second), + button, + }); + assert_eq!(&*activated.borrow(), "grade"); + } +} + +#[test] +fn fusion_uses_one_silhouette_only_during_departure_and_arrival() { + i_slint_backend_testing::init_no_event_loop(); + let ui = AppWindow::new().unwrap(); + ui.show().unwrap(); + fill_home(&ui); + resize(&ui, 1280.0, 800.0); + // Drive frames, not one time jump: the edge recovery starts when the position spring settles. + let settle = || { + for _ in 0..64 { + advance(16); + } + }; + // Vertical sidebar and horizontal Settings categories share the same fusion renderer. + for horizontal in [false, true] { + if horizontal { + ui.set_page(3); + advance(1000); + } + let point = |label: &str| { + let e = ElementHandle::find_by_accessible_label(&ui, label) + .find(|e| { + if horizontal { + e.absolute_position().x > 62.0 && e.absolute_position().y < 100.0 + } else { + e.absolute_position().x < 40.0 + } + }) + .unwrap(); + let (p, s) = (e.absolute_position(), e.size()); + ui.window().dispatch_event(WindowEvent::PointerMoved { + position: slint::LogicalPosition::new(p.x + s.width / 2.0, p.y + s.height / 2.0), + }); + }; + let joined = || { + ElementHandle::find_by_element_id(&ui, "PillList::united-shape").any(|e| { + if horizontal { + e.absolute_position().x > 62.0 + } else { + e.absolute_position().x < 40.0 + } + }) + }; + let (selected, adjacent) = if horizontal { + ("General", "Interface") + } else { + ("Home", "Downloader") + }; + point(selected); + settle(); + assert!(!joined(), "rest retains the original pieces"); + point(adjacent); + advance(1); + advance(16); + assert!( + joined(), + "departure must be one filled silhouette, horizontal={horizontal}" + ); + point(if horizontal { "You" } else { "Converter" }); + advance(1); + assert!( + joined(), + "retargeting a still-connected shape must not expose two inner borders" + ); + settle(); + assert!(!joined(), "neck breaks; original resting borders return"); + point(selected); + advance(1); + advance(16); + assert!(joined(), "arrival must also join without an inner border"); + settle(); + ui.window().dispatch_event(WindowEvent::PointerExited); + settle(); + assert!(!joined()); + } + let motion = ui.global::(); + motion.set_glide(0); + motion.set_trail(0); + motion.set_fade(0); + point_at(&ui, "Settings"); + advance(1); + point_at(&ui, "Home"); + advance(1); + assert!( + ElementHandle::find_by_element_id(&ui, "PillList::united-shape") + .next() + .is_none(), + "reduced motion skips all transient fusion geometry" + ); +} + fn point_at(ui: &AppWindow, label: &str) -> (f32, f32) { // The sidebar's row (Home's strip and the top bar may hold the same name) let row = ElementHandle::find_by_accessible_label(ui, label) diff --git a/crates/halation-app/ui/app.slint b/crates/halation-app/ui/app.slint index 0540c53..5267f62 100644 --- a/crates/halation-app/ui/app.slint +++ b/crates/halation-app/ui/app.slint @@ -434,6 +434,7 @@ export component AppWindow inherits Window { if index == 0 || tool.group != root.active-tools[index - 1].group : SidebarGroup { label: root.group-name(tool.group); open: root.rail-open; + covered-by-fusion: rail-pills.fusion-covers(self.absolute-position.y + self.height / 2); } SidebarItem { icon: tool.icon; @@ -450,6 +451,7 @@ export component AppWindow inherits Window { SidebarGroup { label: ""; open: root.rail-open; + covered-by-fusion: rail-pills.fusion-covers(self.absolute-position.y + self.height / 2); } SidebarItem { icon: "settings"; diff --git a/crates/halation-app/ui/components/dock-light.slint b/crates/halation-app/ui/components/dock-light.slint new file mode 100644 index 0000000..4923bcf --- /dev/null +++ b/crates/halation-app/ui/components/dock-light.slint @@ -0,0 +1,30 @@ +import { Theme } from "../theme.slint"; +import { Motion, Curve } from "../motion.slint"; + +// Local, horizontal pointer light. No blur, layer, timer, or animation at rest. The item hover pill remains separate. +export component DockLight inherits Rectangle { + in property at: root.width / 2; + in property on: false; + in property radius: Theme.radius; + property shown: root.on ? 1 : 0; + animate shown { duration: Motion.hover(root.on); easing: Curve.ease; } + Rectangle { + x: 0px; + y: 0px; + width: root.width; + height: root.height; + border-radius: root.radius; + background: @radial-gradient(circle 90px at root.at root.height / 2, + Theme.text.transparentize(1 - 0.08 * root.shown) 0%, transparent 72%); + } + Rectangle { + x: 0px; + y: 0px; + width: root.width; + height: root.height; + border-radius: root.radius; + border-width: 1px; + border-color: @radial-gradient(circle 80px at root.at root.height / 2, + Theme.text.transparentize(1 - 0.42 * root.shown) 0%, transparent 70%); + } +} diff --git a/crates/halation-app/ui/components/pills.slint b/crates/halation-app/ui/components/pills.slint index cb6ca27..ee646ed 100644 --- a/crates/halation-app/ui/components/pills.slint +++ b/crates/halation-app/ui/components/pills.slint @@ -60,7 +60,9 @@ export component PillList inherits Rectangle { root.hover-idle = false; leave.running = false; root.hover-forward = at - root.origin >= root.hover-at; - root.hover-from = root.hover-snap ? at - root.origin : root.hover-at; + // A rapid sweep can retarget before detachment: keep its connection to the selection until the physical + // union breaks, rather than replacing the origin with an intermediate target it never reached. + root.hover-from = root.hover-snap ? at - root.origin : root.connection-live ? root.select-at : root.hover-at; root.hover-at = at - root.origin; root.hover-size = size; root.hover-on = true; @@ -108,7 +110,7 @@ export component PillList inherits Rectangle { width: selection.width; height: selection.height; border-radius: root.radius; - background: root.select-shown ? Theme.contact : Theme.contact.transparentize(1); + background: root.select-shown ? Theme.contact.transparentize(1 - root.edge-reveal) : Theme.contact.transparentize(1); } selection := Rectangle { x: root.horizontal ? root.select-start : root.inset-left; @@ -116,10 +118,10 @@ export component PillList inherits Rectangle { width: root.horizontal ? max(0px, root.select-end - root.select-start) : parent.width - root.inset-left - root.inset-right; height: root.horizontal ? parent.height : max(0px, root.select-end - root.select-start); border-radius: root.radius; - background: !root.raised-select ? (root.select-shown ? root.select-fill : root.select-fill.transparentize(1)) + background: root.united ? transparent : !root.raised-select ? (root.select-shown ? root.select-fill : root.select-fill.transparentize(1)) : root.select-shown ? Theme.raised-fill : Theme.raised-fill.transparentize(1); border-width: root.raised-select ? 1px : 0px; - border-color: root.select-shown ? Theme.raised-edge : Theme.raised-edge.transparentize(1); + border-color: root.select-shown ? Theme.raised-edge.transparentize(1 - root.edge-reveal) : Theme.raised-edge.transparentize(1); } // The accent bar beside the selected row (vertical lists with `bar`), stretching with the pill if root.bar && !root.horizontal : Rectangle { @@ -140,27 +142,32 @@ export component PillList inherits Rectangle { // Neck reach: pills further apart than this never join property reach: 18px; property hover-moving: abs(root.hover-start - root.hover-at) > 0.5px || abs(root.hover-end - root.hover-at - root.hover-size) > 0.5px; + property select-moving: abs(root.select-start - root.select-at) > 0.5px || abs(root.select-end - root.select-at - root.select-size) > 0.5px; // 1 while the hover pill moves, back to 0 once it rests - property join: root.hover-moving ? 1 : 0; + property join: Motion.glide > 0ms && (root.hover-moving || root.select-moving) ? 1 : 0; animate join { duration: Motion.fade; easing: Curve.ease; } // Only a pill that leaves the selected row or heads for it joins it: passing from one row to another beside the // selection draws no neck between them (Java, 2026-10-22) property touches-selection: abs(root.hover-at - root.select-at) < 0.5px || abs(root.hover-from - root.select-at) < 0.5px; + // Unlike `united`, this survives the old row's exit event before the next row's enter event in the same sweep. + property connection-live: root.join > 0.02 && root.overlap > -root.reach && root.touches-selection; property fusing: root.hover-on && root.select-on && root.has-selection && root.touches-selection; // 0 apart, 1 joined into one surface - property closeness: !root.fusing ? 0 : root.overlap > 0px ? 1 : max(0, 1 + root.overlap / root.reach) * root.join; + property closeness: !root.fusing || Motion.glide <= 0ms ? 0 : root.overlap > 0px ? 1 : max(0, 1 + root.overlap / root.reach) * root.join; + // Transfer the border to one stroked outer contour while joined, then back to the separate pieces on detachment. + // Only internal piece edges/contact shadows are hidden: the visible perimeter never fades away. + property united: root.closeness > 0.02 && (root.join > 0.02 || root.hover-moving || root.select-moving); + property edge-reveal: root.united ? 0 : 1; + // A sidebar separator must not draw a cut through the moving union. Its resting geometry stays unchanged. + public pure function fusion-covers(window-y: length) -> bool { + return !root.horizontal && root.united + && window-y >= root.absolute-position.y + root.union-a + && window-y <= root.absolute-position.y + root.union-b; + } property hover-colour: root.select-fill.mix(root.hover-fill, root.closeness); property hover-alpha: root.hover-on ? 0 : 1; animate hover-alpha { duration: Motion.hover(root.hover-on); easing: Curve.ease; } - // The neck's ends (along the list) and sides (across it), in the list's own coordinates - property hover-first: root.hover-start < root.select-start; - property neck-a: (root.hover-first ? root.hover-end : root.select-end) - root.radius * root.closeness - 1px; - property neck-b: (root.hover-first ? root.select-start : root.hover-start) + root.radius * root.closeness + 1px; - property cross-0: (root.horizontal ? 0px : root.inset-left) + root.radius * (1 - root.closeness); - property cross-1: (root.horizontal ? root.height : root.width - root.inset-right) - root.radius * (1 - root.closeness); - // How far each side bows in at the middle; a cubic with both controls at `bow / 0.75` reaches it - property bow: (root.cross-1 - root.cross-0) / 2 * (1 - root.closeness) * 0.85 / 0.75; // Main and cross coordinates to path numbers pure function px(main: length, across: length) -> float { (root.horizontal ? main : across) / 1px @@ -169,46 +176,98 @@ export component PillList inherits Rectangle { (root.horizontal ? across : main) / 1px } - if root.overlap <= 0px && root.closeness > 0.02 : Path { + // Along-axis extent and rounded ends of the union. A cubic waist pinches as the pieces pull apart; overlapping + // pieces have no waist. One closed, opaque fill avoids alpha accumulation and all internal rounded edges. + property union-stroke: root.raised-select || root.raised-hover ? 1px : 0px; + // Path strokes are centred; Rectangle borders are inside. Inset half a stroke to keep the same outer bounds. + property union-inset: root.union-stroke / 2; + property union-a: min(root.select-start, root.hover-start) + root.union-inset; + property union-b: max(root.select-end, root.hover-end) - root.union-inset; + property union-cross-a: (root.horizontal ? 0px : root.inset-left) + root.union-inset; + property union-cross-b: (root.horizontal ? root.height : root.width - root.inset-right) - root.union-inset; + property union-radius: min(max(0px, root.radius - root.union-inset), (root.union-cross-b - root.union-cross-a) / 2, (root.union-b - root.union-a) / 2); + // Circular quarter-arc approximation. Putting both control points on the corner makes a superellipse that reads + // square during stretching, even with the same nominal radius as the resting Rectangle. + property corner-inset: root.union-radius * 0.44771525; + property waist-at: (min(root.select-end, root.hover-end) + max(root.select-start, root.hover-start)) / 2; + property shoulder-a: max(root.union-a + root.union-radius, min(root.waist-at, min(root.select-end, root.hover-end) - root.union-radius)); + property shoulder-b: min(root.union-b - root.union-radius, max(root.waist-at, max(root.select-start, root.hover-start) + root.union-radius)); + property pinch: root.overlap >= 0px ? 0px : (root.union-cross-b - root.union-cross-a) / 2 * (1 - root.closeness); + if root.united : united-shape := Path { x: 0px; y: 0px; width: root.width; height: root.height; + // Coordinates already are logical pixels with a half-stroke inset. Default fitting reserves stroke space + // again and shrinks/centres the complete shape, especially in a long, shallow horizontal tab strip. + fit: preserve; viewbox-x: 0; viewbox-y: 0; viewbox-width: root.width / 1px; viewbox-height: root.height / 1px; - fill: root.hover-colour.transparentize(root.hover-alpha); + fill: root.raised-select || root.raised-hover ? Theme.raised-flat : root.select-fill; + stroke: Theme.raised-edge; + stroke-width: root.union-stroke; + stroke-line-join: round; MoveTo { - x: root.px(root.neck-a, root.cross-0); - y: root.py(root.neck-a, root.cross-0); + x: root.px(root.union-a + root.union-radius, root.union-cross-a); + y: root.py(root.union-a + root.union-radius, root.union-cross-a); + } + LineTo { x: root.px(root.shoulder-a, root.union-cross-a); y: root.py(root.shoulder-a, root.union-cross-a); } + CubicTo { + control-1-x: root.px(root.waist-at, root.union-cross-a); control-1-y: root.py(root.waist-at, root.union-cross-a); + control-2-x: root.px(root.waist-at, root.union-cross-a + root.pinch); control-2-y: root.py(root.waist-at, root.union-cross-a + root.pinch); + x: root.px(root.waist-at, root.union-cross-a + root.pinch); y: root.py(root.waist-at, root.union-cross-a + root.pinch); + } + CubicTo { + control-1-x: root.px(root.waist-at, root.union-cross-a + root.pinch); control-1-y: root.py(root.waist-at, root.union-cross-a + root.pinch); + control-2-x: root.px(root.waist-at, root.union-cross-a); control-2-y: root.py(root.waist-at, root.union-cross-a); + x: root.px(root.shoulder-b, root.union-cross-a); y: root.py(root.shoulder-b, root.union-cross-a); + } + LineTo { x: root.px(root.union-b - root.union-radius, root.union-cross-a); y: root.py(root.union-b - root.union-radius, root.union-cross-a); } + CubicTo { + control-1-x: root.px(root.union-b - root.corner-inset, root.union-cross-a); control-1-y: root.py(root.union-b - root.corner-inset, root.union-cross-a); + control-2-x: root.px(root.union-b, root.union-cross-a + root.corner-inset); control-2-y: root.py(root.union-b, root.union-cross-a + root.corner-inset); + x: root.px(root.union-b, root.union-cross-a + root.union-radius); y: root.py(root.union-b, root.union-cross-a + root.union-radius); + } + LineTo { x: root.px(root.union-b, root.union-cross-b - root.union-radius); y: root.py(root.union-b, root.union-cross-b - root.union-radius); } + CubicTo { + control-1-x: root.px(root.union-b, root.union-cross-b - root.corner-inset); control-1-y: root.py(root.union-b, root.union-cross-b - root.corner-inset); + control-2-x: root.px(root.union-b - root.corner-inset, root.union-cross-b); control-2-y: root.py(root.union-b - root.corner-inset, root.union-cross-b); + x: root.px(root.union-b - root.union-radius, root.union-cross-b); y: root.py(root.union-b - root.union-radius, root.union-cross-b); } + LineTo { x: root.px(root.shoulder-b, root.union-cross-b); y: root.py(root.shoulder-b, root.union-cross-b); } CubicTo { - control-1-x: root.px(root.neck-a, root.cross-0 + root.bow); - control-1-y: root.py(root.neck-a, root.cross-0 + root.bow); - control-2-x: root.px(root.neck-b, root.cross-0 + root.bow); - control-2-y: root.py(root.neck-b, root.cross-0 + root.bow); - x: root.px(root.neck-b, root.cross-0); - y: root.py(root.neck-b, root.cross-0); + control-1-x: root.px(root.waist-at, root.union-cross-b); control-1-y: root.py(root.waist-at, root.union-cross-b); + control-2-x: root.px(root.waist-at, root.union-cross-b - root.pinch); control-2-y: root.py(root.waist-at, root.union-cross-b - root.pinch); + x: root.px(root.waist-at, root.union-cross-b - root.pinch); y: root.py(root.waist-at, root.union-cross-b - root.pinch); } - LineTo { - x: root.px(root.neck-b, root.cross-1); - y: root.py(root.neck-b, root.cross-1); + CubicTo { + control-1-x: root.px(root.waist-at, root.union-cross-b - root.pinch); control-1-y: root.py(root.waist-at, root.union-cross-b - root.pinch); + control-2-x: root.px(root.waist-at, root.union-cross-b); control-2-y: root.py(root.waist-at, root.union-cross-b); + x: root.px(root.shoulder-a, root.union-cross-b); y: root.py(root.shoulder-a, root.union-cross-b); + } + LineTo { x: root.px(root.union-a + root.union-radius, root.union-cross-b); y: root.py(root.union-a + root.union-radius, root.union-cross-b); } + CubicTo { + control-1-x: root.px(root.union-a + root.corner-inset, root.union-cross-b); control-1-y: root.py(root.union-a + root.corner-inset, root.union-cross-b); + control-2-x: root.px(root.union-a, root.union-cross-b - root.corner-inset); control-2-y: root.py(root.union-a, root.union-cross-b - root.corner-inset); + x: root.px(root.union-a, root.union-cross-b - root.union-radius); y: root.py(root.union-a, root.union-cross-b - root.union-radius); } + LineTo { x: root.px(root.union-a, root.union-cross-a + root.union-radius); y: root.py(root.union-a, root.union-cross-a + root.union-radius); } CubicTo { - control-1-x: root.px(root.neck-b, root.cross-1 - root.bow); - control-1-y: root.py(root.neck-b, root.cross-1 - root.bow); - control-2-x: root.px(root.neck-a, root.cross-1 - root.bow); - control-2-y: root.py(root.neck-a, root.cross-1 - root.bow); - x: root.px(root.neck-a, root.cross-1); - y: root.py(root.neck-a, root.cross-1); + control-1-x: root.px(root.union-a, root.union-cross-a + root.corner-inset); control-1-y: root.py(root.union-a, root.union-cross-a + root.corner-inset); + control-2-x: root.px(root.union-a + root.corner-inset, root.union-cross-a); control-2-y: root.py(root.union-a + root.corner-inset, root.union-cross-a); + x: root.px(root.union-a + root.union-radius, root.union-cross-a); y: root.py(root.union-a + root.union-radius, root.union-cross-a); } Close {} } // Raised: the hover pill carries the raised edges; over or joined to a raised selection it takes them as it // becomes the selection, so hovering the selected row keeps its relief - property hover-strength: root.soft-hover ? 0.45 + 0.55 * root.closeness : 1; + // The shared contour uses the full material. Hand its intensity back to the softer resting hover gradually, + // instead of snapping from 100% to 45% on the frame that the neck detaches. Geometry/stroke handoff stays exact. + property hover-strength: root.united ? 1 : root.soft-hover ? 0.45 + 0.55 * root.closeness : 1; + animate hover-strength { duration: root.united ? 0ms : Motion.fade; easing: Curve.ease; } property hover-clear: 1 - (1 - root.hover-alpha) * root.hover-strength; property edge-clear: root.raised-hover ? root.hover-clear : 1 - root.closeness * (1 - root.hover-alpha); if root.raised-hover || root.raised-select : Rectangle { @@ -217,7 +276,7 @@ export component PillList inherits Rectangle { width: hover-pill.width; height: hover-pill.height; border-radius: root.radius; - background: Theme.contact.transparentize(root.edge-clear); + background: Theme.contact.transparentize(1 - (1 - root.edge-clear) * root.edge-reveal); } hover-pill := Rectangle { x: root.horizontal ? root.hover-start : root.inset-left; @@ -225,8 +284,8 @@ export component PillList inherits Rectangle { width: root.horizontal ? max(0px, root.hover-end - root.hover-start) : parent.width - root.inset-left - root.inset-right; height: root.horizontal ? parent.height : max(0px, root.hover-end - root.hover-start); border-radius: root.radius; - background: root.raised-hover ? Theme.raised-fill.transparentize(root.hover-clear) : root.hover-colour.transparentize(root.hover-alpha); + background: root.united ? transparent : root.raised-hover ? Theme.raised-fill.transparentize(root.hover-clear) : root.hover-colour.transparentize(root.hover-alpha); border-width: root.raised-hover || root.raised-select ? 1px : 0px; - border-color: Theme.raised-edge.transparentize(root.edge-clear); + border-color: Theme.raised-edge.transparentize(1 - (1 - root.edge-clear) * root.edge-reveal); } } diff --git a/crates/halation-app/ui/components/rail-item.slint b/crates/halation-app/ui/components/rail-item.slint index a0751ab..7e6d9f3 100644 --- a/crates/halation-app/ui/components/rail-item.slint +++ b/crates/halation-app/ui/components/rail-item.slint @@ -153,6 +153,7 @@ export component SidebarItem inherits FocusScope { export component SidebarGroup inherits Rectangle { in property label; in property open: true; + in property covered-by-fusion: false; // A fixed gap, the same for every group and open or collapsed, so opening the sidebar moves no row height: 24px; // The line and the name cross-fade (Java, 2026-10-22); both always there, so each fade has a start @@ -161,8 +162,8 @@ export component SidebarGroup inherits Rectangle { y: (parent.height - self.height) / 2; width: root.label == "" ? parent.width - 20px : Theme.sidebar-closed - 17px - 20px; height: 1px; - background: Theme.line-strong.transparentize(root.open && root.label != "" ? 1 : 0); - animate background { duration: Motion.fade; easing: Curve.ease; } + background: Theme.line-strong.transparentize(root.covered-by-fusion || (root.open && root.label != "") ? 1 : 0); + animate background { duration: root.covered-by-fusion ? 0ms : Motion.fade; easing: Curve.ease; } } Text { x: 8px; diff --git a/crates/halation-app/ui/pages/home.slint b/crates/halation-app/ui/pages/home.slint index 9972ca4..d85992a 100644 --- a/crates/halation-app/ui/pages/home.slint +++ b/crates/halation-app/ui/pages/home.slint @@ -5,6 +5,7 @@ import { ToolItem, RecentItem } from "../models.slint"; import { Motion, Curve } from "../motion.slint"; import { PillList } from "../components/pills.slint"; import { Surface, Level } from "../components/surface.slint"; +import { DockLight } from "../components/dock-light.slint"; // One entry of Home's tool strip: icon over its name. Its hover is the strip's sliding pill: it reports where it is. component StripItem inherits FocusScope { @@ -51,6 +52,10 @@ component StripItem inherits FocusScope { } Rectangle { // Sinks at once on press, back on release + x: 0px; + y: 0px; + width: root.width; + height: root.height; // Both axes set explicitly: animating them with only the `transform-scale` shorthand set leaves them at 0 (Slint 1.18) transform-scale-x: touch.pressed ? Motion.press-scale : 100%; transform-scale-y: self.transform-scale-x; @@ -138,7 +143,7 @@ export component HomePage inherits Rectangle { } // Tool strip - Rectangle { + dock := Rectangle { x: (parent.width - self.width) / 2; y: root.hero-top + 138px; width: min(strip.preferred-width, parent.width - 24px); @@ -149,28 +154,49 @@ export component HomePage inherits Rectangle { glass: true; radius: Theme.radius; } - strip-pills := PillList { - x: 5px; - y: 5px; - width: parent.width - 10px; - height: parent.height - 10px; - horizontal: true; - has-selection: false; - hover-fill: Theme.raised-flat; - raised-hover: true; - radius: Theme.radius; - } - strip := HorizontalLayout { - padding-left: 5px; - padding-right: 5px; - padding-top: 5px; - padding-bottom: 5px; - spacing: 0px; - for tool in root.tools : StripItem { - icon: tool.icon; - label: tool.name; - activated => { root.tool-activated(tool.id); } - hovered(on, at, size) => { strip-pills.hover(on, at, size); } + // A parent TouchArea observes the complete dock, including its padding, and forwards input to the items. + // The light uses these local coordinates directly: no window/strip padding conversion or item-exit flicker. + dock-touch := TouchArea { + x: 0px; + y: 0px; + width: dock.width; + height: dock.height; + DockLight { + x: 0px; + y: 0px; + width: dock.width; + height: dock.height; + at: dock-touch.mouse-x; + on: dock-touch.has-hover; + radius: Theme.radius; + } + strip-pills := PillList { + x: 5px; + y: 5px; + width: parent.width - 10px; + height: parent.height - 10px; + horizontal: true; + has-selection: false; + hover-fill: Theme.raised-flat; + raised-hover: true; + radius: Theme.radius; + } + strip := HorizontalLayout { + x: 0px; + y: 0px; + width: dock.width; + height: dock.height; + padding-left: 5px; + padding-right: 5px; + padding-top: 5px; + padding-bottom: 5px; + spacing: 0px; + for tool in root.tools : StripItem { + icon: tool.icon; + label: tool.name; + activated => { root.tool-activated(tool.id); } + hovered(on, at, size) => { strip-pills.hover(on, at, size); } + } } } } @@ -182,31 +208,24 @@ export component HomePage inherits Rectangle { // Taller and wider, recent files lower (Java, 2026-10-22) width: min(780px, parent.width - 48px); height: 196px; - // A panel over the Drape; under a dragged file or keyboard focus, an accent edge and a faint accent veil + // Keep the card's base fill fixed. Pointer light is local, never a veil over the complete interior. Surface { level: Level.bubble; glass: true; radius: Theme.radius; - veil: drop-area.has-drag ? Theme.accent.transparentize(88%) : drop-touch.has-hover ? Theme.hover-fill.transparentize(40%) : Theme.hover-fill.transparentize(1); - animate veil { duration: Motion.hover(drop-touch.has-hover || drop-area.has-drag); easing: Curve.ease; } } - // The pointer light of the original Home (Java, 2026-10-22): a soft white circle under the pointer, brighter - // while a file is over the zone. It is a gradient, not a blur: no shadow is rendered, and the light only - // exists while the drop zone is hovered. - Rectangle { - property glow-radius: drop-area.has-drag ? 420px : 160px; - property glow-x: drop-touch.has-hover ? drop-touch.mouse-x : self.width / 2; - property glow-y: drop-touch.has-hover ? drop-touch.mouse-y : self.height / 2; - // The light fades by its own colour alpha, not by `opacity`: an opacity animation makes Skia compose the - // rectangle offscreen on every frame (tests/services.rs enforces the rule). - property glow-centre: drop-touch.has-hover || drop-area.has-drag - ? Theme.text.transparentize(92%) - : Theme.text.transparentize(100%); - animate glow-centre { duration: Motion.hover(drop-touch.has-hover || drop-area.has-drag); easing: Curve.ease; } + drop-light := Rectangle { + x: 0px; + y: 0px; + width: parent.width; + height: parent.height; border-radius: Theme.radius; - background: @radial-gradient(circle glow-radius at glow-x glow-y, - glow-centre 0%, - Theme.text.transparentize(100%) 72%); + property reach: drop-area.has-drag ? 420px : 160px; + property at-x: drop-touch.has-hover ? drop-touch.mouse-x : self.width / 2; + property at-y: drop-touch.has-hover ? drop-touch.mouse-y : self.height / 2; + property light: Theme.text.transparentize(drop-touch.has-hover || drop-area.has-drag ? 92% : 100%); + animate light { duration: Motion.hover(drop-touch.has-hover || drop-area.has-drag); easing: Curve.ease; } + background: @radial-gradient(circle self.reach at self.at-x self.at-y, self.light 0%, transparent 72%); } Rectangle { border-radius: Theme.radius; @@ -224,11 +243,11 @@ export component HomePage inherits Rectangle { Rectangle { x: (parent.width - self.width) / 2; - // The tile rises 2 px under the pointer, as in the original Home - y: drop-touch.has-hover || drop-area.has-drag ? 46px : 48px; + // The restored pointer light does not move the icon; only drag feedback raises it. + y: drop-area.has-drag ? 46px : 48px; width: 48px; height: 48px; - animate y { duration: Motion.hover(drop-touch.has-hover || drop-area.has-drag); easing: Curve.ease; } + animate y { duration: Motion.hover(drop-area.has-drag); easing: Curve.ease; } Surface { level: Level.raised; radius: Theme.radius; diff --git a/docs/features/motion.md b/docs/features/motion.md index 0b93544..e469bef 100644 --- a/docs/features/motion.md +++ b/docs/features/motion.md @@ -1,6 +1,35 @@ # Movimiento nativo (Slint) Status: Implemented and approved by Java in the native window, 2026-10-22 (native beta build 42cb9ca). +The contour, dock and restored local drop light at `cd79425` were approved by Java on 2026-10-23. The subsequent +material-intensity handoff at `5ee05c3` was also approved by Java on 2026-10-23, with explicit authorization to merge +into `slint/native`. Resting layout, spacing and material remain unchanged. + +### Hover corrections (2026-10-23, supersede the drop-zone light and two-piece neck descriptions below) + +- **Drop zone (latest feedback):** restore the local pointer-following radial light (160 px, white 8%, transparent + at 72%; 420 px while dragging). Keep the base material unchanged: no uniform hover veil over the whole card. + Hover still highlights its border; dragging/focus use the accent edge. Existing press/drag scale and drag icon + movement stay, not hover icon movement. Light fades via `Motion.hover` and is instant with reduced motion. +- **Home tool dock:** a horizontal pointer light (90 px / 8% fill and 80 px / 42% edge, fading out at 72% / 70% of the + radii). A parent TouchArea observes the complete strip, including padding, without taking clicks from its tools. + Coordinates are local to the dock, with no extra inset or per-item exit flicker. Reveal/exit use native + `Motion.hover` tokens (instant with reduced motion); pointer position follows directly. No idle animation is added. +- **Fusion (latest feedback):** a transient union, never a redesign of resting cards/tabs. During departure/arrival + the two pieces are replaced by one closed opaque silhouette with one continuous stroked perimeter and a pinching + waist (18 px reach), not a neck patched between two bordered rectangles. The border never fades out: it follows the + shared contour through fusion and splitting, returning directly to the two individual perimeters on detachment. + Only internal piece borders/contact shadows are suppressed while the shared perimeter is drawn. + On detachment, material intensity blends from the full shared surface to the softer resting hover in `Motion.fade` + (80 ms), rather than jumping from 100% to 45%. This changes neither the approved contour nor resting appearance; + reduced motion remains immediate. This follow-up was approved by Java at `5ee05c3` on 2026-10-23. + Overlap cannot accumulate alpha or retain internal rounded edges. The same `PillList` serves horizontal tabs, + segmented controls and vertical sidebar rows; selection motion participates too. Reversal retargets existing native + springs; reduced motion skips transient fusion. No blur, layer, per-pixel work, or custom animation clock. +- **Evidence:** `ui_layout.rs` exercises departure, arrival, rest, reduced motion, dock alignment at all supported sizes, + and tool clicks through the parent hover observer. `--screenshot motion-home|motion-settings|motion-sidebar 1440x900 + ` writes intermediate frames alongside the final image using real headless pointer events. Wall-clock capture + times are approximate, and software-renderer images do not replace native Skia visual approval. Código: `motion.rs`, `ui/motion.slint`, `ui/components/{pills,tooltip}.slint`; tests en `tests/services.rs` (reglas de coste, tokens) y `tests/ui_layout.rs` (píldoras con eventos de puntero, movimiento reducido). diff --git a/docs/media/brand/halation-app-icon.svg b/docs/media/brand/halation-app-icon.svg index 26e664c..ac6ce6c 100644 --- a/docs/media/brand/halation-app-icon.svg +++ b/docs/media/brand/halation-app-icon.svg @@ -1,5 +1,5 @@ - + diff --git a/docs/media/brand/halation-mark-source.png b/docs/media/brand/halation-mark-source.png index 3c9a534..703e7ba 100644 Binary files a/docs/media/brand/halation-mark-source.png and b/docs/media/brand/halation-mark-source.png differ diff --git a/docs/media/brand/halation-mark.svg b/docs/media/brand/halation-mark.svg index 48c7a90..f9cd329 100644 --- a/docs/media/brand/halation-mark.svg +++ b/docs/media/brand/halation-mark.svg @@ -1 +1 @@ - + diff --git a/docs/media/brand/source/halation-mark.svg b/docs/media/brand/source/halation-mark.svg index 48c7a90..f9cd329 100644 --- a/docs/media/brand/source/halation-mark.svg +++ b/docs/media/brand/source/halation-mark.svg @@ -1 +1 @@ - + diff --git a/tools/render-brand.js b/tools/render-brand.js index ee96b4b..9750dff 100644 --- a/tools/render-brand.js +++ b/tools/render-brand.js @@ -5,6 +5,8 @@ // - assets/halation-mark.png (512 px): the transparent mark. // - assets/halation-app-icon.png (256 px): the window and taskbar icon, the mark at 62% on a flat #111111 rounded // square (the interface's surface grey) with an 8% white hairline. +// - assets/halation-app-icon.ico: the same icon at 16, 24, 32, 48 and 256 px, embedded in the Windows executable +// (crates/halation-app/build.rs) and used for the window and taskbar. // - docs/media/brand/: halation-mark.svg (the source), halation-app-icon.svg, halation-mark-source.png (the mark PNG). // // Usage: node tools/render-brand.js (CHROME and NODE_PATH as needed for Playwright) @@ -14,6 +16,7 @@ const { chromium } = require("playwright"); const MARK_PNG = 512; const ICON_PNG = 256; +const ICO_SIZES = [16, 24, 32, 48, 256]; // Share of the square the mark spans const SPAN = 0.62; @@ -37,7 +40,7 @@ function iconSvg() { } async function rasterize(page, svg, size) { - const base64 = await page.evaluate( + const { png, rgba } = await page.evaluate( async ({ svg, size }) => { const image = new Image(); image.src = "data:image/svg+xml;base64," + btoa(svg); @@ -47,11 +50,62 @@ async function rasterize(page, svg, size) { const context = canvas.getContext("2d"); context.imageSmoothingQuality = "high"; context.drawImage(image, 0, 0, size, size); - return canvas.toDataURL("image/png").split(",")[1]; + return { + png: canvas.toDataURL("image/png").split(",")[1], + rgba: Array.from(context.getImageData(0, 0, size, size).data), + }; }, { svg, size }, ); - return Buffer.from(base64, "base64"); + return { png: Buffer.from(png, "base64"), rgba: Buffer.from(rgba) }; +} + +// One 32-bit bottom-up DIB, the icon format Windows reads without a PNG decoder. The height in the header is twice the +// icon's because the AND mask that follows counts too; the mask is fully transparent (the alpha channel already says +// which pixels show). +function bmpEntry(size, rgba) { + const header = Buffer.alloc(40); + header.writeUInt32LE(40, 0); + header.writeInt32LE(size, 4); + header.writeInt32LE(size * 2, 8); + header.writeUInt16LE(1, 12); + header.writeUInt16LE(32, 14); + header.writeUInt32LE(size * size * 4, 20); + const pixels = Buffer.alloc(size * size * 4); + for (let y = 0; y < size; y += 1) { + for (let x = 0; x < size; x += 1) { + const source = (y * size + x) * 4; + const target = ((size - 1 - y) * size + x) * 4; + pixels[target] = rgba[source + 2]; + pixels[target + 1] = rgba[source + 1]; + pixels[target + 2] = rgba[source]; + pixels[target + 3] = rgba[source + 3]; + } + } + const maskStride = ((size + 31) >> 5) * 4; + return Buffer.concat([header, pixels, Buffer.alloc(maskStride * size)]); +} + +// A Windows .ico: a directory of images at the sizes Explorer, the taskbar and Alt+Tab ask for. PNG compresses the +// 256 px entry (Vista and later read it); the smaller ones stay plain DIBs, the format every Windows version reads. +function ico(entries) { + const header = Buffer.alloc(6); + header.writeUInt16LE(0, 0); + header.writeUInt16LE(1, 2); + header.writeUInt16LE(entries.length, 4); + const directory = Buffer.alloc(16 * entries.length); + let offset = header.length + directory.length; + entries.forEach(({ size, data }, index) => { + const entry = index * 16; + directory.writeUInt8(size === 256 ? 0 : size, entry); + directory.writeUInt8(size === 256 ? 0 : size, entry + 1); + directory.writeUInt16LE(1, entry + 4); + directory.writeUInt16LE(32, entry + 6); + directory.writeUInt32LE(data.length, entry + 8); + directory.writeUInt32LE(offset, entry + 12); + offset += data.length; + }); + return Buffer.concat([header, directory, ...entries.map(({ data }) => data)]); } async function main() { @@ -60,15 +114,21 @@ async function main() { try { const page = await browser.newPage(); const mark = await rasterize(page, markSvg, MARK_PNG); - fs.writeFileSync(path.join(root, "assets", "halation-mark.png"), mark); - fs.writeFileSync(path.join(root, "assets", "halation-app-icon.png"), await rasterize(page, icon, ICON_PNG)); - fs.writeFileSync(path.join(brand, "halation-mark-source.png"), mark); + fs.writeFileSync(path.join(root, "assets", "halation-mark.png"), mark.png); + fs.writeFileSync(path.join(root, "assets", "halation-app-icon.png"), (await rasterize(page, icon, ICON_PNG)).png); + const entries = []; + for (const size of ICO_SIZES) { + const image = await rasterize(page, icon, size); + entries.push({ size, data: size === 256 ? image.png : bmpEntry(size, image.rgba) }); + } + fs.writeFileSync(path.join(root, "assets", "halation-app-icon.ico"), ico(entries)); + fs.writeFileSync(path.join(brand, "halation-mark-source.png"), mark.png); fs.writeFileSync(path.join(brand, "halation-mark.svg"), markSvg); fs.writeFileSync(path.join(brand, "halation-app-icon.svg"), icon); } finally { await browser.close(); } - console.log("wrote assets/halation-mark.png, assets/halation-app-icon.png and docs/media/brand/"); + console.log("wrote assets/halation-mark.png, assets/halation-app-icon.png, assets/halation-app-icon.ico and docs/media/brand/"); } main().catch((error) => {