Draft Box primitive

This commit is contained in:
Héctor Ramón Jiménez 2019-10-06 19:22:25 +02:00
parent 5a5ca34b5f
commit 7765e6da50
4 changed files with 44 additions and 10 deletions

View file

@ -3,5 +3,5 @@ mod primitive;
mod renderer; mod renderer;
pub use mouse_cursor::MouseCursor; pub use mouse_cursor::MouseCursor;
pub use primitive::Primitive; pub use primitive::{Background, Primitive};
pub use renderer::{Renderer, Target}; pub use renderer::{Renderer, Target};

View file

@ -1,4 +1,4 @@
use iced_native::Rectangle; use iced_native::{Color, Rectangle};
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum Primitive { pub enum Primitive {
@ -11,4 +11,13 @@ pub enum Primitive {
bounds: Rectangle, bounds: Rectangle,
size: f32, size: f32,
}, },
Box {
bounds: Rectangle,
background: Background,
},
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Background {
Color(Color),
} }

View file

@ -144,6 +144,9 @@ impl Renderer {
scale: wgpu_glyph::Scale { x: *size, y: *size }, scale: wgpu_glyph::Scale { x: *size, y: *size },
..Default::default() ..Default::default()
}), }),
Primitive::Box { bounds, background } => {
// TODO: Batch boxes and draw them all at once
}
} }
} }
} }

View file

@ -1,18 +1,40 @@
use crate::{Primitive, Renderer}; use crate::{Background, Primitive, Renderer};
use iced_native::{button, Button, Layout, Node, Point, Style}; use iced_native::{button, Button, Color, Layout, Length, Node, Point, Style};
impl button::Renderer for Renderer { impl button::Renderer for Renderer {
fn node<Message>(&self, _button: &Button<Message>) -> Node { fn node<Message>(&self, button: &Button<Message>) -> Node {
Node::new(Style::default()) let style = Style::default()
.width(button.width)
.min_height(Length::Units(30))
.min_width(Length::Units(100))
.align_self(button.align_self);
Node::new(style)
} }
fn draw<Message>( fn draw<Message>(
&mut self, &mut self,
_button: &Button<Message>, button: &Button<Message>,
_layout: Layout<'_>, layout: Layout<'_>,
_cursor_position: Point, _cursor_position: Point,
) -> Self::Primitive { ) -> Self::Primitive {
// TODO Primitive::Group {
Primitive::None primitives: vec![
Primitive::Box {
bounds: layout.bounds(),
background: Background::Color(Color {
r: 0.0,
b: 1.0,
g: 0.0,
a: 1.0,
}),
},
Primitive::Text {
content: button.label.clone(),
size: 20.0,
bounds: layout.bounds(),
},
],
}
} }
} }