Testing new structure

This commit is contained in:
2025-11-18 20:04:14 +01:00
parent c6d11315d6
commit e031f9bcef
28 changed files with 127 additions and 3689 deletions
-48
View File
@@ -1,48 +0,0 @@
use std::sync::Arc;
use osui::prelude::*;
fn main() -> std::io::Result<()> {
let screen = Screen::new();
screen.extension(InputExtension);
app(screen.clone()).draw(&screen);
screen.run()
}
pub fn app(screen: Arc<Screen>) -> Rsx {
let items: State<Vec<i32>> = use_state(Vec::new());
let count = use_state(1);
run! {
ref count, items {
loop {
items.get().push(count.get_dl());
**count.get() += 1;
std::thread::sleep(std::time::Duration::from_millis(100));
}
}
}
rsx! {
@AlwaysFocused;
@Handler::new({
let screen = screen.clone();
move |_, e: &crossterm::event::Event| {
if let crossterm::event::Event::Key(crossterm::event::KeyEvent { code, .. }) = e {
if *code == crossterm::event::KeyCode::Esc {
screen.close();
}
}
}
});
Scroll {
FlexRow {
for item in items {
static "{item}"
}
}
}
}
}
-83
View File
@@ -1,83 +0,0 @@
use std::sync::Arc;
use osui::prelude::*;
fn main() -> std::io::Result<()> {
let screen = Screen::new();
screen.extension(InputExtension);
screen.extension(RelativeFocusExtension::new());
app(screen.clone()).draw(&screen);
screen.run()
}
pub fn app(screen: Arc<Screen>) -> Rsx {
let count = use_state(0);
std::thread::spawn({
let count = count.clone();
move || loop {
**count.get() += 1;
std::thread::sleep(std::time::Duration::from_secs(1));
}
});
rsx! {
@Handler::new({
let screen = screen.clone();
move |_, e: &crossterm::event::Event| {
if let crossterm::event::Event::Key(crossterm::event::KeyEvent { code, .. }) = e {
if *code == crossterm::event::KeyCode::Esc {
screen.close();
}
}
}});
@AlwaysFocused;
Paginator {
FlexRow {
Heading, smooth: false, { "OSUI" }
"Welcome to the OSUI demo!"
"Press tab to switch to the next page or shift+tab to the previous page"
}
FlexCol, gap: 3, {
@Transform::new().padding(2, 2);
@Style { foreground: None, background: Background::RoundedOutline(0x00ff00) };
Div {
"This is text inside a div"
}
@Transform::new().padding(2, 2);
@Style { foreground: None, background: Background::Outline(0x00ff00) };
Div {
"This is text inside a div with square outlines"
}
// TODO: div with width full
}
FlexRow, gap: 1, {
%count
"This will increment every second: {count}"
FlexRow
{
"Username"
@Transform::new().padding(1, 1).dimensions_const(40, 1);
@Style { foreground: Some(0xffffff), background: Background::RoundedOutline(0xff0000) };
@Focused;
Input { }
}
FlexRow
{
"Password"
@Transform::new().padding(1, 1).dimensions_const(40, 1);
@Style { foreground: Some(0xffffff), background: Background::RoundedOutline(0xffff00) };
Input { }
}
}
}
}
}
-52
View File
@@ -1,52 +0,0 @@
use std::sync::Arc;
use osui::prelude::*;
fn main() -> std::io::Result<()> {
let screen = Screen::new();
screen.extension(InputExtension);
app(screen.clone()).draw(&screen);
screen.run()
}
pub fn app(screen: Arc<Screen>) -> Rsx {
rsx! {
@Handler::new({
let screen = screen.clone();
move |_, e: &crossterm::event::Event| {
if let crossterm::event::Event::Key(e) = e {
if e.code == crossterm::event::KeyCode::Esc {
screen.close();
}
}
}
});
@Style { foreground: None, background: Background::Outline(0xff0000) };
VelocityHandler {
@Velocity(700, 0);
@Handler::new({
move |w, e: &crossterm::event::Event| {
if let crossterm::event::Event::Key(e) = e {
if e.code == crossterm::event::KeyCode::Char(' ') {
if let Some(Velocity(v, _)) = w.get() {
w.set_component(Velocity(-v, 0));
} else {
w.component(Velocity(700, 0));
}
}
}
}
});
"(•_•)"
}
@Transform::new().dimensions(Dimension::Full, Dimension::Full);
VelocityHandler {
@Velocity(0, -150);
@Transform::center().bottom();
"^"
}
}
}