Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format the code #134

Merged
merged 1 commit into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/floating_element/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use iced::{
Element, Length, Sandbox, Settings, Theme,
};

use iced_aw::floating_element::{Anchor};
use iced_aw::floating_element::Anchor;
use iced_aw::{helpers::floating_element, Icon, ICON_FONT};

fn main() -> iced::Result {
Expand Down
3 changes: 2 additions & 1 deletion examples/grid/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ impl Sandbox for GridExample {
let mut grid = grid!(
Text::new("Column 1").style(theme::Text::Color(Color::from_rgb8(255, 0, 0))),
Text::new("Column 2").style(theme::Text::Color(Color::from_rgb8(255, 0, 0))),
).strategy(iced_aw::Strategy::Columns(2));
)
.strategy(iced_aw::Strategy::Columns(2));

// Add elements to the grid
for i in 0..self.element_index {
Expand Down
2 changes: 1 addition & 1 deletion examples/number_input/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use iced::{
widget::{Container, Row, Text},
window, Alignment, Element, Length, Sandbox, Settings,
};
use iced_aw::{number_input, style::NumberInputStyles};
use iced_aw::{number_input, style::NumberInputStyles};

#[derive(Default)]
pub struct NumberInputDemo {
Expand Down
2 changes: 1 addition & 1 deletion examples/tab_bar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl Sandbox for TabBarExample {
Message::TabSelected(index) => {
println!("Tab selected: {}", index);
self.active_tab = index
},
}
Message::TabClosed(index) => {
self.tabs.remove(index);
println!("active tab before: {}", self.active_tab);
Expand Down
24 changes: 20 additions & 4 deletions examples/tabs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,26 @@ impl Sandbox for TabBarExample {
.unwrap_or_default();

Tabs::new(Message::TabSelected)
.push(TabId::Login, self.login_tab.tab_label(), self.login_tab.view())
.push(TabId::Ferris, self.ferris_tab.tab_label(), self.ferris_tab.view())
.push(TabId::Counter, self.counter_tab.tab_label(), self.counter_tab.view())
.push(TabId::Settings, self.settings_tab.tab_label(), self.settings_tab.view())
.push(
TabId::Login,
self.login_tab.tab_label(),
self.login_tab.view(),
)
.push(
TabId::Ferris,
self.ferris_tab.tab_label(),
self.ferris_tab.view(),
)
.push(
TabId::Counter,
self.counter_tab.tab_label(),
self.counter_tab.view(),
)
.push(
TabId::Settings,
self.settings_tab.tab_label(),
self.settings_tab.view(),
)
.set_active_tab(&self.active_tab)
.tab_bar_style(theme)
.icon_font(ICON_FONT)
Expand Down
2 changes: 1 addition & 1 deletion src/native/cupertino/cupertino_spinner.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use iced_graphics::{Backend, Renderer};
use iced_native::event::Status;
use iced_native::layout::{Limits, Node};
use iced_native::renderer::Style;
use iced_native::widget::{
tree::{State, Tag},
Tree,
};
use iced_graphics::{Backend, Renderer};

use iced_native::{
window, Clipboard, Color, Element, Event, Layout, Length, Point, Rectangle, Shell, Size,
Expand Down
10 changes: 9 additions & 1 deletion src/native/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@
//!
//!

#[cfg(any(feature = "grid", feature = "menu", feature = "badge", feature = "color_picker", feature = "date_picker", feature = "floating_element", feature = "modal"))]
#[cfg(any(
feature = "grid",
feature = "menu",
feature = "badge",
feature = "color_picker",
feature = "date_picker",
feature = "floating_element",
feature = "modal"
))]
use iced_native::Element;
#[cfg(feature = "color_picker")]
use iced_style::Color;
Expand Down
20 changes: 10 additions & 10 deletions src/native/tab_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub struct TabBar<Message, TabId, Renderer>
where
Renderer: iced_native::Renderer + iced_native::text::Renderer,
Renderer::Theme: StyleSheet,
TabId: Eq + Clone
TabId: Eq + Clone,
{
/// The index of the currently active tab.
active_tab: usize,
Expand Down Expand Up @@ -111,7 +111,7 @@ impl<Message, TabId, Renderer> TabBar<Message, TabId, Renderer>
where
Renderer: iced_native::Renderer + iced_native::text::Renderer<Font = iced_native::Font>,
Renderer::Theme: StyleSheet,
TabId: Eq + Clone
TabId: Eq + Clone,
{
/// Creates a new [`TabBar`](TabBar) with the index of the selected tab and a
/// specified message which will be send when a tab is selected by the user.
Expand Down Expand Up @@ -304,12 +304,11 @@ where
/// Sets up the active tab on the [`TabBar`](TabBar).
#[must_use]
pub fn set_active_tab(mut self, active_tab: &TabId) -> Self {
self.active_tab = if let Some(a) = self
.tab_indices
.iter()
.position(|id| id == active_tab) {
self.active_tab = if let Some(a) = self.tab_indices.iter().position(|id| id == active_tab) {
a
} else { 0 };
} else {
0
};
self
}
}
Expand All @@ -318,7 +317,7 @@ impl<Message, TabId, Renderer> Widget<Message, Renderer> for TabBar<Message, Tab
where
Renderer: iced_native::Renderer + iced_native::text::Renderer<Font = iced_native::Font>,
Renderer::Theme: StyleSheet + iced_style::text::StyleSheet,
TabId: Eq + Clone
TabId: Eq + Clone,
{
fn width(&self) -> Length {
self.width
Expand Down Expand Up @@ -647,12 +646,13 @@ fn draw_tab<Renderer>(
};
}

impl<'a, Message, TabId, Renderer> From<TabBar<Message, TabId, Renderer>> for Element<'a, Message, Renderer>
impl<'a, Message, TabId, Renderer> From<TabBar<Message, TabId, Renderer>>
for Element<'a, Message, Renderer>
where
Renderer: 'a + iced_native::Renderer + iced_native::text::Renderer<Font = iced_native::Font>,
Renderer::Theme: StyleSheet + iced_style::text::StyleSheet,
Message: 'a,
TabId: 'a + Eq + Clone
TabId: 'a + Eq + Clone,
{
fn from(tab_bar: TabBar<Message, TabId, Renderer>) -> Self {
Element::new(tab_bar)
Expand Down
46 changes: 22 additions & 24 deletions src/native/tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub struct Tabs<'a, Message, TabId, Renderer>
where
Renderer: 'a + iced_native::Renderer + iced_native::text::Renderer,
Renderer::Theme: StyleSheet,
TabId: Eq + Clone
TabId: Eq + Clone,
{
/// The [`TabBar`](crate::native::TabBar) of the [`Tabs`](Tabs).
tab_bar: TabBar<Message, TabId, Renderer>,
Expand Down Expand Up @@ -112,7 +112,7 @@ where
let mut elements = Vec::with_capacity(tabs.len());
let mut indices = Vec::with_capacity(tabs.len());

for (id,tab_label, element) in tabs {
for (id, tab_label, element) in tabs {
tab_labels.push((id.clone(), tab_label));
indices.push(id);
elements.push(element);
Expand Down Expand Up @@ -306,15 +306,18 @@ where
.width(self.width)
.height(self.height);

let mut tab_content_node = self.tabs.get(self.tab_bar.get_active_tab_idx()).map_or_else(
|| {
Row::<Message, Renderer>::new()
.width(Length::Fill)
.height(Length::Fill)
.layout(renderer, &tab_content_limits)
},
|element| element.as_widget().layout(renderer, &tab_content_limits),
);
let mut tab_content_node = self
.tabs
.get(self.tab_bar.get_active_tab_idx())
.map_or_else(
|| {
Row::<Message, Renderer>::new()
.width(Length::Fill)
.height(Length::Fill)
.layout(renderer, &tab_content_limits)
},
|element| element.as_widget().layout(renderer, &tab_content_limits),
);

tab_bar_node.move_to(Point::new(
tab_bar_node.bounds().x,
Expand Down Expand Up @@ -388,9 +391,10 @@ where
shell,
);
let idx = self.tab_bar.get_active_tab_idx();
let status_element = self.tabs.get_mut(idx).map_or(
event::Status::Ignored,
|element| {
let status_element = self
.tabs
.get_mut(idx)
.map_or(event::Status::Ignored, |element| {
element.as_widget_mut().on_event(
&mut state.children[idx],
event,
Expand All @@ -400,8 +404,7 @@ where
clipboard,
shell,
)
},
);
});

status_tab_bar.merge(status_element)
}
Expand Down Expand Up @@ -537,13 +540,7 @@ where
self.tabs
.get_mut(idx)
.map(Element::as_widget_mut)
.and_then(|w| {
w.overlay(
&mut state.children[idx],
layout,
renderer,
)
})
.and_then(|w| w.overlay(&mut state.children[idx], layout, renderer))
})
}

Expand All @@ -569,7 +566,8 @@ where
}
}

impl<'a, Message, TabId, Renderer> From<Tabs<'a, Message, TabId, Renderer>> for Element<'a, Message, Renderer>
impl<'a, Message, TabId, Renderer> From<Tabs<'a, Message, TabId, Renderer>>
for Element<'a, Message, Renderer>
where
Renderer: 'a + iced_native::Renderer + iced_native::text::Renderer<Font = iced_native::Font>,
Renderer::Theme: StyleSheet + iced_style::text::StyleSheet,
Expand Down