@@ -0,0 +1,40 @@
|
|||||||
|
use osui::prelude::*;
|
||||||
|
|
||||||
|
pub fn app() -> 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! {
|
||||||
|
FlexRow {
|
||||||
|
FlexCol {
|
||||||
|
@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
|
||||||
|
} (1)
|
||||||
|
|
||||||
|
FlexCol {
|
||||||
|
Div {
|
||||||
|
%count
|
||||||
|
"This will increment every second: {count}"
|
||||||
|
}
|
||||||
|
} (2)
|
||||||
|
} (0)
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -22,7 +22,7 @@ impl Div {
|
|||||||
impl Element for Div {
|
impl Element for Div {
|
||||||
fn render(&mut self, scope: &mut crate::render_scope::RenderScope) {
|
fn render(&mut self, scope: &mut crate::render_scope::RenderScope) {
|
||||||
let (width, height) = scope.get_size_or(self.size.0, self.size.1);
|
let (width, height) = scope.get_size_or(self.size.0, self.size.1);
|
||||||
scope.draw_rect(width, height, 0);
|
scope.use_area(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn after_render(&mut self, scope: &mut crate::render_scope::RenderScope) {
|
fn after_render(&mut self, scope: &mut crate::render_scope::RenderScope) {
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ impl Element for FlexRow {
|
|||||||
transform.height = transform.height.max(v + t.height);
|
transform.height = transform.height.max(v + t.height);
|
||||||
t.x += transform.x;
|
t.x += transform.x;
|
||||||
t.y += transform.y + v;
|
t.y += transform.y + v;
|
||||||
v += t.height + self.gap;
|
v += t.height + self.gap + (t.py * 2);
|
||||||
t.px += transform.px;
|
t.px += transform.px;
|
||||||
t.py += transform.py;
|
t.py += transform.py;
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ impl Element for FlexCol {
|
|||||||
transform.height = transform.height.max(t.height + (t.py * 2));
|
transform.height = transform.height.max(t.height + (t.py * 2));
|
||||||
t.x += transform.x + v;
|
t.x += transform.x + v;
|
||||||
t.y += transform.y;
|
t.y += transform.y;
|
||||||
v += t.width + self.gap;
|
v += t.width + self.gap + (t.px * 2);
|
||||||
t.px += transform.px;
|
t.px += transform.px;
|
||||||
t.py += transform.py;
|
t.py += transform.py;
|
||||||
|
|
||||||
|
|||||||
+2
-14
@@ -1,22 +1,10 @@
|
|||||||
|
mod demos;
|
||||||
use osui::prelude::*;
|
use osui::prelude::*;
|
||||||
|
|
||||||
fn main() -> std::io::Result<()> {
|
fn main() -> std::io::Result<()> {
|
||||||
let screen = Screen::new();
|
let screen = Screen::new();
|
||||||
screen.extension(VelocityExtension);
|
|
||||||
|
|
||||||
let count = use_state(0);
|
demos::app().draw(&screen);
|
||||||
|
|
||||||
rsx! {
|
|
||||||
@Velocity(20, 0);
|
|
||||||
@Transform::new();
|
|
||||||
static "Count: {count}"
|
|
||||||
}
|
|
||||||
.draw(&screen);
|
|
||||||
|
|
||||||
std::thread::spawn(move || loop {
|
|
||||||
**count.get() += 1;
|
|
||||||
std::thread::sleep(std::time::Duration::from_millis(100));
|
|
||||||
});
|
|
||||||
|
|
||||||
screen.run()
|
screen.run()
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-2
@@ -105,8 +105,22 @@ impl RenderScope {
|
|||||||
|
|
||||||
match self.style.background {
|
match self.style.background {
|
||||||
crate::style::Background::NoBackground => {}
|
crate::style::Background::NoBackground => {}
|
||||||
crate::style::Background::Outline(_c) => {
|
crate::style::Background::Outline(c) => {
|
||||||
// TODO: Implement basic outline drawing if needed
|
let width = width + self.transform.px * 2;
|
||||||
|
let height = height + self.transform.py * 2;
|
||||||
|
if width > 1 && height > 1 {
|
||||||
|
let d = "─".repeat(width as usize - 2);
|
||||||
|
utils::print_liner(
|
||||||
|
self.transform.x,
|
||||||
|
self.transform.y,
|
||||||
|
&utils::hex_ansi(c),
|
||||||
|
&format!(
|
||||||
|
"┌{d}┐{}\n└{d}┘",
|
||||||
|
format!("\n│{}│", " ".repeat(width as usize - 2))
|
||||||
|
.repeat(height as usize - 2),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
crate::style::Background::RoundedOutline(c) => {
|
crate::style::Background::RoundedOutline(c) => {
|
||||||
let width = width + self.transform.px * 2;
|
let width = width + self.transform.px * 2;
|
||||||
|
|||||||
Reference in New Issue
Block a user