outlines
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
pub mod div;
|
pub mod div;
|
||||||
pub mod flex;
|
pub mod flex;
|
||||||
|
pub mod shape;
|
||||||
|
|
||||||
pub use div::*;
|
pub use div::*;
|
||||||
pub use flex::*;
|
pub use flex::*;
|
||||||
|
pub use shape::*;
|
||||||
|
|
||||||
use crate::Element;
|
use crate::Element;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
use crate::widget::Element;
|
||||||
|
|
||||||
|
pub struct RoundedOutline;
|
||||||
|
|
||||||
|
impl Element for RoundedOutline {
|
||||||
|
fn render(&mut self, scope: &mut crate::prelude::RenderScope) {
|
||||||
|
let (w, h) = scope.get_size_or_parent();
|
||||||
|
if w > 2 && h > 2 {
|
||||||
|
let d = "─".repeat(w as usize - 2);
|
||||||
|
scope.draw_text(&format!(
|
||||||
|
"╭{d}╮{}\n╰{d}╯",
|
||||||
|
format!("\n│{}│", " ".repeat(w as usize - 2)).repeat(h as usize - 2),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn as_any(&self) -> &dyn std::any::Any {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RoundedOutline {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Outline;
|
||||||
|
|
||||||
|
impl Element for Outline {
|
||||||
|
fn render(&mut self, scope: &mut crate::prelude::RenderScope) {
|
||||||
|
let (w, h) = scope.get_size_or_parent();
|
||||||
|
if w > 2 && h > 2 {
|
||||||
|
let d = "─".repeat(w as usize - 2);
|
||||||
|
scope.draw_text(&format!(
|
||||||
|
"┌{d}┐{}\n└{d}┘",
|
||||||
|
format!("\n│{}│", " ".repeat(w as usize - 2)).repeat(h as usize - 2),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn as_any(&self) -> &dyn std::any::Any {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Outline {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self
|
||||||
|
}
|
||||||
|
}
|
||||||
+13
-27
@@ -10,33 +10,19 @@ fn main() -> std::io::Result<()> {
|
|||||||
|
|
||||||
fn app() -> Rsx {
|
fn app() -> Rsx {
|
||||||
rsx! {
|
rsx! {
|
||||||
|
@transform! {
|
||||||
|
width: Full,
|
||||||
|
height: Full,
|
||||||
|
};
|
||||||
|
Div {
|
||||||
|
@transform! {
|
||||||
|
width: Full,
|
||||||
|
height: Full,
|
||||||
|
};
|
||||||
|
RoundedOutline {}
|
||||||
|
|
||||||
@Transform::center();
|
@Transform::center();
|
||||||
FlexCol {
|
"Welcome To OSUI!"
|
||||||
test => (1)
|
} (0x000000)
|
||||||
test => (3)
|
|
||||||
} (0x0000ff, 4)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn test(inc: i32) -> Rsx {
|
|
||||||
let count = use_state(0);
|
|
||||||
|
|
||||||
std::thread::spawn({
|
|
||||||
let count = count.clone();
|
|
||||||
move || loop {
|
|
||||||
std::thread::sleep(std::time::Duration::from_millis(50));
|
|
||||||
**count.get() += inc;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
rsx! {
|
|
||||||
@Transform::new().dimensions(40, 3);
|
|
||||||
Div {
|
|
||||||
@transform! { x: Center, y: Center, width: 5 };
|
|
||||||
Div {
|
|
||||||
%count
|
|
||||||
"{count}"
|
|
||||||
} (0x00ff00)
|
|
||||||
} (0xff0000)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user