From 10e10e5e06841574425d2633f1c2916733f7b4ff Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 8 Oct 2019 03:13:41 +0200 Subject: Make `iced_core::Button` customizable Now it supports: - Any kind of content - Custom border radius - Custom background --- wgpu/src/renderer/button.rs | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) (limited to 'wgpu/src/renderer/button.rs') diff --git a/wgpu/src/renderer/button.rs b/wgpu/src/renderer/button.rs index f75b44f7..00fcd0eb 100644 --- a/wgpu/src/renderer/button.rs +++ b/wgpu/src/renderer/button.rs @@ -1,22 +1,26 @@ -use crate::{Background, Primitive, Renderer}; -use iced_native::{button, Button, Color, Layout, Length, Node, Point, Style}; +use crate::{Primitive, Renderer}; +use iced_native::{ + button, Align, Background, Button, Color, Layout, Length, Node, Point, + Style, +}; impl button::Renderer for Renderer { - fn node(&self, button: &Button) -> Node { + fn node(&self, button: &Button) -> Node { let style = Style::default() .width(button.width) - .min_height(Length::Units(30)) + .padding(button.padding) .min_width(Length::Units(100)) - .align_self(button.align_self); + .align_self(button.align_self) + .align_items(Align::Stretch); - Node::new(style) + Node::with_children(style, vec![button.content.node(self)]) } fn draw( &mut self, - button: &Button, + button: &Button, layout: Layout<'_>, - _cursor_position: Point, + cursor_position: Point, ) -> Self::Primitive { let bounds = layout.bounds(); @@ -24,18 +28,21 @@ impl button::Renderer for Renderer { primitives: vec![ Primitive::Quad { bounds, - background: Background::Color(Color { - r: 0.8, - b: 0.8, - g: 0.8, - a: 1.0, - }), - }, - Primitive::Text { - content: button.label.clone(), - size: 20.0, - bounds: layout.bounds(), + background: button.background.unwrap_or(Background::Color( + Color { + r: 0.8, + b: 0.8, + g: 0.8, + a: 1.0, + }, + )), + border_radius: button.border_radius, }, + button.content.draw( + self, + layout.children().next().unwrap(), + cursor_position, + ), ], } } -- cgit