Skip to content

Commit

Permalink
Add ability to set tab icon position for tab widget. Also fixed the r…
Browse files Browse the repository at this point in the history
…ight icon position
  • Loading branch information
genusistimelord committed Dec 27, 2023
1 parent bc9e78f commit 205d4d9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/tabs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl Application for TabBarExample {
.clone()

Check failure on line 150 in examples/tabs/src/main.rs

View workflow job for this annotation

GitHub Actions / all

Diff in /home/runner/work/iced_aw/iced_aw/examples/tabs/src/main.rs
.unwrap_or_default();

Tabs::new(Message::TabSelected)
Tabs::new(Message::TabSelected).tab_icon_position(iced_aw::tabs::Position::Bottom)
.push(
TabId::Login,
state.login_tab.tab_label(),
Expand Down
10 changes: 5 additions & 5 deletions src/native/tab_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,15 +424,15 @@ where
column = column.push(
Row::new()
.align_items(Alignment::Center)
.push(layout_icon(
icon,
self.icon_size + 1.0,
self.font,
))
.push(layout_text(
text,
self.text_size + 1.0,
self.text_font,
))
.push(layout_icon(
icon,
self.icon_size + 1.0,
self.font,
)),
);
}
Expand Down
15 changes: 14 additions & 1 deletion src/native/tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
pub mod tab_bar_position;
use crate::{native::tab_bar::TabBar, style::tab_bar::StyleSheet, TabLabel};
pub use crate::tab_bar::Position;

use iced_widget::{
core::{
Expand Down Expand Up @@ -69,6 +70,8 @@ where
indices: Vec<TabId>,
/// The position of the [`TabBar`](crate::native::TabBar).
tab_bar_position: TabBarPosition,
/// The position of the [`TabBar`](crate::native::TabBar) Icon.
tab_icon_position: Position,
/// the width of the [`Tabs`].
width: Length,
/// The height of the [`Tabs`].
Expand Down Expand Up @@ -126,6 +129,7 @@ where
tabs: elements,
indices,
tab_bar_position: TabBarPosition::Top,
tab_icon_position: Position::Left,
width: Length::Fill,
height: Length::Shrink,
}
Expand All @@ -140,6 +144,15 @@ where
self
}

/// Sets the Tabs Icon render Position
/// [`TabLabel`](super::tab_bar::TabLabel) of the
/// [`TabBar`](super::tab_bar::TabBar).
#[must_use]
pub fn tab_icon_position(mut self, position: Position) -> Self {
self.tab_icon_position = position;
self
}

/// Sets the height of the [`Tabs`].
#[must_use]
pub fn height(mut self, height: Length) -> Self {
Expand Down Expand Up @@ -184,7 +197,7 @@ where
where

Check failure on line 197 in src/native/tabs.rs

View workflow job for this annotation

GitHub Actions / all

Diff in /home/runner/work/iced_aw/iced_aw/src/native/tabs.rs
E: Into<Element<'a, Message, Renderer>>,
{
self.tab_bar = self.tab_bar.push(id.clone(), tab_label);
self.tab_bar = self.tab_bar.push(id.clone(), tab_label).set_position(self.tab_icon_position);
self.tabs.push(element.into());
self.indices.push(id);
self
Expand Down

0 comments on commit 205d4d9

Please sign in to comment.