summaryrefslogtreecommitdiffstats
path: root/wgpu
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-10-12 02:32:16 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-10-12 02:32:16 +0200
commite74f1179769cc4dc3e91cb0b5794526b3a8c0dcd (patch)
tree55506a568791ee213fb120befbc0d1faa74c3065 /wgpu
parentc63bdacaad7d923358863e3b6b2524893788d91c (diff)
downloadiced-e74f1179769cc4dc3e91cb0b5794526b3a8c0dcd.tar.gz
iced-e74f1179769cc4dc3e91cb0b5794526b3a8c0dcd.tar.bz2
iced-e74f1179769cc4dc3e91cb0b5794526b3a8c0dcd.zip
Add a slight shadow to buttons for feedback
Diffstat (limited to 'wgpu')
-rw-r--r--wgpu/src/renderer/button.rs30
1 files changed, 28 insertions, 2 deletions
diff --git a/wgpu/src/renderer/button.rs b/wgpu/src/renderer/button.rs
index 275c870f..aa48da93 100644
--- a/wgpu/src/renderer/button.rs
+++ b/wgpu/src/renderer/button.rs
@@ -1,7 +1,7 @@
use crate::{Primitive, Renderer};
use iced_native::{
button, Align, Background, Button, Color, Layout, Length, MouseCursor,
- Node, Point, Style,
+ Node, Point, Rectangle, Style,
};
impl button::Renderer for Renderer {
@@ -30,10 +30,36 @@ impl button::Renderer for Renderer {
cursor_position,
);
+ let is_hover = bounds.contains(cursor_position);
+
+ // TODO: Render proper shadows
+ // TODO: Make hovering and pressed styles configurable
+ let shadow_offset = if button.state.is_pressed {
+ 0.0
+ } else if is_hover {
+ 2.0
+ } else {
+ 1.0
+ };
+
(
Primitive::Group {
primitives: vec![
Primitive::Quad {
+ bounds: Rectangle {
+ x: bounds.x + 1.0,
+ y: bounds.y + shadow_offset,
+ ..bounds
+ },
+ background: Background::Color(Color {
+ r: 0.0,
+ b: 0.0,
+ g: 0.0,
+ a: 0.5,
+ }),
+ border_radius: button.border_radius,
+ },
+ Primitive::Quad {
bounds,
background: button.background.unwrap_or(
Background::Color(Color {
@@ -48,7 +74,7 @@ impl button::Renderer for Renderer {
content,
],
},
- if bounds.contains(cursor_position) {
+ if is_hover {
MouseCursor::Pointer
} else {
MouseCursor::OutOfBounds