Move list_view to libcosmic

This commit is contained in:
Jeremy Soller 2022-09-30 09:57:11 -06:00
parent bfcaf829eb
commit 8e42dc46ea
No known key found for this signature in database
GPG key ID: 87F211AF2BE4C2FE
3 changed files with 97 additions and 92 deletions

View file

@ -3,8 +3,8 @@ use cosmic::{
widget::{ widget::{
button, button,
icon, icon,
list_view,
nav_bar, nav_bar,
list_view_style,
}, },
settings, settings,
iced::{theme, Alignment, Color, Element, Length, Sandbox, Theme}, iced::{theme, Alignment, Color, Element, Length, Sandbox, Theme},
@ -123,97 +123,87 @@ impl Sandbox for Window {
, ,
vertical_space(Length::Units(16)), vertical_space(Length::Units(16)),
text("Buttons").font(FONT_SEMIBOLD), text("Buttons").font(FONT_SEMIBOLD),
container( list_view!(
column![ row![
row![ button!("Primary")
button!("Primary") .style(theme::Button::Primary)
.style(theme::Button::Primary) .on_press(Message::ButtonPressed)
.on_press(Message::ButtonPressed) ,
, button!("Secondary")
button!("Secondary") .style(theme::Button::Secondary)
.style(theme::Button::Secondary) .on_press(Message::ButtonPressed)
.on_press(Message::ButtonPressed) ,
, button!("Positive")
button!("Positive") .style(theme::Button::Positive)
.style(theme::Button::Positive) .on_press(Message::ButtonPressed)
.on_press(Message::ButtonPressed) ,
, button!("Destructive")
button!("Destructive") .style(theme::Button::Destructive)
.style(theme::Button::Destructive) .on_press(Message::ButtonPressed)
.on_press(Message::ButtonPressed) ,
, button!("Text")
button!("Text") .style(theme::Button::Text)
.style(theme::Button::Text) .on_press(Message::ButtonPressed)
.on_press(Message::ButtonPressed) ,
, ].spacing(12),
].spacing(12), horizontal_rule(12),
horizontal_rule(12), row![
row![ button!("Primary")
button!("Primary") .style(theme::Button::Primary)
.style(theme::Button::Primary) .padding([8, 16])
.padding([8, 16]) ,
, button!("Secondary")
button!("Secondary") .style(theme::Button::Secondary)
.style(theme::Button::Secondary) .padding([8, 16])
.padding([8, 16]) ,
, button!("Positive")
button!("Positive") .style(theme::Button::Positive)
.style(theme::Button::Positive) .padding([8, 16])
.padding([8, 16]) ,
, button!("Destructive")
button!("Destructive") .style(theme::Button::Destructive)
.style(theme::Button::Destructive) .padding([8, 16])
.padding([8, 16]) ,
, button!("Text")
button!("Text") .style(theme::Button::Text)
.style(theme::Button::Text) .padding([8, 16])
.padding([8, 16]) ,
, ].spacing(12),
].spacing(12),
]
.padding([12, 16])
.spacing(12)
) )
.style(theme::Container::Custom(list_view_style))
, ,
vertical_space(Length::Units(16)), vertical_space(Length::Units(16)),
text("Controls").font(FONT_SEMIBOLD), text("Controls").font(FONT_SEMIBOLD),
container( list_view!(
column![ row![
row![ text("Toggler"),
text("Toggler"), horizontal_space(Length::Fill),
horizontal_space(Length::Fill), toggler(None, self.toggler_value, Message::TogglerToggled)
toggler(None, self.toggler_value, Message::TogglerToggled) .size(24)
.size(24) .width(Length::Shrink),
.width(Length::Shrink),
]
.padding([0, 8])
,
horizontal_rule(12),
row![
text("Slider"),
horizontal_space(Length::Fill),
slider(0.0..=100.0, self.slider_value, Message::SliderChanged)
.width(Length::Units(250)),
]
.padding([0, 8])
,
horizontal_rule(12),
row![
text("Progress"),
horizontal_space(Length::Fill),
progress_bar(0.0..=100.0, self.slider_value).height(Length::Units(4))
.width(Length::Units(250)),
]
.padding([0, 8])
,
horizontal_rule(12),
checkbox("Checkbox", self.checkbox_value, Message::CheckboxToggled),
] ]
.padding([12, 16]) .padding([0, 8])
.spacing(12) ,
horizontal_rule(12),
row![
text("Slider"),
horizontal_space(Length::Fill),
slider(0.0..=100.0, self.slider_value, Message::SliderChanged)
.width(Length::Units(250)),
]
.padding([0, 8])
,
horizontal_rule(12),
row![
text("Progress"),
horizontal_space(Length::Fill),
progress_bar(0.0..=100.0, self.slider_value).height(Length::Units(4))
.width(Length::Units(250)),
]
.padding([0, 8])
,
horizontal_rule(12),
checkbox("Checkbox", self.checkbox_value, Message::CheckboxToggled),
) )
.style(theme::Container::Custom(list_view_style))
] ]
.spacing(8) .spacing(8)
.padding(24) .padding(24)

View file

@ -2,13 +2,28 @@ use iced::{
Background, Background,
Color, Color,
Theme, Theme,
widget::{ widget,
container,
},
}; };
pub fn list_view_style(theme: &Theme) -> container::Appearance { #[macro_export]
container::Appearance { macro_rules! list_view {
($($x:expr),+ $(,)?) => (
$crate::iced::widget::Container::new(
$crate::iced::widget::Column::with_children(
vec![$($crate::iced::Element::from($x)),+]
)
.spacing(12)
)
.padding([12, 16])
.style(theme::Container::Custom(
$crate::widget::list_view_style
))
);
}
pub use list_view;
pub fn list_view_style(theme: &Theme) -> widget::container::Appearance {
widget::container::Appearance {
text_color: None, text_color: None,
background: Some(Background::Color( background: Some(Background::Color(
match theme { match theme {

View file

@ -16,7 +16,7 @@ mod icon;
pub use self::icon::icon; pub use self::icon::icon;
mod list_view; mod list_view;
pub use list_view::list_view_style; pub use list_view::{list_view, list_view_style};
mod nav_bar; mod nav_bar;
pub use nav_bar::{nav_bar, nav_bar_style}; pub use nav_bar::{nav_bar, nav_bar_style};