todo
This commit is contained in:
+50
-2
@@ -2,12 +2,12 @@ pub mod div;
|
|||||||
|
|
||||||
use crate::widget::Element;
|
use crate::widget::Element;
|
||||||
|
|
||||||
pub struct Rect;
|
pub struct Rect(pub u32);
|
||||||
|
|
||||||
impl Element for Rect {
|
impl Element for Rect {
|
||||||
fn render(&mut self, scope: &mut crate::render::RenderScope) {
|
fn render(&mut self, scope: &mut crate::render::RenderScope) {
|
||||||
let (w, h) = scope.get_size();
|
let (w, h) = scope.get_size();
|
||||||
scope.draw_rect(0, 0, w, h, 0xffffff);
|
scope.draw_rect(0, 0, w, h, self.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn as_any(&self) -> &dyn std::any::Any {
|
fn as_any(&self) -> &dyn std::any::Any {
|
||||||
@@ -32,3 +32,51 @@ impl Element for String {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Element for (String, f32) {
|
||||||
|
fn render(&mut self, scope: &mut crate::render::RenderScope) {
|
||||||
|
scope.draw_text(0, 0, 40.0 * self.1, &self.0, 0xffffff);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn as_any(&self) -> &dyn std::any::Any {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Element for Box<dyn FnMut(&mut crate::render::RenderScope) + Send + Sync> {
|
||||||
|
fn as_any(&self) -> &dyn std::any::Any {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render(&mut self, scope: &mut crate::render::RenderScope) {
|
||||||
|
self(scope)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Element for Box<dyn Fn(&mut crate::render::RenderScope) + Send + Sync> {
|
||||||
|
fn as_any(&self) -> &dyn std::any::Any {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render(&mut self, scope: &mut crate::render::RenderScope) {
|
||||||
|
self(scope)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn custom<F: FnMut(&mut crate::render::RenderScope) + Send + Sync + 'static>(
|
||||||
|
f: F,
|
||||||
|
) -> Box<dyn FnMut(&mut crate::render::RenderScope) + Send + Sync> {
|
||||||
|
Box::new(f)
|
||||||
|
}
|
||||||
|
|||||||
+36
-3
@@ -1,10 +1,14 @@
|
|||||||
use minifb::{Window, WindowOptions};
|
use minifb::{Window, WindowOptions};
|
||||||
use osgui::{
|
use osgui::{
|
||||||
elements::div::{Div, DivStyle},
|
elements::{
|
||||||
|
custom,
|
||||||
|
div::{Div, DivStyle},
|
||||||
|
},
|
||||||
extensions::{
|
extensions::{
|
||||||
mouse::{MouseExtension, OnClick},
|
mouse::{MouseExtension, OnClick},
|
||||||
velocity::{Velocity, VelocityExtension},
|
velocity::{Velocity, VelocityExtension},
|
||||||
},
|
},
|
||||||
|
render::RenderScope,
|
||||||
style::Transform,
|
style::Transform,
|
||||||
Screen,
|
Screen,
|
||||||
};
|
};
|
||||||
@@ -25,7 +29,8 @@ fn main() {
|
|||||||
app.extension(MouseExtension::new());
|
app.extension(MouseExtension::new());
|
||||||
app.extension(VelocityExtension);
|
app.extension(VelocityExtension);
|
||||||
|
|
||||||
milestones(&mut app);
|
// milestones(&mut app);
|
||||||
|
todos(&mut app);
|
||||||
|
|
||||||
app.run().unwrap();
|
app.run().unwrap();
|
||||||
}
|
}
|
||||||
@@ -54,6 +59,34 @@ fn milestones(app: &mut Screen) {
|
|||||||
osgui::style::Position::Const(145 + ((194 + 30) * i)),
|
osgui::style::Position::Const(145 + ((194 + 30) * i)),
|
||||||
))
|
))
|
||||||
.component(OnClick(|_| println!("Clicked!")))
|
.component(OnClick(|_| println!("Clicked!")))
|
||||||
.component(Velocity(50, 0));
|
.component(Velocity(300, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn todos(app: &mut Screen) {
|
||||||
|
todo_box(app, Transform::center(), true, "Hello, World!");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn todo_box(app: &mut Screen, transform: Transform, done: bool, text: &str) {
|
||||||
|
let text = text.to_string();
|
||||||
|
app.draw(custom(move |scope: &mut RenderScope| {
|
||||||
|
scope.draw_rect_rounded(0, 2, 24, 24, 8, 0xffffff);
|
||||||
|
scope.draw_rect_rounded(3, 5, 18, 18, 4, 0x010101);
|
||||||
|
if done {
|
||||||
|
let (mut x, mut y) = (5, 14);
|
||||||
|
while x != 8 {
|
||||||
|
scope.draw_rect_rounded(x, y, 2, 2, 4, 0xffffff);
|
||||||
|
x += 1;
|
||||||
|
y += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
while x != 17 && y != 7 {
|
||||||
|
scope.draw_rect_rounded(x, y, 3, 2, 4, 0xffffff);
|
||||||
|
x += 1;
|
||||||
|
y -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
scope.draw_text(29, 0, 28.0, &text, 0xffffff);
|
||||||
|
}))
|
||||||
|
.component(transform.clone());
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user