diff --git a/app/src/i18n.ts b/app/src/i18n.ts index 6d2b895..06fb6ad 100644 --- a/app/src/i18n.ts +++ b/app/src/i18n.ts @@ -175,11 +175,16 @@ const ES = { appTheme: "Tema", appLanguage: "Idioma", appPicker: "Selector", + pickerLook: "Estilo", pickerClassic: "Clásico", pickerSheet: "Mosaico", pickerCompact: "Compacto", pickerBear: "LinkBear", pickerPreview: "Vista previa", + appPickerPosition: "Dónde aparece", + appPickerPositionNote: "En la pantalla donde está el puntero", + pickerByPointer: "Junto al puntero", + pickerCentered: "Al centro", themeAuto: "Automático", themeLight: "Claro", themeDark: "Oscuro", @@ -514,11 +519,16 @@ const EN: Record = { appTheme: "Theme", appLanguage: "Language", appPicker: "Picker", + pickerLook: "Look", pickerClassic: "Classic", pickerSheet: "Tiles", pickerCompact: "Compact", pickerBear: "LinkBear", pickerPreview: "Preview", + appPickerPosition: "Where it opens", + appPickerPositionNote: "On the screen the pointer is on", + pickerByPointer: "By the pointer", + pickerCentered: "Centered", themeAuto: "Automatic", themeLight: "Light", themeDark: "Dark", diff --git a/app/src/settings/Application.test.tsx b/app/src/settings/Application.test.tsx index 1a0b2e1..c0794e5 100644 --- a/app/src/settings/Application.test.tsx +++ b/app/src/settings/Application.test.tsx @@ -14,6 +14,7 @@ const PREFS = { shortcut: "Alt+Shift+L" as string | null, notify_on_rule: true, picker_style: "classic" as "bear" | "classic" | "sheet" | "compact", + picker_position: "pointer" as "pointer" | "center", looks_for_updates: true, }; @@ -69,7 +70,7 @@ describe("application settings", () => { it("offers the tiles, and keeps the classic picker marked until they are chosen", async () => { mount(); - const picker = within(await screen.findByRole("group", { name: "Selector" })); + const picker = within(await screen.findByRole("group", { name: "Estilo" })); expect(picker.getByRole("radio", { name: "Clásico" })).toBeChecked(); await userEvent.click(picker.getByRole("radio", { name: "Mosaico" })); expect(invoke).toHaveBeenCalledWith("prefs_set", { @@ -78,9 +79,19 @@ describe("application settings", () => { }); /// Every look is offered, the bear among them, and each can be seen before it is kept. + it("opens the picker by the pointer until the center is chosen", async () => { + mount(); + const where = within(await screen.findByRole("group", { name: "Dónde aparece" })); + expect(where.getByRole("radio", { name: "Junto al puntero" })).toBeChecked(); + await userEvent.click(where.getByRole("radio", { name: "Al centro" })); + expect(invoke).toHaveBeenCalledWith("prefs_set", { + prefs: { ...PREFS, picker_position: "center" }, + }); + }); + it("offers the four looks and shows the picker over a sample link", async () => { mount(); - const picker = within(await screen.findByRole("group", { name: "Selector" })); + const picker = within(await screen.findByRole("group", { name: "Estilo" })); for (const look of ["LinkBear", "Clásico", "Mosaico", "Compacto"]) { expect(picker.getByRole("radio", { name: look })).toBeInTheDocument(); } @@ -91,7 +102,7 @@ describe("application settings", () => { /// Once a preview is up, choosing another look redraws it rather than leaving the old one open. it("redraws the preview when another look is chosen", async () => { mount(); - const picker = within(await screen.findByRole("group", { name: "Selector" })); + const picker = within(await screen.findByRole("group", { name: "Estilo" })); await userEvent.click(picker.getByRole("radio", { name: "Mosaico" })); expect(invoke.mock.calls.filter(([cmd]) => cmd === "picker_preview")).toHaveLength(0); diff --git a/app/src/settings/Application.tsx b/app/src/settings/Application.tsx index 009cd9f..3f486cf 100644 --- a/app/src/settings/Application.tsx +++ b/app/src/settings/Application.tsx @@ -8,6 +8,7 @@ import { Card, Line, Section, Switch } from "./parts"; type Theme = "system" | "light" | "dark"; type Locale = "system" | "spanish" | "english"; type PickerStyle = "bear" | "classic" | "sheet" | "compact"; +type PickerPosition = "pointer" | "center"; type Preferences = { schema_version: number; @@ -16,6 +17,7 @@ type Preferences = { shortcut: string | null; notify_on_rule: boolean; picker_style: PickerStyle; + picker_position: PickerPosition; looks_for_updates: boolean; }; @@ -40,6 +42,11 @@ const PICKERS: { id: PickerStyle; label: Key }[] = [ { id: "compact", label: "pickerCompact" }, ]; +const POSITIONS: { id: PickerPosition; label: Key }[] = [ + { id: "pointer", label: "pickerByPointer" }, + { id: "center", label: "pickerCentered" }, +]; + const MODIFIERS = new Set(["Control", "Alt", "Shift", "Meta"]); const RESIDENT_ANSWERS_WITHIN = 1400; @@ -179,12 +186,17 @@ export default function Application({ onPick={(locale) => apply({ locale })} /> - + + + +
+ +
apply({ picker_style }, previewing ? preview : undefined)} />
+ + + apply({ picker_position }, previewing ? preview : undefined) + } + /> +
diff --git a/crates/linkunbound-core/src/i18n.rs b/crates/linkunbound-core/src/i18n.rs index fc04d7e..a8499dd 100644 --- a/crates/linkunbound-core/src/i18n.rs +++ b/crates/linkunbound-core/src/i18n.rs @@ -28,6 +28,7 @@ catalogue! { picker_remember: "Recordar esta elección" | "Remember this choice", picker_private: "Privada" | "Private", picker_copy: "Copiar la dirección" | "Copy the address", + picker_close: "Cerrar" | "Close", picker_ask: "¿Dónde abro este enlace?" | "Where should this link open?", picker_ask_private: "¿Dónde lo abro en privado?" | "Where should it open privately?", picker_private_line: "Se abrirá en una ventana privada" | "It will open in a private window", diff --git a/crates/linkunbound-core/src/lib.rs b/crates/linkunbound-core/src/lib.rs index a7bf911..aae96fc 100644 --- a/crates/linkunbound-core/src/lib.rs +++ b/crates/linkunbound-core/src/lib.rs @@ -37,7 +37,7 @@ pub use icons::{cached_icon, prune as prune_icons}; pub use journal::{JOURNAL, journal, note, scrubbed}; pub use launch::{LaunchError, open as launch, spawn_and_forget}; pub use news::{behind as news_behind, untold as untold_news}; -pub use prefs::{Locale, PickerStyle, Preferences, Theme}; +pub use prefs::{Locale, PickerPosition, PickerStyle, Preferences, Theme}; pub use private::private_flag_for; pub use report::{diagnostics, redact}; pub use rule::{ diff --git a/crates/linkunbound-core/src/prefs.rs b/crates/linkunbound-core/src/prefs.rs index 27d41d5..d183622 100644 --- a/crates/linkunbound-core/src/prefs.rs +++ b/crates/linkunbound-core/src/prefs.rs @@ -30,6 +30,14 @@ pub enum PickerStyle { Bear, } +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)] +#[serde(rename_all = "snake_case")] +pub enum PickerPosition { + #[default] + Pointer, + Center, +} + #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Preferences { #[serde(default)] @@ -49,6 +57,8 @@ pub struct Preferences { pub edge_warning_dismissed: bool, #[serde(default)] pub picker_style: PickerStyle, + #[serde(default)] + pub picker_position: PickerPosition, /// Whether the resident asks about releases on its own, every few hours; off, only the /// settings window ever asks, and only while it is open. #[serde(default = "yes")] @@ -82,6 +92,7 @@ impl Default for Preferences { notify_on_rule: true, edge_warning_dismissed: false, picker_style: PickerStyle::default(), + picker_position: PickerPosition::default(), looks_for_updates: true, here_since: None, asked_for_a_star: false, @@ -163,7 +174,7 @@ fn shortcut_of(said: &str) -> Option { #[cfg(test)] mod tests { - use super::{Locale, PickerStyle, Preferences, Theme}; + use super::{Locale, PickerPosition, PickerStyle, Preferences, Theme}; #[test] fn a_fresh_install_follows_the_system_and_claims_the_default_shortcut() { @@ -282,6 +293,21 @@ mod tests { assert!(written.contains(r#""picker_style":"sheet""#), "{written}"); } + #[test] + fn the_picker_opens_by_the_pointer_unless_the_center_was_asked_for() { + let fresh: Preferences = serde_json::from_str("{}").unwrap(); + assert_eq!(fresh.picker_position, PickerPosition::Pointer); + + let asked: Preferences = serde_json::from_str(r#"{"picker_position": "center"}"#).unwrap(); + assert_eq!(asked.picker_position, PickerPosition::Center); + + let written = serde_json::to_string(&asked).unwrap(); + assert!( + written.contains(r#""picker_position":"center""#), + "{written}" + ); + } + /// Everybody moves to the bear once; after that, what they pick stays picked. #[test] fn the_bear_comes_once_and_a_later_choice_stands() { diff --git a/crates/linkunbound-shell/build.rs b/crates/linkunbound-shell/build.rs index fb67088..18e816b 100644 --- a/crates/linkunbound-shell/build.rs +++ b/crates/linkunbound-shell/build.rs @@ -1,5 +1,11 @@ fn main() { - slint_build::compile("ui/shell.slint").expect("the interface must compile"); + // Tests find the picker's buttons by id; a release build carries no ids it would never use. + let debug = std::env::var("PROFILE").as_deref() == Ok("debug"); + slint_build::compile_with_config( + "ui/shell.slint", + slint_build::CompilerConfiguration::new().with_debug_info(debug), + ) + .expect("the interface must compile"); #[cfg(windows)] if std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("windows") { diff --git a/crates/linkunbound-shell/src/lib.rs b/crates/linkunbound-shell/src/lib.rs index 083ace0..df44d41 100644 --- a/crates/linkunbound-shell/src/lib.rs +++ b/crates/linkunbound-shell/src/lib.rs @@ -419,6 +419,7 @@ pub fn dress(window: &Picker, words: &Strings, url: &str, source: Option<&str>, window.set_chosen_at(-1); window.set_preview(false); window.set_copy_label(words.picker_copy.into()); + window.set_close_label(words.picker_close.into()); window.set_update_later(words.update_later.into()); window.set_private_on(false); // Pinned for a link, not for the day: left set, every later picker opened privately. diff --git a/crates/linkunbound-shell/src/look.rs b/crates/linkunbound-shell/src/look.rs index d67054e..7f79f04 100644 --- a/crates/linkunbound-shell/src/look.rs +++ b/crates/linkunbound-shell/src/look.rs @@ -1,9 +1,14 @@ //! How the picker is drawn: which look, and the material behind it where the system lends one. -use linkunbound_core::PickerStyle; +use linkunbound_core::{PickerPosition, PickerStyle, Preferences}; use linkunbound_shell::{CLASSIC_CORNER, CORNER, HALO, Look, Palette, Picker, place}; use slint::ComponentHandle; +pub fn obey(picker: &Picker, prefs: &Preferences) { + style(picker, prefs.picker_style); + picker.set_centered(prefs.picker_position == PickerPosition::Center); +} + pub fn style(picker: &Picker, chosen: PickerStyle) { picker.set_look(match chosen { PickerStyle::Classic => Look::List, @@ -98,26 +103,26 @@ pub fn dress_the_window(picker: &Picker) { }; crate::host::keep_off_the_taskbar(handle, corner_of(picker)); if wear_backdrop(picker, handle) { - beside_the_pointer(picker); + put_in_place(picker); } follow(picker); crate::host::take_the_keyboard(handle); } -/// The picker belongs to the click that summoned it, not to the middle of a screen. -pub fn beside_the_pointer(picker: &Picker) { +/// Centered or not, the picker opens on the pointer's screen, the one the person is looking at. +pub fn put_in_place(picker: &Picker) { let Some(pointer) = crate::host::cursor() else { return; }; let Some(area) = crate::host::work_area_at(pointer.0, pointer.1) else { return; }; - place_near(picker, pointer, area); + place_for(picker, pointer, area); } /// Where the picker goes for a pointer and the screen area around it, in the units the window is /// placed in. Returns the corner it was put at. -fn place_near( +fn place_for( picker: &Picker, (cx, cy): (i32, i32), (x, y, width, height): (i32, i32, i32, i32), @@ -130,20 +135,22 @@ fn place_near( let size = |logical: f32| crate::physical(logical, scale); let halo = size(picker.get_halo()); - let (at_x, at_y) = place::beside( - (cx, cy), - ( - size(picker.get_wanted_width()), - size(picker.get_wanted_height()), - ), - // The bear rises over the sheet, so the screen it may use starts that much lower. - place::Bounds { - x, - y: y + size(crate::mascot::rise(picker)), - width, - height: height - size(crate::mascot::rise(picker)), - }, + let window = ( + size(picker.get_wanted_width()), + size(picker.get_wanted_height()), ); + // The bear rises over the sheet, so the screen it may use starts that much lower. + let screen = place::Bounds { + x, + y: y + size(crate::mascot::rise(picker)), + width, + height: height - size(crate::mascot::rise(picker)), + }; + let (at_x, at_y) = if picker.get_centered() { + place::centered((window.0 - 2 * halo, window.1 - 2 * halo), screen) + } else { + place::beside((cx, cy), window, screen) + }; // The margin holds the shadow, not the sheet: the sheet's edge is what sits by the pointer, // and the transparent rim may hang past the screen without anyone seeing it. let (at_x, at_y) = (at_x - halo, at_y - halo); @@ -285,7 +292,7 @@ fn wear_glass(_window: isize, _dark: bool, _corner: f64) -> bool { #[cfg(test)] mod tests { - use super::{corner_of, dress_for, native_glass, place_near, style, wear_backdrop}; + use super::{corner_of, dress_for, native_glass, place_for, style, wear_backdrop}; use linkunbound_core::PickerStyle; use linkunbound_shell::{CLASSIC_CORNER, CORNER, HALO, Palette, Picker}; use slint::ComponentHandle; @@ -327,13 +334,13 @@ mod tests { style(&picker, PickerStyle::Classic); dress_for(&picker, false); - let (_, list_y) = place_near(&picker, near_the_top, screen); + let (_, list_y) = place_for(&picker, near_the_top, screen); style(&picker, PickerStyle::Bear); dress_for(&picker, false); picker.set_halo(0.0); - let (_, bear_y) = place_near(&picker, near_the_top, screen); + let (_, bear_y) = place_for(&picker, near_the_top, screen); let rise = crate::mascot::rise(&picker); assert!( f64::from(bear_y) >= f64::from(rise) * f64::from(picker.window().scale_factor()) - 1.0, @@ -342,6 +349,72 @@ mod tests { assert!(bear_y > list_y, "the list needs no room above it"); } + fn click(picker: &Picker, at: slint::LogicalPosition) { + use slint::platform::{PointerEventButton, WindowEvent}; + let window = picker.window(); + window.dispatch_event(WindowEvent::PointerMoved { position: at }); + let button = PointerEventButton::Left; + window.dispatch_event(WindowEvent::PointerPressed { + position: at, + button, + }); + window.dispatch_event(WindowEvent::PointerReleased { + position: at, + button, + }); + } + + #[test] + fn the_close_button_dismisses_the_picker_in_every_look() { + let picker = picker(); + picker.show().expect("shown"); + let closed = std::rc::Rc::new(std::cell::Cell::new(0)); + let counted = closed.clone(); + picker.on_dismissed(move || counted.set(counted.get() + 1)); + let looks = [ + PickerStyle::Classic, + PickerStyle::Sheet, + PickerStyle::Compact, + PickerStyle::Bear, + ]; + + for chosen in looks { + style(&picker, chosen); + let found: Vec<_> = i_slint_backend_testing::ElementHandle::find_by_element_id( + &picker, + "CloseMark::touch", + ) + .collect(); + assert_eq!(found.len(), 1, "{chosen:?}"); + let (at, size) = (found[0].absolute_position(), found[0].size()); + click( + &picker, + slint::LogicalPosition::new(at.x + size.width / 2.0, at.y + size.height / 2.0), + ); + } + assert_eq!(closed.get(), looks.len()); + } + + #[test] + fn a_centered_picker_ignores_the_pointer_and_centres_the_sheet() { + let picker = picker(); + let screen = (0, 0, 1920, 1080); + style(&picker, PickerStyle::Sheet); + dress_for(&picker, true); + picker.set_halo(HALO); + picker.set_centered(true); + + let scale = f64::from(picker.window().scale_factor()); + let size = |logical: f32| crate::physical(logical, scale); + let halo = size(picker.get_halo()); + let sheet = size(picker.get_wanted_width()) - 2 * halo; + + let one = place_for(&picker, (10, 10), screen); + let other = place_for(&picker, (1900, 1000), screen); + assert_eq!(one, other); + assert!(((one.0 + halo) - (1920 - sheet) / 2).abs() <= 1, "{one:?}"); + } + /// A window the system will not dress gets the painted sheet back, and the tiles their /// shadow, which changes the size the window has to be placed at. #[test] diff --git a/crates/linkunbound-shell/src/main.rs b/crates/linkunbound-shell/src/main.rs index 6c04332..9ea3c8c 100644 --- a/crates/linkunbound-shell/src/main.rs +++ b/crates/linkunbound-shell/src/main.rs @@ -467,7 +467,7 @@ fn present(picker: &Picker, words: &Strings, shown: &Rc>, arrival held.rows = listed; held.source = source; } - look::beside_the_pointer(picker); + look::put_in_place(picker); let _ = picker.show(); look::dress_the_window(picker); return true; @@ -482,7 +482,7 @@ fn present(picker: &Picker, words: &Strings, shown: &Rc>, arrival if let Some(ui) = ui() { ui.refresh_strip(); } - look::beside_the_pointer(picker); + look::put_in_place(picker); let asked_at = physical_icon_side(picker); let _ = picker.show(); if let Some(ui) = ui() { @@ -494,7 +494,7 @@ fn present(picker: &Picker, words: &Strings, shown: &Rc>, arrival // asked for at the wrong side. let drawn_at = physical_icon_side(picker); if drawn_at != asked_at { - look::beside_the_pointer(picker); + look::put_in_place(picker); let redrawn = rows(drawn_at); let held = shown.borrow(); if let Some(url) = held.url.as_deref() { @@ -786,7 +786,7 @@ impl Ui { let light = wants_light(prefs.theme); self.light_seen.set(light); paint(&self.picker, &self.notice, light); - look::style(&self.picker, prefs.picker_style); + look::obey(&self.picker, prefs); if let Some(tray) = self.tray.as_ref() { tray.show(true); tray.relabel(&self.words.get()); diff --git a/crates/linkunbound-shell/src/place.rs b/crates/linkunbound-shell/src/place.rs index 89d6aaf..e393a7c 100644 --- a/crates/linkunbound-shell/src/place.rs +++ b/crates/linkunbound-shell/src/place.rs @@ -24,6 +24,23 @@ pub fn beside(cursor: (i32, i32), window: (i32, i32), screen: Bounds) -> (i32, i y = cy - h - OFFSET; } + inside((x, y), window, screen) +} + +#[must_use] +pub fn centered(window: (i32, i32), screen: Bounds) -> (i32, i32) { + let (w, h) = window; + inside( + ( + screen.x + (screen.width - w) / 2, + screen.y + (screen.height - h) / 2, + ), + window, + screen, + ) +} + +fn inside((x, y): (i32, i32), (w, h): (i32, i32), screen: Bounds) -> (i32, i32) { let max_x = (screen.x + screen.width - w).max(screen.x); let max_y = (screen.y + screen.height - h).max(screen.y); (x.clamp(screen.x, max_x), y.clamp(screen.y, max_y)) @@ -114,5 +131,22 @@ mod tests { }; let (x, y) = beside((150, 100), WINDOW, tiny); assert_eq!((x, y), (0, 0)); + assert_eq!(centered(WINDOW, tiny), (0, 0)); + } + + #[test] + fn centered_it_sits_in_the_middle_of_the_work_area() { + assert_eq!(centered(WINDOW, SCREEN), (778, 390)); + } + + #[test] + fn centered_on_another_monitor_it_stays_on_that_monitor() { + let left = Bounds { + x: -1920, + y: 0, + width: 1920, + height: 1040, + }; + assert_eq!(centered(WINDOW, left), (-1142, 370)); } } diff --git a/crates/linkunbound-shell/ui/looks.slint b/crates/linkunbound-shell/ui/looks.slint index 2e93685..f8b552e 100644 --- a/crates/linkunbound-shell/ui/looks.slint +++ b/crates/linkunbound-shell/ui/looks.slint @@ -269,6 +269,7 @@ export component CompactLook inherits Rectangle { in property private-label; in property copied; in property copy-label; + in property close-label; in property remember-label; in property reach-said; in property reach-keeps; @@ -276,6 +277,7 @@ export component CompactLook inherits Rectangle { callback hovered(int); callback toggle-private(); callback copy(); + callback close(); callback turn-reach(); property aimed: root.hovered-at >= 0 ? root.hovered-at : root.chosen-at; @@ -312,8 +314,10 @@ export component CompactLook inherits Rectangle { private-label: root.private-label; copied: root.copied; copy-label: root.copy-label; + close-label: root.close-label; toggle-private => { root.toggle-private(); } copy => { root.copy(); } + close => { root.close(); } } } HorizontalLayout { diff --git a/crates/linkunbound-shell/ui/parts.slint b/crates/linkunbound-shell/ui/parts.slint index a40035f..a5f4b3b 100644 --- a/crates/linkunbound-shell/ui/parts.slint +++ b/crates/linkunbound-shell/ui/parts.slint @@ -330,13 +330,47 @@ export component MaskButton inherits Rectangle { } } +export component CloseMark inherits Rectangle { + in property label; + callback pressed(); + + accessible-role: button; + accessible-label: root.label; + accessible-action-default => { root.pressed(); } + width: 28px; + height: 28px; + border-radius: 6px; + background: touch.has-hover ? Palette.hover : transparent; + Path { + x: 9px; + y: 9px; + width: 10px; + height: 10px; + viewbox-width: 10; + viewbox-height: 10; + commands: "M1 1 L9 9 M9 1 L1 9"; + stroke: touch.has-hover ? Palette.ink : Palette.faint; + stroke-width: 1.5px; + } + touch := TouchArea { + clicked => { root.pressed(); } + } +} + +export global Measures { + out property tools-width: 3 * 28px + 9px + 3 * 2px; +} + export component Tools inherits HorizontalLayout { + width: Measures.tools-width; in property private-on; in property private-label; in property copied; in property copy-label; + in property close-label; callback toggle-private(); callback copy(); + callback close(); spacing: 2px; MaskButton { on: root.private-on; @@ -348,6 +382,20 @@ export component Tools inherits HorizontalLayout { done: root.copied; pressed => { root.copy(); } } + Rectangle { + width: 9px; + Rectangle { + x: 4px; + y: (parent.height - self.height) / 2; + width: 1px; + height: 16px; + background: Palette.hair; + } + } + CloseMark { + label: root.close-label; + pressed => { root.close(); } + } } // The address and, under it, where it came from, what is wrong, or that it opens privately. @@ -360,8 +408,10 @@ export component AddressHead inherits Rectangle { in property private-label; in property copied; in property copy-label; + in property close-label; callback toggle-private(); callback copy(); + callback close(); height: 60px; HorizontalLayout { @@ -402,8 +452,10 @@ export component AddressHead inherits Rectangle { private-label: root.private-label; copied: root.copied; copy-label: root.copy-label; + close-label: root.close-label; toggle-private => { root.toggle-private(); } copy => { root.copy(); } + close => { root.close(); } } } } @@ -419,23 +471,31 @@ export component AskHead inherits Rectangle { in property private-label; in property copied; in property copy-label; + in property close-label; callback toggle-private(); callback copy(); + callback close(); height: 80px; + in property ask-margin: 72px; VerticalLayout { - padding-top: 20px; + padding-top: 18px; padding-left: 72px; padding-right: 72px; spacing: 3px; alignment: start; - Text { - text: root.ask; - font-size: 17px; - font-weight: 700; - color: root.private-on ? Palette.secret : Palette.ink; - horizontal-alignment: center; - overflow: elide; + HorizontalLayout { + padding-left: root.ask-margin - 72px; + padding-right: root.ask-margin - 72px; + padding-bottom: 2px; + Text { + text: root.ask; + font-size: 17px; + font-weight: 700; + color: root.private-on ? Palette.secret : Palette.ink; + horizontal-alignment: center; + overflow: elide; + } } HorizontalLayout { alignment: center; @@ -463,15 +523,16 @@ export component AskHead inherits Rectangle { } Tools { x: root.width - 8px - self.width; - y: 16px; - width: 58px; + y: 14px; height: 28px; private-on: root.private-on; private-label: root.private-label; copied: root.copied; copy-label: root.copy-label; + close-label: root.close-label; toggle-private => { root.toggle-private(); } copy => { root.copy(); } + close => { root.close(); } } } diff --git a/crates/linkunbound-shell/ui/shell.slint b/crates/linkunbound-shell/ui/shell.slint index 5afb082..f8df447 100644 --- a/crates/linkunbound-shell/ui/shell.slint +++ b/crates/linkunbound-shell/ui/shell.slint @@ -1,4 +1,4 @@ -import { Destination, Reach, Palette, Look, UpdateStrip, Hair, AddressHead, AskHead, RememberFoot, ReachMenu } from "parts.slint"; +import { Destination, Reach, Palette, Look, UpdateStrip, Hair, AddressHead, AskHead, RememberFoot, ReachMenu, Measures } from "parts.slint"; import { ListLook, CardsLook, CompactLook } from "looks.slint"; export { Palette, Look } from "parts.slint"; @@ -37,6 +37,7 @@ export component Picker inherits Window { in property look: Look.bear; in property on-mac: false; + in property centered: false; // Room around the sheet for the shadow it draws itself. Zero where the system draws one. in property halo: 0px; @@ -55,6 +56,7 @@ export component Picker inherits Window { in property update-button; in property update-later; in property copy-label; + in property close-label; in property update-far: 0; property update-shown: root.update-stage != ""; property update-busy: root.update-stage == "starting" || root.update-stage == "getting" || root.update-stage == "installing"; @@ -114,17 +116,35 @@ export component Picker inherits Window { visible: false; } + property ask-margin: max(72px, Measures.tools-width + 8px); + // Rounding at fractional scales can shave the exact width and elide the last letter. + property ask-slack: 4px; + property ask-need: max(ask-ruler.preferred-width, ask-private-ruler.preferred-width) + root.ask-slack + 2 * root.ask-margin; + ask-ruler := Text { + text: root.ask; + font-size: 17px; + font-weight: 700; + visible: false; + } + ask-private-ruler := Text { + text: root.ask-private; + font-size: 17px; + font-weight: 700; + visible: false; + } + // Three columns of cards; four rows on screen and the rest scroll. property cards-room: min(4, max(1, Math.ceil(root.count / 3))) * 58px + 10px; property icons-shown: max(1, root.count); - property compact-width: max(280px, root.icons-shown * 54px - 4px + 20px); + property compact-address-room: 196px; + property compact-width: max(root.compact-address-room + Measures.tools-width + 2 * 10px + 6px, root.icons-shown * 54px - 4px + 20px); property compact-height: 12px + 28px + 6px + 72px + 6px + 20px + 6px + 26px + 10px; property foot-room: 74px; property sheet-width: root.look == Look.list ? root.list-width - : root.cards ? max(500px, root.list-width) + : root.cards ? max(500px, root.list-width, root.ask-need) : root.compact-width; property head-room: root.cards ? 80px : 60px; property body-room: @@ -283,6 +303,7 @@ export component Picker inherits Window { private-label: root.private-label; copied: root.copied; copy-label: root.copy-label; + close-label: root.close-label; remember-label: root.remember-short; reach-said: root.reach-said; reach-keeps: root.all-reaches[root.reach-index].keeps; @@ -290,6 +311,7 @@ export component Picker inherits Window { hovered(i) => { root.hovered-at = i; } toggle-private => { root.toggle-private(); } copy => { root.copy(); } + close => { root.dismissed(); } turn-reach => { root.reach-index = root.step-reach(1); } } @@ -297,6 +319,7 @@ export component Picker inherits Window { y: root.strip-room; height: parent.height - root.strip-room; if root.cards: AskHead { + ask-margin: root.ask-margin; ask: root.private-on ? root.ask-private : root.ask; host: root.host; trail: root.trail; @@ -306,8 +329,10 @@ export component Picker inherits Window { private-label: root.private-label; copied: root.copied; copy-label: root.copy-label; + close-label: root.close-label; toggle-private => { root.toggle-private(); } copy => { root.copy(); } + close => { root.dismissed(); } } if !root.cards: AddressHead { host: root.host; @@ -318,8 +343,10 @@ export component Picker inherits Window { private-label: root.private-label; copied: root.copied; copy-label: root.copy-label; + close-label: root.close-label; toggle-private => { root.toggle-private(); } copy => { root.copy(); } + close => { root.dismissed(); } } Hair {} if root.cards: CardsLook {