From eb519782acf92924c6bdb3af44ebdca010e6cc86 Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Mon, 13 Feb 2023 17:38:23 +0100 Subject: [PATCH] improv(segmented-button): extra padding for close icon --- examples/cosmic/src/window/editor.rs | 11 ++++++----- src/widget/segmented_button/widget.rs | 10 ++++------ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/examples/cosmic/src/window/editor.rs b/examples/cosmic/src/window/editor.rs index c9be4cf3..c1423e29 100644 --- a/examples/cosmic/src/window/editor.rs +++ b/examples/cosmic/src/window/editor.rs @@ -1,4 +1,5 @@ -use cosmic::iced::widget::row; +use apply::Apply; +use cosmic::iced::widget::{horizontal_space, row, scrollable}; use cosmic::iced::Length; use cosmic::iced_winit::Alignment; use cosmic::widget::{button, segmented_button, view_switcher}; @@ -65,14 +66,14 @@ impl State { .show_close_icon_on_hover(true) .on_activate(Message::Activate) .on_close(Message::Close) - .width(Length::Fill); + .width(Length::Shrink); let new_tab_button = button(theme::Button::Text) .icon(theme::Svg::Symbolic, "tab-new-symbolic", 20) .on_press(Message::AddNew); - row!(tabs, new_tab_button) - .align_items(Alignment::Center) - .into() + let tab_header = row!(tabs, new_tab_button).align_items(Alignment::Center); + + row!(tab_header, horizontal_space(Length::Fill)).into() } } diff --git a/src/widget/segmented_button/widget.rs b/src/widget/segmented_button/widget.rs index 32bbe68f..e4801574 100644 --- a/src/widget/segmented_button/widget.rs +++ b/src/widget/segmented_button/widget.rs @@ -234,7 +234,7 @@ where // Add close button to measurement if found. if self.model.is_closable(key) { button_height = button_height.max(f32::from(self.icon_size)); - button_width += f32::from(self.icon_size) + f32::from(self.button_spacing); + button_width += f32::from(self.icon_size) + f32::from(self.button_spacing) + 8.0; } height = height.max(button_height); @@ -656,13 +656,11 @@ impl From for widget::Id { /// Calculates the bounds of the close button within the area of an item. fn close_bounds(area: Rectangle, icon_size: f32, button_padding: [u16; 4]) -> Rectangle { - let top = f32::from(button_padding[1]); - let end = f32::from(button_padding[2]); - let unpadded_height = area.height - top - end; + let unpadded_height = area.height - f32::from(button_padding[1]) - f32::from(button_padding[3]); Rectangle { - x: area.x + area.width - icon_size - f32::from(button_padding[2]), - y: area.y + f32::from(button_padding[1]) + (unpadded_height / 2.0), + x: area.x + area.width - icon_size - 8.0, + y: area.y + (unpadded_height / 2.0) - (icon_size / 2.0), width: icon_size, height: icon_size, }