summaryrefslogtreecommitdiffstats
path: root/wgpu
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-12-31 11:36:54 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-12-31 11:36:54 +0100
commitfb9cc0262b30a953e8188897b74abb5106ea1fd8 (patch)
tree11a64f9c7e007f6992250c3d7f0b9c1d1b3c63a6 /wgpu
parent8caa66be2708b1c83e20d905d69902c2567c4692 (diff)
downloadiced-fb9cc0262b30a953e8188897b74abb5106ea1fd8.tar.gz
iced-fb9cc0262b30a953e8188897b74abb5106ea1fd8.tar.bz2
iced-fb9cc0262b30a953e8188897b74abb5106ea1fd8.zip
Draft basic styling for `Container`
Diffstat (limited to 'wgpu')
-rw-r--r--wgpu/src/renderer/widget.rs1
-rw-r--r--wgpu/src/renderer/widget/container.rs46
-rw-r--r--wgpu/src/widget.rs1
-rw-r--r--wgpu/src/widget/container.rs37
4 files changed, 85 insertions, 0 deletions
diff --git a/wgpu/src/renderer/widget.rs b/wgpu/src/renderer/widget.rs
index 91f107e8..8cf79cb0 100644
--- a/wgpu/src/renderer/widget.rs
+++ b/wgpu/src/renderer/widget.rs
@@ -1,6 +1,7 @@
mod button;
mod checkbox;
mod column;
+mod container;
mod image;
mod radio;
mod row;
diff --git a/wgpu/src/renderer/widget/container.rs b/wgpu/src/renderer/widget/container.rs
new file mode 100644
index 00000000..29c709f8
--- /dev/null
+++ b/wgpu/src/renderer/widget/container.rs
@@ -0,0 +1,46 @@
+use crate::{container, defaults, Defaults, Primitive, Renderer};
+use iced_native::{Element, Layout, Point, Rectangle};
+
+impl iced_native::container::Renderer for Renderer {
+ type Style = Box<dyn container::StyleSheet>;
+
+ fn draw<Message>(
+ &mut self,
+ defaults: &Defaults,
+ bounds: Rectangle,
+ cursor_position: Point,
+ style_sheet: &Self::Style,
+ content: &Element<'_, Message, Self>,
+ content_layout: Layout<'_>,
+ ) -> Self::Output {
+ let style = style_sheet.style();
+
+ let defaults = Defaults {
+ text: defaults::Text {
+ color: style.text_color.unwrap_or(defaults.text.color),
+ },
+ ..*defaults
+ };
+
+ 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,
+ };
+
+ (
+ Primitive::Group {
+ primitives: vec![quad, content],
+ },
+ mouse_cursor,
+ )
+ }
+ None => (content, mouse_cursor),
+ }
+ }
+}
diff --git a/wgpu/src/widget.rs b/wgpu/src/widget.rs
index aa200ca2..c6f34301 100644
--- a/wgpu/src/widget.rs
+++ b/wgpu/src/widget.rs
@@ -1 +1,2 @@
pub mod button;
+pub mod container;
diff --git a/wgpu/src/widget/container.rs b/wgpu/src/widget/container.rs
new file mode 100644
index 00000000..1fc0ec98
--- /dev/null
+++ b/wgpu/src/widget/container.rs
@@ -0,0 +1,37 @@
+use iced_native::{Background, Color};
+
+#[derive(Debug, Clone, Copy)]
+pub struct Style {
+ pub text_color: Option<Color>,
+ pub background: Option<Background>,
+ pub border_radius: u16,
+}
+
+pub trait StyleSheet {
+ fn style(&self) -> Style {
+ Style {
+ text_color: None,
+ background: None,
+ border_radius: 0,
+ }
+ }
+}
+
+struct Default;
+
+impl StyleSheet for Default {}
+
+impl std::default::Default for Box<dyn StyleSheet> {
+ fn default() -> Self {
+ Box::new(Default)
+ }
+}
+
+impl<T> From<T> for Box<dyn StyleSheet>
+where
+ T: 'static + StyleSheet,
+{
+ fn from(style: T) -> Self {
+ Box::new(style)
+ }
+}