From fe0a27c56d9d75fb521e69352259f1d737402a20 Mon Sep 17 00:00:00 2001 From: Ben LeFevre Date: Mon, 23 Nov 2020 17:19:21 +0000 Subject: Add support for asymmetrical padding --- graphics/src/widget/button.rs | 4 ++-- graphics/src/widget/pick_list.rs | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'graphics/src/widget') diff --git a/graphics/src/widget/button.rs b/graphics/src/widget/button.rs index 2e3f78ca..60400ed8 100644 --- a/graphics/src/widget/button.rs +++ b/graphics/src/widget/button.rs @@ -5,7 +5,7 @@ use crate::defaults::{self, Defaults}; use crate::{Backend, Primitive, Renderer}; use iced_native::mouse; use iced_native::{ - Background, Color, Element, Layout, Point, Rectangle, Vector, + Background, Color, Element, Layout, Padding, Point, Rectangle, Vector, }; pub use iced_native::button::State; @@ -21,7 +21,7 @@ impl iced_native::button::Renderer for Renderer where B: Backend, { - const DEFAULT_PADDING: u16 = 5; + const DEFAULT_PADDING: Padding = Padding::new(5); type Style = Box; diff --git a/graphics/src/widget/pick_list.rs b/graphics/src/widget/pick_list.rs index f42a8707..c6fbcf76 100644 --- a/graphics/src/widget/pick_list.rs +++ b/graphics/src/widget/pick_list.rs @@ -2,7 +2,8 @@ use crate::backend::{self, Backend}; use crate::{Primitive, Renderer}; use iced_native::{ - mouse, Font, HorizontalAlignment, Point, Rectangle, VerticalAlignment, + mouse, Font, HorizontalAlignment, Padding, Point, Rectangle, + VerticalAlignment, }; use iced_style::menu; @@ -19,7 +20,7 @@ where { type Style = Box; - const DEFAULT_PADDING: u16 = 5; + const DEFAULT_PADDING: Padding = Padding::new(5); fn menu_style(style: &Box) -> menu::Style { style.menu() @@ -30,7 +31,7 @@ where bounds: Rectangle, cursor_position: Point, selected: Option, - padding: u16, + padding: Padding, text_size: u16, font: Font, style: &Box, @@ -56,7 +57,8 @@ where font: B::ICON_FONT, size: bounds.height * style.icon_size, bounds: Rectangle { - x: bounds.x + bounds.width - f32::from(padding) * 2.0, + x: bounds.x + bounds.width + - f32::from(padding.left + padding.right), y: bounds.center_y(), ..bounds }, @@ -74,7 +76,7 @@ where font, color: style.text_color, bounds: Rectangle { - x: bounds.x + f32::from(padding), + x: bounds.x + f32::from(padding.left), y: bounds.center_y(), ..bounds }, -- cgit From 0a14492343e30bf0856088c91406c2da7c7f5860 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Date: Tue, 1 Jun 2021 19:13:52 +0700 Subject: Fix `Tooltip` widget --- graphics/src/widget/tooltip.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'graphics/src/widget') diff --git a/graphics/src/widget/tooltip.rs b/graphics/src/widget/tooltip.rs index 1a1b5352..493a6389 100644 --- a/graphics/src/widget/tooltip.rs +++ b/graphics/src/widget/tooltip.rs @@ -5,7 +5,7 @@ use crate::{Primitive, Renderer, Vector}; use iced_native::container; use iced_native::layout::{self, Layout}; -use iced_native::{Element, Point, Rectangle, Size, Text}; +use iced_native::{Element, Padding, Point, Rectangle, Size, Text}; /// An element decorating some content. /// @@ -49,7 +49,6 @@ where use iced_native::Widget; let gap = f32::from(gap); - let padding = f32::from(padding); let style = style_sheet.style(); let defaults = Defaults { @@ -62,9 +61,10 @@ where tooltip, self, &layout::Limits::new(Size::ZERO, viewport.size()) - .pad(f32::from(padding)), + .pad(Padding::new(padding)), ); + let padding = f32::from(padding); let text_bounds = text_layout.bounds(); let x_center = bounds.x + (bounds.width - text_bounds.width) / 2.0; let y_center = -- cgit From b94cd7a2a83d81769d31f6379539089ce68cbdcd Mon Sep 17 00:00:00 2001 From: Héctor Ramón Date: Tue, 1 Jun 2021 19:21:43 +0700 Subject: Use `Padding::horizontal` and `Padding::vertical` helpers --- graphics/src/widget/pick_list.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'graphics/src/widget') diff --git a/graphics/src/widget/pick_list.rs b/graphics/src/widget/pick_list.rs index c6fbcf76..32dfbdf9 100644 --- a/graphics/src/widget/pick_list.rs +++ b/graphics/src/widget/pick_list.rs @@ -57,8 +57,7 @@ where font: B::ICON_FONT, size: bounds.height * style.icon_size, bounds: Rectangle { - x: bounds.x + bounds.width - - f32::from(padding.left + padding.right), + x: bounds.x + bounds.width - f32::from(padding.horizontal()), y: bounds.center_y(), ..bounds }, -- cgit