gui: rebuild the launcher: Big Picture home, adaptive grid, dense list, game page, settings, six themes
Home has a hero for the focused game (wide art as a cross-fading backdrop, logo, hours, Play) over shelves of covers. Library is a cover grid that adapts to the window, or a dense table, with filter, sort and search. Unfiltered is a grouped list with the detection reasons. Every game has a page with stats, launch profile and reasons. Settings are saved to ui.toml. Keyboard navigation with a focus ring throughout. Lists only create the rows on screen and covers are decoded to thumbnails on a worker thread when a card first appears. Play is real for Steam (steam://rungameid, steam://install), Lutris and hand-added entries (through summit run); pin and unpin write state.json. Change artwork and per-game settings are marked Soon. Normal runs use the OpenGL renderer (FemtoVG) with the software renderer as fallback; SUMMIT_SHOT renders any view headless to a PNG.
This commit is contained in:
1 parent
c7ffbdb7e9
commit
27a559846b
13 files changed
+2288
-239
No files matched your search
Generated
+79
@@ -1106,6 +1106,27 @@ dependencies = [
|
||||
"simd-adler32",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "femtovg"
|
||||
version = "0.28.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bdd6dfbb6f827356c8a284b9b7ab83828d6d630fe5457aa59f56092ee49f407a"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"bytemuck",
|
||||
"cfg_aliases",
|
||||
"fnv",
|
||||
"glow",
|
||||
"imgref",
|
||||
"itertools",
|
||||
"log",
|
||||
"rgb",
|
||||
"slotmap",
|
||||
"swash",
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "field-offset"
|
||||
version = "0.3.6"
|
||||
@@ -1160,6 +1181,12 @@ version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4"
|
||||
|
||||
[[package]]
|
||||
name = "fnv"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||
|
||||
[[package]]
|
||||
name = "foldhash"
|
||||
version = "0.2.0"
|
||||
@@ -1345,6 +1372,28 @@ dependencies = [
|
||||
"slab",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gbm"
|
||||
version = "0.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ce852e998d3ca5e4a97014fb31c940dc5ef344ec7d364984525fd11e8a547e6a"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"drm",
|
||||
"drm-fourcc",
|
||||
"gbm-sys",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gbm-sys"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c13a5f2acc785d8fb6bf6b7ab6bfb0ef5dad4f4d97e8e70bb8e470722312f76f"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gethostname"
|
||||
version = "1.1.0"
|
||||
@@ -1588,8 +1637,12 @@ dependencies = [
|
||||
"calloop 0.14.5",
|
||||
"cfg_aliases",
|
||||
"drm",
|
||||
"gbm",
|
||||
"gbm-sys",
|
||||
"glutin",
|
||||
"i-slint-common",
|
||||
"i-slint-core",
|
||||
"i-slint-renderer-femtovg",
|
||||
"i-slint-renderer-software",
|
||||
"input",
|
||||
"libseat",
|
||||
@@ -1597,6 +1650,7 @@ dependencies = [
|
||||
"memmap2",
|
||||
"nix",
|
||||
"pkg-config",
|
||||
"raw-window-handle",
|
||||
"xkbcommon",
|
||||
]
|
||||
|
||||
@@ -1613,6 +1667,7 @@ dependencies = [
|
||||
"i-slint-common",
|
||||
"i-slint-core",
|
||||
"i-slint-core-macros",
|
||||
"i-slint-renderer-femtovg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1644,6 +1699,7 @@ dependencies = [
|
||||
"i-slint-common",
|
||||
"i-slint-core",
|
||||
"i-slint-core-macros",
|
||||
"i-slint-renderer-femtovg",
|
||||
"i-slint-renderer-skia",
|
||||
"i-slint-renderer-software",
|
||||
"imgref",
|
||||
@@ -1793,6 +1849,26 @@ dependencies = [
|
||||
"syn 3.0.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "i-slint-renderer-femtovg"
|
||||
version = "1.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af1892857762af5466d723f41febf4f80f92d1455de839ca9a76c955bf8793b9"
|
||||
dependencies = [
|
||||
"const-field-offset",
|
||||
"femtovg",
|
||||
"glow",
|
||||
"i-slint-common",
|
||||
"i-slint-core",
|
||||
"i-slint-core-macros",
|
||||
"imgref",
|
||||
"lyon_path",
|
||||
"pin-weak",
|
||||
"rgb",
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "i-slint-renderer-skia"
|
||||
version = "1.19.0"
|
||||
@@ -2074,6 +2150,7 @@ checksum = "85ab80394333c02fe689eaf900ab500fbd0c2213da414687ebf995a65d5a6104"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"byteorder-lite",
|
||||
"image-webp",
|
||||
"moxcms",
|
||||
"num-traits",
|
||||
"png",
|
||||
@@ -3854,6 +3931,7 @@ dependencies = [
|
||||
"i-slint-common",
|
||||
"i-slint-core",
|
||||
"i-slint-core-macros",
|
||||
"i-slint-renderer-femtovg",
|
||||
"i-slint-renderer-software",
|
||||
"once_cell",
|
||||
"pin-weak",
|
||||
@@ -4134,6 +4212,7 @@ dependencies = [
|
||||
name = "summit-gui"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"image",
|
||||
"slint",
|
||||
"slint-build",
|
||||
"summit-core",
|
||||
|
||||
@@ -10,7 +10,9 @@ path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
summit-core = { path = "../summit-core" }
|
||||
slint = { version = "1.19", default-features = false, features = ["std", "backend-winit", "renderer-software", "software-renderer-systemfonts", "compat-1-2"] }
|
||||
# renderer-femtovg (OpenGL) is what a normal run uses; renderer-software is the fallback and the headless screenshot mode.
|
||||
slint = { version = "1.19", default-features = false, features = ["std", "backend-winit", "renderer-femtovg", "renderer-software", "software-renderer-systemfonts", "compat-1-2"] }
|
||||
image = { version = "0.25", default-features = false, features = ["jpeg", "png", "webp"] }
|
||||
|
||||
[build-dependencies]
|
||||
slint-build = "1.19"
|
||||
@@ -0,0 +1,182 @@
|
||||
//! Image work, kept off the UI thread: cover thumbnails, the hero backdrop and logos.
|
||||
//! Everything is decoded to a small pixel buffer, so a library of hundreds of games never holds full-size art.
|
||||
use image::{imageops, imageops::FilterType, DynamicImage, RgbImage, RgbaImage};
|
||||
use slint::{Rgb8Pixel, Rgba8Pixel, SharedPixelBuffer};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
pub const COVER_W: u32 = 300;
|
||||
pub const COVER_H: u32 = 450;
|
||||
|
||||
pub type Rgb = SharedPixelBuffer<Rgb8Pixel>;
|
||||
pub type Rgba = SharedPixelBuffer<Rgba8Pixel>;
|
||||
|
||||
pub enum Job {
|
||||
Cover { idx: usize, path: PathBuf },
|
||||
Backdrop { idx: usize, seq: u64, hero: Option<PathBuf>, cover: Option<PathBuf>, logo: Option<PathBuf>, c1: [u8; 3], c2: [u8; 3] },
|
||||
}
|
||||
|
||||
pub enum Done {
|
||||
Cover { idx: usize, img: Option<Rgb> },
|
||||
Backdrop { idx: usize, seq: u64, img: Rgb, logo: Option<Rgba> },
|
||||
}
|
||||
|
||||
fn to_rgb(img: &RgbImage) -> Rgb { Rgb::clone_from_slice(img.as_raw(), img.width(), img.height()) }
|
||||
fn to_rgba(img: &RgbaImage) -> Rgba { Rgba::clone_from_slice(img.as_raw(), img.width(), img.height()) }
|
||||
|
||||
/// A soft, dark version of an image: shrink, blur, grow. Cheap, and it hides how small the source was.
|
||||
fn soft(img: &DynamicImage, w: u32, h: u32, sigma: f32) -> RgbImage {
|
||||
let small = img.resize_to_fill(w / 8, h / 8, FilterType::Triangle).to_rgb8();
|
||||
let blurred = imageops::blur(&small, sigma);
|
||||
imageops::resize(&blurred, w, h, FilterType::CatmullRom)
|
||||
}
|
||||
|
||||
/// 2:3 thumbnail. Portrait art is cropped to fill; wide art (Steam's header.jpg) is centred on a soft copy of itself.
|
||||
pub fn cover(path: &Path) -> Option<Rgb> {
|
||||
let img = image::open(path).ok()?;
|
||||
let (w, h) = (img.width(), img.height());
|
||||
if w == 0 || h == 0 { return None; }
|
||||
let out = if (w as f32 / h as f32) < 1.05 {
|
||||
img.resize_to_fill(COVER_W, COVER_H, FilterType::Triangle).to_rgb8()
|
||||
} else {
|
||||
let mut bg = soft(&img, COVER_W, COVER_H, 3.0);
|
||||
for p in bg.pixels_mut() { p.0 = [p.0[0] / 2, p.0[1] / 2, p.0[2] / 2]; }
|
||||
let fh = (COVER_W as f32 * h as f32 / w as f32).round().max(1.0) as u32;
|
||||
let fit = img.resize_exact(COVER_W, fh, FilterType::Triangle).to_rgb8();
|
||||
imageops::overlay(&mut bg, &fit, 0, ((COVER_H - fh.min(COVER_H)) / 2) as i64);
|
||||
bg
|
||||
};
|
||||
Some(to_rgb(&out))
|
||||
}
|
||||
|
||||
fn gradient(c1: [u8; 3], c2: [u8; 3]) -> RgbImage {
|
||||
let (w, h) = (320u32, 120u32);
|
||||
RgbImage::from_fn(w, h, |x, y| {
|
||||
let t = (x as f32 / w as f32 * 0.7 + y as f32 / h as f32 * 0.3).clamp(0.0, 1.0);
|
||||
image::Rgb([0, 1, 2].map(|i| (c1[i] as f32 + (c2[i] as f32 - c1[i] as f32) * t) as u8))
|
||||
})
|
||||
}
|
||||
|
||||
/// Backdrop for the hero: the game's wide hero art if there is one, else a blurred cover, else its two colours.
|
||||
pub fn backdrop(hero: Option<&Path>, cover: Option<&Path>, c1: [u8; 3], c2: [u8; 3]) -> Rgb {
|
||||
if let Some(img) = hero.and_then(|p| image::open(p).ok()) {
|
||||
let img = if img.width() > 1600 { img.resize(1600, 1600, FilterType::Triangle) } else { img };
|
||||
return to_rgb(&img.to_rgb8());
|
||||
}
|
||||
if let Some(img) = cover.and_then(|p| image::open(p).ok()) {
|
||||
// the middle band of the cover, where the subject usually is
|
||||
let (w, h) = (img.width(), img.height());
|
||||
let band = (w as f32 / 2.6).min(h as f32) as u32;
|
||||
let crop = img.crop_imm(0, (h - band) / 3, w, band.max(1));
|
||||
return to_rgb(&soft(&crop, 832, 320, 2.2));
|
||||
}
|
||||
to_rgb(&gradient(c1, c2))
|
||||
}
|
||||
|
||||
/// Logo with its transparent margins trimmed, so it lines up with the text under it.
|
||||
pub fn logo(path: &Path) -> Option<Rgba> {
|
||||
let img = image::open(path).ok()?.to_rgba8();
|
||||
let (mut x0, mut y0, mut x1, mut y1) = (img.width(), img.height(), 0u32, 0u32);
|
||||
for (x, y, p) in img.enumerate_pixels() {
|
||||
if p.0[3] > 16 { x0 = x0.min(x); y0 = y0.min(y); x1 = x1.max(x); y1 = y1.max(y); }
|
||||
}
|
||||
if x1 <= x0 || y1 <= y0 { return None; }
|
||||
let cut = imageops::crop_imm(&img, x0, y0, x1 - x0 + 1, y1 - y0 + 1).to_image();
|
||||
let cut = if cut.width() > 720 { imageops::resize(&cut, 720, (cut.height() as f32 * 720.0 / cut.width() as f32).max(1.0) as u32, FilterType::Triangle) } else { cut };
|
||||
Some(to_rgba(&cut))
|
||||
}
|
||||
|
||||
pub fn run(job: Job) -> Done {
|
||||
match job {
|
||||
Job::Cover { idx, path } => Done::Cover { idx, img: cover(&path) },
|
||||
Job::Backdrop { idx, seq, hero, cover, logo: l, c1, c2 } => Done::Backdrop {
|
||||
idx, seq, img: backdrop(hero.as_deref(), cover.as_deref(), c1, c2), logo: l.as_deref().and_then(logo),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Jobs either go to a worker thread (normal run) or wait in a queue that the caller drains (headless screenshots).
|
||||
pub enum Loader {
|
||||
Thread(std::sync::mpsc::Sender<Job>),
|
||||
Queue(std::cell::RefCell<Vec<Job>>),
|
||||
}
|
||||
|
||||
impl Loader {
|
||||
/// `deliver` runs on the worker thread; it is expected to hop to the UI thread itself.
|
||||
pub fn threaded(deliver: impl Fn(Done) + Send + 'static) -> Self {
|
||||
let (tx, rx) = std::sync::mpsc::channel::<Job>();
|
||||
std::thread::Builder::new().name("summit-art".into()).spawn(move || {
|
||||
while let Ok(first) = rx.recv() {
|
||||
// Take everything that is waiting. Only the newest backdrop matters: focus has moved on from the others.
|
||||
let mut jobs = vec![first];
|
||||
while let Ok(j) = rx.try_recv() { jobs.push(j); }
|
||||
let newest = jobs.iter().rposition(|j| matches!(j, Job::Backdrop { .. }));
|
||||
for (i, j) in jobs.into_iter().enumerate() {
|
||||
if matches!(j, Job::Backdrop { .. }) && Some(i) != newest { continue; }
|
||||
deliver(run(j));
|
||||
}
|
||||
}
|
||||
}).expect("art thread");
|
||||
Loader::Thread(tx)
|
||||
}
|
||||
pub fn queued() -> Self { Loader::Queue(Default::default()) }
|
||||
pub fn push(&self, job: Job) {
|
||||
match self {
|
||||
Loader::Thread(tx) => { let _ = tx.send(job); }
|
||||
Loader::Queue(q) => q.borrow_mut().push(job),
|
||||
}
|
||||
}
|
||||
/// Queue mode only: take the waiting jobs.
|
||||
pub fn take(&self) -> Vec<Job> {
|
||||
match self { Loader::Queue(q) => std::mem::take(&mut *q.borrow_mut()), Loader::Thread(_) => vec![] }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
fn tmp(name: &str) -> PathBuf {
|
||||
let d = std::env::temp_dir().join(format!("summit-art-test-{}", std::process::id()));
|
||||
std::fs::create_dir_all(&d).unwrap();
|
||||
d.join(name)
|
||||
}
|
||||
#[test]
|
||||
fn portrait_and_wide_art_both_become_2_by_3() {
|
||||
let p = tmp("portrait.png"); RgbImage::from_pixel(60, 90, image::Rgb([200, 10, 10])).save(&p).unwrap();
|
||||
let w = tmp("wide.png"); RgbImage::from_pixel(460, 215, image::Rgb([10, 200, 10])).save(&w).unwrap();
|
||||
for f in [&p, &w] {
|
||||
let c = cover(f).unwrap();
|
||||
assert_eq!((c.width(), c.height()), (COVER_W, COVER_H));
|
||||
}
|
||||
// the wide image sits in the middle, on a darker copy of itself
|
||||
let c = cover(&w).unwrap();
|
||||
let px = |x: u32, y: u32| c.as_slice()[(y * COVER_W + x) as usize];
|
||||
assert!(px(150, 225).g > 180);
|
||||
assert!(px(150, 10).g < 140);
|
||||
}
|
||||
#[test]
|
||||
fn backdrop_falls_back_to_cover_then_colours() {
|
||||
let c = tmp("cover.png"); RgbImage::from_pixel(60, 90, image::Rgb([9, 9, 200])).save(&c).unwrap();
|
||||
let b = backdrop(None, Some(&c), [0; 3], [0; 3]);
|
||||
assert_eq!((b.width(), b.height()), (832, 320));
|
||||
let g = backdrop(Some(Path::new("/nonexistent.jpg")), None, [255, 0, 0], [0, 0, 255]);
|
||||
assert!(g.as_slice()[0].r > 200 && g.as_slice().last().unwrap().b > 200);
|
||||
}
|
||||
#[test]
|
||||
fn logo_is_trimmed_to_its_pixels() {
|
||||
let p = tmp("logo.png");
|
||||
let mut img = RgbaImage::new(100, 40);
|
||||
for x in 20..60 { for y in 10..30 { img.put_pixel(x, y, image::Rgba([255, 255, 255, 255])); } }
|
||||
img.save(&p).unwrap();
|
||||
let l = logo(&p).unwrap();
|
||||
assert_eq!((l.width(), l.height()), (40, 20));
|
||||
let empty = tmp("empty.png"); RgbaImage::new(10, 10).save(&empty).unwrap();
|
||||
assert!(logo(&empty).is_none());
|
||||
}
|
||||
#[test]
|
||||
fn queue_loader_hands_jobs_back() {
|
||||
let l = Loader::queued();
|
||||
l.push(Job::Cover { idx: 3, path: "/x".into() });
|
||||
assert_eq!(l.take().len(), 1);
|
||||
assert!(l.take().is_empty());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
//! What the views show, computed from the scanned entries. No UI types here, so it is unit tested.
|
||||
use summit_core::model::{Entry, Kind, Source};
|
||||
use summit_core::profile::Profile;
|
||||
|
||||
pub const SHELF_MAX: usize = 24;
|
||||
|
||||
pub fn hours_long(m: u64) -> String {
|
||||
if m == 0 { "Never played".into() } else if m < 60 { format!("{m} min") } else if m < 6000 { format!("{:.1} hours", m as f64 / 60.0) } else { format!("{:.0} hours", m as f64 / 60.0) }
|
||||
}
|
||||
pub fn hours_short(m: u64) -> String {
|
||||
if m == 0 { String::new() } else if m < 60 { format!("{m} min") } else if m < 6000 { format!("{:.1} h", m as f64 / 60.0) } else { format!("{:.0} h", m as f64 / 60.0) }
|
||||
}
|
||||
|
||||
/// "Today", "Yesterday", "12 days ago", "3 months ago", "2 years ago". Empty when never played.
|
||||
pub fn ago(last: Option<u64>, now: u64) -> String {
|
||||
let Some(t) = last.filter(|t| *t > 0) else { return String::new() };
|
||||
let days = now.saturating_sub(t) / 86400;
|
||||
let plural = |n: u64, unit: &str| format!("{n} {unit}{} ago", if n == 1 { "" } else { "s" });
|
||||
match days {
|
||||
0 => "Today".into(),
|
||||
1 => "Yesterday".into(),
|
||||
2..=29 => plural(days, "day"),
|
||||
30..=364 => plural(days / 30, "month"),
|
||||
_ => plural(days / 365, "year"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn source_label(s: Source) -> &'static str {
|
||||
match s { Source::Steam => "Steam", Source::Heroic => "Heroic", Source::Lutris => "Lutris", Source::Heuristic => "Found on disk", Source::Custom => "Added by you" }
|
||||
}
|
||||
pub fn kind_label(k: Kind) -> &'static str { match k { Kind::Game => "Game", Kind::Software => "Software", Kind::Tool => "Tool" } }
|
||||
|
||||
/// Two colours for an entry without art, stable for a given title.
|
||||
pub fn colors(title: &str) -> ([u8; 3], [u8; 3]) {
|
||||
const PAIRS: [([u8; 3], [u8; 3]); 8] = [
|
||||
([0x6d, 0x4a, 0xe6], [0x1b, 0x12, 0x4d]), ([0x1f, 0x8a, 0x9c], [0x0a, 0x2c, 0x3d]), ([0xc9, 0x45, 0x55], [0x45, 0x12, 0x25]), ([0x2f, 0x8f, 0x5b], [0x0c, 0x33, 0x2a]),
|
||||
([0xc7, 0x7a, 0x24], [0x4a, 0x21, 0x0e]), ([0x3d, 0x63, 0xd6], [0x10, 0x1c, 0x52]), ([0xb0, 0x48, 0xb8], [0x35, 0x12, 0x4a]), ([0x4f, 0x6b, 0x82], [0x17, 0x22, 0x30]),
|
||||
];
|
||||
let h = title.bytes().fold(7u32, |a, b| a.wrapping_mul(31).wrapping_add(b as u32));
|
||||
PAIRS[(h % PAIRS.len() as u32) as usize]
|
||||
}
|
||||
|
||||
fn by_title(entries: &[Entry]) -> impl Fn(&usize, &usize) -> std::cmp::Ordering + '_ {
|
||||
|a, b| entries[*a].title.to_lowercase().cmp(&entries[*b].title.to_lowercase())
|
||||
}
|
||||
|
||||
/// Home shelves as indexes into `entries`: recently played, pinned (in pin order), most played.
|
||||
pub fn shelves(entries: &[Entry], pinned: &[String]) -> (Vec<usize>, Vec<usize>, Vec<usize>) {
|
||||
let games: Vec<usize> = (0..entries.len()).filter(|i| entries[*i].kind == Kind::Game).collect();
|
||||
let mut recent: Vec<usize> = games.iter().copied().filter(|i| entries[*i].last_played.unwrap_or(0) > 0).collect();
|
||||
recent.sort_by(|a, b| entries[*b].last_played.cmp(&entries[*a].last_played).then(by_title(entries)(a, b)));
|
||||
recent.truncate(SHELF_MAX);
|
||||
let pins: Vec<usize> = pinned.iter().filter_map(|id| entries.iter().position(|e| &e.id == id)).collect();
|
||||
let mut most: Vec<usize> = games.iter().copied().filter(|i| entries[*i].playtime_minutes > 0).collect();
|
||||
most.sort_by(|a, b| entries[*b].playtime_minutes.cmp(&entries[*a].playtime_minutes).then(by_title(entries)(a, b)));
|
||||
most.truncate(SHELF_MAX);
|
||||
(recent, pins, most)
|
||||
}
|
||||
|
||||
/// Library view. filter: 0 all, 1 installed, 2 not installed. sort: 0 recently played, 1 most played, 2 A to Z.
|
||||
pub fn library(entries: &[Entry], filter: i32, sort: i32, search: &str) -> Vec<usize> {
|
||||
let needle = search.trim().to_lowercase();
|
||||
let mut v: Vec<usize> = (0..entries.len()).filter(|i| {
|
||||
let e = &entries[*i];
|
||||
e.kind == Kind::Game
|
||||
&& match filter { 1 => e.installed, 2 => !e.installed, _ => true }
|
||||
&& (needle.is_empty() || e.title.to_lowercase().contains(&needle))
|
||||
}).collect();
|
||||
let t = by_title(entries);
|
||||
match sort {
|
||||
1 => v.sort_by(|a, b| entries[*b].playtime_minutes.cmp(&entries[*a].playtime_minutes).then(t(a, b))),
|
||||
2 => v.sort_by(&t),
|
||||
_ => v.sort_by(|a, b| entries[*b].last_played.unwrap_or(0).cmp(&entries[*a].last_played.unwrap_or(0))
|
||||
.then(entries[*b].installed.cmp(&entries[*a].installed)).then(entries[*b].playtime_minutes.cmp(&entries[*a].playtime_minutes)).then(t(a, b))),
|
||||
}
|
||||
v
|
||||
}
|
||||
|
||||
pub enum Row { Header { label: String, count: usize }, Item(usize) }
|
||||
|
||||
/// Unfiltered view: everything that is on this machine, grouped by source and kind, each group under a header.
|
||||
pub fn unfiltered(entries: &[Entry]) -> Vec<Row> {
|
||||
let mut out = vec![];
|
||||
for src in [Source::Steam, Source::Heroic, Source::Lutris, Source::Custom, Source::Heuristic] {
|
||||
for (kind, label) in [(Kind::Game, "GAMES"), (Kind::Software, "SOFTWARE"), (Kind::Tool, "TOOLS")] {
|
||||
let mut items: Vec<usize> = (0..entries.len()).filter(|i| entries[*i].source == src && entries[*i].kind == kind && entries[*i].installed).collect();
|
||||
if items.is_empty() { continue; }
|
||||
items.sort_by(by_title(entries));
|
||||
out.push(Row::Header { label: format!("{} · {label}", source_label(src).to_uppercase()), count: items.len() });
|
||||
out.extend(items.into_iter().map(Row::Item));
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
pub struct ProfileSummary { pub monitor: String, pub mode: String, pub upscaler: String, pub framegen: String, pub window: String, pub set: bool }
|
||||
|
||||
pub fn upscaler_label(u: &str) -> String {
|
||||
match u { "" | "none" => "None".into(), "fsr" => "FSR".into(), "nis" => "NIS".into(), "rtx-vsr" | "vsr" => "RTX Video Super Resolution".into(), "dlss" => "DLSS".into(), o => o.to_string() }
|
||||
}
|
||||
|
||||
pub fn profile_summary(p: &Profile) -> ProfileSummary {
|
||||
let res = match (p.width, p.height) { (Some(w), Some(h)) => Some(format!("{w} × {h}")), _ => None };
|
||||
let hz = p.refresh_hz.map(|r| if r.fract() == 0.0 { format!("{r:.0} Hz") } else { format!("{r:.2} Hz") });
|
||||
let mode = match (res, hz) { (Some(r), Some(h)) => format!("{r} at {h}"), (Some(r), None) => r, (None, Some(h)) => h, (None, None) => "Default".into() };
|
||||
let framegen = match p.framegen.as_str() {
|
||||
"" | "none" => "None".to_string(),
|
||||
f => {
|
||||
let name = if f == "rife" { "RIFE".to_string() } else if f == "lsfg" { "lsfg-vk".to_string() } else { f.to_string() };
|
||||
match (p.framegen_multiplier, p.target_hz) {
|
||||
(m, Some(hz)) if m > 1 => format!("{name} ×{m}, {hz} Hz out"),
|
||||
(m, None) if m > 1 => format!("{name} ×{m}"),
|
||||
(_, Some(hz)) => format!("{name}, {hz} Hz out"),
|
||||
_ => name,
|
||||
}
|
||||
}
|
||||
};
|
||||
let window = match (p.fullscreen, p.focus) { (true, true) => "Fullscreen, focused", (true, false) => "Fullscreen", (false, true) => "Focused", _ => "Default" };
|
||||
ProfileSummary {
|
||||
monitor: p.monitor.clone().unwrap_or_else(|| "Default".into()), mode, upscaler: upscaler_label(&p.upscaler), framegen, window: window.into(),
|
||||
set: *p != Profile::default(),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
fn e(id: &str, title: &str, kind: Kind, src: Source, installed: bool, minutes: u64, last: u64) -> Entry {
|
||||
Entry { id: id.into(), title: title.into(), source: src, kind, installed, path: None, steam_app_id: None, playtime_minutes: minutes, last_played: if last > 0 { Some(last) } else { None }, reasons: vec![] }
|
||||
}
|
||||
fn lib() -> Vec<Entry> {
|
||||
vec![
|
||||
e("a", "Zeta", Kind::Game, Source::Steam, true, 600, 50),
|
||||
e("b", "alpha", Kind::Game, Source::Steam, false, 9000, 10),
|
||||
e("c", "Mid", Kind::Game, Source::Custom, true, 0, 0),
|
||||
e("d", "Proton", Kind::Tool, Source::Steam, true, 0, 0),
|
||||
e("e", "Editor", Kind::Software, Source::Heuristic, true, 0, 0),
|
||||
e("f", "Beta", Kind::Game, Source::Lutris, true, 30, 90),
|
||||
]
|
||||
}
|
||||
#[test]
|
||||
fn hours_and_ago_read_naturally() {
|
||||
assert_eq!((hours_long(0).as_str(), hours_long(45).as_str(), hours_long(90).as_str(), hours_long(10938).as_str()), ("Never played", "45 min", "1.5 hours", "182 hours"));
|
||||
assert_eq!((hours_short(0).as_str(), hours_short(90).as_str(), hours_short(10938).as_str()), ("", "1.5 h", "182 h"));
|
||||
let now = 1_000_000_000;
|
||||
let d = 86400;
|
||||
assert_eq!(ago(None, now), "");
|
||||
assert_eq!(ago(Some(now - 100), now), "Today");
|
||||
assert_eq!(ago(Some(now - d - 5), now), "Yesterday");
|
||||
assert_eq!(ago(Some(now - 12 * d), now), "12 days ago");
|
||||
assert_eq!(ago(Some(now - 31 * d), now), "1 month ago");
|
||||
assert_eq!(ago(Some(now - 200 * d), now), "6 months ago");
|
||||
assert_eq!(ago(Some(now - 800 * d), now), "2 years ago");
|
||||
assert_eq!(ago(Some(now + 500), now), "Today"); // clock skew never underflows
|
||||
}
|
||||
#[test]
|
||||
fn shelves_only_hold_games_and_keep_pin_order() {
|
||||
let l = lib();
|
||||
let (recent, pins, most) = shelves(&l, &["e".into(), "missing".into(), "a".into()]);
|
||||
assert_eq!(recent, vec![5, 0, 1]); // by last played, newest first; never-played and tools left out
|
||||
assert_eq!(pins, vec![4, 0]); // pin order, unknown ids skipped, software may be pinned
|
||||
assert_eq!(most, vec![1, 0, 5]);
|
||||
}
|
||||
#[test]
|
||||
fn library_filters_sorts_and_searches() {
|
||||
let l = lib();
|
||||
assert_eq!(library(&l, 0, 2, ""), vec![1, 5, 2, 0]); // A to Z, case-insensitive, games only
|
||||
assert_eq!(library(&l, 1, 1, ""), vec![0, 5, 2]); // installed, most played
|
||||
assert_eq!(library(&l, 2, 0, ""), vec![1]); // not installed
|
||||
assert_eq!(library(&l, 0, 0, ""), vec![5, 0, 1, 2]); // recently played, never-played last
|
||||
assert_eq!(library(&l, 0, 2, " ET "), vec![5, 0]); // search trims and ignores case
|
||||
assert!(library(&l, 0, 0, "nothing like this").is_empty());
|
||||
}
|
||||
#[test]
|
||||
fn unfiltered_groups_installed_entries_under_headers() {
|
||||
let rows = unfiltered(&lib());
|
||||
let shape: Vec<String> = rows.iter().map(|r| match r { Row::Header { label, count } => format!("{label}={count}"), Row::Item(i) => i.to_string() }).collect();
|
||||
assert_eq!(shape, vec!["STEAM · GAMES=1", "0", "STEAM · TOOLS=1", "3", "LUTRIS · GAMES=1", "5", "ADDED BY YOU · GAMES=1", "2", "FOUND ON DISK · SOFTWARE=1", "4"]);
|
||||
}
|
||||
#[test]
|
||||
fn profile_summary_says_default_when_unset() {
|
||||
let s = profile_summary(&Profile::default());
|
||||
assert_eq!((s.monitor.as_str(), s.mode.as_str(), s.upscaler.as_str(), s.framegen.as_str(), s.window.as_str(), s.set), ("Default", "Default", "None", "None", "Default", false));
|
||||
let p = Profile { monitor: Some("HDMI-A-1".into()), width: Some(3840), height: Some(2160), refresh_hz: Some(59.94), fullscreen: true, focus: true, upscaler: "fsr".into(), framegen: "rife".into(), framegen_multiplier: 2, target_hz: Some(120), ..Default::default() };
|
||||
let s = profile_summary(&p);
|
||||
assert_eq!((s.monitor.as_str(), s.mode.as_str(), s.upscaler.as_str(), s.framegen.as_str(), s.window.as_str(), s.set), ("HDMI-A-1", "3840 × 2160 at 59.94 Hz", "FSR", "RIFE ×2, 120 Hz out", "Fullscreen, focused", true));
|
||||
}
|
||||
#[test]
|
||||
fn colours_are_stable_per_title() { assert_eq!(colors("Portal 2"), colors("Portal 2")); }
|
||||
}
|
||||
+409
-82
@@ -1,94 +1,421 @@
|
||||
use slint::{Color, Image, ModelRc, SharedString, VecModel};
|
||||
use std::path::Path;
|
||||
use summit_core::{display, model::{Entry, Kind, Source}, scan, state, steam};
|
||||
//! Summit launcher window. The UI is in ui/*.slint; this file feeds it data and carries out its actions.
|
||||
mod art;
|
||||
mod data;
|
||||
mod shot;
|
||||
|
||||
use slint::{ComponentHandle, Image, Model, ModelRc, SharedString, VecModel};
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::collections::{HashSet, VecDeque};
|
||||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
use summit_core::{display, launch, model::{Entry, Kind, Source}, profile, scan, state, steam, ui as prefs};
|
||||
|
||||
slint::include_modules!();
|
||||
|
||||
fn accent(title: &str) -> Color {
|
||||
let h = title.bytes().fold(7u32, |a, b| a.wrapping_mul(31).wrapping_add(b as u32));
|
||||
let hues = [(0x5b, 0x3d, 0xd8), (0x1f, 0x7a, 0x8c), (0xc2, 0x41, 0x4b), (0x2e, 0x7d, 0x4f), (0xb5, 0x6a, 0x1e), (0x3a, 0x5b, 0xc7)];
|
||||
let (r, g, b) = hues[(h % hues.len() as u32) as usize];
|
||||
Color::from_rgb_u8(r, g, b)
|
||||
}
|
||||
fn hours(m: u64) -> String { if m == 0 { "Never played".into() } else if m < 60 { format!("{m} min") } else { format!("{:.1} h", m as f64 / 60.0) } }
|
||||
fn src_name(s: Source) -> &'static str { match s { Source::Steam => "STEAM", Source::Heroic => "HEROIC / EPIC / GOG", Source::Lutris => "LUTRIS", Source::Heuristic => "FOUND ON DISK", Source::Custom => "ADDED BY YOU" } }
|
||||
/// Thumbnails kept in memory. Beyond this the oldest are dropped; a card asks again when it comes back on screen.
|
||||
const COVERS_MAX: usize = 320;
|
||||
|
||||
fn card(e: &Entry, pinned: bool, art: &std::collections::HashMap<String, String>) -> Card {
|
||||
let cover_path = art.get(&e.id).map(std::path::PathBuf::from).or_else(|| e.steam_app_id.and_then(steam::cover));
|
||||
let img = cover_path.as_deref().and_then(|p: &Path| Image::load_from_path(p).ok());
|
||||
Card {
|
||||
title: SharedString::from(e.title.as_str()), hours: SharedString::from(hours(e.playtime_minutes)),
|
||||
source: SharedString::from(src_name(e.source)), installed: e.installed,
|
||||
has_cover: img.is_some(), cover: img.unwrap_or_default(), pinned, section: false,
|
||||
reasons: SharedString::from(e.reasons.join(" · ")), accent: accent(&e.title),
|
||||
thread_local! { static APP: RefCell<Option<Rc<App>>> = const { RefCell::new(None) }; }
|
||||
fn with_app(f: impl FnOnce(&App)) { APP.with(|a| { if let Some(app) = a.borrow().clone() { f(&app) } }) }
|
||||
|
||||
fn now() -> u64 { std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).map(|d| d.as_secs()).unwrap_or(0) }
|
||||
fn rgb(c: [u8; 3]) -> slint::Color { slint::Color::from_rgb_u8(c[0], c[1], c[2]) }
|
||||
|
||||
pub struct App {
|
||||
pub ui: MainWindow,
|
||||
entries: RefCell<Vec<Entry>>,
|
||||
state: RefCell<state::State>,
|
||||
games: Rc<VecModel<Game>>,
|
||||
loader: art::Loader,
|
||||
requested: RefCell<HashSet<usize>>,
|
||||
loaded: RefCell<VecDeque<usize>>,
|
||||
keep: RefCell<HashSet<usize>>,
|
||||
backdrop_seq: Cell<u64>,
|
||||
backdrop_for: Cell<i64>,
|
||||
settings: RefCell<prefs::UiSettings>,
|
||||
default_profile: RefCell<profile::Profile>,
|
||||
theme_keys: Vec<String>,
|
||||
pub headless: bool,
|
||||
base_scale: Cell<f32>,
|
||||
fullscreen: Cell<bool>,
|
||||
save_timer: slint::Timer,
|
||||
}
|
||||
|
||||
impl App {
|
||||
fn cover_path(&self, e: &Entry) -> Option<PathBuf> {
|
||||
self.state.borrow().artwork.get(&e.id).map(PathBuf::from).filter(|p| p.is_file()).or_else(|| e.steam_app_id.and_then(steam::cover))
|
||||
}
|
||||
fn hero_path(&self, e: &Entry) -> Option<PathBuf> {
|
||||
self.state.borrow().hero_art(&e.id).map(PathBuf::from).filter(|p| p.is_file()).or_else(|| e.steam_app_id.and_then(steam::hero))
|
||||
}
|
||||
fn logo_path(&self, e: &Entry) -> Option<PathBuf> {
|
||||
self.state.borrow().logo_art(&e.id).map(PathBuf::from).filter(|p| p.is_file()).or_else(|| e.steam_app_id.and_then(steam::logo))
|
||||
}
|
||||
fn cli(&self) -> Option<PathBuf> {
|
||||
std::env::current_exe().ok().and_then(|p| p.parent().map(|d| d.join("summit"))).filter(|p| p.is_file())
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut all = scan::full(&std::env::args().skip(1).filter(|a| !a.starts_with("--")).map(Into::into).collect::<Vec<_>>(), 4);
|
||||
let st = state::load();
|
||||
state::apply(&mut all, &st);
|
||||
let games: Vec<&Entry> = all.iter().filter(|e| e.kind == Kind::Game).collect();
|
||||
|
||||
let mut home: Vec<&Entry> = games.iter().copied().filter(|e| e.installed || e.playtime_minutes > 0).collect();
|
||||
home.sort_by(|a, b| st.pinned.contains(&b.id).cmp(&st.pinned.contains(&a.id)).then(b.playtime_minutes.cmp(&a.playtime_minutes)));
|
||||
home.truncate(14);
|
||||
let mut lib = games.clone();
|
||||
lib.sort_by(|a, b| b.installed.cmp(&a.installed).then(b.playtime_minutes.cmp(&a.playtime_minutes)));
|
||||
|
||||
let mut unf: Vec<Card> = vec![];
|
||||
for src in [Source::Steam, Source::Heroic, Source::Lutris, Source::Custom, Source::Heuristic] {
|
||||
for (kind, label) in [(Kind::Game, "GAMES"), (Kind::Software, "SOFTWARE"), (Kind::Tool, "TOOLS")] {
|
||||
let mut items: Vec<&Entry> = all.iter().filter(|e| e.source == src && e.kind == kind && e.installed).collect();
|
||||
if items.is_empty() { continue; }
|
||||
items.sort_by(|a, b| a.title.to_lowercase().cmp(&b.title.to_lowercase()));
|
||||
let mut h = card(items[0], false, &st.artwork);
|
||||
h.section = true; h.title = SharedString::from(format!("{} · {} ({})", src_name(src), label, items.len()));
|
||||
unf.push(h);
|
||||
for e in items { unf.push(card(e, false, &st.artwork)); }
|
||||
fn row(&self, e: &Entry, keep: Option<&Game>) -> Game {
|
||||
let (c1, c2) = data::colors(&e.title);
|
||||
let action = match launch::plan(e, self.cli().as_deref()) {
|
||||
launch::Plan::Run(_) if launch::is_install(e) => "INSTALL",
|
||||
launch::Plan::Run(_) => "PLAY",
|
||||
launch::Plan::Unsupported(_) => "",
|
||||
};
|
||||
Game {
|
||||
id: e.id.as_str().into(), title: e.title.as_str().into(),
|
||||
hours: data::hours_long(e.playtime_minutes).into(), hours_short: data::hours_short(e.playtime_minutes).into(),
|
||||
last: data::ago(e.last_played, now()).into(),
|
||||
source: data::source_label(e.source).into(), kind: data::kind_label(e.kind).into(),
|
||||
installed: e.installed, pinned: self.state.borrow().is_pinned(&e.id),
|
||||
cover: keep.map(|g| g.cover.clone()).unwrap_or_default(), has_cover: keep.map_or(false, |g| g.has_cover),
|
||||
c1: rgb(c1), c2: rgb(c2), reasons: e.reasons.join(" · ").into(), action: action.into(),
|
||||
}
|
||||
}
|
||||
|
||||
let total: u64 = all.iter().filter(|e| e.source == Source::Steam).map(|e| e.playtime_minutes).sum();
|
||||
let shot = std::env::var("SUMMIT_SHOT").ok();
|
||||
let build = || {
|
||||
let ui = MainWindow::new().unwrap();
|
||||
ui.set_home(ModelRc::new(VecModel::from(home.iter().map(|e| card(e, st.pinned.contains(&e.id), &st.artwork)).collect::<Vec<_>>())));
|
||||
ui.set_library(ModelRc::new(VecModel::from(lib.iter().map(|e| card(e, st.pinned.contains(&e.id), &st.artwork)).collect::<Vec<_>>())));
|
||||
ui.set_unfiltered(ModelRc::new(VecModel::from(unf)));
|
||||
ui.set_stats(format!("{} games in library · {} installed · {:.0} h on Steam", games.len(), games.iter().filter(|e| e.installed).count(), total as f64 / 60.0).into());
|
||||
ui.set_session(format!("{:?} · {:?}", display::detect_session(), display::detect_desktop()).into());
|
||||
if let Ok(t) = std::env::var("SUMMIT_LAYOUT") { ui.set_layout(t.parse().unwrap_or(0)); }
|
||||
if let Ok(t) = std::env::var("SUMMIT_THEME") { ui.set_theme(t.parse().unwrap_or(0)); }
|
||||
if let Ok(t) = std::env::var("SUMMIT_TAB") { ui.set_tab(t.parse().unwrap_or(0)); }
|
||||
if let Ok(s) = std::env::var("SUMMIT_ANIM") { ui.set_anim_speed(s.parse().unwrap_or(1.0)); }
|
||||
ui
|
||||
};
|
||||
match shot { Some(d) => shoot(&d, build), None => build().run().unwrap() }
|
||||
fn ints(v: Vec<usize>) -> ModelRc<i32> { ModelRc::new(VecModel::from(v.into_iter().map(|i| i as i32).collect::<Vec<_>>())) }
|
||||
|
||||
fn rebuild_shelves(&self) {
|
||||
let (recent, pins, most) = data::shelves(&self.entries.borrow(), &self.state.borrow().pinned);
|
||||
*self.keep.borrow_mut() = recent.iter().chain(&pins).chain(&most).copied().collect();
|
||||
let lib = self.ui.global::<Lib>();
|
||||
lib.set_recent(Self::ints(recent)); lib.set_pinned(Self::ints(pins)); lib.set_most(Self::ints(most));
|
||||
self.ui.invoke_resync();
|
||||
}
|
||||
|
||||
fn requery(&self) {
|
||||
let lib = self.ui.global::<Lib>();
|
||||
let v = data::library(&self.entries.borrow(), lib.get_filter(), lib.get_sort(), &lib.get_search());
|
||||
lib.set_library(Self::ints(v));
|
||||
}
|
||||
|
||||
fn fill_static(&self) {
|
||||
let entries = self.entries.borrow();
|
||||
let lib = self.ui.global::<Lib>();
|
||||
let rows: Vec<URow> = data::unfiltered(&entries).into_iter().map(|r| match r {
|
||||
data::Row::Header { label, count } => URow { header: true, label: label.into(), count: count as i32, idx: 0 },
|
||||
data::Row::Item(i) => URow { header: false, label: SharedString::new(), count: 0, idx: i as i32 },
|
||||
}).collect();
|
||||
lib.set_unfiltered(ModelRc::new(VecModel::from(rows)));
|
||||
let games: Vec<&Entry> = entries.iter().filter(|e| e.kind == Kind::Game).collect();
|
||||
let installed = games.iter().filter(|e| e.installed).count();
|
||||
let steam_minutes: u64 = entries.iter().filter(|e| e.source == Source::Steam).map(|e| e.playtime_minutes).sum();
|
||||
lib.set_total_games(games.len() as i32);
|
||||
lib.set_total_installed(installed as i32);
|
||||
lib.set_stats(format!("{} games · {} installed · {:.0} h on Steam", games.len(), installed, steam_minutes as f64 / 60.0).into());
|
||||
lib.set_session(format!("{:?} session, {:?} desktop", display::detect_session(), display::detect_desktop()).into());
|
||||
}
|
||||
|
||||
// ---- art ----
|
||||
fn want_cover(&self, idx: usize) {
|
||||
if idx >= self.entries.borrow().len() || !self.requested.borrow_mut().insert(idx) { return; }
|
||||
let path = self.cover_path(&self.entries.borrow()[idx]);
|
||||
if let Some(path) = path { self.loader.push(art::Job::Cover { idx, path }); }
|
||||
}
|
||||
|
||||
fn focus_game(&self, idx: i32) {
|
||||
if idx < 0 || idx as usize >= self.entries.borrow().len() || self.backdrop_for.get() == idx as i64 { return; }
|
||||
self.backdrop_for.set(idx as i64);
|
||||
let seq = self.backdrop_seq.get() + 1;
|
||||
self.backdrop_seq.set(seq);
|
||||
let e = self.entries.borrow()[idx as usize].clone();
|
||||
let (c1, c2) = data::colors(&e.title);
|
||||
self.loader.push(art::Job::Backdrop { idx: idx as usize, seq, hero: self.hero_path(&e), cover: self.cover_path(&e), logo: self.logo_path(&e), c1, c2 });
|
||||
}
|
||||
|
||||
pub fn apply(&self, done: art::Done) {
|
||||
match done {
|
||||
art::Done::Cover { idx, img } => {
|
||||
let Some(img) = img else { return };
|
||||
let Some(mut g) = self.games.row_data(idx) else { return };
|
||||
g.cover = Image::from_rgb8(img); g.has_cover = true;
|
||||
self.games.set_row_data(idx, g);
|
||||
let dropped: Vec<usize> = {
|
||||
let (mut loaded, keep) = (self.loaded.borrow_mut(), self.keep.borrow());
|
||||
loaded.push_back(idx);
|
||||
let mut out = vec![];
|
||||
let mut tries = loaded.len();
|
||||
while loaded.len() > COVERS_MAX && tries > 0 {
|
||||
tries -= 1;
|
||||
let Some(old) = loaded.pop_front() else { break };
|
||||
if keep.contains(&old) { loaded.push_back(old); } else { out.push(old); }
|
||||
}
|
||||
out
|
||||
};
|
||||
for old in dropped {
|
||||
self.requested.borrow_mut().remove(&old);
|
||||
if let Some(mut g) = self.games.row_data(old) { g.cover = Image::default(); g.has_cover = false; self.games.set_row_data(old, g); }
|
||||
}
|
||||
}
|
||||
art::Done::Backdrop { idx, seq, img, logo } => {
|
||||
if seq != self.backdrop_seq.get() { return; }
|
||||
let img = Image::from_rgb8(img);
|
||||
if self.ui.get_bg_flip() { self.ui.set_bg_a(img); self.ui.set_bg_flip(false); } else { self.ui.set_bg_b(img); self.ui.set_bg_flip(true); }
|
||||
match logo {
|
||||
Some(l) => { self.ui.set_logo(Image::from_rgba8(l)); self.ui.set_logo_idx(idx as i32); }
|
||||
None => self.ui.set_logo_idx(-1),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Headless mode: run the art jobs that are waiting, on this thread.
|
||||
pub fn drain_art(&self) -> usize {
|
||||
let jobs = self.loader.take();
|
||||
let n = jobs.len();
|
||||
for j in jobs { self.apply(art::run(j)); }
|
||||
n
|
||||
}
|
||||
|
||||
// ---- actions ----
|
||||
pub fn toast(&self, msg: impl Into<SharedString>) { self.ui.set_toast(msg.into()); self.ui.set_toast_shown(true); }
|
||||
|
||||
pub fn open_detail(&self, idx: i32) {
|
||||
let Some(e) = self.entries.borrow().get(idx.max(0) as usize).cloned() else { return };
|
||||
let p = data::profile_summary(&profile::load(&e.id).unwrap_or_default());
|
||||
let st = self.state.borrow();
|
||||
let (sessions, note) = if e.source == Source::Steam {
|
||||
("–".to_string(), "Steam does not report sessions")
|
||||
} else {
|
||||
(st.tracked.get(&e.id).map_or(0, |t| t.sessions).to_string(), "Counted when Summit starts it")
|
||||
};
|
||||
let (label, can, play_note) = match launch::plan(&e, self.cli().as_deref()) {
|
||||
launch::Plan::Run(_) if launch::is_install(&e) => ("INSTALL", true, "Opens Steam's install dialog for this game.".to_string()),
|
||||
launch::Plan::Run(_) if e.source == Source::Steam => ("PLAY", true, "Starts through the Steam client. Steam keeps the playtime.".to_string()),
|
||||
launch::Plan::Run(_) if e.source == Source::Lutris => ("PLAY", true, "Starts through Lutris. Not tested yet.".to_string()),
|
||||
launch::Plan::Run(_) => ("PLAY", true, "Summit starts it, applies the launch profile and tracks the session.".to_string()),
|
||||
launch::Plan::Unsupported(why) => ("PLAY", false, format!("Summit cannot start this yet: {why}.")),
|
||||
};
|
||||
let reasons: Vec<SharedString> = e.reasons.iter().map(|r| r.as_str().into()).collect();
|
||||
self.ui.global::<Lib>().set_detail(Detail {
|
||||
idx, sessions: sessions.into(), sessions_note: note.into(), reasons: ModelRc::new(VecModel::from(reasons)),
|
||||
path: e.path.clone().unwrap_or_default().into(),
|
||||
monitor: p.monitor.into(), mode: p.mode.into(), upscaler: p.upscaler.into(), framegen: p.framegen.into(), window: p.window.into(), profile_set: p.set,
|
||||
play_label: label.into(), play_note: play_note.into(), can_play: can,
|
||||
});
|
||||
drop(st);
|
||||
self.want_cover(idx as usize);
|
||||
self.ui.set_detail_open(true);
|
||||
self.focus_game(idx);
|
||||
}
|
||||
|
||||
fn play(&self, idx: i32) {
|
||||
let Some(e) = self.entries.borrow().get(idx.max(0) as usize).cloned() else { return };
|
||||
let argv = match launch::plan(&e, self.cli().as_deref()) {
|
||||
launch::Plan::Run(argv) => argv,
|
||||
launch::Plan::Unsupported(why) => return self.toast(format!("Cannot start {}: {why}", e.title)),
|
||||
};
|
||||
if self.headless { return self.toast(format!("Headless render, nothing started. Would run: {}", argv.join(" "))); }
|
||||
use std::process::{Command, Stdio};
|
||||
match Command::new(&argv[0]).args(&argv[1..]).stdin(Stdio::null()).stdout(Stdio::null()).stderr(Stdio::null()).spawn() {
|
||||
Ok(mut child) => {
|
||||
self.toast(if launch::is_install(&e) { format!("Asked Steam to install {}", e.title) } else if e.source == Source::Steam { format!("Starting {} through Steam", e.title) } else { format!("Starting {}", e.title) });
|
||||
// When it exits, pick up the session `summit run` recorded.
|
||||
std::thread::spawn(move || { let _ = child.wait(); let _ = slint::invoke_from_event_loop(|| with_app(|a| a.refresh_tracked())); });
|
||||
}
|
||||
Err(err) => self.toast(format!("Could not run {}: {err}", argv[0])),
|
||||
}
|
||||
}
|
||||
|
||||
fn refresh_row(&self, idx: usize) {
|
||||
let old = self.games.row_data(idx);
|
||||
let row = self.row(&self.entries.borrow()[idx], old.as_ref());
|
||||
self.games.set_row_data(idx, row);
|
||||
}
|
||||
|
||||
fn refresh_tracked(&self) {
|
||||
*self.state.borrow_mut() = state::load();
|
||||
state::apply(&mut self.entries.borrow_mut(), &self.state.borrow());
|
||||
let n = self.entries.borrow().len();
|
||||
for i in 0..n { if self.entries.borrow()[i].source != Source::Steam { self.refresh_row(i); } }
|
||||
self.rebuild_shelves();
|
||||
self.requery();
|
||||
}
|
||||
|
||||
fn toggle_pin(&self, idx: i32) {
|
||||
let Some(e) = self.entries.borrow().get(idx.max(0) as usize).cloned() else { return };
|
||||
// Load first, so a pin made from the command line while the window is open is not lost.
|
||||
let mut st = state::load();
|
||||
let pinned = st.toggle_pin(&e.id);
|
||||
match state::save(&st) {
|
||||
Ok(()) => {
|
||||
*self.state.borrow_mut() = st;
|
||||
self.refresh_row(idx as usize);
|
||||
self.rebuild_shelves();
|
||||
self.toast(if pinned { format!("Pinned {} to Home", e.title) } else { format!("Unpinned {}", e.title) });
|
||||
}
|
||||
Err(err) => self.toast(format!("Could not save the pin: {err}")),
|
||||
}
|
||||
}
|
||||
|
||||
// ---- settings ----
|
||||
fn load_settings_into_ui(&self) {
|
||||
let s = self.settings.borrow();
|
||||
self.ui.set_layout(s.layout_index() as i32);
|
||||
self.ui.set_theme(self.theme_keys.iter().position(|k| *k == s.theme).unwrap_or(0) as i32);
|
||||
self.ui.set_anim_speed(s.anim_speed);
|
||||
self.ui.set_anim_style(s.anim_style_index() as i32);
|
||||
let p = self.ui.global::<Prefs>();
|
||||
p.set_scale(nearest(prefs::UI_SCALES, s.ui_scale) as i32);
|
||||
p.set_replay(prefs::CLIP_LENGTHS.iter().position(|c| *c == s.replay_seconds).unwrap_or(2) as i32);
|
||||
p.set_clip(prefs::CLIP_LENGTHS.iter().position(|c| *c == s.clip_seconds).unwrap_or(1) as i32);
|
||||
p.set_clip_lengths(ModelRc::new(VecModel::from(prefs::CLIP_LENGTHS.iter().map(|c| prefs::clip_label(*c).into()).collect::<Vec<SharedString>>())));
|
||||
p.set_scales(ModelRc::new(VecModel::from(prefs::UI_SCALES.iter().map(|c| format!("{:.0}%", c * 100.0).into()).collect::<Vec<SharedString>>())));
|
||||
p.set_file(prefs::path().map(|f| tilde(&f)).unwrap_or_default().into());
|
||||
let d = self.default_profile.borrow();
|
||||
p.set_upscaler(match d.upscaler.as_str() { "fsr" => 1, "rtx-vsr" | "vsr" => 2, _ => 0 });
|
||||
p.set_framegen(if d.framegen == "rife" { 1 } else { 0 });
|
||||
}
|
||||
|
||||
fn settings_from_ui(&self) -> prefs::UiSettings {
|
||||
let p = self.ui.global::<Prefs>();
|
||||
let pick = |v: i32, n: usize| (v.max(0) as usize).min(n - 1);
|
||||
prefs::UiSettings {
|
||||
layout: prefs::LAYOUTS[pick(self.ui.get_layout(), 3)].into(),
|
||||
theme: self.theme_keys.get(self.ui.get_theme().max(0) as usize).cloned().unwrap_or_else(|| "midnight".into()),
|
||||
anim_speed: self.ui.get_anim_speed(),
|
||||
anim_style: prefs::ANIM_STYLES[pick(self.ui.get_anim_style(), 3)].into(),
|
||||
ui_scale: prefs::UI_SCALES[pick(p.get_scale(), prefs::UI_SCALES.len())],
|
||||
replay_seconds: prefs::CLIP_LENGTHS[pick(p.get_replay(), 6)],
|
||||
clip_seconds: prefs::CLIP_LENGTHS[pick(p.get_clip(), 6)],
|
||||
}.sanitized()
|
||||
}
|
||||
|
||||
fn settings_changed(&self) {
|
||||
let new = self.settings_from_ui();
|
||||
let scale_changed = new.ui_scale != self.settings.borrow().ui_scale;
|
||||
if new != *self.settings.borrow() {
|
||||
*self.settings.borrow_mut() = new;
|
||||
if self.headless { self.save_settings(); } else {
|
||||
// a slider drag changes the value many times a second: write once it settles
|
||||
self.save_timer.start(slint::TimerMode::SingleShot, std::time::Duration::from_millis(350), || with_app(|a| a.save_settings()));
|
||||
}
|
||||
}
|
||||
if scale_changed { self.apply_scale(); }
|
||||
let p = self.ui.global::<Prefs>();
|
||||
let (up, fg) = (["none", "fsr", "rtx-vsr"][p.get_upscaler().clamp(0, 2) as usize], ["none", "rife"][p.get_framegen().clamp(0, 1) as usize]);
|
||||
let mut d = self.default_profile.borrow_mut();
|
||||
let same = |a: &str, b: &str| a == b || (a.is_empty() && b == "none");
|
||||
if !same(&d.upscaler, up) || !same(&d.framegen, fg) {
|
||||
d.upscaler = up.into(); d.framegen = fg.into();
|
||||
if let Err(err) = profile::save("default", &d) { self.toast(format!("Could not save the default profile: {err}")); }
|
||||
}
|
||||
}
|
||||
|
||||
fn save_settings(&self) {
|
||||
if let Err(err) = prefs::save(&self.settings.borrow()) { self.toast(format!("Could not save settings: {err}")); }
|
||||
}
|
||||
|
||||
/// The launcher's own scale sits on top of the system's scale factor.
|
||||
pub fn apply_scale(&self) {
|
||||
let f = self.base_scale.get() * self.settings.borrow().ui_scale;
|
||||
self.ui.window().dispatch_event(slint::platform::WindowEvent::ScaleFactorChanged { scale_factor: f });
|
||||
if !self.headless {
|
||||
// the window keeps its size in pixels, so lay it out again at the new scale
|
||||
let s = self.ui.window().size();
|
||||
self.ui.window().dispatch_event(slint::platform::WindowEvent::Resized { size: s.to_logical(f) });
|
||||
}
|
||||
}
|
||||
|
||||
fn toggle_fullscreen(&self) {
|
||||
self.fullscreen.set(!self.fullscreen.get());
|
||||
self.ui.window().set_fullscreen(self.fullscreen.get());
|
||||
}
|
||||
}
|
||||
|
||||
/// Headless renderer for README screenshots: no display needed. Writes tab0..2.ppm into `dir`.
|
||||
fn shoot(dir: &str, build: impl FnOnce() -> MainWindow) {
|
||||
use slint::platform::software_renderer::{MinimalSoftwareWindow, RepaintBufferType, Rgb565Pixel};
|
||||
let _ = Rgb565Pixel::default();
|
||||
struct P(std::rc::Rc<MinimalSoftwareWindow>);
|
||||
impl slint::platform::Platform for P {
|
||||
fn create_window_adapter(&self) -> Result<std::rc::Rc<dyn slint::platform::WindowAdapter>, slint::PlatformError> { Ok(self.0.clone()) }
|
||||
}
|
||||
let win = MinimalSoftwareWindow::new(RepaintBufferType::NewBuffer);
|
||||
slint::platform::set_platform(Box::new(P(win.clone()))).unwrap();
|
||||
let (w, h) = (1600u32, 900u32);
|
||||
win.set_size(slint::PhysicalSize::new(w, h));
|
||||
let ui = build();
|
||||
ui.set_anim_speed(0.0);
|
||||
ui.show().unwrap();
|
||||
for t in 0..3 {
|
||||
ui.set_tab(t);
|
||||
slint::platform::update_timers_and_animations();
|
||||
let mut buf = vec![slint::Rgb8Pixel::default(); (w * h) as usize];
|
||||
win.draw_if_needed(|r| { r.render(&mut buf, w as usize); });
|
||||
let mut out = format!("P6\n{w} {h}\n255\n").into_bytes();
|
||||
for p in &buf { out.extend_from_slice(&[p.r, p.g, p.b]); }
|
||||
std::fs::write(format!("{dir}/tab{t}.ppm"), out).unwrap();
|
||||
}
|
||||
fn nearest(all: &[f32], v: f32) -> usize {
|
||||
(0..all.len()).min_by(|a, b| (all[*a] - v).abs().total_cmp(&(all[*b] - v).abs())).unwrap_or(0)
|
||||
}
|
||||
fn tilde(p: &std::path::Path) -> String {
|
||||
let s = p.to_string_lossy().into_owned();
|
||||
match std::env::var("HOME") { Ok(h) if !h.is_empty() && s.starts_with(&h) => format!("~{}", &s[h.len()..]), _ => s }
|
||||
}
|
||||
|
||||
/// Look a name up in a list ("grid", "violet") or take a number.
|
||||
fn pick(v: &str, names: &[String]) -> Option<i32> {
|
||||
let v = v.trim().to_lowercase();
|
||||
names.iter().position(|n| *n == v).map(|i| i as i32).or_else(|| v.parse().ok())
|
||||
}
|
||||
|
||||
/// Create the window, scan the library and wire everything up. The platform must already be set for headless use.
|
||||
pub fn build(headless: bool) -> Rc<App> {
|
||||
let args: Vec<String> = std::env::args().skip(1).collect();
|
||||
let folders: Vec<PathBuf> = args.iter().filter(|a| !a.starts_with("--")).map(Into::into).collect();
|
||||
let mut entries = scan::full(&folders, 4);
|
||||
let st = state::load();
|
||||
state::apply(&mut entries, &st);
|
||||
|
||||
let ui = MainWindow::new().expect("could not create the window");
|
||||
let theme_keys: Vec<String> = ui.get_palettes().iter().map(|p| p.key.to_string()).collect();
|
||||
let loader = if headless { art::Loader::queued() } else {
|
||||
art::Loader::threaded(|done| { let _ = slint::invoke_from_event_loop(move || with_app(|a| a.apply(done))); })
|
||||
};
|
||||
let app = Rc::new(App {
|
||||
ui, entries: RefCell::new(entries), state: RefCell::new(st), games: Rc::new(VecModel::default()), loader,
|
||||
requested: Default::default(), loaded: Default::default(), keep: Default::default(),
|
||||
backdrop_seq: Cell::new(0), backdrop_for: Cell::new(-1),
|
||||
settings: RefCell::new(prefs::load()), default_profile: RefCell::new(profile::load("default").unwrap_or_default()),
|
||||
theme_keys, headless, base_scale: Cell::new(1.0), fullscreen: Cell::new(false), save_timer: slint::Timer::default(),
|
||||
});
|
||||
APP.with(|a| *a.borrow_mut() = Some(app.clone()));
|
||||
|
||||
let rows: Vec<Game> = app.entries.borrow().iter().map(|e| app.row(e, None)).collect();
|
||||
app.games.set_vec(rows);
|
||||
let lib = app.ui.global::<Lib>();
|
||||
lib.set_games(ModelRc::from(app.games.clone()));
|
||||
lib.set_renderer(match std::env::var("SLINT_BACKEND") {
|
||||
Ok(b) if !b.is_empty() => format!("SLINT_BACKEND={b}"),
|
||||
_ if headless => "software renderer (headless)".into(),
|
||||
_ => "OpenGL renderer (FemtoVG), software fallback".into(),
|
||||
}.into());
|
||||
app.fill_static();
|
||||
app.load_settings_into_ui();
|
||||
|
||||
lib.on_want_cover(|i| with_app(|a| a.want_cover(i.max(0) as usize)));
|
||||
lib.on_focus_game(|i| with_app(|a| a.focus_game(i)));
|
||||
lib.on_query(|| with_app(|a| a.requery()));
|
||||
lib.on_open_detail(|i| with_app(|a| a.open_detail(i)));
|
||||
lib.on_play(|i| with_app(|a| a.play(i)));
|
||||
lib.on_toggle_pin(|i| with_app(|a| a.toggle_pin(i)));
|
||||
lib.on_settings_changed(|| with_app(|a| a.settings_changed()));
|
||||
lib.on_toggle_fullscreen(|| with_app(|a| a.toggle_fullscreen()));
|
||||
|
||||
// Overrides for screenshots and testing. They are not written to ui.toml unless a setting is changed afterwards.
|
||||
let env = |k: &str| std::env::var(k).ok().filter(|v| !v.is_empty());
|
||||
let names = |v: &[&str]| v.iter().map(|s| s.to_string()).collect::<Vec<_>>();
|
||||
if let Some(v) = env("SUMMIT_LAYOUT").and_then(|v| pick(&v, &names(prefs::LAYOUTS))) { app.ui.set_layout(v.clamp(0, 2)); }
|
||||
if let Some(v) = env("SUMMIT_THEME").and_then(|v| pick(&v, &app.theme_keys)) { app.ui.set_theme(v.clamp(0, app.theme_keys.len() as i32 - 1)); }
|
||||
if let Some(v) = env("SUMMIT_ANIM").and_then(|v| v.parse::<f32>().ok()) { app.ui.set_anim_speed(v.clamp(0.0, 2.0)); }
|
||||
if let Some(v) = env("SUMMIT_SCALE").and_then(|v| v.parse::<f32>().ok()) { app.settings.borrow_mut().ui_scale = v.clamp(0.5, 3.0); }
|
||||
app.rebuild_shelves();
|
||||
app.requery();
|
||||
if let Some(v) = env("SUMMIT_VIEW").or_else(|| env("SUMMIT_TAB")).and_then(|v| pick(&v, &names(&["home", "library", "unfiltered", "settings"]))) { app.ui.invoke_goto(v.clamp(0, 3)); }
|
||||
if let Some(v) = env("SUMMIT_FOCUS").and_then(|v| v.parse::<i32>().ok()) { app.ui.set_lib_focus(v); app.ui.set_unf_focus(v); app.ui.set_settings_row(v.clamp(0, 8)); }
|
||||
if let Some(want) = env("SUMMIT_DETAIL") {
|
||||
let w = want.to_lowercase();
|
||||
let hit = app.entries.borrow().iter().position(|e| e.id.to_lowercase() == w).or_else(|| app.entries.borrow().iter().position(|e| e.title.to_lowercase().contains(&w)));
|
||||
if let Some(i) = hit { app.open_detail(i as i32); }
|
||||
}
|
||||
app
|
||||
}
|
||||
|
||||
fn main() {
|
||||
if let Ok(dir) = std::env::var("SUMMIT_SHOT") { return shot::run(&dir); }
|
||||
let app = build(false);
|
||||
if std::env::args().any(|a| a == "--fullscreen") { app.toggle_fullscreen(); }
|
||||
app.ui.show().expect("could not show the window");
|
||||
// The backend sets the system's scale factor when it creates the window, so ours goes on top once that has happened.
|
||||
slint::Timer::single_shot(std::time::Duration::from_millis(60), || with_app(|a| {
|
||||
a.base_scale.set(a.ui.window().scale_factor());
|
||||
if (a.settings.borrow().ui_scale - 1.0).abs() > 0.001 { a.apply_scale(); }
|
||||
}));
|
||||
// Test hook: SUMMIT_KEYS="Down Right Enter" presses those keys, one every 400 ms.
|
||||
let keys_timer = slint::Timer::default();
|
||||
if let Ok(keys) = std::env::var("SUMMIT_KEYS") {
|
||||
let mut queue: VecDeque<String> = keys.split_whitespace().map(String::from).collect();
|
||||
keys_timer.start(slint::TimerMode::Repeated, std::time::Duration::from_millis(400), move || {
|
||||
if let Some(k) = queue.pop_front() { with_app(|a| shot::press(a.ui.window(), &k)); }
|
||||
});
|
||||
}
|
||||
slint::run_event_loop().expect("event loop");
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
//! Headless renders with the software renderer, for README screenshots and for checking the UI without a display.
|
||||
//!
|
||||
//! SUMMIT_SHOT=<dir> write <dir>/<name>.png and exit
|
||||
//! SUMMIT_NAME=<name> file name without extension (default "shot")
|
||||
//! SUMMIT_SIZE=1600x900 window size in pixels
|
||||
//! SUMMIT_VIEW=home|library|unfiltered|settings SUMMIT_LAYOUT=bigpicture|grid|list SUMMIT_THEME=<key>
|
||||
//! SUMMIT_DETAIL=<entry id or part of a title> open that game's page
|
||||
//! SUMMIT_FOCUS=<n> focused item in the library, unfiltered list or settings
|
||||
//! SUMMIT_KEYS="Down Right Enter" press keys before the render
|
||||
//! SUMMIT_SCALE=1.25 interface scale
|
||||
//!
|
||||
//! Animations are off in these renders: each one is the settled state.
|
||||
use slint::platform::software_renderer::{MinimalSoftwareWindow, RepaintBufferType};
|
||||
use slint::platform::{Key, WindowEvent};
|
||||
use slint::ComponentHandle;
|
||||
use std::rc::Rc;
|
||||
|
||||
fn key_text(name: &str) -> slint::SharedString {
|
||||
let k = match name.to_lowercase().as_str() {
|
||||
"up" => Key::UpArrow, "down" => Key::DownArrow, "left" => Key::LeftArrow, "right" => Key::RightArrow,
|
||||
"enter" | "return" => Key::Return, "esc" | "escape" => Key::Escape, "tab" => Key::Tab, "backtab" => Key::Backtab,
|
||||
"pagedown" => Key::PageDown, "pageup" => Key::PageUp, "home" => Key::Home, "end" => Key::End, "f11" => Key::F11,
|
||||
"backspace" => Key::Backspace,
|
||||
"space" => return " ".into(),
|
||||
_ => return name.into(),
|
||||
};
|
||||
k.into()
|
||||
}
|
||||
|
||||
/// Press and release one key, named as in SUMMIT_KEYS. Anything that is not a key name is typed as text.
|
||||
/// Two extras for tests: "wheel:-240" scrolls at the middle of the window, "wait:300" sleeps that many milliseconds.
|
||||
pub fn press(window: &slint::Window, name: &str) {
|
||||
if let Some(ms) = name.strip_prefix("wait:").and_then(|v| v.parse::<u64>().ok()) {
|
||||
let until = std::time::Instant::now() + std::time::Duration::from_millis(ms);
|
||||
while std::time::Instant::now() < until { slint::platform::update_timers_and_animations(); std::thread::sleep(std::time::Duration::from_millis(8)); }
|
||||
return;
|
||||
}
|
||||
if let Some(dy) = name.strip_prefix("wheel:").and_then(|v| v.parse::<f32>().ok()) {
|
||||
let s = window.size().to_logical(window.scale_factor());
|
||||
let position = slint::LogicalPosition::new(s.width / 2.0, s.height / 2.0);
|
||||
window.dispatch_event(WindowEvent::PointerMoved { position });
|
||||
window.dispatch_event(WindowEvent::PointerScrolled { position, delta_x: 0.0, delta_y: dy });
|
||||
return;
|
||||
}
|
||||
let text = key_text(name);
|
||||
window.dispatch_event(WindowEvent::KeyPressed { text: text.clone() });
|
||||
window.dispatch_event(WindowEvent::KeyReleased { text });
|
||||
}
|
||||
|
||||
struct Headless(Rc<MinimalSoftwareWindow>);
|
||||
impl slint::platform::Platform for Headless {
|
||||
fn create_window_adapter(&self) -> Result<Rc<dyn slint::platform::WindowAdapter>, slint::PlatformError> { Ok(self.0.clone()) }
|
||||
}
|
||||
|
||||
pub fn run(dir: &str) {
|
||||
let env = |k: &str| std::env::var(k).ok().filter(|v| !v.is_empty());
|
||||
let (w, h) = env("SUMMIT_SIZE").and_then(|s| { let (a, b) = s.split_once('x')?; Some((a.parse().ok()?, b.parse().ok()?)) }).unwrap_or((1600u32, 900u32));
|
||||
let win = MinimalSoftwareWindow::new(RepaintBufferType::NewBuffer);
|
||||
slint::platform::set_platform(Box::new(Headless(win.clone()))).expect("platform already set");
|
||||
win.set_size(slint::PhysicalSize::new(w, h));
|
||||
|
||||
let app = crate::build(true);
|
||||
// SUMMIT_MOTION=1 keeps animations running, to test them with "wait:" steps
|
||||
app.ui.set_still(env("SUMMIT_MOTION").is_none());
|
||||
app.ui.show().expect("show");
|
||||
app.apply_scale();
|
||||
win.set_size(slint::PhysicalSize::new(w, h)); // the size is in pixels whatever the scale
|
||||
|
||||
let mut buf = vec![slint::Rgb8Pixel::default(); (w * h) as usize];
|
||||
// Draw, then load the art the visible items asked for, until nothing new is asked for.
|
||||
let settle = |buf: &mut Vec<slint::Rgb8Pixel>| {
|
||||
for _ in 0..6 {
|
||||
slint::platform::update_timers_and_animations();
|
||||
win.request_redraw();
|
||||
win.draw_if_needed(|r| { r.render(buf, w as usize); });
|
||||
if app.drain_art() == 0 { break; }
|
||||
}
|
||||
};
|
||||
settle(&mut buf);
|
||||
for k in env("SUMMIT_KEYS").unwrap_or_default().split_whitespace() {
|
||||
press(app.ui.window(), k);
|
||||
settle(&mut buf);
|
||||
}
|
||||
settle(&mut buf);
|
||||
|
||||
let raw: Vec<u8> = buf.iter().flat_map(|p| [p.r, p.g, p.b]).collect();
|
||||
let out = std::path::Path::new(dir).join(format!("{}.png", env("SUMMIT_NAME").unwrap_or_else(|| "shot".into())));
|
||||
std::fs::create_dir_all(dir).expect("create output folder");
|
||||
image::RgbImage::from_raw(w, h, raw).expect("buffer size").save(&out).expect("write png");
|
||||
println!("{}", out.display());
|
||||
}
|
||||
+186
-156
@@ -1,178 +1,208 @@
|
||||
import { ScrollView, Slider } from "std-widgets.slint";
|
||||
// Summit launcher window: navbar, the four views, a game's page, the art backdrop and keyboard navigation.
|
||||
import { Theme, Palette } from "theme.slint";
|
||||
import { Lib, Prefs, Game, URow, Detail, Icon, Icons, Wordmark, KeyCap, Toast, FocusRing } from "widgets.slint";
|
||||
import { HomeView } from "home.slint";
|
||||
import { LibraryView, UnfilteredView } from "library.slint";
|
||||
import { DetailView } from "detail.slint";
|
||||
import { SettingsView } from "settings.slint";
|
||||
export { Lib, Prefs, Game, URow, Detail, Palette }
|
||||
|
||||
export struct Card {
|
||||
title: string, hours: string, source: string, installed: bool,
|
||||
cover: image, has-cover: bool, pinned: bool, reasons: string, section: bool, accent: color,
|
||||
}
|
||||
|
||||
global Theme {
|
||||
// 0 Midnight, 1 Steam blue, 2 Daylight, 3 Violet
|
||||
in-out property <int> id: 0;
|
||||
out property <color> bg: id == 0 ? #0b0d12 : id == 1 ? #171a21 : id == 2 ? #eef0f4 : #120d1f;
|
||||
out property <color> panel: id == 0 ? #12151c : id == 1 ? #1b2838 : id == 2 ? #ffffff : #1b1430;
|
||||
out property <color> line: id == 0 ? #1f2430 : id == 1 ? #2a475e : id == 2 ? #d5d9e2 : #2c2150;
|
||||
out property <color> text: id == 2 ? #14171f : #e8ebf2;
|
||||
out property <color> dim: id == 2 ? #5b6475 : id == 1 ? #8f98a0 : #8a93a6;
|
||||
out property <color> accent: id == 0 ? #ffb02e : id == 1 ? #66c0f4 : id == 2 ? #2563eb : #b388ff;
|
||||
// Animation speed multiplier, user tweakable (1.0 = default, 0 = off).
|
||||
in-out property <float> speed: 1.0;
|
||||
pure public function ms(base: int) -> duration { return (base * 1ms) / Math.max(root.speed, 0.01) * (root.speed > 0 ? 1 : 0); }
|
||||
}
|
||||
|
||||
component Tab inherits Rectangle {
|
||||
component NavTab inherits Rectangle {
|
||||
in property <string> label;
|
||||
in property <string> icon;
|
||||
in property <bool> active;
|
||||
in property <bool> focused;
|
||||
callback clicked;
|
||||
width: l.preferred-width + 36px; height: 44px;
|
||||
background: transparent;
|
||||
l := Text { text: root.label; color: root.active ? Theme.text : Theme.dim; font-size: 15px; font-weight: root.active ? 700 : 500; horizontal-alignment: center; vertical-alignment: center;
|
||||
height: Theme.big ? 44px : 38px; width: (root.label == "" ? 0px : l.preferred-width + 10px) + self.height + (root.label == "" ? 0px : 10px);
|
||||
border-radius: self.height / 2;
|
||||
background: root.active ? Theme.p.raised.with-alpha(0.9) : ta.has-hover ? Theme.p.raised.with-alpha(0.5) : transparent;
|
||||
border-width: root.active ? Theme.p.border-w : 0px; border-color: Theme.p.border;
|
||||
animate background { duration: Theme.ms(180); }
|
||||
Icon { x: (root.height - 20px) / 2 + (root.label == "" ? 0px : 4px); y: (root.height - 20px) / 2; size: 20px; color: root.active ? Theme.p.accent : Theme.p.dim; commands: root.icon; }
|
||||
l := Text { x: root.height + 2px; height: parent.height; text: root.label; color: root.active ? Theme.p.text : Theme.p.dim; font-size: Theme.big ? Theme.t-md + 1px : Theme.t-md; font-weight: root.active ? 700 : 500; vertical-alignment: center;
|
||||
animate color { duration: Theme.ms(180); } }
|
||||
Rectangle { y: parent.height - 3px; height: 3px; border-radius: 2px; background: Theme.accent;
|
||||
width: root.active ? parent.width - 28px : 0px; x: (parent.width - self.width) / 2;
|
||||
animate width { duration: Theme.ms(260); easing: ease-out-expo; } }
|
||||
ta := TouchArea { clicked => { root.clicked(); } }
|
||||
FocusRing { on: root.focused; radius: root.height / 2; }
|
||||
ta := TouchArea { mouse-cursor: pointer; clicked => { root.clicked(); } }
|
||||
}
|
||||
|
||||
component CoverCard inherits Rectangle {
|
||||
in property <Card> c;
|
||||
callback pin;
|
||||
width: 190px; height: 330px; background: transparent;
|
||||
property <bool> hot: ta.has-hover;
|
||||
box := Rectangle {
|
||||
width: parent.width; height: 285px; border-radius: 10px; clip: true; background: Theme.panel;
|
||||
y: root.hot ? -6px : 0px;
|
||||
animate y { duration: Theme.ms(180); easing: ease-out; }
|
||||
drop-shadow-blur: root.hot ? 26px : 8px; drop-shadow-color: root.hot ? Theme.accent.with-alpha(0.35) : #00000088; drop-shadow-offset-y: 6px;
|
||||
animate drop-shadow-blur { duration: Theme.ms(200); }
|
||||
if root.c.has-cover: Image { source: root.c.cover; width: parent.width; height: parent.height; image-fit: cover; opacity: root.c.installed ? 1.0 : 0.5; }
|
||||
if !root.c.has-cover: Rectangle {
|
||||
background: @linear-gradient(160deg, root.c.accent, #12151c);
|
||||
Text { text: root.c.title; color: white; font-size: 20px; font-weight: 800; wrap: word-wrap; width: parent.width - 28px; horizontal-alignment: center; vertical-alignment: center; }
|
||||
}
|
||||
Rectangle { y: parent.height - 52px; height: 52px; background: @linear-gradient(180deg, #00000000, #000000d0);
|
||||
Text { text: root.c.hours; color: Theme.accent; font-size: 13px; font-weight: 700; x: 12px; y: 24px; } }
|
||||
if !root.c.installed: Rectangle { x: 10px; y: 10px; width: 78px; height: 24px; border-radius: 12px; background: #000000b0;
|
||||
Text { text: "Not installed"; color: Theme.text; font-size: 11px; } }
|
||||
if root.c.pinned: Rectangle { x: parent.width - 34px; y: 10px; width: 24px; height: 24px; border-radius: 12px; background: Theme.accent;
|
||||
Text { text: "★"; color: #1a1300; font-size: 13px; font-weight: 800; } }
|
||||
}
|
||||
Text { y: 295px; text: root.c.title; color: Theme.text; font-size: 13px; font-weight: 600; width: parent.width; overflow: elide; }
|
||||
ta := TouchArea { clicked => { root.pin(); } }
|
||||
}
|
||||
|
||||
component ListRow inherits Rectangle {
|
||||
in property <Card> c;
|
||||
callback pin;
|
||||
height: 64px; border-radius: 8px;
|
||||
background: ta.has-hover ? Theme.panel : transparent;
|
||||
animate background { duration: Theme.ms(140); }
|
||||
Rectangle { x: 10px; y: 6px; width: 38px; height: 52px; border-radius: 5px; clip: true; background: Theme.line;
|
||||
if root.c.has-cover: Image { source: root.c.cover; width: parent.width; height: parent.height; image-fit: cover; opacity: root.c.installed ? 1.0 : 0.5; }
|
||||
if !root.c.has-cover: Rectangle { background: root.c.accent; } }
|
||||
Text { x: 64px; text: root.c.title; color: root.c.installed ? Theme.text : Theme.dim; font-size: 15px; font-weight: 600; vertical-alignment: center; width: 420px; overflow: elide; }
|
||||
Text { x: 500px; text: root.c.hours; color: Theme.accent; font-size: 13px; font-weight: 700; vertical-alignment: center; width: 110px; }
|
||||
Text { x: 620px; text: root.c.source; color: Theme.dim; font-size: 12px; vertical-alignment: center; width: 200px; }
|
||||
Text { x: 830px; text: root.c.installed ? "Installed" : "Not installed"; color: Theme.dim; font-size: 12px; vertical-alignment: center; }
|
||||
if root.c.pinned: Text { x: parent.width - 40px; text: "★"; color: Theme.accent; font-size: 16px; vertical-alignment: center; }
|
||||
ta := TouchArea { clicked => { root.pin(); } }
|
||||
}
|
||||
|
||||
component CardView inherits Rectangle {
|
||||
in property <[Card]> cards;
|
||||
in property <int> layout;
|
||||
callback pin(int);
|
||||
height: layout == 0 ? 345px * ceil(cards.length / 7.0) : 66px * cards.length;
|
||||
if root.layout == 0: Rectangle {
|
||||
for c[i] in root.cards: CoverCard { c: c; x: mod(i, 7) * 208px; y: floor(i / 7) * 345px; pin => { root.pin(i); } }
|
||||
}
|
||||
if root.layout == 1: Rectangle {
|
||||
for c[i] in root.cards: ListRow { c: c; y: i * 66px; width: root.width; pin => { root.pin(i); } }
|
||||
// The focused game's art behind the hero, cross-faded between two layers and faded into the theme background.
|
||||
component Backdrop inherits Rectangle {
|
||||
in property <image> a;
|
||||
in property <image> b;
|
||||
in property <bool> flip;
|
||||
in property <length> art-h;
|
||||
in property <float> dim;
|
||||
clip: true;
|
||||
Rectangle {
|
||||
y: 0; height: root.art-h;
|
||||
animate height { duration: Theme.ms(360); easing: Theme.ease; }
|
||||
Image { source: root.a; width: parent.width; height: parent.height; image-fit: cover; opacity: root.flip ? 0 : 1; animate opacity { duration: Theme.ms(420); easing: ease-in-out; } }
|
||||
Image { source: root.b; width: parent.width; height: parent.height; image-fit: cover; opacity: root.flip ? 1 : 0; animate opacity { duration: Theme.ms(420); easing: ease-in-out; } }
|
||||
Rectangle { x: 0; width: parent.width * 0.8; background: @linear-gradient(90deg, Theme.p.bg.with-alpha(Theme.p.scrim) 0%, Theme.p.bg.with-alpha(Theme.p.scrim * 0.72) 38%, Theme.p.bg.with-alpha(0) 100%); }
|
||||
Rectangle { y: 0; height: 132px; background: @linear-gradient(180deg, Theme.p.bg.with-alpha(0.8) 0%, Theme.p.bg.with-alpha(0) 100%); }
|
||||
Rectangle { y: parent.height * 0.42; height: parent.height * 0.58 + 1px; background: @linear-gradient(180deg, Theme.p.bg.with-alpha(0) 0%, Theme.p.bg.with-alpha(0.7) 55%, Theme.p.bg 100%); }
|
||||
}
|
||||
Rectangle { background: Theme.p.bg.with-alpha(root.dim); animate background { duration: Theme.ms(300); } }
|
||||
}
|
||||
|
||||
export component MainWindow inherits Window {
|
||||
title: "Summit";
|
||||
preferred-width: 1600px; preferred-height: 900px; background: Theme.bg;
|
||||
in property <[Card]> home;
|
||||
in property <[Card]> library;
|
||||
in property <[Card]> unfiltered;
|
||||
in property <string> stats;
|
||||
in property <string> session;
|
||||
in-out property <int> tab: 0;
|
||||
in-out property <int> layout: 0;
|
||||
in-out property <int> theme <=> Theme.id;
|
||||
in-out property <float> anim-speed <=> Theme.speed;
|
||||
callback pin(int);
|
||||
preferred-width: 1600px; preferred-height: 900px; min-width: 880px; min-height: 560px;
|
||||
background: Theme.p.bg;
|
||||
default-font-size: Theme.t-md;
|
||||
forward-focus: fs;
|
||||
|
||||
VerticalLayout {
|
||||
Rectangle { height: 64px; background: Theme.panel;
|
||||
Rectangle { y: parent.height - 1px; height: 1px; background: Theme.line; }
|
||||
HorizontalLayout { padding-left: 28px; padding-right: 28px; spacing: 8px; alignment: start;
|
||||
Text { text: "▲ SUMMIT"; color: Theme.accent; font-size: 19px; font-weight: 900; vertical-alignment: center; letter-spacing: 3px; }
|
||||
Rectangle { width: 36px; }
|
||||
Tab { label: "Home"; active: root.tab == 0; clicked => { root.tab = 0; } }
|
||||
Tab { label: "Library"; active: root.tab == 1; clicked => { root.tab = 1; } }
|
||||
Tab { label: "Unfiltered"; active: root.tab == 2; clicked => { root.tab = 2; } }
|
||||
Rectangle { horizontal-stretch: 1; }
|
||||
Rectangle { width: 74px; height: 30px; y: 17px; border-radius: 6px; background: Theme.line;
|
||||
Text { text: root.layout == 0 ? "Big grid" : "List"; color: Theme.text; font-size: 12px; horizontal-alignment: center; vertical-alignment: center; }
|
||||
TouchArea { clicked => { root.layout = root.layout == 0 ? 1 : 0; } } }
|
||||
Rectangle { width: 6px; }
|
||||
Rectangle { width: 92px; height: 30px; y: 17px; border-radius: 6px; background: Theme.line;
|
||||
Text { text: root.theme == 0 ? "Midnight" : root.theme == 1 ? "Steam blue" : root.theme == 2 ? "Daylight" : "Violet"; color: Theme.accent; font-size: 12px; horizontal-alignment: center; vertical-alignment: center; }
|
||||
TouchArea { clicked => { root.theme = mod(root.theme + 1, 4); } } }
|
||||
Rectangle { width: 14px; }
|
||||
Text { text: "Animations"; color: Theme.dim; font-size: 12px; vertical-alignment: center; }
|
||||
Slider { width: 110px; minimum: 0; maximum: 2; value <=> Theme.speed; }
|
||||
Rectangle { width: 14px; }
|
||||
Text { text: root.session; color: Theme.dim; font-size: 12px; vertical-alignment: center; }
|
||||
// theme, layout and motion, for Rust (ui.toml) and the SUMMIT_* overrides
|
||||
in-out property <int> theme <=> Theme.id;
|
||||
in-out property <int> layout <=> Theme.layout;
|
||||
in-out property <float> anim-speed <=> Theme.speed;
|
||||
in-out property <int> anim-style <=> Theme.style;
|
||||
out property <[Palette]> palettes: Theme.palettes;
|
||||
in property <bool> still <=> Theme.still;
|
||||
in-out property <int> view: 0; // 0 home, 1 library, 2 unfiltered, 3 settings
|
||||
in-out property <int> zone: 1; // 0 navbar, 1 content
|
||||
in-out property <bool> detail-open: false;
|
||||
in property <image> bg-a;
|
||||
in property <image> bg-b;
|
||||
in property <bool> bg-flip;
|
||||
in property <image> logo;
|
||||
in property <int> logo-idx: -1;
|
||||
in-out property <string> toast;
|
||||
in-out property <bool> toast-shown;
|
||||
in-out property <int> home-row <=> home.srow;
|
||||
in-out property <int> lib-focus <=> library.sel;
|
||||
in-out property <int> lib-zone <=> library.zone;
|
||||
in-out property <int> unf-focus <=> unfiltered.sel;
|
||||
in-out property <int> settings-row <=> settings.srow;
|
||||
out property <int> hero-idx: home.hero-idx;
|
||||
property <length> navbar-h: Theme.big ? 76px : 60px;
|
||||
property <length> hint-h: Theme.big ? 40px : 0px;
|
||||
property <bool> art: (root.view == 0 && !home.empty) || root.detail-open;
|
||||
|
||||
public function resync() { home.sync(); }
|
||||
public function goto(v: int) {
|
||||
root.view = v;
|
||||
if (v == 0) { home.sync(); Lib.focus-game(home.hero-idx); }
|
||||
}
|
||||
public function close-detail() {
|
||||
root.detail-open = false;
|
||||
if (root.view == 0) { Lib.focus-game(home.hero-idx); }
|
||||
}
|
||||
|
||||
Rectangle { height: 420px; y: 0; background: @linear-gradient(180deg, Theme.p.bg2 0%, Theme.p.bg 100%); }
|
||||
|
||||
Backdrop {
|
||||
a: root.bg-a; b: root.bg-b; flip: root.bg-flip;
|
||||
art-h: root.detail-open ? root.height * 0.74 : home.hero-h + 88px;
|
||||
dim: root.detail-open ? 0.38 : home.scrolled ? 0.8 : 0;
|
||||
opacity: root.art ? 1 : 0;
|
||||
animate opacity { duration: Theme.ms(300); }
|
||||
}
|
||||
|
||||
fs := FocusScope {
|
||||
key-pressed(e) => {
|
||||
if (e.text == Key.F11) { Lib.toggle-fullscreen(); return accept; }
|
||||
if (root.detail-open) {
|
||||
if (e.text == Key.Tab || e.text == Key.Backtab) { return accept; }
|
||||
return detail.key(e) ? accept : reject;
|
||||
}
|
||||
if (e.text == Key.Backtab || (e.text == Key.Tab && e.modifiers.shift)) { root.goto(Math.mod(root.view + 3, 4)); root.zone = 1; return accept; }
|
||||
if (e.text == Key.Tab) { root.goto(Math.mod(root.view + 1, 4)); root.zone = 1; return accept; }
|
||||
if (e.text == "/" || (e.modifiers.control && e.text == "f")) { root.goto(1); root.zone = 1; library.focus-search(); return accept; }
|
||||
if (root.zone == 0) {
|
||||
if (e.text == Key.LeftArrow) { root.goto(Math.max(0, root.view - 1)); return accept; }
|
||||
if (e.text == Key.RightArrow) { root.goto(Math.min(3, root.view + 1)); return accept; }
|
||||
if (e.text == Key.DownArrow || e.text == Key.Return || e.text == " ") { root.zone = 1; return accept; }
|
||||
return reject;
|
||||
}
|
||||
if (root.view == 0 ? home.key(e) : root.view == 1 ? library.key(e) : root.view == 2 ? unfiltered.key(e) : settings.key(e)) { return accept; }
|
||||
if (e.text == Key.Escape) { if (root.view != 0) { root.goto(0); } return accept; }
|
||||
return reject;
|
||||
}
|
||||
|
||||
// ---- views: each one fades and rises into place ----
|
||||
Rectangle {
|
||||
y: 0; height: root.height - root.hint-h;
|
||||
home := HomeView {
|
||||
navbar-h: root.navbar-h; logo: root.logo; logo-idx: root.logo-idx;
|
||||
active: root.view == 0 && root.zone == 1 && !root.detail-open;
|
||||
opacity: root.view == 0 && !root.detail-open ? 1 : 0; visible: self.opacity > 0.01;
|
||||
y: root.view == 0 ? 0px : 16px;
|
||||
animate opacity { duration: Theme.ms(240); } animate y { duration: Theme.ms(320); easing: Theme.ease; }
|
||||
exit-up => { root.zone = 0; }
|
||||
}
|
||||
library := LibraryView {
|
||||
y: root.navbar-h + (root.view == 1 ? 0px : 16px); height: parent.height - root.navbar-h;
|
||||
active: root.view == 1 && root.zone == 1 && !root.detail-open;
|
||||
opacity: root.view == 1 && !root.detail-open ? 1 : 0; visible: self.opacity > 0.01;
|
||||
animate opacity { duration: Theme.ms(240); } animate y { duration: Theme.ms(320); easing: Theme.ease; }
|
||||
exit-up => { root.zone = 0; }
|
||||
refocus => { fs.focus(); }
|
||||
}
|
||||
unfiltered := UnfilteredView {
|
||||
y: root.navbar-h + (root.view == 2 ? 0px : 16px); height: parent.height - root.navbar-h;
|
||||
active: root.view == 2 && root.zone == 1 && !root.detail-open;
|
||||
opacity: root.view == 2 && !root.detail-open ? 1 : 0; visible: self.opacity > 0.01;
|
||||
animate opacity { duration: Theme.ms(240); } animate y { duration: Theme.ms(320); easing: Theme.ease; }
|
||||
exit-up => { root.zone = 0; }
|
||||
}
|
||||
settings := SettingsView {
|
||||
y: root.navbar-h + (root.view == 3 ? 0px : 16px); height: parent.height - root.navbar-h;
|
||||
active: root.view == 3 && root.zone == 1 && !root.detail-open;
|
||||
opacity: root.view == 3 && !root.detail-open ? 1 : 0; visible: self.opacity > 0.01;
|
||||
animate opacity { duration: Theme.ms(240); } animate y { duration: Theme.ms(320); easing: Theme.ease; }
|
||||
exit-up => { root.zone = 0; }
|
||||
}
|
||||
}
|
||||
|
||||
// ---- navbar ----
|
||||
Rectangle {
|
||||
vertical-stretch: 1; clip: true;
|
||||
// Each tab is a layer that fades and slides; user speed scales it.
|
||||
Rectangle { opacity: root.tab == 0 ? 1 : 0; x: root.tab == 0 ? 0px : -30px; visible: self.opacity > 0.01;
|
||||
animate opacity { duration: Theme.ms(260); } animate x { duration: Theme.ms(300); easing: ease-out; }
|
||||
ScrollView { viewport-width: self.width;
|
||||
VerticalLayout { padding: 32px; spacing: 14px; alignment: start;
|
||||
Text { text: "Your most played"; color: Theme.text; font-size: 24px; font-weight: 800; }
|
||||
Text { text: root.stats; color: Theme.dim; font-size: 13px; }
|
||||
Rectangle { height: 6px; }
|
||||
CardView { cards: root.home; layout: root.layout; pin(i) => { root.pin(i); } }
|
||||
}
|
||||
}
|
||||
y: 0; height: root.navbar-h;
|
||||
opacity: root.detail-open ? 0 : 1; visible: self.opacity > 0.01;
|
||||
animate opacity { duration: Theme.ms(200); }
|
||||
// covers slide under the navbar once Home scrolls, so it gets a solid back then
|
||||
Rectangle { background: Theme.p.bg; opacity: root.view == 0 && home.moved ? 0.94 : 0; animate opacity { duration: Theme.ms(200); } }
|
||||
Rectangle { y: parent.height - 1px; height: 1px; background: Theme.p.border; opacity: root.view == 0 && !home.moved ? 0 : 1; }
|
||||
Wordmark { x: Theme.pad; y: (parent.height - self.height) / 2; size: Theme.big ? 30px : 26px; }
|
||||
HorizontalLayout {
|
||||
x: Theme.pad + (Theme.big ? 196px : 172px); y: 0; height: parent.height; spacing: 6px; alignment: start;
|
||||
VerticalLayout { alignment: center; NavTab { label: "Home"; icon: Icons.home; active: root.view == 0; focused: root.zone == 0 && root.view == 0; clicked => { root.goto(0); root.zone = 1; } } }
|
||||
VerticalLayout { alignment: center; NavTab { label: "Library"; icon: Icons.grid; active: root.view == 1; focused: root.zone == 0 && root.view == 1; clicked => { root.goto(1); root.zone = 1; } } }
|
||||
VerticalLayout { alignment: center; NavTab { label: "Unfiltered"; icon: Icons.layers; active: root.view == 2; focused: root.zone == 0 && root.view == 2; clicked => { root.goto(2); root.zone = 1; } } }
|
||||
}
|
||||
Rectangle { opacity: root.tab == 1 ? 1 : 0; x: root.tab == 1 ? 0px : (root.tab < 1 ? 30px : -30px); visible: self.opacity > 0.01;
|
||||
animate opacity { duration: Theme.ms(260); } animate x { duration: Theme.ms(300); easing: ease-out; }
|
||||
ScrollView { viewport-width: self.width;
|
||||
VerticalLayout { padding: 32px; spacing: 14px; alignment: start;
|
||||
Text { text: "Library"; color: Theme.text; font-size: 24px; font-weight: 800; }
|
||||
Text { text: "Installed and not installed. Click a cover to pin it to Home."; color: Theme.dim; font-size: 13px; }
|
||||
Rectangle { height: 6px; }
|
||||
CardView { cards: root.library; layout: root.layout; pin(i) => { root.pin(i); } }
|
||||
}
|
||||
}
|
||||
if root.width >= 1180px: Text {
|
||||
x: parent.width - Theme.pad - 60px - self.width; width: 420px; height: parent.height; horizontal-alignment: right; vertical-alignment: center;
|
||||
text: Lib.stats; color: Theme.p.dim; font-size: Theme.t-sm;
|
||||
}
|
||||
Rectangle { opacity: root.tab == 2 ? 1 : 0; x: root.tab == 2 ? 0px : 30px; visible: self.opacity > 0.01;
|
||||
animate opacity { duration: Theme.ms(260); } animate x { duration: Theme.ms(300); easing: ease-out; }
|
||||
ScrollView { viewport-width: self.width;
|
||||
VerticalLayout { padding: 32px; spacing: 3px; alignment: start;
|
||||
Text { text: "Unfiltered"; color: Theme.text; font-size: 24px; font-weight: 800; }
|
||||
Text { text: "Everything Summit found, and why."; color: Theme.dim; font-size: 13px; }
|
||||
Rectangle { height: 10px; }
|
||||
for c in root.unfiltered: Rectangle {
|
||||
height: c.section ? 40px : 30px;
|
||||
if c.section: Text { x: 0px; text: c.title; color: Theme.accent; font-size: 13px; font-weight: 800; letter-spacing: 1.5px; y: 14px; }
|
||||
if !c.section: Rectangle { background: Theme.panel; border-radius: 5px;
|
||||
Rectangle { x: 0; width: 3px; background: c.accent; }
|
||||
Text { x: 16px; text: c.title; color: Theme.text; font-size: 13px; font-weight: 600; vertical-alignment: center; width: 330px; overflow: elide; }
|
||||
Text { x: 360px; text: c.hours; color: Theme.dim; font-size: 12px; vertical-alignment: center; width: 90px; }
|
||||
Text { x: 460px; text: c.reasons; color: Theme.dim; font-size: 12px; vertical-alignment: center; width: parent.width - 480px; overflow: elide; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
NavTab { x: parent.width - Theme.pad - self.width; y: (parent.height - self.height) / 2; label: ""; icon: Icons.gear; active: root.view == 3; focused: root.zone == 0 && root.view == 3; clicked => { root.goto(3); root.zone = 1; } }
|
||||
}
|
||||
|
||||
// ---- a game's page ----
|
||||
detail := DetailView {
|
||||
open: root.detail-open;
|
||||
opacity: root.detail-open ? 1 : 0; visible: self.opacity > 0.01;
|
||||
y: root.detail-open ? 0px : 20px; height: root.height - root.hint-h;
|
||||
animate opacity { duration: Theme.ms(260); } animate y { duration: Theme.ms(340); easing: Theme.ease; }
|
||||
close => { root.close-detail(); }
|
||||
}
|
||||
|
||||
// ---- key hints (big picture) ----
|
||||
if root.hint-h > 0px: Rectangle {
|
||||
y: root.height - root.hint-h; height: root.hint-h; background: Theme.p.bg.with-alpha(0.92);
|
||||
Rectangle { height: 1px; y: 0; background: Theme.p.border.with-alpha(0.6); }
|
||||
HorizontalLayout {
|
||||
x: Theme.pad; width: parent.width - 2 * Theme.pad; alignment: end; spacing: 24px;
|
||||
VerticalLayout { alignment: center; KeyCap { key: "Arrows"; label: "Navigate"; } }
|
||||
VerticalLayout { alignment: center; KeyCap { key: "Enter"; label: root.detail-open ? "Activate" : "Select"; } }
|
||||
if !root.detail-open: VerticalLayout { alignment: center; KeyCap { key: "Tab"; label: "Next section"; } }
|
||||
if root.view != 3 || root.detail-open: VerticalLayout { alignment: center; KeyCap { key: "P"; label: "Pin"; } }
|
||||
if root.view == 1 && !root.detail-open: VerticalLayout { alignment: center; KeyCap { key: "/"; label: "Search"; } }
|
||||
if root.detail-open || root.view != 0: VerticalLayout { alignment: center; KeyCap { key: "Esc"; label: root.detail-open ? "Back" : "Home"; } }
|
||||
if root.width >= 1100px: VerticalLayout { alignment: center; KeyCap { key: "F11"; label: "Fullscreen"; } }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Toast { max-w: root.width - 48px; x: (parent.width - self.width) / 2; y: parent.height - root.hint-h - 72px; text: root.toast; shown: root.toast-shown; }
|
||||
Timer { interval: 4s; running: root.toast-shown; triggered => { root.toast-shown = false; } }
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
// A game's page: art, stats, why Summit lists it, its launch profile and the actions.
|
||||
import { Theme } from "theme.slint";
|
||||
import { Lib, Game, Detail, Icon, Icons, Btn, Tag, CoverArt } from "widgets.slint";
|
||||
|
||||
component Stat inherits Rectangle {
|
||||
in property <string> label;
|
||||
in property <string> value;
|
||||
in property <string> note;
|
||||
in property <bool> small;
|
||||
height: 88px; border-radius: Theme.r-md;
|
||||
background: Theme.p.surface.with-alpha(Theme.p.dark ? 0.78 : 0.92); border-width: Theme.p.border-w; border-color: Theme.p.border;
|
||||
Text { x: 20px; y: 16px; text: root.label; color: Theme.p.dim; font-size: 10px; font-weight: 800; letter-spacing: 1.6px; }
|
||||
Text { x: 20px; y: 36px; width: parent.width - 40px; text: root.value; color: Theme.p.text; font-size: root.small ? Theme.t-lg : Theme.t-xl; font-weight: 800; overflow: elide; }
|
||||
if root.note != "": Text { x: 20px; y: 68px; width: parent.width - 40px; text: root.note; color: Theme.p.faint; font-size: 10px; overflow: elide; }
|
||||
}
|
||||
|
||||
component Panel inherits Rectangle {
|
||||
in property <string> title;
|
||||
in property <string> icon;
|
||||
border-radius: Theme.r-lg;
|
||||
background: Theme.p.surface.with-alpha(Theme.p.dark ? 0.78 : 0.92); border-width: Theme.p.border-w; border-color: Theme.p.border;
|
||||
Icon { x: 20px; y: 18px; size: 18px; color: Theme.p.accent; commands: root.icon; }
|
||||
Text { x: 48px; y: 18px; text: root.title; color: Theme.p.text; font-size: Theme.t-sm; font-weight: 800; letter-spacing: 1.2px; }
|
||||
@children
|
||||
}
|
||||
|
||||
component Field inherits Rectangle {
|
||||
in property <string> label;
|
||||
in property <string> value;
|
||||
in property <bool> unset;
|
||||
height: 28px;
|
||||
Text { x: 0; width: 150px; height: parent.height; text: root.label; color: Theme.p.dim; font-size: Theme.t-sm; vertical-alignment: center; }
|
||||
Text { x: 150px; width: parent.width - 150px; height: parent.height; text: root.value; color: root.unset ? Theme.p.faint : Theme.p.text; font-size: Theme.t-sm; font-weight: 600; vertical-alignment: center; overflow: elide; }
|
||||
}
|
||||
|
||||
export component DetailView inherits Rectangle {
|
||||
in property <bool> open;
|
||||
in-out property <int> btn: 0; // 0 play, 1 pin, 2 artwork, 3 settings
|
||||
callback close();
|
||||
property <Detail> d: Lib.detail;
|
||||
property <Game> g: Lib.games[root.d.idx];
|
||||
property <length> pad: Theme.pad + 8px;
|
||||
property <length> cw: Math.min(Math.clamp(root.width * 0.19, 150px, 300px), (root.height - 96px - 40px) / 1.5);
|
||||
property <length> rx: root.pad + root.cw + (root.width < 1000px ? 32px : 48px);
|
||||
property <length> rw: root.width - root.rx - root.pad;
|
||||
property <bool> wide: root.rw >= 720px;
|
||||
property <bool> compact: root.rw < 660px;
|
||||
property <length> reasons-h: 56px + root.d.reasons.length * 26px + 44px;
|
||||
property <length> profile-h: 56px + 5 * 28px + 62px;
|
||||
|
||||
public function key(e: KeyEvent) -> bool {
|
||||
if (e.text == Key.Escape || e.text == Key.Backspace) { root.close(); }
|
||||
else if (e.text == Key.RightArrow) { root.btn = Math.min(3, root.btn + 1); }
|
||||
else if (e.text == Key.LeftArrow) { root.btn = Math.max(0, root.btn - 1); }
|
||||
else if (e.text == Key.DownArrow) { body.content-y = Math.max(Math.min(0px, body.height - body.content-height), body.content-y - 96px); }
|
||||
else if (e.text == Key.UpArrow) { body.content-y = Math.min(0px, body.content-y + 96px); }
|
||||
else if (e.text == Key.Return || e.text == " ") {
|
||||
if (root.btn == 0) { if (root.d.can-play) { Lib.play(root.d.idx); } } else if (root.btn == 1) { Lib.toggle-pin(root.d.idx); }
|
||||
} else if (e.text == "p" || e.text == "P") { Lib.toggle-pin(root.d.idx); }
|
||||
else { return false; }
|
||||
return true;
|
||||
}
|
||||
changed open => { if (root.open) { root.btn = 0; body.content-y = 0; } }
|
||||
|
||||
TouchArea { } // swallow clicks so the view underneath does not react
|
||||
|
||||
Btn { x: root.pad; y: 24px; h: 40px; text: "Back"; icon: Icons.back; clicked => { root.close(); } }
|
||||
Text { x: root.pad + 124px; y: 24px; height: 40px; vertical-alignment: center; text: "Esc"; color: Theme.p.faint; font-size: Theme.t-xs; font-weight: 700; letter-spacing: 1px; }
|
||||
|
||||
// cover
|
||||
Rectangle {
|
||||
x: root.pad; y: 96px; width: root.cw; height: root.cw * 1.5; border-radius: Theme.r-lg;
|
||||
drop-shadow-blur: 40px; drop-shadow-offset-y: 16px; drop-shadow-color: Theme.p.dark ? #000000b0 : #2a355066;
|
||||
background: Theme.p.surface;
|
||||
Rectangle { border-radius: Theme.r-lg; clip: true; CoverArt { g: root.g; width: parent.width; height: parent.height; } }
|
||||
Rectangle { border-radius: Theme.r-lg; border-width: Theme.p.border-w; border-color: Theme.p.border-w > 1px ? Theme.p.border : (Theme.p.dark ? #ffffff24 : #0000001a); background: transparent; }
|
||||
}
|
||||
|
||||
body := Flickable {
|
||||
x: root.rx; y: 88px; width: root.rw + root.pad; height: root.height - 88px;
|
||||
content-width: self.width; content-height: col.preferred-height + 40px;
|
||||
col := VerticalLayout {
|
||||
x: 0; y: 0; width: root.rw; padding-top: 8px; spacing: 16px; alignment: start;
|
||||
Text { text: root.g.title; color: Theme.p.text; font-size: root.compact ? Theme.t-2xl : 40px; font-weight: 800; wrap: word-wrap; }
|
||||
HorizontalLayout { alignment: start; spacing: 8px;
|
||||
Tag { text: root.g.installed ? "Installed" : "Not installed"; dot: true; tint: root.g.installed ? Theme.p.ok : Theme.p.faint; }
|
||||
Tag { text: root.g.source; }
|
||||
Tag { text: root.g.kind; }
|
||||
if root.g.pinned: Tag { text: "Pinned to Home"; tint: Theme.p.accent; }
|
||||
}
|
||||
HorizontalLayout { alignment: start; spacing: 12px; padding-top: 8px;
|
||||
Btn { h: 56px; primary: true; enabled: root.d.can-play; text: root.d.play-label; icon: root.d.play-label == "INSTALL" ? Icons.download : Icons.play; icon-solid: root.d.play-label != "INSTALL";
|
||||
focused: root.open && root.btn == 0; clicked => { Lib.play(root.d.idx); } }
|
||||
Btn { h: 56px; text: root.g.pinned ? "Unpin" : "Pin"; icon: Icons.pin; icon-solid: root.g.pinned; focused: root.open && root.btn == 1; clicked => { Lib.toggle-pin(root.d.idx); } }
|
||||
Btn { h: 56px; enabled: false; text: root.compact ? "" : "Change artwork"; icon: Icons.picture; badge: "Soon"; focused: root.open && root.btn == 2; }
|
||||
Btn { h: 56px; enabled: false; text: root.compact ? "" : "Settings"; icon: Icons.sliders; badge: "Soon"; focused: root.open && root.btn == 3; }
|
||||
}
|
||||
Text {
|
||||
text: root.btn == 2 ? "Changing artwork here is not built yet. For now: summit art " + root.g.id + " cover.png"
|
||||
: root.btn == 3 ? "Editing the launch profile here is not built yet. For now: summit profile set " + root.g.id + " --monitor … --width … --height … --refresh …"
|
||||
: root.d.play-note;
|
||||
color: Theme.p.dim; font-size: Theme.t-sm; wrap: word-wrap; min-height: 18px;
|
||||
}
|
||||
HorizontalLayout { spacing: 16px;
|
||||
Stat { small: root.compact; label: "PLAYED"; value: root.g.hours; }
|
||||
Stat { small: root.compact; label: "SESSIONS"; value: root.d.sessions; note: root.d.sessions-note; }
|
||||
Stat { small: root.compact; label: "LAST PLAYED"; value: root.g.last == "" ? "Never" : root.g.last; }
|
||||
}
|
||||
Rectangle {
|
||||
height: root.wide ? Math.max(root.reasons-h, root.profile-h) : root.reasons-h + 16px + root.profile-h;
|
||||
Panel {
|
||||
x: 0; y: 0; width: root.wide ? (parent.width - 16px) / 2 : parent.width; height: root.wide ? parent.height : root.profile-h;
|
||||
title: "LAUNCH PROFILE"; icon: Icons.monitor;
|
||||
VerticalLayout { x: 20px; y: 52px; width: parent.width - 40px; alignment: start;
|
||||
Field { label: "Monitor"; value: root.d.monitor; unset: root.d.monitor == "Default"; }
|
||||
Field { label: "Resolution, refresh"; value: root.d.mode; unset: root.d.mode == "Default"; }
|
||||
Field { label: "Upscaler"; value: root.d.upscaler; unset: root.d.upscaler == "None"; }
|
||||
Field { label: "Frame generation"; value: root.d.framegen; unset: root.d.framegen == "None"; }
|
||||
Field { label: "Window"; value: root.d.window; unset: root.d.window == "Default"; }
|
||||
Rectangle { height: 8px; }
|
||||
Text { text: root.g.source == "Steam" ? "Steam games start through the Steam client, so this profile is not applied to them yet." : "Monitor and mode are applied when Summit starts the game. Upscaling and frame generation are stored, not applied yet."; color: Theme.p.faint; font-size: Theme.t-xs; wrap: word-wrap; }
|
||||
}
|
||||
}
|
||||
Panel {
|
||||
x: root.wide ? (parent.width + 16px) / 2 : 0; y: root.wide ? 0 : root.profile-h + 16px; width: root.wide ? (parent.width - 16px) / 2 : parent.width; height: root.wide ? parent.height : root.reasons-h;
|
||||
title: "WHY IT IS HERE"; icon: Icons.layers;
|
||||
VerticalLayout { x: 20px; y: 52px; width: parent.width - 40px; alignment: start;
|
||||
for r in root.d.reasons: Rectangle { height: 26px;
|
||||
Rectangle { x: 2px; y: 10px; width: 6px; height: 6px; border-radius: 3px; background: Theme.p.accent; }
|
||||
Text { x: 20px; width: parent.width - 20px; height: parent.height; text: r; color: Theme.p.text; font-size: Theme.t-sm; vertical-alignment: center; overflow: elide; }
|
||||
}
|
||||
Rectangle { height: 8px; }
|
||||
Text { text: root.d.path == "" ? "No path on this machine" : root.d.path; color: Theme.p.faint; font-size: Theme.t-xs; overflow: elide; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
// Home: the focused game as a hero (art comes from the window backdrop behind this view) and shelves of covers.
|
||||
import { Theme } from "theme.slint";
|
||||
import { Lib, Game, Icon, Icons, Btn, Tag, CoverCard, LogoMark } from "widgets.slint";
|
||||
|
||||
component Shelf inherits Rectangle {
|
||||
in property <string> title;
|
||||
in property <[int]> items;
|
||||
in property <bool> active;
|
||||
in property <int> cur;
|
||||
in property <length> card-w;
|
||||
callback pick(int);
|
||||
property <length> gap: Theme.big ? 20px : 16px;
|
||||
property <length> step: root.card-w + root.gap;
|
||||
property <int> nvis: Math.max(1, Math.floor((root.width - 2 * Theme.pad + root.gap) / root.step));
|
||||
property <int> first: 0;
|
||||
function follow() {
|
||||
if (root.cur < root.first) { root.first = root.cur; }
|
||||
else if (root.cur > root.first + root.nvis - 1) { root.first = root.cur - root.nvis + 1; }
|
||||
if (root.first > Math.max(0, root.items.length - root.nvis)) { root.first = Math.max(0, root.items.length - root.nvis); }
|
||||
}
|
||||
changed cur => { root.follow(); }
|
||||
changed nvis => { root.follow(); }
|
||||
height: 40px + root.card-w * 1.5 + 32px;
|
||||
Text { x: Theme.pad; y: 4px; text: root.title; color: root.active ? Theme.p.text : Theme.p.dim; font-size: Theme.t-sm; font-weight: 800; letter-spacing: 1.6px;
|
||||
animate color { duration: Theme.ms(160); } }
|
||||
Text { x: Theme.pad + 12px + tw.preferred-width; y: 4px; text: root.items.length; color: Theme.p.faint; font-size: Theme.t-sm; font-weight: 600; }
|
||||
tw := Text { visible: false; text: root.title; font-size: Theme.t-sm; font-weight: 800; letter-spacing: 1.6px; }
|
||||
Rectangle {
|
||||
y: 40px; height: root.card-w * 1.5;
|
||||
x: Theme.pad - root.first * root.step; width: root.items.length * root.step;
|
||||
animate x { duration: Theme.ms(280); easing: Theme.ease; }
|
||||
for idx[i] in root.items: CoverCard {
|
||||
x: i * root.step; y: 0; width: root.card-w;
|
||||
idx: idx; focused: root.active && root.cur == i;
|
||||
clicked => { root.pick(i); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export component HomeView inherits Rectangle {
|
||||
in property <bool> active;
|
||||
in property <image> logo;
|
||||
in property <int> logo-idx: -1;
|
||||
in property <length> navbar-h;
|
||||
in-out property <int> srow: 0; // -1 hero buttons, 0 recent, 1 pinned, 2 most played
|
||||
in-out property <int> btn: 0; // 0 play, 1 details, 2 pin
|
||||
out property <int> hero-idx: -1;
|
||||
out property <length> hero-h: Theme.big ? Math.clamp(root.height * 0.5, 352px, 580px) : Math.clamp(root.height * 0.38, 264px, 360px);
|
||||
out property <bool> moved: root.page-y > 1px;
|
||||
out property <bool> scrolled: root.page-y > root.hero-h * 0.25;
|
||||
out property <bool> empty: Lib.recent.length + Lib.pinned.length + Lib.most.length == 0;
|
||||
callback exit-up();
|
||||
property <int> c0; property <int> c1; property <int> c2;
|
||||
// covers shrink on short windows so the first shelf still fits under the hero
|
||||
property <length> card-w: Math.clamp((root.height - root.hero-h - 88px) / 1.5, 104px, Theme.big ? 176px : Theme.layout == 1 ? 148px : 128px);
|
||||
property <length> shelf-h: 40px + root.card-w * 1.5 + 32px;
|
||||
property <Game> g: Lib.games[root.hero-idx];
|
||||
property <bool> show-logo: Theme.p.dark && root.logo-idx == root.hero-idx && root.hero-idx >= 0;
|
||||
|
||||
pure function len(r: int) -> int { return r == 0 ? Lib.recent.length : r == 1 ? Lib.pinned.length : r == 2 ? Lib.most.length : 0; }
|
||||
pure function colof(r: int) -> int { return Math.max(0, Math.min(root.len(r) - 1, r == 0 ? root.c0 : r == 1 ? root.c1 : root.c2)); }
|
||||
pure function item(r: int, c: int) -> int { return r == 0 ? Lib.recent[c] : r == 1 ? Lib.pinned[c] : Lib.most[c]; }
|
||||
function set-col(r: int, v: int) { if (r == 0) { root.c0 = v; } else if (r == 1) { root.c1 = v; } else { root.c2 = v; } }
|
||||
pure function next(r: int) -> int { return r < 0 && root.len(0) > 0 ? 0 : r < 1 && root.len(1) > 0 ? 1 : r < 2 && root.len(2) > 0 ? 2 : r; }
|
||||
pure function prev(r: int) -> int { return r > 1 && root.len(1) > 0 ? 1 : r > 0 && root.len(0) > 0 ? 0 : -1; }
|
||||
// how many shelves are drawn above shelf r
|
||||
pure function above(r: int) -> int { return (r > 0 && root.len(0) > 0 ? 1 : 0) + (r > 1 && root.len(1) > 0 ? 1 : 0); }
|
||||
pure function shelf-y(r: int) -> length { return root.hero-h + root.above(r) * root.shelf-h; }
|
||||
property <length> page-y: root.srow < 0 ? 0px : Math.max(0px, root.shelf-y(root.srow) + root.shelf-h - (root.height - (root.srow == 0 ? 0px : 16px)));
|
||||
|
||||
// Keep the focus on something that exists, and point the hero (and the backdrop) at it.
|
||||
public function sync() {
|
||||
if (root.srow >= 0 && root.len(root.srow) == 0) { root.srow = root.next(-1) == -1 ? -1 : root.next(-1); }
|
||||
if (root.srow >= 0) {
|
||||
if (root.hero-idx != root.item(root.srow, root.colof(root.srow))) {
|
||||
root.hero-idx = root.item(root.srow, root.colof(root.srow));
|
||||
Lib.focus-game(root.hero-idx);
|
||||
}
|
||||
} else if (root.hero-idx < 0 && Lib.games.length > 0 && !root.empty) {
|
||||
root.hero-idx = root.item(root.next(-1), 0);
|
||||
Lib.focus-game(root.hero-idx);
|
||||
}
|
||||
}
|
||||
function pick(r: int, c: int) {
|
||||
if (root.srow == r && root.colof(r) == c) { Lib.open-detail(root.item(r, c)); }
|
||||
else { root.srow = r; root.set-col(r, c); root.sync(); }
|
||||
}
|
||||
function hero-action(b: int) {
|
||||
if (root.hero-idx < 0) { return; }
|
||||
if (b == 0) { Lib.play(root.hero-idx); } else if (b == 1) { Lib.open-detail(root.hero-idx); } else { Lib.toggle-pin(root.hero-idx); }
|
||||
}
|
||||
public function key(e: KeyEvent) -> bool {
|
||||
if (root.empty) { if (e.text == Key.UpArrow) { root.exit-up(); return true; } return false; }
|
||||
if (e.text == Key.RightArrow) {
|
||||
if (root.srow == -1) { root.btn = Math.min(2, root.btn + 1); } else { root.set-col(root.srow, Math.min(root.len(root.srow) - 1, root.colof(root.srow) + 1)); }
|
||||
} else if (e.text == Key.LeftArrow) {
|
||||
if (root.srow == -1) { root.btn = Math.max(0, root.btn - 1); } else { root.set-col(root.srow, Math.max(0, root.colof(root.srow) - 1)); }
|
||||
} else if (e.text == Key.DownArrow) {
|
||||
root.srow = root.next(root.srow);
|
||||
} else if (e.text == Key.UpArrow) {
|
||||
if (root.srow == -1) { root.exit-up(); } else { root.srow = root.prev(root.srow); root.btn = 0; }
|
||||
} else if (e.text == Key.Home && root.srow >= 0) { root.set-col(root.srow, 0);
|
||||
} else if (e.text == Key.End && root.srow >= 0) { root.set-col(root.srow, root.len(root.srow) - 1);
|
||||
} else if (e.text == Key.Return || e.text == " ") {
|
||||
if (root.srow == -1) { root.hero-action(root.btn); } else { Lib.open-detail(root.item(root.srow, root.colof(root.srow))); }
|
||||
} else if (e.text == "p" || e.text == "P") { Lib.toggle-pin(root.srow == -1 ? root.hero-idx : root.item(root.srow, root.colof(root.srow)));
|
||||
} else { return false; }
|
||||
root.sync();
|
||||
return true;
|
||||
}
|
||||
|
||||
TouchArea {
|
||||
scroll-event(e) => {
|
||||
if (e.delta-y < 0 && root.next(root.srow) != root.srow) { root.srow = root.next(root.srow); root.sync(); return accept; }
|
||||
if (e.delta-y > 0 && root.srow > root.next(-1)) { root.srow = root.prev(root.srow); root.sync(); return accept; }
|
||||
return reject;
|
||||
}
|
||||
}
|
||||
|
||||
if root.empty: Rectangle {
|
||||
VerticalLayout { alignment: center; spacing: 16px;
|
||||
HorizontalLayout { alignment: center; LogoMark { size: 88px; } }
|
||||
Text { text: "No games yet"; color: Theme.p.text; font-size: Theme.t-2xl; font-weight: 800; horizontal-alignment: center; }
|
||||
Text { text: "Summit looks in Steam, Heroic and Lutris. Nothing was found on this machine."; color: Theme.p.dim; font-size: Theme.t-md; horizontal-alignment: center; }
|
||||
Text { text: "Add anything by hand: summit add \"My Game\" ~/Games/mygame/run.sh"; color: Theme.p.faint; font-size: Theme.t-sm; horizontal-alignment: center; }
|
||||
}
|
||||
}
|
||||
|
||||
if !root.empty: Rectangle {
|
||||
y: -root.page-y; height: root.height;
|
||||
animate y { duration: Theme.ms(320); easing: Theme.ease; }
|
||||
|
||||
// ---- hero text and actions ----
|
||||
Rectangle {
|
||||
x: Theme.pad; y: root.navbar-h; width: Math.min(root.width - 2 * Theme.pad, 760px); height: root.hero-h - root.navbar-h - (Theme.big && root.hero-h > 400px ? 40px : 24px);
|
||||
opacity: root.scrolled ? 0 : 1;
|
||||
animate opacity { duration: Theme.ms(200); }
|
||||
VerticalLayout {
|
||||
alignment: end; spacing: Theme.big ? 16px : 12px;
|
||||
Text {
|
||||
text: root.srow == 0 ? "JUMP BACK IN" : root.srow == 1 ? "PINNED" : root.srow == 2 ? "MOST PLAYED" : "SELECTED";
|
||||
color: Theme.p.accent; font-size: Theme.t-xs; font-weight: 800; letter-spacing: 2.4px;
|
||||
}
|
||||
if root.show-logo: HorizontalLayout { alignment: start;
|
||||
Image { source: root.logo; height: Theme.big ? Math.min(128px, root.hero-h * 0.22) : 72px; width: Math.min(root.width - 2 * Theme.pad, Theme.big ? 560px : 400px); image-fit: contain; horizontal-alignment: left; vertical-alignment: bottom; }
|
||||
}
|
||||
if !root.show-logo: Text {
|
||||
text: root.g.title; color: Theme.p.text; font-size: Theme.big ? Theme.t-3xl : Theme.t-2xl; font-weight: 800; wrap: word-wrap; overflow: elide;
|
||||
max-height: (Theme.big ? Theme.t-3xl : Theme.t-2xl) * 2.6;
|
||||
}
|
||||
HorizontalLayout {
|
||||
alignment: start; spacing: 12px;
|
||||
Tag { text: root.g.installed ? "Installed" : "Not installed"; dot: true; tint: root.g.installed ? Theme.p.ok : Theme.p.faint; }
|
||||
Tag { text: root.g.source; }
|
||||
Rectangle { width: 4px; }
|
||||
VerticalLayout { alignment: center; Icon { size: 16px; weight: 1.8px; color: Theme.p.dim; commands: Icons.clock; } }
|
||||
Text { text: root.g.hours + (root.g.last == "" ? "" : " · Last played " + root.g.last); color: Theme.p.text; font-size: Theme.t-md; font-weight: 500; vertical-alignment: center; }
|
||||
}
|
||||
HorizontalLayout {
|
||||
alignment: start; spacing: 12px; padding-top: 4px;
|
||||
Btn { h: Theme.big ? 56px : 48px; primary: true; enabled: root.g.action != ""; text: root.g.action == "" ? "PLAY" : root.g.action; icon: root.g.action == "INSTALL" ? Icons.download : Icons.play; icon-solid: root.g.action != "INSTALL";
|
||||
focused: root.active && root.srow == -1 && root.btn == 0; clicked => { root.hero-action(0); } }
|
||||
Btn { h: Theme.big ? 56px : 48px; text: "Details"; icon: Icons.info; focused: root.active && root.srow == -1 && root.btn == 1; clicked => { root.hero-action(1); } }
|
||||
Btn { h: Theme.big ? 56px : 48px; text: root.g.pinned ? "Pinned" : "Pin"; icon: Icons.pin; icon-solid: root.g.pinned; focused: root.active && root.srow == -1 && root.btn == 2; clicked => { root.hero-action(2); } }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---- shelves ----
|
||||
if Lib.recent.length > 0: Shelf { y: root.shelf-y(0); width: root.width; title: "JUMP BACK IN"; items: Lib.recent; card-w: root.card-w;
|
||||
active: root.active && root.srow == 0; cur: root.colof(0); pick(c) => { root.pick(0, c); } }
|
||||
if Lib.pinned.length > 0: Shelf { y: root.shelf-y(1); width: root.width; title: "PINNED"; items: Lib.pinned; card-w: root.card-w;
|
||||
active: root.active && root.srow == 1; cur: root.colof(1); pick(c) => { root.pick(1, c); } }
|
||||
if Lib.most.length > 0: Shelf { y: root.shelf-y(2); width: root.width; title: "MOST PLAYED"; items: Lib.most; card-w: root.card-w;
|
||||
active: root.active && root.srow == 2; cur: root.colof(2); pick(c) => { root.pick(2, c); } }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,260 @@
|
||||
// Library (cover grid or dense list, with filter, sort and search) and the Unfiltered list.
|
||||
import { ListView } from "std-widgets.slint";
|
||||
import { Theme } from "theme.slint";
|
||||
import { Lib, Game, URow, Icon, Icons, Chip, Tag, CoverCard, CoverArt, FocusRing } from "widgets.slint";
|
||||
|
||||
component SearchBox inherits Rectangle {
|
||||
in property <bool> focused;
|
||||
out property <bool> typing: input.has-focus;
|
||||
callback done();
|
||||
public function grab() { input.focus(); }
|
||||
height: 40px; border-radius: 20px;
|
||||
background: root.typing ? Theme.p.raised : Theme.p.surface;
|
||||
border-width: root.typing ? 2px : Theme.p.border-w; border-color: root.typing ? Theme.p.accent : Theme.p.border;
|
||||
Icon { x: 14px; y: 11px; size: 18px; color: Theme.p.dim; commands: Icons.search; }
|
||||
if input.text == "": Text { x: 42px; height: parent.height; text: "Search /"; color: Theme.p.faint; font-size: Theme.t-sm; vertical-alignment: center; }
|
||||
input := TextInput {
|
||||
x: 42px; width: parent.width - 60px; height: parent.height; vertical-alignment: center; single-line: true;
|
||||
color: Theme.p.text; font-size: Theme.t-sm; selection-background-color: Theme.p.accent; selection-foreground-color: Theme.p.on-accent;
|
||||
text <=> Lib.search;
|
||||
edited => { Lib.query(); }
|
||||
accepted => { root.done(); }
|
||||
key-pressed(e) => {
|
||||
if (e.text == Key.Escape || e.text == Key.DownArrow || e.text == Key.Tab) { root.done(); return accept; }
|
||||
return reject;
|
||||
}
|
||||
}
|
||||
FocusRing { on: root.focused && !root.typing; radius: 20px; }
|
||||
}
|
||||
|
||||
component ListRow inherits Rectangle {
|
||||
in property <int> idx;
|
||||
in property <bool> focused;
|
||||
in property <bool> odd;
|
||||
callback clicked;
|
||||
property <Game> g: Lib.games[root.idx];
|
||||
init => { Lib.want-cover(root.idx); }
|
||||
changed idx => { Lib.want-cover(root.idx); }
|
||||
height: 52px;
|
||||
Rectangle {
|
||||
x: Theme.pad - 12px; width: parent.width - 2 * Theme.pad + 24px; border-radius: Theme.r-sm;
|
||||
background: root.focused ? Theme.p.raised : ta.has-hover ? Theme.p.surface : root.odd ? Theme.p.surface.with-alpha(0.45) : transparent;
|
||||
border-width: root.focused ? 2px : 0px; border-color: Theme.p.focus;
|
||||
animate background { duration: Theme.ms(120); }
|
||||
Rectangle { x: 12px; y: 5px; width: 28px; height: 42px; border-radius: 4px; clip: true; opacity: root.g.installed ? 1 : 0.55;
|
||||
CoverArt { g: root.g; width: parent.width; height: parent.height; } }
|
||||
Text { x: 56px; width: parent.width - 56px - 560px; height: parent.height; text: root.g.title; color: root.g.installed ? Theme.p.text : Theme.p.dim; font-size: Theme.t-md - 1px; font-weight: 600; vertical-alignment: center; overflow: elide; }
|
||||
Text { x: parent.width - 548px; width: 100px; height: parent.height; text: root.g.hours-short == "" ? "–" : root.g.hours-short; color: root.g.hours-short == "" ? Theme.p.faint : Theme.p.text; font-size: Theme.t-sm; font-weight: 600; vertical-alignment: center; horizontal-alignment: right; }
|
||||
Text { x: parent.width - 424px; width: 130px; height: parent.height; text: root.g.last == "" ? "Never" : root.g.last; color: Theme.p.dim; font-size: Theme.t-sm; vertical-alignment: center; overflow: elide; }
|
||||
Text { x: parent.width - 284px; width: 100px; height: parent.height; text: root.g.source; color: Theme.p.dim; font-size: Theme.t-sm; vertical-alignment: center; overflow: elide; }
|
||||
Rectangle { x: parent.width - 172px; y: 22px; width: 8px; height: 8px; border-radius: 4px; background: root.g.installed ? Theme.p.ok : transparent; border-width: root.g.installed ? 0px : 1.5px; border-color: Theme.p.faint; }
|
||||
Text { x: parent.width - 156px; width: 110px; height: parent.height; text: root.g.installed ? "Installed" : "Not installed"; color: root.g.installed ? Theme.p.text : Theme.p.faint; font-size: Theme.t-sm; vertical-alignment: center; }
|
||||
if root.g.pinned: Icon { x: parent.width - 34px; y: 17px; size: 18px; solid: true; color: Theme.p.accent; commands: Icons.pin; }
|
||||
}
|
||||
ta := TouchArea { mouse-cursor: pointer; clicked => { root.clicked(); } }
|
||||
}
|
||||
|
||||
component EmptyState inherits Rectangle {
|
||||
in property <string> title;
|
||||
in property <string> hint;
|
||||
VerticalLayout { alignment: center; spacing: 12px;
|
||||
HorizontalLayout { alignment: center; Icon { size: 56px; weight: 1.4px; color: Theme.p.faint; commands: Icons.search; } }
|
||||
Text { text: root.title; color: Theme.p.text; font-size: Theme.t-xl; font-weight: 800; horizontal-alignment: center; }
|
||||
Text { text: root.hint; color: Theme.p.dim; font-size: Theme.t-sm; horizontal-alignment: center; }
|
||||
}
|
||||
}
|
||||
|
||||
export component LibraryView inherits Rectangle {
|
||||
in property <bool> active;
|
||||
in-out property <int> zone: 1; // 0 toolbar, 1 items
|
||||
in-out property <int> tool: 0; // 0..2 filter chips, 3 sort chip, 4 search
|
||||
in-out property <int> sel: 0;
|
||||
out property <bool> typing: search.typing;
|
||||
callback exit-up();
|
||||
callback refocus(); // give the keyboard back to the window
|
||||
property <bool> list: Theme.layout == 2;
|
||||
property <int> n: Lib.library.length;
|
||||
property <length> gap: Theme.big ? 24px : 18px;
|
||||
property <length> min-w: Theme.big ? Math.clamp(root.width / 7, 152px, 184px) : 148px;
|
||||
property <int> cols: Math.max(1, Math.floor((root.width - 2 * Theme.pad + root.gap) / (root.min-w + root.gap)));
|
||||
property <length> card-w: (root.width - 2 * Theme.pad - (root.cols - 1) * root.gap) / root.cols;
|
||||
property <length> row-h: root.list ? 52px : root.card-w * 1.5 + root.gap;
|
||||
property <int> rows: root.list ? root.n : Math.ceil(root.n / root.cols);
|
||||
property <length> head-h: 128px;
|
||||
property <length> top-pad: root.list ? 0px : 12px;
|
||||
property <[string]> sorts: ["Recently played", "Most played", "A to Z"];
|
||||
|
||||
public function focus-search() { root.zone = 0; root.tool = 4; search.grab(); }
|
||||
function reveal() {
|
||||
if (root.zone != 1) { return; }
|
||||
if (root.list) { list-view.show(root.sel); } else { grid-view.show(Math.floor(root.sel / root.cols)); }
|
||||
}
|
||||
function activate(t: int) {
|
||||
if (t <= 2) { Lib.filter = t; Lib.query(); }
|
||||
else if (t == 3) { Lib.sort = Math.mod(Lib.sort + 1, 3); Lib.query(); }
|
||||
else { search.grab(); }
|
||||
}
|
||||
changed n => { if (root.sel > Math.max(0, root.n - 1)) { root.sel = 0; } if (root.n == 0) { root.zone = 0; } }
|
||||
public function key(e: KeyEvent) -> bool {
|
||||
if (root.zone == 0) {
|
||||
if (e.text == Key.LeftArrow) { root.tool = Math.max(0, root.tool - 1); }
|
||||
else if (e.text == Key.RightArrow) { root.tool = Math.min(4, root.tool + 1); }
|
||||
else if (e.text == Key.DownArrow) { if (root.n > 0) { root.zone = 1; root.reveal(); } }
|
||||
else if (e.text == Key.UpArrow) { root.exit-up(); }
|
||||
else if (e.text == Key.Return || e.text == " ") { root.activate(root.tool); }
|
||||
else { return false; }
|
||||
return true;
|
||||
}
|
||||
if (e.text == Key.Return || e.text == " ") { Lib.open-detail(Lib.library[root.sel]); return true; }
|
||||
if (e.text == "p" || e.text == "P") { Lib.toggle-pin(Lib.library[root.sel]); return true; }
|
||||
if (root.list) {
|
||||
if (e.text == Key.DownArrow) { root.sel = Math.min(root.n - 1, root.sel + 1); }
|
||||
else if (e.text == Key.UpArrow) { if (root.sel == 0) { root.zone = 0; } else { root.sel -= 1; } }
|
||||
else if (e.text == Key.PageDown) { root.sel = Math.min(root.n - 1, root.sel + 10); }
|
||||
else if (e.text == Key.PageUp) { root.sel = Math.max(0, root.sel - 10); }
|
||||
else if (e.text == Key.Home) { root.sel = 0; }
|
||||
else if (e.text == Key.End) { root.sel = root.n - 1; }
|
||||
else { return false; }
|
||||
} else {
|
||||
if (e.text == Key.RightArrow) { root.sel = Math.min(root.n - 1, root.sel + 1); }
|
||||
else if (e.text == Key.LeftArrow) { root.sel = Math.max(0, root.sel - 1); }
|
||||
else if (e.text == Key.DownArrow) { if (Math.floor(root.sel / root.cols) < root.rows - 1) { root.sel = Math.min(root.n - 1, root.sel + root.cols); } }
|
||||
else if (e.text == Key.UpArrow) { if (root.sel < root.cols) { root.zone = 0; } else { root.sel -= root.cols; } }
|
||||
else if (e.text == Key.PageDown) { root.sel = Math.min(root.n - 1, root.sel + 3 * root.cols); }
|
||||
else if (e.text == Key.PageUp) { root.sel = Math.max(Math.mod(root.sel, root.cols), root.sel - 3 * root.cols); }
|
||||
else if (e.text == Key.Home) { root.sel = 0; }
|
||||
else if (e.text == Key.End) { root.sel = root.n - 1; }
|
||||
else { return false; }
|
||||
}
|
||||
root.reveal();
|
||||
return true;
|
||||
}
|
||||
|
||||
// ---- header ----
|
||||
Text { x: Theme.pad; y: 20px; text: "Library"; color: Theme.p.text; font-size: Theme.t-xl; font-weight: 800; }
|
||||
Text { x: Theme.pad + 104px; y: 30px; text: root.n == Lib.total-games ? root.n + " games" : root.n + " of " + Lib.total-games + " games"; color: Theme.p.dim; font-size: Theme.t-sm; }
|
||||
search := SearchBox {
|
||||
x: root.width - Theme.pad - self.width; y: 16px; width: Math.min(320px, root.width - 2 * Theme.pad - 260px);
|
||||
focused: root.active && root.zone == 0 && root.tool == 4;
|
||||
done => { root.refocus(); if (root.n > 0) { root.zone = 1; root.sel = 0; root.reveal(); } }
|
||||
}
|
||||
HorizontalLayout {
|
||||
x: Theme.pad; y: 70px; height: 34px; width: root.width - 2 * Theme.pad; spacing: 8px; alignment: start;
|
||||
Chip { text: "All"; active: Lib.filter == 0; focused: root.active && root.zone == 0 && root.tool == 0; clicked => { root.activate(0); } }
|
||||
Chip { text: "Installed"; active: Lib.filter == 1; focused: root.active && root.zone == 0 && root.tool == 1; clicked => { root.activate(1); } }
|
||||
Chip { text: "Not installed"; active: Lib.filter == 2; focused: root.active && root.zone == 0 && root.tool == 2; clicked => { root.activate(2); } }
|
||||
Rectangle { width: 16px; Rectangle { x: 8px; y: 7px; width: 1px; height: 20px; background: Theme.p.border; } }
|
||||
Chip { text: "Sort: " + root.sorts[Lib.sort]; focused: root.active && root.zone == 0 && root.tool == 3; clicked => { root.activate(3); } }
|
||||
}
|
||||
|
||||
if root.n == 0: EmptyState { y: root.head-h; height: root.height - root.head-h;
|
||||
title: Lib.total-games == 0 ? "No games yet" : "Nothing matches";
|
||||
hint: Lib.total-games == 0 ? "Summit found no games on this machine. Add one with: summit add \"My Game\" /path/to/game" : "Try another filter, or clear the search."; }
|
||||
|
||||
// ---- cover grid: one ListView row per grid row, so only the rows on screen exist ----
|
||||
grid-view := ListView {
|
||||
visible: !root.list && root.n > 0;
|
||||
y: root.head-h - 16px; height: root.height - self.y; width: root.width;
|
||||
animate content-y { duration: Theme.ms(200); easing: ease-out; }
|
||||
public function show(r: int) {
|
||||
if (r * root.row-h + root.top-pad < -self.content-y) { self.content-y = -(r * root.row-h); }
|
||||
else if ((r + 1) * root.row-h + root.top-pad + 16px > -self.content-y + self.visible-height) { self.content-y = -((r + 1) * root.row-h + root.top-pad + 16px - self.visible-height); }
|
||||
}
|
||||
for r in (root.list ? 0 : root.rows): Rectangle {
|
||||
height: root.row-h;
|
||||
for c in root.cols: Rectangle {
|
||||
x: Theme.pad + c * (root.card-w + root.gap); y: root.top-pad + 4px; width: root.card-w; height: root.card-w * 1.5;
|
||||
if r * root.cols + c < root.n: CoverCard {
|
||||
width: parent.width;
|
||||
idx: Lib.library[r * root.cols + c];
|
||||
focused: root.active && root.zone == 1 && root.sel == r * root.cols + c;
|
||||
clicked => {
|
||||
if (root.sel == r * root.cols + c && root.zone == 1) { Lib.open-detail(self.idx); }
|
||||
else { root.zone = 1; root.sel = r * root.cols + c; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---- dense list ----
|
||||
if root.list && root.n > 0: Rectangle {
|
||||
y: root.head-h - 12px; height: 28px; x: Theme.pad - 12px; width: root.width - 2 * Theme.pad + 24px;
|
||||
Text { x: 56px; text: "TITLE"; color: Theme.p.faint; font-size: 10px; font-weight: 800; letter-spacing: 1.4px; }
|
||||
Text { x: parent.width - 548px; width: 100px; horizontal-alignment: right; text: "PLAYED"; color: Theme.p.faint; font-size: 10px; font-weight: 800; letter-spacing: 1.4px; }
|
||||
Text { x: parent.width - 424px; text: "LAST PLAYED"; color: Theme.p.faint; font-size: 10px; font-weight: 800; letter-spacing: 1.4px; }
|
||||
Text { x: parent.width - 284px; text: "SOURCE"; color: Theme.p.faint; font-size: 10px; font-weight: 800; letter-spacing: 1.4px; }
|
||||
Text { x: parent.width - 172px; text: "STATE"; color: Theme.p.faint; font-size: 10px; font-weight: 800; letter-spacing: 1.4px; }
|
||||
Rectangle { y: parent.height - 5px; height: 1px; background: Theme.p.border; }
|
||||
}
|
||||
list-view := ListView {
|
||||
visible: root.list && root.n > 0;
|
||||
y: root.head-h + 16px; height: root.height - self.y; width: root.width;
|
||||
animate content-y { duration: Theme.ms(160); easing: ease-out; }
|
||||
public function show(i: int) {
|
||||
if (i * 52px < -self.content-y) { self.content-y = -(i * 52px); }
|
||||
else if ((i + 1) * 52px + 12px > -self.content-y + self.visible-height) { self.content-y = -((i + 1) * 52px + 12px - self.visible-height); }
|
||||
}
|
||||
for idx[i] in (root.list ? Lib.library : []): ListRow {
|
||||
idx: idx; odd: Math.mod(i, 2) == 1; focused: root.active && root.zone == 1 && root.sel == i;
|
||||
clicked => { if (root.sel == i && root.zone == 1) { Lib.open-detail(idx); } else { root.zone = 1; root.sel = i; } }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export component UnfilteredView inherits Rectangle {
|
||||
in property <bool> active;
|
||||
in-out property <int> sel: 1;
|
||||
callback exit-up();
|
||||
property <int> n: Lib.unfiltered.length;
|
||||
pure function step(from: int, d: int) -> int {
|
||||
// next row that is not a section header; headers never follow each other
|
||||
return from + d < 0 || from + d >= root.n ? from : Lib.unfiltered[from + d].header ? (from + 2 * d < 0 || from + 2 * d >= root.n ? from : from + 2 * d) : from + d;
|
||||
}
|
||||
public function key(e: KeyEvent) -> bool {
|
||||
if (root.n == 0) { if (e.text == Key.UpArrow) { root.exit-up(); return true; } return false; }
|
||||
if (e.text == Key.DownArrow) { root.sel = root.step(root.sel, 1); }
|
||||
else if (e.text == Key.UpArrow) { if (root.step(root.sel, -1) == root.sel) { root.exit-up(); view.content-y = 0; } else { root.sel = root.step(root.sel, -1); } }
|
||||
else if (e.text == Key.PageDown) { root.sel = root.step(Math.min(root.n - 1, root.sel + 8), 1); }
|
||||
else if (e.text == Key.PageUp) { root.sel = root.step(Math.max(0, root.sel - 8), -1); if (Lib.unfiltered[root.sel].header) { root.sel += 1; } }
|
||||
else if (e.text == Key.Return || e.text == " ") { Lib.open-detail(Lib.unfiltered[root.sel].idx); return true; }
|
||||
else { return false; }
|
||||
view.show(root.sel);
|
||||
return true;
|
||||
}
|
||||
Text { x: Theme.pad; y: 20px; text: "Unfiltered"; color: Theme.p.text; font-size: Theme.t-xl; font-weight: 800; }
|
||||
Text { x: Theme.pad; y: 58px; width: root.width - 2 * Theme.pad; text: "Everything Summit found that is on this machine, grouped by where it came from, with the reason for every entry."; color: Theme.p.dim; font-size: Theme.t-sm; overflow: elide; }
|
||||
if root.n == 0: EmptyState { y: 96px; height: root.height - 96px; title: "Nothing found"; hint: "Scan a folder: summit-gui ~/Games"; }
|
||||
view := ListView {
|
||||
y: 96px; height: root.height - self.y; width: root.width; visible: root.n > 0;
|
||||
animate content-y { duration: Theme.ms(160); easing: ease-out; }
|
||||
public function show(i: int) {
|
||||
if ((i - 1) * 56px < -self.content-y) { self.content-y = -Math.max(0px, (i - 1) * 56px); }
|
||||
else if ((i + 1) * 56px + 12px > -self.content-y + self.visible-height) { self.content-y = -((i + 1) * 56px + 12px - self.visible-height); }
|
||||
}
|
||||
for r[i] in Lib.unfiltered: Rectangle {
|
||||
height: 56px;
|
||||
property <Game> g: Lib.games[r.idx];
|
||||
property <bool> focused: root.active && root.sel == i;
|
||||
if r.header: Rectangle {
|
||||
x: Theme.pad; width: parent.width - 2 * Theme.pad;
|
||||
Text { x: 0; y: 24px; text: r.label; color: Theme.p.accent; font-size: Theme.t-xs; font-weight: 800; letter-spacing: 1.8px; }
|
||||
Rectangle { x: parent.width - 44px; y: 20px; width: 44px; height: 22px; border-radius: 11px; background: Theme.p.raised; border-width: Theme.p.border-w; border-color: Theme.p.border;
|
||||
Text { text: r.count; color: Theme.p.text; font-size: Theme.t-xs; font-weight: 700; horizontal-alignment: center; vertical-alignment: center; } }
|
||||
Rectangle { y: parent.height - 6px; height: 1px; background: Theme.p.border; }
|
||||
}
|
||||
if !r.header: Rectangle {
|
||||
x: Theme.pad - 12px; width: parent.width - 2 * Theme.pad + 24px; y: 2px; height: 52px; border-radius: Theme.r-sm;
|
||||
background: focused ? Theme.p.raised : ta.has-hover ? Theme.p.surface : transparent;
|
||||
border-width: focused ? 2px : 0px; border-color: Theme.p.focus;
|
||||
animate background { duration: Theme.ms(120); }
|
||||
Rectangle { x: 12px; y: 14px; width: 4px; height: 24px; border-radius: 2px; background: g.c1; }
|
||||
Text { x: 28px; y: 8px; width: parent.width - 28px - 220px; text: g.title; color: Theme.p.text; font-size: Theme.t-md - 1px; font-weight: 600; overflow: elide; }
|
||||
Text { x: 28px; y: 29px; width: parent.width - 28px - 220px; text: g.reasons; color: Theme.p.dim; font-size: Theme.t-sm - 1px; overflow: elide; }
|
||||
Text { x: parent.width - 200px; width: 100px; height: parent.height; horizontal-alignment: right; vertical-alignment: center; text: g.hours-short == "" ? "Not played" : g.hours-short; color: g.hours-short == "" ? Theme.p.faint : Theme.p.text; font-size: Theme.t-sm; font-weight: 600; }
|
||||
Text { x: parent.width - 84px; width: 72px; height: parent.height; horizontal-alignment: right; vertical-alignment: center; text: g.kind; color: Theme.p.faint; font-size: Theme.t-xs; font-weight: 700; letter-spacing: 0.8px; }
|
||||
ta := TouchArea { mouse-cursor: pointer; clicked => { if (root.sel == i) { Lib.open-detail(r.idx); } else { root.sel = i; } } }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
// Settings: layout, theme, UI scale, motion, clip lengths and the default enhance profile.
|
||||
import { Theme, Palette } from "theme.slint";
|
||||
import { Lib, Prefs, Icon, Icons, Segmented, SliderBar, FocusRing } from "widgets.slint";
|
||||
|
||||
component Section inherits Rectangle {
|
||||
in property <string> title;
|
||||
in property <string> icon;
|
||||
height: 48px;
|
||||
Icon { x: 0; y: 20px; size: 18px; color: Theme.p.accent; commands: root.icon; }
|
||||
Text { x: 28px; y: 20px; text: root.title; color: Theme.p.accent; font-size: Theme.t-xs; font-weight: 800; letter-spacing: 2px; }
|
||||
}
|
||||
|
||||
component Row inherits Rectangle {
|
||||
in property <string> label;
|
||||
in property <string> hint;
|
||||
in property <bool> focused;
|
||||
callback hit;
|
||||
height: 72px; border-radius: Theme.r-md;
|
||||
background: root.focused ? Theme.p.raised : Theme.p.surface.with-alpha(0.7);
|
||||
border-width: Theme.p.border-w; border-color: Theme.p.border;
|
||||
animate background { duration: Theme.ms(140); }
|
||||
TouchArea { clicked => { root.hit(); } }
|
||||
Text { x: 20px; y: root.hint == "" ? 26px : 15px; text: root.label; color: Theme.p.text; font-size: Theme.t-md; font-weight: 600; }
|
||||
Text { x: 20px; y: 39px; width: parent.width - 40px; text: root.hint; color: Theme.p.dim; font-size: Theme.t-sm - 1px; overflow: elide; }
|
||||
FocusRing { on: root.focused; radius: Theme.r-md; }
|
||||
@children
|
||||
}
|
||||
|
||||
component Swatch inherits Rectangle {
|
||||
in property <Palette> p;
|
||||
in property <bool> active;
|
||||
callback clicked;
|
||||
height: 84px; border-radius: Theme.r-md;
|
||||
background: root.p.bg; border-width: root.active ? 3px : 1px; border-color: root.active ? Theme.p.accent : Theme.p.border;
|
||||
Rectangle { x: 10px; y: 10px; width: parent.width - 20px; height: 34px; border-radius: 6px; background: root.p.surface; border-width: 1px; border-color: root.p.border;
|
||||
Rectangle { x: 8px; y: 9px; width: 16px; height: 16px; border-radius: 8px; background: @linear-gradient(120deg, root.p.accent 0%, root.p.accent2 100%); }
|
||||
Rectangle { x: 32px; y: 11px; width: parent.width * 0.4; height: 4px; border-radius: 2px; background: root.p.text; }
|
||||
Rectangle { x: 32px; y: 20px; width: parent.width * 0.26; height: 4px; border-radius: 2px; background: root.p.dim; }
|
||||
}
|
||||
Text { x: 12px; y: 54px; width: parent.width - 24px; text: root.p.name; color: root.p.text; font-size: Theme.t-sm - 1px; font-weight: 700; overflow: elide; }
|
||||
TouchArea { mouse-cursor: pointer; clicked => { root.clicked(); } }
|
||||
}
|
||||
|
||||
export component SettingsView inherits Rectangle {
|
||||
in property <bool> active;
|
||||
in-out property <int> srow: 0;
|
||||
callback exit-up();
|
||||
property <length> cw: Math.min(root.width - 2 * Theme.pad, 1040px);
|
||||
property <length> cx: Theme.pad;
|
||||
pure function ry(i: int) -> length {
|
||||
return i == 0 ? 136px : i == 1 ? 216px : i == 2 ? 384px : i == 3 ? 520px : i == 4 ? 600px : i == 5 ? 736px : i == 6 ? 816px : i == 7 ? 952px : 1032px;
|
||||
}
|
||||
pure function rh(i: int) -> length { return i == 1 ? 160px : 72px; }
|
||||
function reveal() {
|
||||
if (root.srow == 0) { flick.content-y = 0; }
|
||||
else if (root.ry(root.srow) - 56px < -flick.content-y) { flick.content-y = -(root.ry(root.srow) - 56px); }
|
||||
else if (root.ry(root.srow) + root.rh(root.srow) + 24px > -flick.content-y + flick.height) { flick.content-y = -(root.ry(root.srow) + root.rh(root.srow) + 24px - flick.height); }
|
||||
}
|
||||
function save() { Lib.settings-changed(); }
|
||||
function adjust(d: int) {
|
||||
if (root.srow == 0) { Theme.layout = Math.clamp(Theme.layout + d, 0, 2); }
|
||||
else if (root.srow == 1) { Theme.id = Math.mod(Theme.id + d + Theme.palettes.length, Theme.palettes.length); }
|
||||
else if (root.srow == 2) { Prefs.scale = Math.clamp(Prefs.scale + d, 0, Prefs.scales.length - 1); }
|
||||
else if (root.srow == 3) { Theme.speed = Math.clamp(Math.round((Theme.speed + d * 0.25) * 4) / 4, 0, 2); }
|
||||
else if (root.srow == 4) { Theme.style = Math.clamp(Theme.style + d, 0, 2); }
|
||||
else if (root.srow == 5) { Prefs.replay = Math.clamp(Prefs.replay + d, 0, 5); Prefs.clip = Math.min(Prefs.clip, Prefs.replay); }
|
||||
else if (root.srow == 6) { Prefs.clip = Math.clamp(Prefs.clip + d, 0, Prefs.replay); }
|
||||
else if (root.srow == 7) { Prefs.upscaler = Math.clamp(Prefs.upscaler + d, 0, 2); }
|
||||
else { Prefs.framegen = Math.clamp(Prefs.framegen + d, 0, 1); }
|
||||
root.save();
|
||||
}
|
||||
public function key(e: KeyEvent) -> bool {
|
||||
if (e.text == Key.DownArrow) { root.srow = Math.min(8, root.srow + 1); }
|
||||
else if (e.text == Key.UpArrow) { if (root.srow == 0) { root.exit-up(); } else { root.srow -= 1; } }
|
||||
else if (e.text == Key.RightArrow) { root.adjust(1); }
|
||||
else if (e.text == Key.LeftArrow) { root.adjust(-1); }
|
||||
else { return false; }
|
||||
root.reveal();
|
||||
return true;
|
||||
}
|
||||
|
||||
flick := Flickable {
|
||||
width: root.width; height: root.height; content-width: root.width; content-height: 1180px;
|
||||
animate content-y { duration: Theme.ms(220); easing: ease-out; }
|
||||
Text { x: root.cx; y: 20px; text: "Settings"; color: Theme.p.text; font-size: Theme.t-xl; font-weight: 800; }
|
||||
Text { x: root.cx; y: 58px; width: root.cw; text: "Saved to " + Prefs.file + " as you change them."; color: Theme.p.dim; font-size: Theme.t-sm; overflow: elide; }
|
||||
|
||||
Section { x: root.cx; y: 88px; width: root.cw; title: "APPEARANCE"; icon: Icons.grid; }
|
||||
Row { x: root.cx; y: root.ry(0); width: root.cw; label: "Layout"; hint: "Big picture is cover first and made for a TV and a controller. List is a dense table."; focused: root.active && root.srow == 0; hit => { root.srow = 0; }
|
||||
Segmented { x: parent.width - self.width - 16px; y: 16px; width: 3 * 112px + 8px; options: ["Big picture", "Grid", "List"]; value <=> Theme.layout; changed => { root.srow = 0; root.save(); } }
|
||||
}
|
||||
Row { x: root.cx; y: root.ry(1); width: root.cw; height: 160px; label: "Theme"; hint: ""; focused: root.active && root.srow == 1; hit => { root.srow = 1; }
|
||||
for p[i] in Theme.palettes: Swatch {
|
||||
property <length> sw: Math.min(160px, (parent.width - 40px - (Theme.palettes.length - 1) * 12px) / Theme.palettes.length);
|
||||
x: 20px + i * (self.sw + 12px); y: 60px; width: self.sw; p: p; active: Theme.id == i;
|
||||
clicked => { Theme.id = i; root.srow = 1; root.save(); }
|
||||
}
|
||||
Text { x: 20px + 64px; y: 28px; text: Theme.p.name; color: Theme.p.dim; font-size: Theme.t-sm; }
|
||||
}
|
||||
Row { x: root.cx; y: root.ry(2); width: root.cw; label: "Interface size"; hint: "Scales the whole launcher, on top of your system's display scale."; focused: root.active && root.srow == 2; hit => { root.srow = 2; }
|
||||
Segmented { x: parent.width - self.width - 16px; y: 16px; width: 6 * 76px + 8px; options: Prefs.scales; value <=> Prefs.scale; changed => { root.srow = 2; root.save(); } }
|
||||
}
|
||||
|
||||
Section { x: root.cx; y: 472px; width: root.cw; title: "MOTION"; icon: Icons.sparkle; }
|
||||
Row { x: root.cx; y: root.ry(3); width: root.cw; label: "Animation speed"; hint: "Drag to zero to turn every animation off."; focused: root.active && root.srow == 3; hit => { root.srow = 3; }
|
||||
Text { x: parent.width - 16px - 280px - 96px; width: 80px; height: parent.height; horizontal-alignment: right; vertical-alignment: center;
|
||||
text: Theme.speed < 0.01 ? "Off" : Math.round(Theme.speed * 100) + "%"; color: Theme.speed < 0.01 ? Theme.p.faint : Theme.p.text; font-size: Theme.t-md; font-weight: 700; }
|
||||
SliderBar { x: parent.width - self.width - 16px; y: 16px; minimum: 0; maximum: 2; value <=> Theme.speed; focused: false; changed => { root.srow = 3; root.save(); } }
|
||||
}
|
||||
Row { x: root.cx; y: root.ry(4); width: root.cw; label: "Animation style"; hint: "Smooth eases out gently, Snappy is short and sharp, Bouncy overshoots a little."; focused: root.active && root.srow == 4; hit => { root.srow = 4; }
|
||||
Segmented { x: parent.width - self.width - 16px; y: 16px; width: 3 * 112px + 8px; options: ["Smooth", "Snappy", "Bouncy"]; value <=> Theme.style; changed => { root.srow = 4; root.save(); } }
|
||||
}
|
||||
|
||||
Section { x: root.cx; y: 688px; width: root.cw; title: "CLIPS"; icon: Icons.film; }
|
||||
Row { x: root.cx; y: root.ry(5); width: root.cw; label: "Keep the last"; hint: "Instant replay buffer. Used by the engine (summit enhance)."; focused: root.active && root.srow == 5; hit => { root.srow = 5; }
|
||||
Segmented { x: parent.width - self.width - 16px; y: 16px; width: 6 * 76px + 8px; options: Prefs.clip-lengths; value <=> Prefs.replay; changed => { root.srow = 5; Prefs.clip = Math.min(Prefs.clip, Prefs.replay); root.save(); } }
|
||||
}
|
||||
Row { x: root.cx; y: root.ry(6); width: root.cw; label: "A save writes"; hint: "Never longer than the buffer. No in-game overlay yet."; focused: root.active && root.srow == 6; hit => { root.srow = 6; }
|
||||
Segmented { x: parent.width - self.width - 16px; y: 16px; width: 6 * 76px + 8px; options: Prefs.clip-lengths; limit: Prefs.replay; value <=> Prefs.clip; changed => { root.srow = 6; root.save(); } }
|
||||
}
|
||||
|
||||
Section { x: root.cx; y: 904px; width: root.cw; title: "ENHANCE DEFAULTS"; icon: Icons.monitor; }
|
||||
Row { x: root.cx; y: root.ry(7); width: root.cw; label: "Default upscaler"; hint: "Stored in the \"default\" profile for summit enhance. Not applied to launched games yet."; focused: root.active && root.srow == 7; hit => { root.srow = 7; }
|
||||
Segmented { x: parent.width - self.width - 16px; y: 16px; width: 3 * 100px + 8px; options: ["None", "FSR", "RTX VSR"]; value <=> Prefs.upscaler; changed => { root.srow = 7; root.save(); } }
|
||||
}
|
||||
Row { x: root.cx; y: root.ry(8); width: root.cw; label: "Default frame generation"; hint: "RIFE needs an NVIDIA GPU and the engine's Python environment."; focused: root.active && root.srow == 8; hit => { root.srow = 8; }
|
||||
Segmented { x: parent.width - self.width - 16px; y: 16px; width: 2 * 100px + 8px; options: ["None", "RIFE"]; value <=> Prefs.framegen; changed => { root.srow = 8; root.save(); } }
|
||||
}
|
||||
Text { x: root.cx; y: 1124px; width: root.cw; text: Lib.stats + " · " + Lib.session + " · " + Lib.renderer; color: Theme.p.faint; font-size: Theme.t-xs; overflow: elide; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
// Themes, motion and the type scale. To add a theme, append one Palette to `Theme.palettes`:
|
||||
// the settings page, SUMMIT_THEME and ui.toml (which stores `key`) pick it up without other changes.
|
||||
|
||||
export struct Palette {
|
||||
key: string, // stored in ui.toml
|
||||
name: string, // shown in settings
|
||||
dark: bool, // false for light themes (dark text on light surfaces)
|
||||
bg: color, // window background, top
|
||||
bg2: color, // window background, bottom
|
||||
surface: color, // panels, rows, cards
|
||||
raised: color, // hover, chips, inputs
|
||||
border: color,
|
||||
border-w: length, // 1px normally, thicker for high contrast
|
||||
text: color,
|
||||
dim: color, // secondary text
|
||||
faint: color, // tertiary text, disabled
|
||||
accent: color,
|
||||
accent2: color, // end of the accent gradient
|
||||
on-accent: color, // text on accent
|
||||
focus: color, // focus ring
|
||||
glow: color, // soft shadow around the focused item
|
||||
ok: color, // "installed"
|
||||
scrim: float, // how strongly art is darkened behind text (0..1)
|
||||
}
|
||||
|
||||
export global Theme {
|
||||
in property <[Palette]> palettes: [
|
||||
{ key: "midnight", name: "Midnight", dark: true, bg: #0a0c11, bg2: #0d1017, surface: #141821, raised: #1d2330, border: #272e3d, border-w: 1px,
|
||||
text: #eef1f7, dim: #9aa3b5, faint: #5f687a, accent: #ffb02e, accent2: #ff7a3d, on-accent: #1a1200, focus: #ffc65c, glow: #ffb02e, ok: #4ade80, scrim: 0.92 },
|
||||
{ key: "steam", name: "Steam blue", dark: true, bg: #171a21, bg2: #1b2838, surface: #202c3c, raised: #2a3f55, border: #34506a, border-w: 1px,
|
||||
text: #e9f1f7, dim: #94a3b3, faint: #66788a, accent: #66c0f4, accent2: #1a9fff, on-accent: #06131f, focus: #a5e0ff, glow: #1a9fff, ok: #a4d007, scrim: 0.9 },
|
||||
{ key: "daylight", name: "Daylight", dark: false, bg: #f4f6fa, bg2: #e8ecf3, surface: #ffffff, raised: #edf0f6, border: #d5dae5, border-w: 1px,
|
||||
text: #131722, dim: #566074, faint: #8d96a8, accent: #2563eb, accent2: #5b4be8, on-accent: #ffffff, focus: #2563eb, glow: #2563eb, ok: #15803d, scrim: 0.94 },
|
||||
{ key: "violet", name: "Violet", dark: true, bg: #0f0a1b, bg2: #1a1030, surface: #1c1433, raised: #2a1e4a, border: #3b2b64, border-w: 1px,
|
||||
text: #f2edff, dim: #a99dca, faint: #716694, accent: #b68cff, accent2: #f06bd6, on-accent: #1a0b33, focus: #d6beff, glow: #a56bff, ok: #5eead4, scrim: 0.9 },
|
||||
{ key: "contrast", name: "High contrast", dark: true, bg: #000000, bg2: #000000, surface: #000000, raised: #1c1c1c, border: #ffffff, border-w: 2px,
|
||||
text: #ffffff, dim: #e6e6e6, faint: #bdbdbd, accent: #ffe600, accent2: #ffe600, on-accent: #000000, focus: #00e5ff, glow: #00e5ff, ok: #3dff8a, scrim: 1.0 },
|
||||
{ key: "oled", name: "OLED black", dark: true, bg: #000000, bg2: #000000, surface: #0b0b0c, raised: #161617, border: #222224, border-w: 1px,
|
||||
text: #f3f3f4, dim: #8e8e93, faint: #5c5c61, accent: #ff4d67, accent2: #ff8a5c, on-accent: #ffffff, focus: #ff7a8e, glow: #ff4d67, ok: #34d399, scrim: 0.96 },
|
||||
];
|
||||
in-out property <int> id: 0;
|
||||
out property <Palette> p: root.palettes[Math.max(0, Math.min(root.id, root.palettes.length - 1))];
|
||||
|
||||
// 0 Big picture, 1 Grid, 2 List
|
||||
in-out property <int> layout: 0;
|
||||
out property <bool> big: root.layout == 0;
|
||||
out property <length> pad: root.big ? 56px : 32px;
|
||||
|
||||
// ---- motion: speed 0 = off, 1 = default, 2 = twice as fast. style 0 smooth, 1 snappy, 2 bouncy ----
|
||||
in-out property <float> speed: 1.0;
|
||||
in-out property <int> style: 0;
|
||||
in property <bool> still: false; // headless renders: jump straight to the settled state
|
||||
out property <bool> motion: root.speed > 0.01 && !root.still;
|
||||
out property <easing> ease: root.style == 1 ? Easing.ease-out-expo : root.style == 2 ? Easing.ease-out-back : Easing.ease-out-quart;
|
||||
pure public function ms(base: int) -> duration {
|
||||
return root.motion ? (base * (root.style == 1 ? 0.65 : root.style == 2 ? 1.25 : 1.0) / root.speed) * 1ms : 0ms;
|
||||
}
|
||||
|
||||
// ---- type scale ----
|
||||
out property <length> t-xs: 11px;
|
||||
out property <length> t-sm: 13px;
|
||||
out property <length> t-md: 15px;
|
||||
out property <length> t-lg: 18px;
|
||||
out property <length> t-xl: 24px;
|
||||
out property <length> t-2xl: 34px;
|
||||
out property <length> t-3xl: 48px;
|
||||
// ---- radii (spacing is on an 8px grid throughout) ----
|
||||
out property <length> r-sm: 6px;
|
||||
out property <length> r-md: 10px;
|
||||
out property <length> r-lg: 16px;
|
||||
}
|
||||
@@ -0,0 +1,370 @@
|
||||
// Data model shared with Rust, plus the small building blocks: icons, logo, buttons, chips, cover cards.
|
||||
import { Theme } from "theme.slint";
|
||||
|
||||
export struct Game {
|
||||
id: string,
|
||||
title: string,
|
||||
hours: string, // "182.3 hours", "45 min", "Never played"
|
||||
hours-short: string, // "182.3 h", "45 min", ""
|
||||
last: string, // "Today", "3 days ago", "Never"
|
||||
source: string, // "Steam", "Heroic", ...
|
||||
kind: string, // "Game", "Software", "Tool"
|
||||
installed: bool,
|
||||
pinned: bool,
|
||||
cover: image,
|
||||
has-cover: bool,
|
||||
c1: color, // fallback gradient, from the title
|
||||
c2: color,
|
||||
reasons: string, // detection reasons on one line
|
||||
action: string, // "Play", "Install", or "" when Summit cannot start it yet
|
||||
}
|
||||
|
||||
export struct URow { header: bool, label: string, count: int, idx: int }
|
||||
|
||||
// Filled by Rust when a game's page opens.
|
||||
export struct Detail {
|
||||
idx: int,
|
||||
sessions: string,
|
||||
sessions-note: string,
|
||||
reasons: [string],
|
||||
path: string,
|
||||
monitor: string,
|
||||
mode: string,
|
||||
upscaler: string,
|
||||
framegen: string,
|
||||
window: string,
|
||||
profile-set: bool,
|
||||
play-label: string,
|
||||
play-note: string,
|
||||
can-play: bool,
|
||||
}
|
||||
|
||||
// Preferences edited on the settings page (layout, theme and motion live in Theme). Rust saves them to ui.toml.
|
||||
export global Prefs {
|
||||
in-out property <int> scale: 2; // index into scales
|
||||
in property <[string]> scales: ["80%", "90%", "100%", "110%", "125%", "150%"];
|
||||
in-out property <int> replay: 2; // index into clip-lengths
|
||||
in-out property <int> clip: 1;
|
||||
in property <[string]> clip-lengths: ["15 s", "30 s", "1 min", "3 min", "5 min", "10 min"];
|
||||
in-out property <int> upscaler: 0; // none, fsr, rtx-vsr
|
||||
in-out property <int> framegen: 0; // none, rife
|
||||
in property <string> file; // where the settings are stored, for display
|
||||
}
|
||||
|
||||
export global Lib {
|
||||
in property <[Game]> games;
|
||||
in property <[int]> recent;
|
||||
in property <[int]> pinned;
|
||||
in property <[int]> most;
|
||||
in property <[int]> library; // after filter, sort and search
|
||||
in property <[URow]> unfiltered;
|
||||
in property <int> total-games;
|
||||
in property <int> total-installed;
|
||||
in property <string> stats;
|
||||
in property <string> session;
|
||||
in property <string> renderer;
|
||||
in-out property <int> filter: 0; // 0 all, 1 installed, 2 not installed
|
||||
in-out property <int> sort: 0; // 0 recent, 1 most played, 2 A-Z
|
||||
in-out property <string> search;
|
||||
in property <Detail> detail;
|
||||
callback want-cover(int);
|
||||
callback focus-game(int); // load the backdrop for this game
|
||||
callback query(); // filter, sort or search changed
|
||||
callback open-detail(int);
|
||||
callback play(int);
|
||||
callback toggle-pin(int);
|
||||
callback settings-changed();
|
||||
callback toggle-fullscreen();
|
||||
}
|
||||
|
||||
// 24x24 line icons, drawn as paths so they follow the theme and scale cleanly.
|
||||
export component Icon inherits Path {
|
||||
in property <color> color: Theme.p.text;
|
||||
in property <bool> solid: false;
|
||||
in property <length> size: 20px;
|
||||
in property <length> weight: 2px;
|
||||
width: root.size; height: root.size;
|
||||
viewbox-width: 24; viewbox-height: 24;
|
||||
stroke: root.solid ? transparent : root.color;
|
||||
stroke-width: root.solid ? 0px : root.weight;
|
||||
fill: root.solid ? root.color : transparent;
|
||||
stroke-line-cap: round;
|
||||
stroke-line-join: round;
|
||||
}
|
||||
|
||||
export global Icons {
|
||||
out property <string> home: "M3 11.5 L12 3.5 L21 11.5 M5.5 10 V20 H10 V14.5 H14 V20 H18.5 V10";
|
||||
out property <string> grid: "M4 4 H10 V10 H4 Z M14 4 H20 V10 H14 Z M4 14 H10 V20 H4 Z M14 14 H20 V20 H14 Z";
|
||||
out property <string> list: "M8 6 H20 M8 12 H20 M8 18 H20 M4 6 H4.01 M4 12 H4.01 M4 18 H4.01";
|
||||
out property <string> layers: "M12 3 L21 8 L12 13 L3 8 Z M3 12.5 L12 17.5 L21 12.5 M3 17 L12 22 L21 17";
|
||||
out property <string> gear: "M12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6z M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z";
|
||||
out property <string> search: "M11 4a7 7 0 1 0 0 14a7 7 0 0 0 0-14z M20.5 20.5l-4.4-4.4";
|
||||
out property <string> play: "M7 4.5 L19.5 12 L7 19.5 Z";
|
||||
out property <string> pin: "M7 3.5 H17 V20.5 L12 16.5 L7 20.5 Z";
|
||||
out property <string> check: "M5 12.5 L10 17.5 L19 7";
|
||||
out property <string> download: "M12 4 V15 M7 10.5 L12 15.5 L17 10.5 M5 20 H19";
|
||||
out property <string> picture: "M4 5 H20 V19 H4 Z M4 16 L9 11 L13 15 L16 12 L20 16 M8.5 8.5 H8.51";
|
||||
out property <string> close: "M6 6 L18 18 M18 6 L6 18";
|
||||
out property <string> back: "M14.5 5 L7.5 12 L14.5 19";
|
||||
out property <string> clock: "M12 3a9 9 0 1 0 0 18a9 9 0 0 0 0-18z M12 7.5 V12 L15.5 14";
|
||||
out property <string> monitor: "M3 5 H21 V16 H3 Z M8.5 20 H15.5 M12 16 V20";
|
||||
out property <string> sliders: "M4 7 H13 M17 7 H20 M4 17 H7 M11 17 H20 M15 4.5 V9.5 M9 14.5 V19.5";
|
||||
out property <string> info: "M12 3a9 9 0 1 0 0 18a9 9 0 0 0 0-18z M12 11 V16.5 M12 7.6 H12.01";
|
||||
out property <string> sparkle: "M12 3 L13.8 10.2 L21 12 L13.8 13.8 L12 21 L10.2 13.8 L3 12 L10.2 10.2 Z";
|
||||
out property <string> film: "M3 6 H15 V18 H3 Z M15 10.5 L21 7 V17 L15 13.5";
|
||||
}
|
||||
|
||||
// The mark: two peaks, the front one in the accent gradient.
|
||||
export component LogoMark inherits Rectangle {
|
||||
in property <length> size: 28px;
|
||||
width: root.size; height: root.size;
|
||||
Path {
|
||||
width: parent.width; height: parent.height; viewbox-width: 24; viewbox-height: 24;
|
||||
commands: "M9 21 L16.5 8.5 L23.5 21 Z";
|
||||
fill: Theme.p.accent.with-alpha(0.45); stroke-width: 0px;
|
||||
}
|
||||
Path {
|
||||
width: parent.width; height: parent.height; viewbox-width: 24; viewbox-height: 24;
|
||||
commands: "M0.5 21 L9.5 3.5 L18.5 21 Z";
|
||||
fill: @linear-gradient(160deg, Theme.p.accent 0%, Theme.p.accent2 100%); stroke-width: 0px;
|
||||
}
|
||||
Path {
|
||||
width: parent.width; height: parent.height; viewbox-width: 24; viewbox-height: 24;
|
||||
commands: "M9.5 3.5 L12.6 9.6 L10.6 8.6 L9.3 10.6 L8 8.8 L6.5 9.4 Z";
|
||||
fill: Theme.p.dark ? #ffffffd8 : #ffffff; stroke-width: 0px;
|
||||
}
|
||||
}
|
||||
|
||||
export component Wordmark inherits Rectangle {
|
||||
in property <length> size: 28px;
|
||||
height: root.size; width: mark.width + 12px + txt.preferred-width;
|
||||
mark := LogoMark { x: 0; size: root.size; }
|
||||
txt := Text {
|
||||
x: mark.width + 12px; height: parent.height; vertical-alignment: center;
|
||||
text: "SUMMIT"; color: Theme.p.text; font-size: root.size * 0.68; font-weight: 800; letter-spacing: root.size * 0.16;
|
||||
}
|
||||
}
|
||||
|
||||
// Focus ring drawn around its parent: ring plus a soft glow in the theme's glow colour.
|
||||
export component FocusRing inherits Rectangle {
|
||||
in property <bool> on;
|
||||
in property <length> radius: Theme.r-md;
|
||||
in property <length> gap: 3px;
|
||||
Rectangle {
|
||||
x: -root.gap; y: -root.gap; width: root.width + 2 * root.gap; height: root.height + 2 * root.gap;
|
||||
border-radius: root.radius + root.gap;
|
||||
border-width: 3px; border-color: Theme.p.focus;
|
||||
background: transparent;
|
||||
opacity: root.on ? 1 : 0;
|
||||
animate opacity { duration: Theme.ms(140); }
|
||||
}
|
||||
}
|
||||
|
||||
export component Btn inherits Rectangle {
|
||||
in property <string> text;
|
||||
in property <string> icon;
|
||||
in property <bool> icon-solid: false;
|
||||
in property <bool> primary: false;
|
||||
in property <bool> focused: false;
|
||||
in property <bool> enabled: true;
|
||||
in property <string> badge; // e.g. "Soon" for things that are not built yet
|
||||
in property <length> h: 48px;
|
||||
callback clicked;
|
||||
property <bool> hot: ta.has-hover && root.enabled;
|
||||
property <color> fg: !root.enabled ? Theme.p.faint : root.primary ? Theme.p.on-accent : Theme.p.text;
|
||||
height: root.h;
|
||||
width: row.preferred-width;
|
||||
border-radius: root.h / 2;
|
||||
background: root.primary && root.enabled ? @linear-gradient(100deg, Theme.p.accent 0%, Theme.p.accent2 100%) : (root.hot || root.focused ? Theme.p.raised : Theme.p.surface.with-alpha(Theme.p.dark ? 0.72 : 0.9));
|
||||
border-width: root.primary && root.enabled ? 0px : Theme.p.border-w;
|
||||
border-color: Theme.p.border;
|
||||
drop-shadow-blur: root.focused ? 24px : 0px;
|
||||
drop-shadow-color: root.focused ? Theme.p.glow.with-alpha(0.55) : transparent;
|
||||
animate drop-shadow-blur { duration: Theme.ms(160); }
|
||||
Rectangle { border-radius: parent.border-radius; background: root.primary && root.hot ? #ffffff26 : transparent; }
|
||||
row := HorizontalLayout {
|
||||
padding-left: root.text == "" ? (root.h - 20px) / 2 : root.h * 0.5; padding-right: root.text == "" ? (root.h - 20px) / 2 : root.h * 0.5; spacing: 10px; alignment: center;
|
||||
if root.icon != "": VerticalLayout { alignment: center; Icon { commands: root.icon; color: root.fg; solid: root.icon-solid; size: 20px; } }
|
||||
if root.text != "": Text { text: root.text; color: root.fg; font-size: root.primary ? Theme.t-md + 1px : Theme.t-md; font-weight: root.primary ? 800 : 600; vertical-alignment: center; letter-spacing: root.primary ? 1px : 0px; }
|
||||
if root.badge != "": VerticalLayout { alignment: center;
|
||||
Rectangle { height: 20px; width: bt.preferred-width + 14px; border-radius: 10px; background: Theme.p.raised; border-width: 1px; border-color: Theme.p.border;
|
||||
bt := Text { text: root.badge; color: Theme.p.dim; font-size: 10px; font-weight: 700; letter-spacing: 0.6px; horizontal-alignment: center; vertical-alignment: center; } } }
|
||||
}
|
||||
FocusRing { on: root.focused; radius: root.h / 2; }
|
||||
ta := TouchArea { enabled: root.enabled; mouse-cursor: pointer; clicked => { root.clicked(); } }
|
||||
}
|
||||
|
||||
// Small status label: source, kind, installed state.
|
||||
export component Tag inherits Rectangle {
|
||||
in property <string> text;
|
||||
in property <color> tint: Theme.p.dim;
|
||||
in property <bool> dot: false;
|
||||
height: 24px; width: l.preferred-width + (root.dot ? 30px : 18px); border-radius: 12px;
|
||||
background: Theme.p.raised.with-alpha(0.85); border-width: Theme.p.border-w; border-color: Theme.p.border;
|
||||
if root.dot: Rectangle { x: 9px; y: 8px; width: 8px; height: 8px; border-radius: 4px; background: root.tint; }
|
||||
l := Text { x: root.dot ? 22px : 9px; text: root.text; color: root.dot ? Theme.p.text : root.tint; font-size: Theme.t-xs; font-weight: 700; letter-spacing: 0.5px; vertical-alignment: center; height: parent.height; }
|
||||
}
|
||||
|
||||
// Filter / sort chip.
|
||||
export component Chip inherits Rectangle {
|
||||
in property <string> text;
|
||||
in property <bool> active;
|
||||
in property <bool> focused;
|
||||
callback clicked;
|
||||
height: 34px; width: l.preferred-width + 30px; border-radius: 17px;
|
||||
background: root.active ? Theme.p.accent : (ta.has-hover || root.focused ? Theme.p.raised : Theme.p.surface);
|
||||
border-width: root.active ? 0px : Theme.p.border-w; border-color: Theme.p.border;
|
||||
animate background { duration: Theme.ms(140); }
|
||||
l := Text { text: root.text; color: root.active ? Theme.p.on-accent : Theme.p.text; font-size: Theme.t-sm; font-weight: root.active ? 700 : 500; horizontal-alignment: center; vertical-alignment: center; }
|
||||
FocusRing { on: root.focused; radius: 17px; }
|
||||
ta := TouchArea { mouse-cursor: pointer; clicked => { root.clicked(); } }
|
||||
}
|
||||
|
||||
// One-of-N choice. `limit` disables options after that index (used for clip length vs buffer length).
|
||||
export component Segmented inherits Rectangle {
|
||||
in property <[string]> options;
|
||||
in-out property <int> value;
|
||||
in property <bool> focused;
|
||||
in property <int> limit: 99;
|
||||
callback changed(int);
|
||||
property <length> cell: Math.max(72px, (root.width - 8px) / Math.max(1, root.options.length));
|
||||
height: 40px; border-radius: 20px;
|
||||
width: root.options.length * 96px + 8px;
|
||||
background: Theme.p.surface; border-width: Theme.p.border-w; border-color: Theme.p.border;
|
||||
Rectangle {
|
||||
x: 4px + root.value * root.cell; y: 4px; width: root.cell; height: parent.height - 8px; border-radius: self.height / 2;
|
||||
background: @linear-gradient(100deg, Theme.p.accent 0%, Theme.p.accent2 100%);
|
||||
animate x { duration: Theme.ms(220); easing: Theme.ease; }
|
||||
}
|
||||
for o[i] in root.options: Rectangle {
|
||||
x: 4px + i * root.cell; y: 4px; width: root.cell; height: parent.height - 8px;
|
||||
Text { text: o; color: i == root.value ? Theme.p.on-accent : i > root.limit ? Theme.p.faint : Theme.p.text; font-size: Theme.t-sm; font-weight: i == root.value ? 700 : 500; horizontal-alignment: center; vertical-alignment: center;
|
||||
animate color { duration: Theme.ms(160); } }
|
||||
TouchArea { enabled: i <= root.limit; mouse-cursor: pointer; clicked => { if (root.value != i) { root.value = i; root.changed(i); } } }
|
||||
}
|
||||
FocusRing { on: root.focused; radius: 20px; }
|
||||
}
|
||||
|
||||
export component SliderBar inherits Rectangle {
|
||||
in-out property <float> value;
|
||||
in property <float> minimum: 0;
|
||||
in property <float> maximum: 1;
|
||||
in property <bool> focused;
|
||||
callback changed(float);
|
||||
property <float> t: (root.value - root.minimum) / (root.maximum - root.minimum);
|
||||
height: 40px; width: 280px;
|
||||
track := Rectangle { y: (parent.height - 6px) / 2; height: 6px; border-radius: 3px; background: Theme.p.raised; border-width: Theme.p.border-w; border-color: Theme.p.border; }
|
||||
Rectangle { x: 0; y: track.y; height: 6px; border-radius: 3px; width: 11px + (root.width - 22px) * root.t; background: @linear-gradient(90deg, Theme.p.accent 0%, Theme.p.accent2 100%); }
|
||||
Rectangle {
|
||||
x: (root.width - 22px) * root.t; y: (parent.height - 22px) / 2; width: 22px; height: 22px; border-radius: 11px;
|
||||
background: Theme.p.dark ? white : Theme.p.accent; border-width: 3px; border-color: Theme.p.accent;
|
||||
drop-shadow-blur: 8px; drop-shadow-color: #00000066; drop-shadow-offset-y: 2px;
|
||||
FocusRing { on: root.focused; radius: 11px; }
|
||||
}
|
||||
ta := TouchArea {
|
||||
mouse-cursor: pointer;
|
||||
function set(px: length) {
|
||||
root.value = Math.round((root.minimum + (root.maximum - root.minimum) * Math.clamp((px - 11px) / (root.width - 22px), 0, 1)) * 20) / 20;
|
||||
root.changed(root.value);
|
||||
}
|
||||
pointer-event(e) => { if (e.kind == PointerEventKind.down) { self.set(self.mouse-x); } }
|
||||
moved => { if (self.pressed) { self.set(self.mouse-x); } }
|
||||
}
|
||||
}
|
||||
|
||||
// A key cap for the hint bar.
|
||||
export component KeyCap inherits Rectangle {
|
||||
in property <string> key;
|
||||
in property <string> label;
|
||||
height: 22px; width: cap.width + 8px + l.preferred-width;
|
||||
cap := Rectangle { x: 0; height: 22px; width: Math.max(22px, k.preferred-width + 12px); border-radius: 5px; background: Theme.p.raised; border-width: 1px; border-color: Theme.p.border;
|
||||
k := Text { text: root.key; color: Theme.p.text; font-size: 11px; font-weight: 700; horizontal-alignment: center; vertical-alignment: center; } }
|
||||
l := Text { x: cap.width + 8px; height: parent.height; text: root.label; color: Theme.p.dim; font-size: Theme.t-sm - 1px; vertical-alignment: center; }
|
||||
}
|
||||
|
||||
// Art with a fallback: gradient from the title's colours, a soft shape and the title itself.
|
||||
export component CoverArt inherits Rectangle {
|
||||
in property <Game> g;
|
||||
in property <length> title-size: Math.max(11px, root.width * 0.105);
|
||||
clip: true;
|
||||
background: @linear-gradient(155deg, root.g.c1 0%, root.g.c2 100%);
|
||||
if !root.g.has-cover: Rectangle {
|
||||
Rectangle { x: parent.width * 0.35; y: -parent.width * 0.35; width: parent.width * 1.1; height: self.width; border-radius: self.width / 2; background: #ffffff14; }
|
||||
Rectangle { x: -parent.width * 0.5; y: parent.height * 0.62; width: parent.width * 1.3; height: self.width; border-radius: self.width / 2; background: #00000024; }
|
||||
if root.width > 60px: Text {
|
||||
x: root.width * 0.1; y: root.height * 0.1; width: root.width * 0.8; height: root.height * 0.62;
|
||||
text: root.g.title; color: white; font-size: root.title-size; font-weight: 800; wrap: word-wrap; overflow: elide;
|
||||
vertical-alignment: top;
|
||||
}
|
||||
if root.width > 110px: Text {
|
||||
x: root.width * 0.1; y: root.height - 30px; text: root.g.source; color: #ffffffb0; font-size: 10px; font-weight: 700; letter-spacing: 1.2px;
|
||||
}
|
||||
}
|
||||
if root.g.has-cover: Image { source: root.g.cover; width: parent.width; height: parent.height; image-fit: cover; }
|
||||
}
|
||||
|
||||
// 2:3 cover card. The slot keeps its size; the art inside lifts and grows when focused or hovered.
|
||||
export component CoverCard inherits Rectangle {
|
||||
in property <int> idx;
|
||||
in property <bool> focused;
|
||||
callback clicked;
|
||||
property <Game> g: Lib.games[root.idx];
|
||||
property <bool> hot: ta.has-hover;
|
||||
property <float> k: root.focused ? 1.07 : root.hot ? 1.03 : 1.0;
|
||||
animate k { duration: Theme.ms(200); easing: Theme.ease; }
|
||||
height: self.width * 1.5;
|
||||
init => { Lib.want-cover(root.idx); }
|
||||
changed idx => { Lib.want-cover(root.idx); }
|
||||
box := Rectangle {
|
||||
width: root.width * root.k; height: root.height * root.k;
|
||||
x: (root.width - self.width) / 2; y: (root.height - self.height) / 2 - (root.focused ? 4px : 0px);
|
||||
animate y { duration: Theme.ms(200); easing: Theme.ease; }
|
||||
border-radius: Theme.r-md;
|
||||
background: Theme.p.surface;
|
||||
drop-shadow-blur: root.focused ? 36px : root.hot ? 22px : 12px;
|
||||
drop-shadow-offset-y: root.focused ? 10px : 6px;
|
||||
drop-shadow-color: root.focused ? Theme.p.glow.with-alpha(0.5) : (Theme.p.dark ? #000000a0 : #2a35504d);
|
||||
animate drop-shadow-blur { duration: Theme.ms(200); }
|
||||
Rectangle {
|
||||
border-radius: Theme.r-md; clip: true;
|
||||
CoverArt { g: root.g; width: parent.width; height: parent.height; }
|
||||
if !root.g.installed: Rectangle { background: Theme.p.bg.with-alpha(root.focused || root.hot ? 0.12 : 0.42); animate background { duration: Theme.ms(160); } }
|
||||
// title and hours, shown on focus or hover
|
||||
Rectangle {
|
||||
y: parent.height - self.height; height: Math.min(parent.height, 84px);
|
||||
opacity: root.focused || root.hot ? 1 : 0;
|
||||
animate opacity { duration: Theme.ms(180); }
|
||||
background: @linear-gradient(180deg, #00000000 0%, #000000d9 70%, #000000f0 100%);
|
||||
Text { x: 12px; y: parent.height - 44px; width: parent.width - 24px; text: root.g.title; color: white; font-size: Theme.t-sm; font-weight: 700; overflow: elide; }
|
||||
Text { x: 12px; y: parent.height - 25px; width: parent.width - 24px; text: root.g.hours; color: #ffffffc0; font-size: Theme.t-xs; font-weight: 500; overflow: elide; }
|
||||
}
|
||||
if !root.g.installed: Rectangle {
|
||||
x: 8px; y: 8px; height: 24px; width: root.width > 150px ? ni.preferred-width + 34px : 24px; border-radius: 12px; background: #000000b8;
|
||||
Icon { x: 5px; y: 5px; size: 14px; weight: 1.6px; color: #ffffffd0; commands: Icons.download; }
|
||||
ni := Text { x: 24px; height: parent.height; visible: root.width > 150px; text: "Not installed"; color: #ffffffd0; font-size: 10px; font-weight: 600; vertical-alignment: center; }
|
||||
}
|
||||
if root.g.pinned: Rectangle {
|
||||
x: parent.width - 32px; y: 8px; width: 24px; height: 24px; border-radius: 12px; background: Theme.p.accent;
|
||||
drop-shadow-blur: 6px; drop-shadow-color: #00000080;
|
||||
Icon { x: 5px; y: 5px; size: 14px; solid: true; color: Theme.p.on-accent; commands: Icons.pin; }
|
||||
}
|
||||
}
|
||||
Rectangle { border-radius: Theme.r-md; border-width: Theme.p.border-w; border-color: Theme.p.dark ? #ffffff1c : #0000001a; background: transparent; visible: Theme.p.border-w <= 1px; }
|
||||
Rectangle { border-radius: Theme.r-md; border-width: 2px; border-color: Theme.p.border; background: transparent; visible: Theme.p.border-w > 1px; }
|
||||
FocusRing { on: root.focused; radius: Theme.r-md; gap: 4px; }
|
||||
}
|
||||
ta := TouchArea { mouse-cursor: pointer; clicked => { root.clicked(); } }
|
||||
}
|
||||
|
||||
export component Toast inherits Rectangle {
|
||||
in property <string> text;
|
||||
in property <bool> shown;
|
||||
in property <length> max-w: 800px;
|
||||
height: 48px; width: Math.min(root.max-w, t.preferred-width + 72px); border-radius: 24px;
|
||||
background: Theme.p.raised; border-width: Theme.p.border-w; border-color: Theme.p.border;
|
||||
drop-shadow-blur: 30px; drop-shadow-color: #00000090; drop-shadow-offset-y: 8px;
|
||||
opacity: root.shown ? 1 : 0;
|
||||
animate opacity { duration: Theme.ms(220); }
|
||||
Icon { x: 18px; y: 14px; size: 20px; color: Theme.p.accent; commands: Icons.info; }
|
||||
t := Text { x: 48px; width: parent.width - 66px; height: parent.height; text: root.text; color: Theme.p.text; font-size: Theme.t-sm; font-weight: 600; vertical-alignment: center; overflow: elide; }
|
||||
}
|
||||
Reference in new issue
Block a user