OXYGENHUB
◆ v0.1.4 oxygenhub-android / rust-core / src / backdrop / scene.rs
2.4 KiB · Rust · last changed The hub's living backgrounds in the app: the mark at sign-in, Your sky on the dashboard, live runs pulse (refs #23) 8 days ago source blame history raw
1
// Copied from OxygenHub crates/backdrop/src/scene.rs (6dc080f6) by
2
// scripts/sync-backdrop.sh: change it there, never here.
3
//! A backdrop's scene (docs/backgrounds.md §2): what it draws and how it
4
//! moves. The engine (lib.rs) drives any of them the same way.
5
6
use crate::backdrop::sky::{Colours, Kind};
7
8
pub trait Scene {
9
    /// The view is now `w` by `h` CSS pixels, the page's content column
10
    /// between `avoid`'s left and right.
11
    fn resize(&mut self, w: f32, h: f32, avoid: Option<(f32, f32)>);
12
    /// The cursor moved to `(x, y)`, or left the page.
13
    fn point(&mut self, at: Option<(f32, f32)>);
14
    /// Move on by `dt` seconds.
15
    fn step(&mut self, dt: f32);
16
    /// The marks, 8 floats each (sky::Sky::instances).
17
    fn instances(&self, c: &Colours, out: &mut Vec<f32>);
18
    /// The links, 12 floats each (sky::Sky::links).
19
    fn links(&self, c: &Colours, out: &mut Vec<f32>);
20
    /// The name a resting cursor shows, and where.
21
    fn label(&self) -> Option<(&str, f32, f32)>;
22
    /// New activity in repository `repo` (§5, "Live"); only the sky shows it.
23
    fn arrive(&mut self, _repo: &str, _kind: Kind, _n: u32) {}
24
    /// Whether a frame would show anything new besides the drift, which
25
    /// the engine stops drawing a while after the last input (§6).
26
    fn busy(&self) -> bool;
27
    fn still(&self) -> bool;
28
    fn size(&self) -> (f32, f32);
29
}
30
31
impl Scene for crate::backdrop::sky::Sky {
32
    fn resize(&mut self, w: f32, h: f32, avoid: Option<(f32, f32)>) {
33
        crate::backdrop::sky::Sky::resize(self, w, h, avoid)
34
    }
35
    fn point(&mut self, at: Option<(f32, f32)>) {
36
        crate::backdrop::sky::Sky::point(self, at)
37
    }
38
    fn step(&mut self, dt: f32) {
39
        crate::backdrop::sky::Sky::step(self, dt)
40
    }
41
    fn instances(&self, c: &Colours, out: &mut Vec<f32>) {
42
        crate::backdrop::sky::Sky::instances(self, c, out)
43
    }
44
    fn links(&self, c: &Colours, out: &mut Vec<f32>) {
45
        crate::backdrop::sky::Sky::links(self, c, out)
46
    }
47
    fn label(&self) -> Option<(&str, f32, f32)> {
48
        crate::backdrop::sky::Sky::label(self)
49
    }
50
    fn arrive(&mut self, repo: &str, kind: Kind, n: u32) {
51
        crate::backdrop::sky::Sky::arrive(self, repo, kind, n)
52
    }
53
    fn busy(&self) -> bool {
54
        crate::backdrop::sky::Sky::busy(self)
55
    }
56
    fn still(&self) -> bool {
57
        self.still
58
    }
59
    fn size(&self) -> (f32, f32) {
60
        (self.w, self.h)
61
    }
62
}