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

@ -174,11 +174,7 @@ impl Default for Checkbox {
impl checkbox::StyleSheet for Theme {
type Style = Checkbox;
fn active(
&self,
style: &Self::Style,
is_checked: bool,
) -> checkbox::Appearance {
fn active(&self, style: &Self::Style, is_checked: bool) -> checkbox::Appearance {
let palette = self.extended_palette();
match style {
@ -209,11 +205,7 @@ impl checkbox::StyleSheet for Theme {
}
}
fn hovered(
&self,
style: &Self::Style,
is_checked: bool,
) -> checkbox::Appearance {
fn hovered(&self, style: &Self::Style, is_checked: bool) -> checkbox::Appearance {
let palette = self.extended_palette();
match style {
@ -252,11 +244,7 @@ fn checkbox_appearance(
is_checked: bool,
) -> checkbox::Appearance {
checkbox::Appearance {
background: Background::Color(if is_checked {
accent.color
} else {
base.color
}),
background: Background::Color(if is_checked { accent.color } else { base.color }),
checkmark_color,
border_radius: 4.0,
border_width: if is_checked { 0.0 } else { 1.0 },
@ -355,21 +343,17 @@ impl slider::StyleSheet for Theme {
Color::TRANSPARENT,
),
handle: slider::Handle {
shape: slider::HandleShape::Circle {
radius: 10.0,
},
shape: slider::HandleShape::Circle { radius: 10.0 },
color: cosmic.accent.base.into(),
border_color: Color::TRANSPARENT,
border_width: 0.0,
}
},
}
}
fn hovered(&self, style: &Self::Style) -> slider::Appearance {
let mut style = self.active(&style);
style.handle.shape = slider::HandleShape::Circle {
radius: 16.0
};
style.handle.shape = slider::HandleShape::Circle { radius: 16.0 };
style.handle.border_width = 6.0;
style.handle.border_color = match self {
Theme::Dark => Color::from_rgba8(0xFF, 0xFF, 0xFF, 0.1),
@ -475,11 +459,7 @@ impl radio::StyleSheet for Theme {
impl toggler::StyleSheet for Theme {
type Style = ();
fn active(
&self,
_style: &Self::Style,
is_active: bool,
) -> toggler::Appearance {
fn active(&self, _style: &Self::Style, is_active: bool) -> toggler::Appearance {
let palette = self.palette();
toggler::Appearance {
@ -502,14 +482,10 @@ impl toggler::StyleSheet for Theme {
}
}
fn hovered(
&self,
style: &Self::Style,
is_active: bool,
) -> toggler::Appearance {
fn hovered(&self, style: &Self::Style, is_active: bool) -> toggler::Appearance {
//TODO: grab colors from palette
match self {
Theme::Dark => toggler::Appearance {
Theme::Dark => toggler::Appearance {
background: if is_active {
Color::from_rgb8(0x9f, 0xed, 0xed)
} else {
@ -517,14 +493,14 @@ impl toggler::StyleSheet for Theme {
},
..self.active(&style, is_active)
},
Theme::Light => toggler::Appearance {
Theme::Light => toggler::Appearance {
background: if is_active {
Color::from_rgb8(0x00, 0x42, 0x62)
} else {
Color::from_rgb8(0x54, 0x54, 0x54)
},
..self.active(&style, is_active)
}
},
}
}
}
@ -666,7 +642,6 @@ impl scrollable::StyleSheet for Theme {
}
}
#[derive(Default, Clone, Copy)]
pub enum Svg {
Custom(fn(&Theme) -> svg::Appearance),
@ -715,7 +690,7 @@ impl text::StyleSheet for Theme {
fn appearance(&self, style: Self::Style) -> text::Appearance {
match style {
Text::Accent => text::Appearance {
color: Some(self.cosmic().accent.base.into())
color: Some(self.cosmic().accent.base.into()),
},
Text::Default => Default::default(),
Text::Color(c) => text::Appearance { color: Some(c) },

View file

@ -46,7 +46,7 @@ impl Palette {
background: Color::from_rgb(
0x1e as f32 / 255.0,
0x1e as f32 / 255.0,
0x1e as f32 / 255.0
0x1e as f32 / 255.0,
),
text: Color::from_rgb(
0xe4 as f32 / 255.0,
@ -80,8 +80,7 @@ pub struct Extended {
}
lazy_static! {
pub static ref EXTENDED_LIGHT: Extended =
Extended::generate(Palette::LIGHT);
pub static ref EXTENDED_LIGHT: Extended = Extended::generate(Palette::LIGHT);
pub static ref EXTENDED_DARK: Extended = Extended::generate(Palette::DARK);
}
@ -89,22 +88,10 @@ impl Extended {
pub fn generate(palette: Palette) -> Self {
Self {
background: Background::new(palette.background, palette.text),
primary: Primary::generate(
palette.primary,
palette.background,
palette.text,
),
primary: Primary::generate(palette.primary, palette.background, palette.text),
secondary: Secondary::generate(palette.background, palette.text),
success: Success::generate(
palette.success,
palette.background,
palette.text,
),
danger: Danger::generate(
palette.danger,
palette.background,
palette.text,
),
success: Success::generate(palette.success, palette.background, palette.text),
danger: Danger::generate(palette.danger, palette.background, palette.text),
}
}
}

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)