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

59 lines
1.7 KiB
Rust
Raw Normal View History

use crate::{Primitive, Renderer};
use iced_native::{
2019-10-11 23:30:53 +02:00
button, Align, Background, Button, Color, Layout, Length, MouseCursor,
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-11 23:30:53 +02:00
let (content, _) = button.content.draw(
self,
layout.children().next().unwrap(),
cursor_position,
);
(
Primitive::Group {
primitives: vec![
Primitive::Quad {
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,
},
content,
],
},
if bounds.contains(cursor_position) {
MouseCursor::Pointer
} else {
MouseCursor::OutOfBounds
},
)
2019-10-05 19:22:51 +02:00
}
}