iced-yoda/wgpu/src/renderer/button.rs

50 lines
1.4 KiB
Rust
Raw Normal View History

use crate::{Primitive, Renderer};
use iced_native::{
button, Align, Background, Button, Color, Layout, Length, Node, Point,
Style,
};
2019-10-05 19:22:51 +02:00
impl button::Renderer for Renderer {
fn node<Message>(&self, button: &Button<Message, Self>) -> Node {
2019-10-06 19:22:25 +02:00
let style = Style::default()
.width(button.width)
.padding(button.padding)
2019-10-06 19:22:25 +02:00
.min_width(Length::Units(100))
.align_self(button.align_self)
.align_items(Align::Stretch);
2019-10-06 19:22:25 +02:00
Node::with_children(style, vec![button.content.node(self)])
2019-10-05 19:22:51 +02:00
}
fn draw<Message>(
&mut self,
button: &Button<Message, Self>,
2019-10-06 19:22:25 +02:00
layout: Layout<'_>,
cursor_position: Point,
) -> Self::Output {
2019-10-07 03:56:16 +02:00
let bounds = layout.bounds();
2019-10-06 19:22:25 +02:00
Primitive::Group {
primitives: vec![
2019-10-07 02:17:40 +02:00
Primitive::Quad {
2019-10-07 03:56:16 +02:00
bounds,
background: button.background.unwrap_or(Background::Color(
Color {
r: 0.8,
b: 0.8,
g: 0.8,
a: 1.0,
},
)),
border_radius: button.border_radius,
2019-10-06 19:22:25 +02:00
},
button.content.draw(
self,
layout.children().next().unwrap(),
cursor_position,
),
2019-10-06 19:22:25 +02:00
],
}
2019-10-05 19:22:51 +02:00
}
}