feat(k-ui): first slice: App trait + run loop, builders (column/row/text/button), flex layout, theme tokens (Whimsy Dark), tiny-skia + fontdue render (Noto Sans Latin subset), keyboard focus ring; tally demo; manifest memory key (pm spawns with it)
This commit is contained in:
13
crates/apps/tally/Cargo.toml
Normal file
13
crates/apps/tally/Cargo.toml
Normal file
@@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "tally"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[[bin]]
|
||||
name = "tally"
|
||||
test = false
|
||||
bench = false
|
||||
|
||||
[dependencies]
|
||||
libkos = { workspace = true }
|
||||
k-ui = { workspace = true }
|
||||
10
crates/apps/tally/manifest.toml
Normal file
10
crates/apps/tally/manifest.toml
Normal file
@@ -0,0 +1,10 @@
|
||||
[app]
|
||||
id = "kos.tally"
|
||||
name = "Tally"
|
||||
version = "1.0.0"
|
||||
binary = "tally"
|
||||
author = "K-OS"
|
||||
memory = "3 MiB"
|
||||
|
||||
[capabilities]
|
||||
required = ["display"]
|
||||
61
crates/apps/tally/src/main.rs
Normal file
61
crates/apps/tally/src/main.rs
Normal file
@@ -0,0 +1,61 @@
|
||||
//! A count, and buttons to change it: the first K-UI app. Tab and the
|
||||
//! arrows move between the buttons, Enter presses, Escape leaves.
|
||||
|
||||
#![no_std]
|
||||
#![forbid(unsafe_code)]
|
||||
#![no_main]
|
||||
|
||||
extern crate alloc;
|
||||
extern crate libkos;
|
||||
|
||||
use alloc::format;
|
||||
use k_ui::{App, ButtonVariant, Element, Spacing, TextColour, TextStyle, button, column, row, text};
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
enum Event {
|
||||
Add,
|
||||
Subtract,
|
||||
Reset,
|
||||
}
|
||||
|
||||
struct Tally(i64);
|
||||
|
||||
impl App for Tally {
|
||||
type Event = Event;
|
||||
|
||||
fn init() -> Self {
|
||||
Tally(0)
|
||||
}
|
||||
|
||||
fn update(&mut self, event: Event) {
|
||||
match event {
|
||||
Event::Add => self.0 += 1,
|
||||
Event::Subtract => self.0 -= 1,
|
||||
Event::Reset => self.0 = 0,
|
||||
}
|
||||
}
|
||||
|
||||
fn view(&self) -> Element<Event> {
|
||||
let mut buttons = row()
|
||||
.gap(Spacing::Md)
|
||||
.child(button("Subtract", Event::Subtract))
|
||||
.child(button("Add", Event::Add).variant(ButtonVariant::Primary));
|
||||
if self.0 != 0 {
|
||||
buttons = buttons.child(button("Reset", Event::Reset).variant(ButtonVariant::Destructive));
|
||||
}
|
||||
column()
|
||||
.padding(Spacing::Xl)
|
||||
.gap(Spacing::Lg)
|
||||
.child(text("Tally").style(TextStyle::Heading))
|
||||
.child(text(format!("{}", self.0)).style(TextStyle::Subheading).colour(TextColour::Accent))
|
||||
.child(buttons)
|
||||
.child(text("Tab moves, Enter presses, Esc leaves").style(TextStyle::Caption).colour(TextColour::Secondary))
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
libkos::entry!(main);
|
||||
|
||||
fn main() {
|
||||
k_ui::run::<Tally>();
|
||||
}
|
||||
Reference in New Issue
Block a user