Add Store support and unsigned app releases
This commit is contained in:
21
crates/sf-ui/gallery/Cargo.toml
Normal file
21
crates/sf-ui/gallery/Cargo.toml
Normal file
@@ -0,0 +1,21 @@
|
||||
[package]
|
||||
name = "sf-ui-gallery"
|
||||
description = "Every sf-ui component on one screen (example and visual test)"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
license = "GPL-3.0-only"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
sf-ui = { path = ".." }
|
||||
slint = "1.18"
|
||||
anyhow.workspace = true
|
||||
log.workspace = true
|
||||
env_logger.workspace = true
|
||||
|
||||
[features]
|
||||
# SF_UI_VIDEO=<uri>: plays a video as the backdrop (Linux, GStreamer).
|
||||
video = ["sf-ui/video"]
|
||||
|
||||
[build-dependencies]
|
||||
slint-build = "1.18"
|
||||
7
crates/sf-ui/gallery/build.rs
Normal file
7
crates/sf-ui/gallery/build.rs
Normal file
@@ -0,0 +1,7 @@
|
||||
fn main() {
|
||||
// sf-ui's build script publishes where its Slint library is.
|
||||
let sf_ui = std::env::var("DEP_SF_UI_UI_DIR").expect("sf-ui must be a direct dependency");
|
||||
let config = slint_build::CompilerConfiguration::new()
|
||||
.with_library_paths(std::collections::HashMap::from([("sf-ui".to_string(), sf_ui.into())]));
|
||||
slint_build::compile_with_config("ui/gallery.slint", config).expect("compiling ui/gallery.slint");
|
||||
}
|
||||
101
crates/sf-ui/gallery/src/main.rs
Normal file
101
crates/sf-ui/gallery/src/main.rs
Normal file
@@ -0,0 +1,101 @@
|
||||
//! sf-ui gallery: every component on one screen.
|
||||
//!
|
||||
//! cargo run -p sf-ui-gallery
|
||||
//! SF_UI_SIZE=1920x1080 SF_UI_KEYS="down right" SF_UI_SNAPSHOT=shot.png cargo run -p sf-ui-gallery
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use slint::{ComponentHandle, Model, Rgba8Pixel, SharedPixelBuffer, VecModel};
|
||||
|
||||
slint::include_modules!();
|
||||
sf_ui::glue!(Gallery);
|
||||
|
||||
/// Stand-in artwork: a soft two-colour gradient with a light blob.
|
||||
fn artwork(a: [u8; 3], b: [u8; 3], w: u32, h: u32) -> SharedPixelBuffer<Rgba8Pixel> {
|
||||
let mut px = SharedPixelBuffer::<Rgba8Pixel>::new(w, h);
|
||||
let (cw, ch) = (w as f32, h as f32);
|
||||
for (i, p) in px.make_mut_slice().iter_mut().enumerate() {
|
||||
let (x, y) = ((i as u32 % w) as f32 / cw, (i as u32 / w) as f32 / ch);
|
||||
let t = (x * 0.6 + y * 0.4).clamp(0.0, 1.0);
|
||||
let d = ((x - 0.7).powi(2) + (y - 0.3).powi(2)).sqrt();
|
||||
let glow = (1.0 - d * 2.2).max(0.0).powi(2) * 0.55;
|
||||
let c = |k: usize| ((a[k] as f32 * (1.0 - t) + b[k] as f32 * t) * (1.0 - glow) + 255.0 * glow) as u8;
|
||||
*p = Rgba8Pixel { r: c(0), g: c(1), b: c(2), a: 255 };
|
||||
}
|
||||
px
|
||||
}
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
|
||||
sf_ui::init()?;
|
||||
let ui = Gallery::new()?;
|
||||
ui.sf_ui_setup();
|
||||
|
||||
let colours = [
|
||||
([190, 70, 40], [30, 10, 40]),
|
||||
([30, 110, 160], [10, 20, 40]),
|
||||
([60, 140, 80], [10, 30, 20]),
|
||||
([170, 140, 40], [40, 20, 10]),
|
||||
([120, 60, 170], [20, 10, 40]),
|
||||
];
|
||||
let pictures: Vec<SharedPixelBuffer<Rgba8Pixel>> = colours.iter().map(|(a, b)| artwork(*a, *b, 640, 360)).collect();
|
||||
let images: Vec<slint::Image> = pictures.iter().map(|p| slint::Image::from_rgba8(p.clone())).collect();
|
||||
ui.set_art(slint::ModelRc::new(VecModel::from(images)));
|
||||
let weak = ui.as_weak();
|
||||
ui.on_search(move |text| {
|
||||
if let Some(ui) = weak.upgrade() {
|
||||
ui.set_typed(text);
|
||||
}
|
||||
});
|
||||
|
||||
let glass = sf_ui::Glass::install(&ui, |ui, panels| {
|
||||
panels.extend(ui.get_glass().iter());
|
||||
panels.extend(ui.get_glass_menu().iter());
|
||||
panels.extend(ui.get_glass_modal().iter());
|
||||
panels.extend(ui.get_glass_keyboard().iter());
|
||||
})?;
|
||||
glass.set_palette(sf_ui::Palette::from_hex(["#ffb27a", "#8a3d12", "#120805"]));
|
||||
|
||||
// SF_UI_VIDEO=<uri> (feature "video"): the film plays under the glass.
|
||||
#[cfg(feature = "video")]
|
||||
let _video = match std::env::var("SF_UI_VIDEO") {
|
||||
Ok(uri) => {
|
||||
sf_ui::video::init()?;
|
||||
log::info!("hardware decoding: {}", sf_ui::video::hardware_decoding());
|
||||
let player = std::rc::Rc::new(std::cell::RefCell::new(sf_ui::video::Player::new(&uri, Default::default())?));
|
||||
glass.set_video(Some(player.borrow().video()));
|
||||
let p = player.clone();
|
||||
let poll = slint::Timer::default();
|
||||
poll.start(slint::TimerMode::Repeated, Duration::from_millis(100), move || {
|
||||
let mut p = p.borrow_mut();
|
||||
for ev in p.poll() {
|
||||
log::info!("video: {ev:?}");
|
||||
if let sf_ui::video::Event::Ready { .. } = ev {
|
||||
log::info!("audio: {:?}", p.audio_tracks());
|
||||
log::info!("text: {:?}", p.text_tracks());
|
||||
}
|
||||
}
|
||||
});
|
||||
Some((player, poll))
|
||||
}
|
||||
Err(_) => None,
|
||||
};
|
||||
|
||||
// The focused card's artwork becomes the backdrop (crossfades), and the
|
||||
// light follows the focus.
|
||||
let weak = ui.as_weak();
|
||||
let mut shown: Option<usize> = None;
|
||||
let timer = slint::Timer::default();
|
||||
timer.start(slint::TimerMode::Repeated, Duration::from_millis(100), move || {
|
||||
let Some(ui) = weak.upgrade() else { return };
|
||||
let want = (ui.get_area() == 2).then(|| ui.get_card() as usize);
|
||||
if want != shown {
|
||||
shown = want;
|
||||
glass.set_backdrop(want.map(|i| sf_ui::Backdrop::new(pictures[i].clone()).dim(0.2)));
|
||||
}
|
||||
glass.set_light((ui.get_card() as f32 - 2.0) * 0.08);
|
||||
});
|
||||
|
||||
ui.run()?;
|
||||
Ok(())
|
||||
}
|
||||
181
crates/sf-ui/gallery/ui/gallery.slint
Normal file
181
crates/sf-ui/gallery/ui/gallery.slint
Normal file
@@ -0,0 +1,181 @@
|
||||
// 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 <float> progress: 0.36;
|
||||
in property <string> typed;
|
||||
callback search(string);
|
||||
|
||||
// Focus: 0 = buttons, 1 = menu, 2 = cards.
|
||||
in-out property <int> area: 0;
|
||||
in-out property <int> button: 0;
|
||||
in-out property <int> item: 1;
|
||||
in-out property <int> card: 0;
|
||||
in-out property <bool> kb-open;
|
||||
out property <float> 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 <float> 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;
|
||||
}
|
||||
Reference in New Issue
Block a user