diff options
| author | 2020-05-19 14:23:28 +0200 | |
|---|---|---|
| committer | 2020-05-19 14:23:28 +0200 | |
| commit | d4743183d40c6044ce6fa39e2a52919a32912cda (patch) | |
| tree | d2dec81cd9b419262cf2aa57ad793895ccacb320 /glow/src/renderer/widget/container.rs | |
| parent | 33448508a524db6447b380cc236be6f0d5ca8a86 (diff) | |
| download | iced-d4743183d40c6044ce6fa39e2a52919a32912cda.tar.gz iced-d4743183d40c6044ce6fa39e2a52919a32912cda.tar.bz2 iced-d4743183d40c6044ce6fa39e2a52919a32912cda.zip | |
Draft first working version of `iced_glow` :tada:
Diffstat (limited to 'glow/src/renderer/widget/container.rs')
| -rw-r--r-- | glow/src/renderer/widget/container.rs | 48 | 
1 files changed, 48 insertions, 0 deletions
| diff --git a/glow/src/renderer/widget/container.rs b/glow/src/renderer/widget/container.rs new file mode 100644 index 00000000..30cc3f07 --- /dev/null +++ b/glow/src/renderer/widget/container.rs @@ -0,0 +1,48 @@ +use crate::{container, defaults, Defaults, Primitive, Renderer}; +use iced_native::{Background, Color, 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), +            }, +        }; + +        let (content, mouse_interaction) = +            content.draw(self, &defaults, content_layout, cursor_position); + +        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_interaction, +            ) +        } else { +            (content, mouse_interaction) +        } +    } +} | 
