summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-01-05 18:38:03 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-01-05 18:38:03 +0100
commit2116fbb3c2412030a676c60d65784b9dfa467a0a (patch)
tree0c8d73990f11a00b6cd9c52ab2518b037cd35e26
parent8d6f86b317303c06a0daf1ca3ce91c29670dd674 (diff)
downloadiced-2116fbb3c2412030a676c60d65784b9dfa467a0a.tar.gz
iced-2116fbb3c2412030a676c60d65784b9dfa467a0a.tar.bz2
iced-2116fbb3c2412030a676c60d65784b9dfa467a0a.zip
Add border styling to `Container`
-rw-r--r--style/src/container.rs4
-rw-r--r--wgpu/src/renderer/widget/container.rs37
2 files changed, 23 insertions, 18 deletions
diff --git a/style/src/container.rs b/style/src/container.rs
index a9cd3ccc..484fdfda 100644
--- a/style/src/container.rs
+++ b/style/src/container.rs
@@ -7,6 +7,8 @@ pub struct Style {
pub text_color: Option<Color>,
pub background: Option<Background>,
pub border_radius: u16,
+ pub border_width: u16,
+ pub border_color: Color,
}
/// A set of rules that dictate the style of a container.
@@ -23,6 +25,8 @@ impl StyleSheet for Default {
text_color: None,
background: None,
border_radius: 0,
+ border_width: 0,
+ border_color: Color::TRANSPARENT,
}
}
}
diff --git a/wgpu/src/renderer/widget/container.rs b/wgpu/src/renderer/widget/container.rs
index 18908571..2d4d1db8 100644
--- a/wgpu/src/renderer/widget/container.rs
+++ b/wgpu/src/renderer/widget/container.rs
@@ -1,5 +1,5 @@
use crate::{container, defaults, Defaults, Primitive, Renderer};
-use iced_native::{Color, Element, Layout, Point, Rectangle};
+use iced_native::{Background, Color, Element, Layout, Point, Rectangle};
impl iced_native::container::Renderer for Renderer {
type Style = Box<dyn container::StyleSheet>;
@@ -25,24 +25,25 @@ impl iced_native::container::Renderer for Renderer {
let (content, mouse_cursor) =
content.draw(self, &defaults, content_layout, cursor_position);
- match style.background {
- Some(background) => {
- let quad = Primitive::Quad {
- bounds,
- background,
- border_radius: style.border_radius,
- border_width: 0,
- border_color: Color::TRANSPARENT,
- };
+ if style.background.is_some() || style.border_width > 0 {
+ let quad = Primitive::Quad {
+ bounds,
+ background: style
+ .background
+ .unwrap_or(Background::Color(Color::TRANSPARENT)),
+ border_radius: style.border_radius,
+ border_width: style.border_width,
+ border_color: style.border_color,
+ };
- (
- Primitive::Group {
- primitives: vec![quad, content],
- },
- mouse_cursor,
- )
- }
- None => (content, mouse_cursor),
+ (
+ Primitive::Group {
+ primitives: vec![quad, content],
+ },
+ mouse_cursor,
+ )
+ } else {
+ (content, mouse_cursor)
}
}
}