// sf-ui: the SmartFox TV UI kit for Slint (guide: docs/sf-ui.md). // // import { TvWindow, Tv, SfText, GlassRect, GlassPane, GlassButton } from "@sf-ui/sf-ui.slint"; // // Two layers make up the screen: // 1. the glass layer (Rust, OpenGL): the backdrop (gradient, picture or // video) and every glass pane, drawn first; // 2. Slint: text, icons and pictures, drawn on top. // So Slint never draws the glass itself. Each glass component here exposes // `out property glass` (its window position, size and look); // your root component lists them in exported `[GlassRect]` arrays, and Rust // hands those to the glass layer every frame. Nothing Slint draws may sit // *under* a glass pane: the pane would cover it. // // Sizes are design pixels on a 1920x1080 grid times `Tv.u` (TvWindow keeps // `Tv.u` up to date), so the UI scales with the screen. import "fonts/Onest-Regular.ttf"; import "fonts/Onest-Medium.ttf"; import "fonts/Onest-SemiBold.ttf"; import "fonts/Onest-Bold.ttf"; // One glass panel, in window coordinates (logical px). export struct GlassRect { x: length, y: length, w: length, h: length, // Corner radius. r: length, // 0..1: light from within, brighter rim, accent glow. focus: float, // 0..1: fade in/out (the glass "materializes": lensing ramps with it). alpha: float, // Frost (blur of the backdrop seen through it): ~1.2 small controls, // 2-4 big panes. Negative: nested glass that sits on another pane. blur: float, // Accent light colour (a solid colour). glow: brush, // Tint colour (solid); its alpha is the amount (0 = clear glass). tint: brush, // Consecutive rects with the same group (> 0) melt together like liquid. group: int, } // Design tokens. All lengths: design px * Tv.u. export global Tv { // One design pixel (1920x1080 grid) in logical px. Set by TvWindow. in-out property u: 1px; // Text and focus (DESIGN.md, Fennec OS). out property text: #ffffff; out property text-secondary: #ffffffb8; out property text-tertiary: #ffffff8f; // Text and icons on a focused (white) platter. out property ink: #121317; out property platter: #ffffffe0; // Dark tint of grouping glass (use with alpha 0.30-0.48). out property smoke: #0b0c12; out property hairline: #ffffff1f; out property night: #050506; // System accent (system actions only) and states: glass tone + ink tone. out property orange: #ff7a35; out property orange-ink: #ff9a5c; out property ok: #34c759; out property ok-ink: #5ee07a; out property warn: #ff9f0a; out property warn-ink: #ffb340; out property danger: #ff453a; out property danger-ink: #ff8278; // Safe area: keep content this far from the screen edges. out property safe-x: 96 * self.u; out property safe-y: 64 * self.u; } // String helpers Slint lacks; wired to Rust by `sf_ui::glue!(App)` and // `ui.sf_ui_setup()`. Export it from your main .slint file. export global SfText { // The text without its last character. pure callback drop-last(string) -> string; // n bullets (a masked password). pure callback dots(int) -> string; // The first n characters. pure callback truncate(string, int) -> string; // Only the typable characters of a key event's text (no arrows, Return...). pure callback typable(string) -> string; } // Base window for TV apps: night background (under the glass layer), the // Onest font, and `Tv.u` kept in sync with the window size. export component TvWindow inherits Window { background: Tv.night; default-font-family: "Onest"; default-font-size: 28 * Tv.u; title: "SmartFox"; preferred-width: 1600px; preferred-height: 900px; init => { Tv.u = min(self.width / 1920, self.height / 1080); } changed width => { Tv.u = min(self.width / 1920, self.height / 1080); } changed height => { Tv.u = min(self.width / 1920, self.height / 1080); } } // ---- type styles (Onest; tracking tightens from 48 px up) ---------------- // The one big name on a screen (96/700). export component Display inherits Text { font-size: 96 * Tv.u; font-weight: 700; letter-spacing: -2 * Tv.u; color: Tv.text; overflow: elide; } // Screen titles (56/700). export component Headline inherits Text { font-size: 56 * Tv.u; font-weight: 700; letter-spacing: -1 * Tv.u; color: Tv.text; overflow: elide; } // Section and page titles (40/700). export component Title inherits Text { font-size: 40 * Tv.u; font-weight: 700; color: Tv.text; overflow: elide; } // Row titles (36/600). export component SectionTitle inherits Text { font-size: 36 * Tv.u; font-weight: 600; color: Tv.text; overflow: elide; } // Descriptions (28/400); wraps. export component Body inherits Text { font-size: 28 * Tv.u; font-weight: 400; color: Tv.text-secondary; wrap: word-wrap; overflow: elide; } // List and menu items (26/600). export component Item inherits Text { font-size: 26 * Tv.u; font-weight: 600; color: Tv.text; overflow: elide; } // Labels, facts (24/500): the smallest text the household must read. export component Label inherits Text { font-size: 24 * Tv.u; font-weight: 500; color: Tv.text-secondary; overflow: elide; } // Hints and details (22/500). export component Caption inherits Text { font-size: 22 * Tv.u; font-weight: 500; color: Tv.text-tertiary; overflow: elide; } // ---- icons ------------------------------------------------------------------ // Line icons on a 32-unit grid. Names: play, pause, back, forward, up, down, // plus, check, close, search, info, rewind, fast-forward, next, previous, // subtitles, audio, list, star, home, film, tv, user, settings, warning, // space, delete, refresh. export component Icon inherits Rectangle { in property name; in property ink: Tv.text; in property size: 32 * Tv.u; width: self.size; height: self.size; property filled: self.name == "play" || self.name == "star"; Path { width: 100%; height: 100%; viewbox-width: 32; viewbox-height: 32; stroke: root.filled ? transparent : root.ink; stroke-width: root.size * (root.name == "pause" ? 3.2 : 2.4) / 32; fill: root.filled ? root.ink : transparent; commands: root.name == "play" ? "M 10 6.5 L 25.5 16 L 10 25.5 Z" : root.name == "pause" ? "M 11 7 L 11 25 M 21 7 L 21 25" : root.name == "back" ? "M 20 6 L 10 16 L 20 26" : root.name == "forward" ? "M 12 6 L 22 16 L 12 26" : root.name == "up" ? "M 6 20 L 16 10 L 26 20" : root.name == "down" ? "M 6 12 L 16 22 L 26 12" : root.name == "plus" ? "M 16 6 L 16 26 M 6 16 L 26 16" : root.name == "check" ? "M 6.5 16.5 L 13 23 L 25.5 9.5" : root.name == "close" ? "M 8 8 L 24 24 M 24 8 L 8 24" : root.name == "search" ? "M 14 5 A 9 9 0 1 1 14 23 A 9 9 0 1 1 14 5 M 20.5 20.5 L 27 27" : root.name == "info" ? "M 16 4 A 12 12 0 1 1 16 28 A 12 12 0 1 1 16 4 M 16 14.5 L 16 22.5 M 16 9.5 L 16 10" : root.name == "rewind" ? "M 15 8 L 7 16 L 15 24 M 25 8 L 17 16 L 25 24" : root.name == "fast-forward" ? "M 7 8 L 15 16 L 7 24 M 17 8 L 25 16 L 17 24" : root.name == "next" ? "M 8 7.5 L 20 16 L 8 24.5 Z M 24.5 8 L 24.5 24" : root.name == "previous" ? "M 24 7.5 L 12 16 L 24 24.5 Z M 7.5 8 L 7.5 24" : root.name == "subtitles" ? "M 5 8 L 27 8 L 27 24 L 5 24 Z M 9 15 L 15 15 M 18 15 L 23 15 M 9 19.5 L 19 19.5" : root.name == "audio" ? "M 5 12.5 L 10 12.5 L 16 7 L 16 25 L 10 19.5 L 5 19.5 Z M 20.5 11.5 A 6 6 0 0 1 20.5 20.5 M 24 8 A 11 11 0 0 1 24 24" : root.name == "list" ? "M 6 9 L 26 9 M 6 16 L 26 16 M 6 23 L 26 23" : root.name == "star" ? "M 16 4 L 19.6 11.6 L 27.8 12.5 L 21.7 18.1 L 23.3 26.2 L 16 22.1 L 8.7 26.2 L 10.3 18.1 L 4.2 12.5 L 12.4 11.6 Z" : root.name == "home" ? "M 5 15 L 16 5.5 L 27 15 M 8.5 12.5 L 8.5 26 L 23.5 26 L 23.5 12.5" : root.name == "film" ? "M 6 6 L 26 6 L 26 26 L 6 26 Z M 11 6 L 11 26 M 21 6 L 21 26 M 6 16 L 11 16 M 21 16 L 26 16" : root.name == "tv" ? "M 4 8 L 28 8 L 28 23 L 4 23 Z M 11 27 L 21 27" : root.name == "user" ? "M 16 5 A 5.5 5.5 0 1 1 16 16 A 5.5 5.5 0 1 1 16 5 M 6 27 A 10 9 0 0 1 26 27" : root.name == "settings" ? "M 6 10 L 26 10 M 6 22 L 26 22 M 12 7 L 12 13 M 20 19 L 20 25" : root.name == "warning" ? "M 16 4.5 L 28.5 26.5 L 3.5 26.5 Z M 16 12.5 L 16 19 M 16 22.5 L 16 23" : root.name == "space" ? "M 6 15 L 6 21 L 26 21 L 26 15" : root.name == "delete" ? "M 11 7 L 28 7 L 28 25 L 11 25 L 3 16 Z M 15 12 L 23 20 M 23 12 L 15 20" : root.name == "refresh" ? "M 25 16 A 9 9 0 1 1 22.4 9.6 M 23 4.5 L 23 10 L 17.5 10" : ""; } } // ---- glass ------------------------------------------------------------------ // A glass pane; put content inside. List `pane.glass` in an exported // [GlassRect] so the glass layer draws it. Content fades by itself: set its // opacity together with `alpha`. export component GlassPane inherits Rectangle { in property radius: 48 * Tv.u; // Big modal panes 3-4, grouping platters ~2.2, small controls ~1.2. in property frost: 3.0; // Smoke at 30-48% for grouping and modal panes; a colour for accents. in property tint: Tv.smoke.with-alpha(0.38); in property glow: #ffffff; // 0..1: light from within and a brighter rim (a focused pane). in property lit: 0; in property alpha: 1; in property group: 0; // Sits on another glass pane (lights what is beneath, no own frost). in property nested: false; out property glass: { x: self.absolute-position.x, y: self.absolute-position.y, w: self.width, h: self.height, r: min(self.radius, min(self.width, self.height) / 2), focus: self.lit, alpha: self.alpha, blur: self.nested ? -1 : self.frost, glow: self.glow, tint: self.tint, group: self.group, }; } // A capsule button. Focus is state you own (`focused`), shown as a white // platter with dark ink and a small lift; `primary` buttons are accent glass. export component GlassButton inherits Rectangle { in property text; in property icon; in property focused; in property primary; in property enabled: true; in property nested; in property accent: Tv.orange; in property alpha: 1; // Height; width follows the content (icon-only buttons are round). in property size: 72 * Tv.u; out property f: self.focused && self.enabled ? 1 : 0; animate f { duration: 240ms; easing: cubic-bezier(0.22, 1, 0.36, 1); } property s: 1 + 0.05 * self.f; property ink: self.primary ? Tv.text : Tv.ink.mix(Tv.text, self.f); height: self.size; min-width: self.size; inner := Rectangle { transform-scale: root.s; opacity: root.alpha * (root.enabled ? 1 : 0.45); HorizontalLayout { padding-left: root.text == "" ? (root.size - 32 * Tv.u) / 2 : (root.icon == "" ? 36 : 28) * Tv.u; padding-right: root.text == "" ? (root.size - 32 * Tv.u) / 2 : 36 * Tv.u; spacing: 12 * Tv.u; alignment: center; if root.icon != "": Icon { y: (parent.height - self.height) / 2; name: root.icon; ink: root.ink; } if root.text != "": Text { vertical-alignment: center; text: root.text; font-size: 26 * Tv.u; font-weight: 600; color: root.ink; } } } out property glass: { x: self.absolute-position.x - self.width * (self.s - 1) / 2, y: self.absolute-position.y - self.height * (self.s - 1) / 2, w: self.width * self.s, h: self.height * self.s, r: self.height * self.s / 2, focus: self.f, alpha: self.alpha * (self.enabled ? 1 : 0.6), blur: self.nested ? -1 : 1.4, glow: self.primary ? self.accent : #ffffff, tint: self.primary ? self.accent.with-alpha(self.enabled ? 0.34 + 0.5 * self.f : 0.1) : #ffffff.with-alpha(0.06 + 0.82 * self.f), group: 0, }; } // A track with a fill (playback position, download...). The track is glass, // the fill is drawn by Slint on top. export component ProgressBar inherits Rectangle { in property value; in property buffered; in property fill: Tv.text; in property alpha: 1; in property nested: true; height: 12 * Tv.u; Rectangle { x: 0; width: parent.width * clamp(root.buffered, 0, 1); border-radius: self.height / 2; background: #ffffff30; opacity: root.alpha; } Rectangle { x: 0; width: max(self.height, parent.width * clamp(root.value, 0, 1)); border-radius: self.height / 2; background: root.fill; opacity: root.value > 0 ? root.alpha : 0; } out property glass: { x: self.absolute-position.x, y: self.absolute-position.y, w: self.width, h: self.height, r: self.height / 2, focus: 0, alpha: self.alpha, blur: self.nested ? -1 : 1.2, glow: #ffffff, tint: #00000038, group: 0, }; } // A spinning arc (loading). export component Spinner inherits Rectangle { in property size: 56 * Tv.u; in property ink: Tv.text; width: self.size; height: self.size; Path { width: 100%; height: 100%; viewbox-width: 32; viewbox-height: 32; commands: "M 16 3 A 13 13 0 1 1 3 16"; stroke: root.ink; stroke-width: root.size * 3 / 32; transform-rotation: mod(animation-tick() / 1ms, 1000) / 1000 * 360deg; } } // Artwork (poster, still, logo) with rounded corners and a focus lift. // Plain Slint, no glass: shadows on imagery are Slint's job. export component ArtworkCard inherits Rectangle { in property image; // Shown while there is no picture. in property placeholder; in property focused; // 0..1 bar along the bottom; negative = none. in property progress: -1; // Small text over the top-left corner ("Új rész"). in property badge; in property radius: 24 * Tv.u; in property lift: 0.08; in property accent: Tv.text; out property f: self.focused ? 1 : 0; animate f { duration: 260ms; easing: cubic-bezier(0.22, 1, 0.36, 1); } Rectangle { transform-scale: 1 + root.lift * root.f; // Shadow and the empty-card tone. Rectangle { border-radius: root.radius; background: #1b1d24; drop-shadow-blur: (14 + 22 * root.f) * Tv.u; drop-shadow-offset-y: (8 + 12 * root.f) * Tv.u; drop-shadow-color: #00000090; } Rectangle { border-radius: root.radius; clip: true; if root.image.width == 0: Text { x: 24 * Tv.u; width: parent.width - 48 * Tv.u; horizontal-alignment: center; vertical-alignment: center; text: root.placeholder; font-size: 26 * Tv.u; font-weight: 600; color: Tv.text-tertiary; wrap: word-wrap; } Image { width: 100%; height: 100%; source: root.image; image-fit: cover; } // Resting cards sit back a little. Rectangle { background: #000000; opacity: 0.22 * (1 - root.f); } if root.progress >= 0: Rectangle { y: parent.height - 8 * Tv.u; height: 8 * Tv.u; background: #00000099; Rectangle { x: 0; width: parent.width * clamp(root.progress, 0, 1); background: root.accent; } } } if root.badge != "": Rectangle { x: 14 * Tv.u; y: 14 * Tv.u; width: badge-text.preferred-width + 24 * Tv.u; height: 36 * Tv.u; border-radius: self.height / 2; background: #000000b0; badge-text := Text { text: root.badge; font-size: 20 * Tv.u; font-weight: 600; color: Tv.text; } } } } // One row of a GlassMenu. export struct MenuItem { text: string, detail: string, checked: bool, } // A list on a smoke glass platter with a white focus pill: track pickers, // option lists. Focus and scrolling follow `focused-index`. // `glass` holds two rects (platter, pill): list both. export component GlassMenu inherits Rectangle { in property <[MenuItem]> items; // The focused row (also where the list scrolls to); -1 = none. in property focused-index: 0; // False: the list keeps its scroll position but shows no focus pill // (another list on screen has the focus). in property active: true; in property title; in property alpha: 1; in property row-h: 72 * Tv.u; in property visible-rows: 7; in property accent: Tv.orange; property pad: 12 * Tv.u; property head: self.title == "" ? 0 : 72 * Tv.u; property shown-rows: min(self.items.length, self.visible-rows); out property pos: self.focused-index; animate pos { duration: 220ms; easing: cubic-bezier(0.22, 1, 0.36, 1); } property first: clamp(self.pos - (self.visible-rows - 1) / 2, 0, max(0, self.items.length - self.visible-rows)); width: 560 * Tv.u; height: self.head + 2 * self.pad + self.shown-rows * self.row-h; if root.title != "": Text { x: 32 * Tv.u; y: root.pad; height: root.head; vertical-alignment: center; text: root.title; font-size: 24 * Tv.u; font-weight: 600; color: Tv.text-secondary; opacity: root.alpha; } Rectangle { x: root.pad; y: root.pad + root.head; width: root.width - 2 * root.pad; height: root.shown-rows * root.row-h; clip: true; for item[i] in root.items: Rectangle { property f: root.active ? max(0, 1 - abs(root.pos - i)) : 0; y: (i - root.first) * root.row-h; height: root.row-h; opacity: root.alpha; HorizontalLayout { padding-left: 24 * Tv.u; padding-right: 24 * Tv.u; spacing: 12 * Tv.u; Rectangle { width: 32 * Tv.u; if item.checked: Icon { y: (parent.height - self.height) / 2; name: "check"; ink: f > 0.5 ? Tv.ink : root.accent.brighter(0.3); } } Text { horizontal-stretch: 1; vertical-alignment: center; text: item.text; font-size: 26 * Tv.u; font-weight: 600; color: Tv.ink.mix(Tv.text, f); overflow: elide; } if item.detail != "": Text { vertical-alignment: center; text: item.detail; font-size: 22 * Tv.u; color: f > 0.5 ? #121317a0 : Tv.text-tertiary; } } } } out property <[GlassRect]> glass: [ { x: self.absolute-position.x, y: self.absolute-position.y, w: self.width, h: self.height, r: 32 * Tv.u, focus: 0.1, alpha: self.alpha, blur: 3.0, glow: #ffffff, tint: Tv.smoke.with-alpha(0.46), group: 0, }, { x: self.absolute-position.x + self.pad, y: self.absolute-position.y + self.pad + self.head + (self.pos - self.first) * self.row-h, w: self.width - 2 * self.pad, h: self.row-h, r: self.row-h / 2, focus: 0.6, alpha: self.items.length > 0 && self.focused-index >= 0 && self.active ? self.alpha : 0, blur: -1, glow: #ffffff, tint: #ffffff.with-alpha(0.86), group: 0, }, ]; } // ---- on-screen keyboard ------------------------------------------------------- // tvOS-style keyboard: a text field, one row of keys with a gliding focus // lens, mode chips. Remote: left/right move, OK types, down = chips, up = // keys, Back = cancel. A real keyboard types directly. // // Pass key events to it while it is open: `kb.key(event)` from your // FocusScope. Its `glass` holds 9 rects: list them all. Needs SfText. // Size: 1920 x 572 design px (432 when `compact`); its width may be smaller. export component Keyboard inherits Rectangle { in property title; in property subtitle; in property placeholder; // Shows dots (with a "Megjelenítés" chip). in property secret; in property submit-label: "Kész"; in property min-length: 0; in property max-length: 64; in property alpha: 1; // False while the focus is elsewhere on the screen (no focus lens). in property active: true; // No title/subtitle: 1920 x 432 design px. in property compact: false; in-out property text; // Shown in red under the field until the text changes ("Hibás jelszó"). in-out property error; callback submitted(string); callback cancelled(); // Up on the key row / down on the chips: the focus wants to leave the // keyboard (e.g. to search results). Ignore them to keep it inside. callback exit-up(); callback exit-down(); in-out property mode: 0; // abc, ABC, 123, #+= in-out property index: 1; in-out property area: 0; // 0 = keys, 1 = chips in-out property chip: 0; in-out property reveal: false; out property <[string]> keys: self.mode == 1 ? ["A", "Á", "B", "C", "D", "E", "É", "F", "G", "H", "I", "Í", "J", "K", "L", "M", "N", "O", "Ó", "Ö", "Ő", "P", "Q", "R", "S", "T", "U", "Ú", "Ü", "Ű", "V", "W", "X", "Y", "Z"] : self.mode == 2 ? ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", ".", ",", "-", "_", "@", "!", "?", "#", "$", "%", "&", "*", ":", "/"] : self.mode == 3 ? ["+", "=", "\\", ";", "'", "\"", "(", ")", "[", "]", "{", "}", "<", ">", "^", "`", "|", "~"] : ["a", "á", "b", "c", "d", "e", "é", "f", "g", "h", "i", "í", "j", "k", "l", "m", "n", "o", "ó", "ö", "ő", "p", "q", "r", "s", "t", "u", "ú", "ü", "ű", "v", "w", "x", "y", "z"]; property n: self.keys.length + 2; out property <[string]> chips: [ "abc", "ABC", ".?123", "#+=", self.secret ? (self.reveal ? "Elrejtés" : "Megjelenítés") : "Törlés", self.submit-label, ]; property len: self.text.character-count; out property can-submit: self.len >= self.min-length; property hint: self.error != "" ? self.error : !self.can-submit && self.len == 0 ? "Legalább \{self.min-length} karakter" : !self.can-submit ? "Még \{self.min-length - self.len} karakter kell" : self.len >= self.max-length ? "Legfeljebb \{self.max-length} karakter" : self.secret ? "\{self.len} karakter" : ""; property shown-text: self.secret && !self.reveal ? SfText.dots(self.len) : self.text; out property pos: self.index; animate pos { duration: 200ms; easing: cubic-bezier(0.22, 1, 0.36, 1); } out property cpos: self.chip; animate cpos { duration: 300ms; easing: cubic-bezier(0.22, 1, 0.36, 1); } out property keys-active: self.active && self.area == 0 ? 1 : 0; animate keys-active { duration: 260ms; easing: ease-out; } out property chips-active: self.active && self.area == 1 ? 1 : 0; animate chips-active { duration: 260ms; easing: ease-out; } // Geometry (local), design px * u. property field-w: 1200 * Tv.u; property field-h: 96 * Tv.u; property field-x: (self.width - self.field-w) / 2; property top: self.compact ? 0 : 140 * Tv.u; property field-y: self.top; property key-w: min(54 * Tv.u, 1640 * Tv.u / self.n); property row-x: (self.width - self.n * self.key-w) / 2; property row-y: self.top + 180 * Tv.u; property row-h: 120 * Tv.u; property chip-w: 200 * Tv.u; property chip-h: 72 * Tv.u; property chip-step: 216 * Tv.u; property chip-x: (self.width - 6 * self.chip-step + 16 * Tv.u) / 2; property chip-y: self.top + 360 * Tv.u; width: 1920 * Tv.u; height: self.top + 432 * Tv.u; // Clears the text and puts the focus back on the first key. public function reset() { root.text = ""; root.error = ""; root.mode = 0; root.index = 1; root.area = 0; root.chip = 0; root.reveal = false; } function type-text(s: string) { if s != "" && root.len < root.max-length { root.text = SfText.truncate(root.text + s, root.max-length); root.error = ""; } } function delete-char() { root.text = SfText.drop-last(root.text); root.error = ""; } function press-key() { if root.index == 0 { root.type-text(" "); } else if root.index >= root.n - 1 { root.delete-char(); } else { root.type-text(root.keys[root.index - 1]); } } function press-chip() { if root.chip < 4 { root.mode = root.chip; root.index = min(root.index, root.keys.length + 1); root.area = 0; } else if root.chip == 4 { if root.secret { root.reveal = !root.reveal; } else { root.text = ""; root.error = ""; } } else if root.can-submit { root.submitted(root.text); } } // Handles one key press; call it from your FocusScope while open. public function key(event: KeyEvent) -> EventResult { if event.text == Key.Escape { root.cancelled(); } else if event.text == Key.Backspace { root.delete-char(); } else if event.text == Key.Return { if root.area == 0 { root.press-key(); } else { root.press-chip(); } } else if event.text == Key.LeftArrow { if root.area == 0 { root.index = root.index <= 0 ? root.n - 1 : root.index - 1; } else { root.chip = max(0, root.chip - 1); } } else if event.text == Key.RightArrow { if root.area == 0 { root.index = root.index >= root.n - 1 ? 0 : root.index + 1; } else { root.chip = min(5, root.chip + 1); } } else if event.text == Key.DownArrow { if root.area == 0 { root.area = 1; root.chip = root.can-submit ? 5 : root.mode; } else { root.exit-down(); } } else if event.text == Key.UpArrow { if root.area == 1 { root.area = 0; } else { root.exit-up(); } } else if !event.modifiers.control && !event.modifiers.alt && !event.modifiers.meta { root.type-text(SfText.typable(event.text)); } accept } // ---- heading ---- Text { y: 0; width: root.width; height: 60 * Tv.u; horizontal-alignment: center; vertical-alignment: center; text: root.title; font-weight: 700; font-size: 48 * Tv.u; letter-spacing: -0.8 * Tv.u; color: Tv.text; opacity: root.compact ? 0 : root.alpha; overflow: elide; } Text { x: 160 * Tv.u; y: 72 * Tv.u; width: root.width - 320 * Tv.u; horizontal-alignment: center; text: root.subtitle; font-size: 24 * Tv.u; color: Tv.text-secondary; opacity: root.compact ? 0 : root.alpha; overflow: elide; } // ---- text field ---- Rectangle { x: root.field-x; y: root.field-y; width: root.field-w; height: root.field-h; clip: true; opacity: root.alpha; HorizontalLayout { padding-left: 36 * Tv.u; padding-right: 36 * Tv.u; alignment: start; spacing: 4 * Tv.u; if root.shown-text == "": Text { vertical-alignment: center; text: root.placeholder; font-size: 32 * Tv.u; color: #ffffff59; } if root.shown-text != "": Text { vertical-alignment: center; text: root.shown-text; font-size: 34 * Tv.u; font-weight: 500; letter-spacing: 1 * Tv.u; color: Tv.text; } Rectangle { width: 3 * Tv.u; Rectangle { y: (parent.height - self.height) / 2; width: 100%; height: 44 * Tv.u; border-radius: self.width / 2; background: Tv.orange-ink; opacity: mod(animation-tick() / 1ms, 1000) < 550 ? 1 : 0; } } } } Text { x: root.field-x; y: root.field-y + root.field-h + 20 * Tv.u; width: root.field-w; horizontal-alignment: center; text: root.hint; font-size: 22 * Tv.u; color: root.error != "" ? Tv.danger-ink : #ffffff99; opacity: root.alpha; } // ---- key row: keys grow as the lens passes them ---- for key[i] in root.keys: Text { property f: max(0, 1 - abs(root.pos - (i + 1))) * root.keys-active; x: root.row-x + (i + 1) * root.key-w - 20 * Tv.u; y: root.row-y; width: root.key-w + 40 * Tv.u; height: root.row-h; horizontal-alignment: center; vertical-alignment: center; text: key; font-size: (31 + 17 * self.f) * Tv.u; font-weight: self.f > 0.5 ? 700 : 500; color: self.f > 0.5 ? Tv.ink : #ffffffd8; opacity: root.alpha; } Icon { property f: max(0, 1 - abs(root.pos)) * root.keys-active; size: (30 + 10 * self.f) * Tv.u; x: root.row-x + (root.key-w - self.size) / 2; y: root.row-y + (root.row-h - self.size) / 2; name: "space"; ink: self.f > 0.5 ? Tv.ink : #ffffffd8; opacity: root.alpha; } Icon { property f: max(0, 1 - abs(root.pos - (root.n - 1))) * root.keys-active; size: (32 + 10 * self.f) * Tv.u; x: root.row-x + (root.n - 1) * root.key-w + (root.key-w - self.size) / 2; y: root.row-y + (root.row-h - self.size) / 2; name: "delete"; ink: self.f > 0.5 ? Tv.ink : #ffffffd8; opacity: root.alpha; } // ---- chips ---- for label[i] in root.chips: Text { property f: max(0, 1 - abs(root.cpos - i)) * root.chips-active; property submit: i == root.chips.length - 1; property selected: i < 4 && i == root.mode; x: root.chip-x + i * root.chip-step; y: root.chip-y; width: root.chip-w; height: root.chip-h; horizontal-alignment: center; vertical-alignment: center; text: label; font-size: 24 * Tv.u; font-weight: self.submit || self.selected ? 700 : 500; color: self.submit ? (root.can-submit ? Tv.text : #ffffff66) : self.f > 0.5 ? Tv.ink : self.selected ? Tv.orange-ink : #ffffffc8; opacity: root.alpha; } // ---- glass ---- property ax: self.absolute-position.x; property ay: self.absolute-position.y; property track-h: self.row-h - 28 * Tv.u; property lens-w: 86 * Tv.u; property lens-h: 112 * Tv.u; pure function chip-rect(i: int) -> GlassRect { let f = max(0, 1 - abs(root.cpos - i)) * root.chips-active; let s = 1 + 0.05 * f; let sel = i < 4 && i == root.mode ? 0.16 : 0; { x: root.ax + root.chip-x + i * root.chip-step - root.chip-w * (s - 1) / 2, y: root.ay + root.chip-y - root.chip-h * (s - 1) / 2, w: root.chip-w * s, h: root.chip-h * s, r: root.chip-h * s / 2, focus: f, alpha: root.alpha, blur: -1, glow: i == 5 ? Tv.orange : #ffffff, tint: i == 5 ? Tv.orange.with-alpha(root.can-submit ? 0.34 + 0.56 * f : 0.08 + 0.2 * f) : #ffffff.with-alpha(0.04 + sel + 0.80 * f), group: 0, } } out property <[GlassRect]> glass: [ { x: root.ax + root.field-x, y: root.ay + root.field-y, w: root.field-w, h: root.field-h, r: 30 * Tv.u, focus: 0.25, alpha: root.alpha, blur: -1, glow: Tv.orange, tint: #ffffff12, group: 0, }, { x: root.ax + root.row-x - 26 * Tv.u, y: root.ay + root.row-y + 14 * Tv.u, w: root.n * root.key-w + 52 * Tv.u, h: root.track-h, r: root.track-h / 2, focus: 0, alpha: root.alpha, blur: -1, glow: #ffffff, tint: #ffffff09, group: 0, }, { x: root.ax + root.row-x + (root.pos + 0.5) * root.key-w - root.lens-w / 2, y: root.ay + root.row-y + (root.row-h - root.lens-h) / 2, w: root.lens-w, h: root.lens-h, r: 30 * Tv.u, focus: root.keys-active, alpha: root.alpha * root.keys-active, blur: -1, glow: #ffffff, tint: #ffffff.with-alpha(0.88 * root.keys-active), group: 0, }, root.chip-rect(0), root.chip-rect(1), root.chip-rect(2), root.chip-rect(3), root.chip-rect(4), root.chip-rect(5), ]; }