List hierarchy changes
This commit is contained in:
parent
5d25af14a9
commit
ae3f5b9b2e
2 changed files with 60 additions and 43 deletions
|
|
@ -1,9 +1,9 @@
|
|||
use cosmic::{
|
||||
font::FONT_SEMIBOLD,
|
||||
widget::{
|
||||
button,
|
||||
icon,
|
||||
list_item,
|
||||
list_section,
|
||||
list_view,
|
||||
nav_bar,
|
||||
toggler,
|
||||
|
|
@ -11,7 +11,7 @@ use cosmic::{
|
|||
settings,
|
||||
iced::{theme, Alignment, Color, Element, Length, Sandbox, Theme},
|
||||
iced::widget::{
|
||||
checkbox, column, container, horizontal_space, progress_bar, radio,
|
||||
checkbox, container, horizontal_space, progress_bar, radio,
|
||||
row, slider, text,
|
||||
vertical_space,
|
||||
},
|
||||
|
|
@ -100,7 +100,7 @@ impl Sandbox for Window {
|
|||
.into();
|
||||
|
||||
let choose_theme = [Theme::Light, Theme::Dark].iter().fold(
|
||||
row![text("Theme:")].spacing(10).align_items(Alignment::Center),
|
||||
row![text("Debug theme:")].spacing(10).align_items(Alignment::Center),
|
||||
|row, theme| {
|
||||
row.push(radio(
|
||||
format!("{:?}", theme),
|
||||
|
|
@ -111,18 +111,18 @@ impl Sandbox for Window {
|
|||
},
|
||||
);
|
||||
|
||||
let content: Element<_> = column![
|
||||
choose_theme,
|
||||
vertical_space(Length::Units(16)),
|
||||
toggler(
|
||||
String::from("Debug layout"),
|
||||
self.debug,
|
||||
Message::Debug,
|
||||
)
|
||||
,
|
||||
vertical_space(Length::Units(16)),
|
||||
text("Buttons").font(FONT_SEMIBOLD),
|
||||
list_view!(
|
||||
let content: Element<_> = list_view!(
|
||||
list_section!(
|
||||
"Debug",
|
||||
choose_theme,
|
||||
toggler(
|
||||
String::from("Debug layout"),
|
||||
self.debug,
|
||||
Message::Debug,
|
||||
)
|
||||
),
|
||||
list_section!(
|
||||
"Buttons",
|
||||
list_item!(
|
||||
button!("Primary")
|
||||
.style(theme::Button::Primary)
|
||||
|
|
@ -167,11 +167,9 @@ impl Sandbox for Window {
|
|||
.padding([8, 16])
|
||||
,
|
||||
),
|
||||
)
|
||||
,
|
||||
vertical_space(Length::Units(16)),
|
||||
text("Controls").font(FONT_SEMIBOLD),
|
||||
list_view!(
|
||||
),
|
||||
list_section!(
|
||||
"Controls",
|
||||
list_item!(
|
||||
text("Toggler"),
|
||||
horizontal_space(Length::Fill),
|
||||
|
|
@ -191,10 +189,7 @@ impl Sandbox for Window {
|
|||
),
|
||||
checkbox("Checkbox", self.checkbox_value, Message::CheckboxToggled),
|
||||
)
|
||||
]
|
||||
.spacing(8)
|
||||
.padding(24)
|
||||
.max_width(600)
|
||||
)
|
||||
.into();
|
||||
|
||||
container(row![
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ use iced::{
|
|||
macro_rules! list_item {
|
||||
($($x:expr),+ $(,)?) => (
|
||||
$crate::iced::widget::Row::with_children(vec![$($crate::iced::Element::from($x)),+])
|
||||
.align_items(Alignment::Center)
|
||||
.padding([0, 8])
|
||||
.spacing(12)
|
||||
);
|
||||
|
|
@ -16,30 +17,38 @@ macro_rules! list_item {
|
|||
pub use list_item;
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! list_view {
|
||||
($($x:expr),+ $(,)?) => (
|
||||
$crate::iced::widget::Container::new({
|
||||
let mut children = vec![$($crate::iced::Element::from($x)),+];
|
||||
macro_rules! list_section {
|
||||
($heading:expr, $($x:expr),+ $(,)?) => (
|
||||
$crate::iced::widget::Column::with_children(vec![
|
||||
$crate::iced::widget::Text::new($heading)
|
||||
.font($crate::font::FONT_SEMIBOLD)
|
||||
.into()
|
||||
,
|
||||
$crate::iced::widget::Container::new({
|
||||
let mut children = vec![$($crate::iced::Element::from($x)),+];
|
||||
|
||||
//TODO: more efficient method for adding separators
|
||||
let mut i = 1;
|
||||
while i < children.len() {
|
||||
children.insert(i, $crate::iced::widget::horizontal_rule(12).into());
|
||||
i += 2;
|
||||
}
|
||||
//TODO: more efficient method for adding separators
|
||||
let mut i = 1;
|
||||
while i < children.len() {
|
||||
children.insert(i, $crate::iced::widget::horizontal_rule(12).into());
|
||||
i += 2;
|
||||
}
|
||||
|
||||
$crate::iced::widget::Column::with_children(children)
|
||||
.spacing(12)
|
||||
})
|
||||
.padding([12, 16])
|
||||
.style(theme::Container::Custom(
|
||||
$crate::widget::list_view_style
|
||||
))
|
||||
$crate::iced::widget::Column::with_children(children)
|
||||
.spacing(12)
|
||||
})
|
||||
.padding([12, 16])
|
||||
.style(theme::Container::Custom(
|
||||
$crate::widget::list_section_style
|
||||
))
|
||||
.into()
|
||||
])
|
||||
.spacing(8)
|
||||
);
|
||||
}
|
||||
pub use list_view;
|
||||
pub use list_section;
|
||||
|
||||
pub fn list_view_style(theme: &Theme) -> widget::container::Appearance {
|
||||
pub fn list_section_style(theme: &Theme) -> widget::container::Appearance {
|
||||
widget::container::Appearance {
|
||||
text_color: None,
|
||||
background: Some(Background::Color(
|
||||
|
|
@ -53,3 +62,16 @@ pub fn list_view_style(theme: &Theme) -> widget::container::Appearance {
|
|||
border_color: Color::TRANSPARENT,
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! list_view {
|
||||
($($x:expr),+ $(,)?) => (
|
||||
$crate::iced::widget::Column::with_children(
|
||||
vec![$($crate::iced::Element::from($x)),+]
|
||||
)
|
||||
.spacing(24)
|
||||
.padding(24)
|
||||
.max_width(600)
|
||||
);
|
||||
}
|
||||
pub use list_view;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue