summaryrefslogtreecommitdiffstats
path: root/wgpu/src/renderer/widget/button.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-11-21 13:47:20 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-11-21 13:47:20 +0100
commit65eb218d3d7ba52b2869a586a1480eeb3c8f84e4 (patch)
tree644f27f40f2f4b8ee1abe7743aac426297503eea /wgpu/src/renderer/widget/button.rs
parentd3553adf278e5b616fbd885f321faa83a4d24b56 (diff)
downloadiced-65eb218d3d7ba52b2869a586a1480eeb3c8f84e4.tar.gz
iced-65eb218d3d7ba52b2869a586a1480eeb3c8f84e4.tar.bz2
iced-65eb218d3d7ba52b2869a586a1480eeb3c8f84e4.zip
Move widgets from `core` to `native` and `web`
Also made fields private and improved `Renderer` traits.
Diffstat (limited to 'wgpu/src/renderer/widget/button.rs')
-rw-r--r--wgpu/src/renderer/widget/button.rs52
1 files changed, 11 insertions, 41 deletions
diff --git a/wgpu/src/renderer/widget/button.rs b/wgpu/src/renderer/widget/button.rs
index a19c7d86..86963053 100644
--- a/wgpu/src/renderer/widget/button.rs
+++ b/wgpu/src/renderer/widget/button.rs
@@ -1,52 +1,22 @@
use crate::{Primitive, Renderer};
-use iced_native::{
- button, layout, Background, Button, Layout, Length, MouseCursor, Point,
- Rectangle,
-};
+use iced_native::{button, Background, MouseCursor, Point, Rectangle};
impl button::Renderer for Renderer {
- fn layout<Message>(
- &self,
- button: &Button<Message, Self>,
- limits: &layout::Limits,
- ) -> layout::Node {
- let padding = f32::from(button.padding);
- let limits = limits
- .min_width(button.min_width)
- .width(button.width)
- .height(Length::Shrink)
- .pad(padding);
-
- let mut content = button.content.layout(self, &limits);
-
- content.bounds.x = padding;
- content.bounds.y = padding;
-
- let size = limits.resolve(content.size()).pad(padding);
-
- layout::Node::with_children(size, vec![content])
- }
-
- fn draw<Message>(
+ fn draw(
&mut self,
- button: &Button<Message, Self>,
- layout: Layout<'_>,
+ bounds: Rectangle,
cursor_position: Point,
+ is_pressed: bool,
+ background: Option<Background>,
+ border_radius: u16,
+ (content, _): Self::Output,
) -> Self::Output {
- let bounds = layout.bounds();
-
- let (content, _) = button.content.draw(
- self,
- layout.children().next().unwrap(),
- cursor_position,
- );
-
let is_mouse_over = bounds.contains(cursor_position);
// TODO: Render proper shadows
// TODO: Make hovering and pressed styles configurable
let shadow_offset = if is_mouse_over {
- if button.state.is_pressed {
+ if is_pressed {
0.0
} else {
2.0
@@ -56,7 +26,7 @@ impl button::Renderer for Renderer {
};
(
- match button.background {
+ match background {
None => content,
Some(background) => Primitive::Group {
primitives: vec![
@@ -69,12 +39,12 @@ impl button::Renderer for Renderer {
background: Background::Color(
[0.0, 0.0, 0.0, 0.5].into(),
),
- border_radius: button.border_radius,
+ border_radius,
},
Primitive::Quad {
bounds,
background,
- border_radius: button.border_radius,
+ border_radius,
},
content,
],