wip: example applet

This commit is contained in:
Ashley Wulber 2022-11-11 05:06:54 +01:00
parent 45ccc8c3d2
commit b1c3a52589
No known key found for this signature in database
GPG key ID: 5216D4F46A90A820
18 changed files with 525 additions and 103 deletions

View file

@ -1,8 +1,8 @@
use crate::{theme, Element, Renderer};
use apply::Apply;
use derive_setters::*;
use iced::{self, alignment::Vertical, widget, Length};
use iced_lazy::Component;
use crate::{theme, Element, Renderer};
#[derive(Setters)]
pub struct HeaderBar<Message> {

View file

@ -1,5 +1,5 @@
pub use iced::{widget, Background, Color};
pub use crate::Theme;
pub use iced::{widget, Background, Color};
pub mod list_view {
#[macro_export]
@ -82,8 +82,8 @@ pub mod list_view {
}
use crate::widget::{Background, Color};
use iced::widget;
use crate::Theme;
use iced::widget;
pub use list_view;
pub use list_view_item;

View file

@ -1,6 +1,6 @@
pub mod nav_bar {
use iced::{widget, Background, Color};
use crate::Theme;
use iced::{widget, Background, Color};
#[macro_export]
macro_rules! nav_button {

View file

@ -98,7 +98,7 @@ where
<<Renderer as iced_native::Renderer>::Theme as container::StyleSheet>::Style:
From<theme::Container>,
<<Renderer as iced_native::Renderer>::Theme as text::StyleSheet>::Style: From<theme::Text>,
Renderer::Theme: iced_native::svg::StyleSheet
Renderer::Theme: iced_native::svg::StyleSheet,
{
type State = NavBarState;
type Event = NavBarEvent;
@ -146,11 +146,13 @@ where
.height(Length::Units(50))
.align_items(Alignment::Center),
)
.style(if *section == state.selected_section && state.section_active {
theme::Button::Primary.into()
} else {
theme::Button::Text.into()
})
.style(
if *section == state.selected_section && state.section_active {
theme::Button::Primary.into()
} else {
theme::Button::Text.into()
},
)
.on_press(NavBarEvent::SectionSelected(section.clone()))
.into(),
);
@ -159,17 +161,15 @@ where
pages.push(
button(row![text(&page.title).size(16).width(Length::Fill)])
.padding(10)
.style(
if let Some(selected_page) = &state.selected_page {
if state.page_active && page == selected_page {
theme::Button::Primary.into()
} else {
theme::Button::Text.into()
}
.style(if let Some(selected_page) = &state.selected_page {
if state.page_active && page == selected_page {
theme::Button::Primary.into()
} else {
theme::Button::Text.into()
}
)
} else {
theme::Button::Text.into()
})
.on_press(NavBarEvent::PageSelected(section.clone(), page.clone()))
.into(),
);
@ -180,13 +180,13 @@ where
let nav_bar: Element<Self::Event, Renderer> =
container(if self.condensed && state.selected_page.is_some() {
row![container(scrollable!(column(pages)
.spacing(10)
.padding(10)
.max_width(200)
.width(Length::Units(200))
.height(Length::Shrink)))
.height(Length::Fill)
.style(theme::Container::Custom(nav_bar_pages_style))]
.spacing(10)
.padding(10)
.max_width(200)
.width(Length::Units(200))
.height(Length::Shrink)))
.height(Length::Fill)
.style(theme::Container::Custom(nav_bar_pages_style))]
} else if !state.section_active || self.condensed && state.selected_page.is_none() {
row![scrollable!(column(sections)
.spacing(10)
@ -222,8 +222,7 @@ where
}
}
impl<'a, Message: 'a, Renderer> From<NavBar<'a, Message>>
for Element<'a, Message, Renderer>
impl<'a, Message: 'a, Renderer> From<NavBar<'a, Message>> for Element<'a, Message, Renderer>
where
Renderer: iced_native::text::Renderer + iced_native::svg::Renderer + 'a,
<Renderer as iced_native::Renderer>::Theme:
@ -232,7 +231,7 @@ where
<<Renderer as iced_native::Renderer>::Theme as container::StyleSheet>::Style:
From<theme::Container>,
<<Renderer as iced_native::Renderer>::Theme as text::StyleSheet>::Style: From<theme::Text>,
Renderer::Theme: iced_native::svg::StyleSheet
Renderer::Theme: iced_native::svg::StyleSheet,
{
fn from(nav_bar: NavBar<'a, Message>) -> Self {
iced_lazy::component(nav_bar)