// sf-ui gallery: every component on one screen. Also the smallest complete // example of an sf-ui app: TvWindow root, one FocusScope that owns the // focus state, glass exported as [GlassRect] arrays for the Rust side. import { TvWindow, Tv, SfText, GlassRect, GlassPane, GlassButton, GlassMenu, MenuItem, ProgressBar, ArtworkCard, Spinner, Keyboard, Icon, Headline, Title, Body, Label, Caption, SectionTitle } from "@sf-ui/sf-ui.slint"; // Rust needs these two globals (sf_ui::glue! wires SfText). export { Tv, SfText } export component Gallery inherits TvWindow { title: "sf-ui gallery"; forward-focus: keys; in property <[image]> art; in-out property progress: 0.36; in property typed; callback search(string); // Focus: 0 = buttons, 1 = menu, 2 = cards. in-out property area: 0; in-out property button: 0; in-out property item: 1; in-out property card: 0; in-out property kb-open; out property kb-t: self.kb-open ? 1 : 0; animate kb-t { duration: 480ms; easing: cubic-bezier(0.22, 1, 0.36, 1); } // Content under the keyboard pane goes away completely before it arrives. property dim: max(0, 1 - 1.6 * self.kb-t); keys := FocusScope { key-pressed(event) => { if root.kb-open { return kb.key(event); } if event.text == Key.UpArrow { if root.area == 1 { root.item = max(0, root.item - 1); } if root.area == 2 { root.area = 0; } } else if event.text == Key.DownArrow { if root.area == 1 { if root.item < 4 { root.item += 1; } else { root.area = 2; } } if root.area == 0 { root.area = 2; } } else if event.text == Key.LeftArrow { if root.area == 0 { root.button = max(0, root.button - 1); } if root.area == 2 { root.card = max(0, root.card - 1); } if root.area == 1 { root.area = 0; } } else if event.text == Key.RightArrow { if root.area == 0 { if root.button < 2 { root.button += 1; } else { root.area = 1; } } if root.area == 2 { root.card = min(4, root.card + 1); } } else if event.text == Key.Return { if root.area == 0 && root.button == 1 { kb.reset(); root.kb-open = true; } else if root.area == 0 && root.button == 0 { root.progress = root.progress > 0.9 ? 0 : root.progress + 0.1; } } else { return reject; } accept } } // ---- heading ---- Headline { x: Tv.safe-x; y: Tv.safe-y; text: "sf-ui"; opacity: root.dim; } Caption { x: Tv.safe-x; y: Tv.safe-y + 72 * Tv.u; text: "Nyilak: mozgás · OK: kiválasztás · Keresés: billentyűzet"; opacity: root.dim; } // ---- a details pane with buttons ---- pane := GlassPane { x: Tv.safe-x; y: 200 * Tv.u; width: 1040 * Tv.u; height: 520 * Tv.u; alpha: root.dim; VerticalLayout { padding: 56 * Tv.u; spacing: 20 * Tv.u; opacity: root.dim; Label { text: "Film · 2024 · 2 ó 16 p"; } Title { text: "A dűne második része"; } Body { text: "Paul Atreides egyesül Chanival és a fremenekkel, miközben bosszút áll a családját elpusztító összeesküvőkön."; vertical-stretch: 1; } HorizontalLayout { spacing: 24 * Tv.u; alignment: start; b0 := GlassButton { text: "Lejátszás"; icon: "play"; primary: true; nested: true; focused: root.area == 0 && root.button == 0; alpha: root.dim; } b1 := GlassButton { text: "Keresés"; icon: "search"; nested: true; focused: root.area == 0 && root.button == 1; alpha: root.dim; } b2 := GlassButton { icon: "plus"; nested: true; focused: root.area == 0 && root.button == 2; alpha: root.dim; } } bar := ProgressBar { value: root.progress; buffered: root.progress + 0.2; alpha: root.dim; } } } // ---- a menu ---- menu := GlassMenu { x: 1264 * Tv.u; y: 200 * Tv.u; title: "Hang"; alpha: root.dim; focused-index: root.area == 1 ? root.item : -1; items: [ { text: "Magyar", detail: "5.1", checked: root.item == 0 }, { text: "Angol", detail: "Atmos", checked: root.item == 1 }, { text: "Angol — Kommentár", detail: "Sztereó", checked: root.item == 2 }, { text: "Német", detail: "5.1", checked: root.item == 3 }, { text: "Francia", detail: "Sztereó", checked: root.item == 4 }, ]; } // ---- artwork ---- SectionTitle { x: Tv.safe-x; y: 760 * Tv.u; text: root.typed == "" ? "Népszerű" : "Keresés: " + root.typed; opacity: root.dim; } for i in 5: ArtworkCard { x: Tv.safe-x + i * 344 * Tv.u; y: 830 * Tv.u; width: 312 * Tv.u; height: 176 * Tv.u; image: i < root.art.length ? root.art[i] : @image-url(""); placeholder: "Kártya \{i + 1}"; progress: i == 1 ? 0.4 : -1; badge: i == 0 ? "Új rész" : ""; focused: root.area == 2 && root.card == i; opacity: root.dim; } Spinner { x: 1264 * Tv.u + 560 * Tv.u - self.width; y: Tv.safe-y; opacity: root.dim; } // ---- keyboard on a modal pane ---- modal := GlassPane { x: (root.width - self.width) / 2; y: (root.height - self.height) / 2; width: 1720 * Tv.u; height: 760 * Tv.u; radius: 56 * Tv.u; frost: 3.8; tint: Tv.smoke.with-alpha(0.48); glow: Tv.orange; alpha: root.kb-t; kb := Keyboard { x: 0; y: 96 * Tv.u; width: parent.width; title: "Keresés"; subtitle: "Filmek és sorozatok címe"; placeholder: "Cím"; submit-label: "Keresés"; min-length: 2; alpha: root.kb-t; submitted(text) => { root.kb-open = false; root.search(text); } cancelled => { root.kb-open = false; } } } // ---- glass, in drawing order ---- out property <[GlassRect]> glass: [pane.glass, b0.glass, b1.glass, b2.glass, bar.glass]; out property <[GlassRect]> glass-menu: menu.glass; out property <[GlassRect]> glass-modal: [modal.glass]; out property <[GlassRect]> glass-keyboard: kb.glass; }