git clone https://garage44.eu/jeroen/pinnacle.git.. /programs/src/bin/about.rs
//! About this device: the system, its cores and its memory. The first app
//! built from a view (`pinnacle_view`): the stylesheet lays it out for any
//! window, so it has no rectangles of its own.
#![no_std]
#![no_main]
extern crate alloc;
use alloc::format;
use alloc::string::String;
use pinnacle_locale::t;
use pinnacle_ui::{App, Event};
use pinnacle_view::{IntoView, Screen, Signal, View, el, signal};
/// One row of the card: a name and its value.
fn row(label: &'static str, value: impl IntoView) -> View {
el("div")
.class("m-list-item")
.attr("role", "listitem")
.child(
el("span")
.class("m-list-item__body")
.child(el("span").class("m-list-item__title").child(label)),
)
.child(el("span").class("m-list-item__end").child(value))
.into_view()
}
fn page(up: Signal<u64>) -> View {
let (cores, ram, free) = pinnacle_rt::info();
el("main")
.attr(
"style",
"max-width: 560px; margin: 0 auto; padding: 32px 16px; \
display: flex; flex-direction: column; align-items: stretch; gap: 8px",
)
.child(
el("div")
.attr(
"style",
"align-self: center; width: 96px; height: 96px; border-radius: 48px; \
background: var(--m-accent); color: #ffffff; font-size: 56px; \
display: flex; align-items: center; justify-content: center",
)
.child("P"),
)
.child(
el("h1")
.attr("style", "font-size: 32px; text-align: center; margin: 16px 0 0")
.child("Pinnacle"),
)
.child(
el("p")
.attr(
"style",
"color: var(--m-text-muted); text-align: center; margin: 0 0 16px",
)
.child(t("An operating system written in Rust")),
)
.child(
el("section").class("m-section").child(
el("div")
.class("m-list")
.attr("role", "list")
.child(row(t("Version"), String::from(env!("CARGO_PKG_VERSION"))))
.child(row(t("Cores"), format!("{cores}")))
.child(row(t("Memory"), format!("{} MiB", ram >> 20)))
.child(row(t("Free"), format!("{} MiB", free >> 20)))
.child(row(t("Up"), move || format!("{} s", up.get()))),
),
)
.into_view()
}
#[unsafe(no_mangle)]
fn main(_argument: u64) -> u64 {
let mut app = App::new("About");
let mut screen = Screen::new(app.width, app.height);
let up = signal(pinnacle_rt::time() / 1000);
screen.mount(page(up.clone()));
screen.draw(&mut app.canvas(), true);
app.present_all();
loop {
match app.next_event(None) {
Event::Shown(true) => {
up.set(pinnacle_rt::time() / 1000);
screen.draw(&mut app.canvas(), true);
app.present_all();
}
Event::Resized => {
screen.resize(app.width, app.height);
screen.draw(&mut app.canvas(), true);
app.present_all();
}
Event::Input(input) => {
screen.input(&input);
if let Some(area) = screen.draw(&mut app.canvas(), false) {
app.present(area);
}
}
Event::Preferences => {
screen.restyle();
screen.mount(page(up.clone()));
screen.draw(&mut app.canvas(), true);
app.present_all();
}
Event::Closed => return 0,
_ => {}
}
}
}