From d138c86a11af3993e4f3c2136dd5100e7b2bc51a Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 24 Apr 2024 13:57:41 -0600 Subject: [PATCH] nav_bar: allow setting close_icon and on_close --- src/widget/nav_bar.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/widget/nav_bar.rs b/src/widget/nav_bar.rs index 764f8050..3aa45818 100644 --- a/src/widget/nav_bar.rs +++ b/src/widget/nav_bar.rs @@ -12,7 +12,7 @@ use iced::{ }; use iced_core::{Border, Color, Shadow}; -use crate::widget::{container, menu, scrollable, segmented_button, Container}; +use crate::widget::{container, menu, scrollable, segmented_button, Container, Icon}; use crate::{theme, Theme}; use super::dnd_destination::DragId; @@ -62,6 +62,11 @@ pub struct NavBar<'a, Message> { } impl<'a, Message: Clone + 'static> NavBar<'a, Message> { + pub fn close_icon(mut self, close_icon: Icon) -> Self { + self.segmented_button = self.segmented_button.close_icon(close_icon); + self + } + pub fn context_menu(mut self, context_menu: Option>>) -> Self { self.segmented_button = self.segmented_button.context_menu(context_menu); self @@ -78,6 +83,15 @@ impl<'a, Message: Clone + 'static> NavBar<'a, Message> { Container::from(self) } + /// Emitted when a tab close button is pressed. + pub fn on_close(mut self, on_close: T) -> Self + where + T: Fn(Id) -> Message + 'static, + { + self.segmented_button = self.segmented_button.on_close(on_close); + self + } + /// Emitted when a button is right-clicked. pub fn on_context(mut self, on_context: T) -> Self where