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;
pub use mouse_cursor::MouseCursor;
pub use primitive::Primitive;
pub use primitive::{Background, Primitive};
pub use renderer::{Renderer, Target};

View File

@ -1,4 +1,4 @@
use iced_native::Rectangle;
use iced_native::{Color, Rectangle};
#[derive(Debug, Clone)]
pub enum Primitive {
@ -11,4 +11,13 @@ pub enum Primitive {
bounds: Rectangle,
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 },
..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 iced_native::{button, Button, Layout, Node, Point, Style};
use crate::{Background, Primitive, Renderer};
use iced_native::{button, Button, Color, Layout, Length, Node, Point, Style};
impl button::Renderer for Renderer {
fn node<Message>(&self, _button: &Button<Message>) -> Node {
Node::new(Style::default())
fn node<Message>(&self, button: &Button<Message>) -> Node {
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>(
&mut self,
_button: &Button<Message>,
_layout: Layout<'_>,
button: &Button<Message>,
layout: Layout<'_>,
_cursor_position: Point,
) -> Self::Primitive {
// TODO
Primitive::None
Primitive::Group {
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(),
},
],
}
}
}