improv(about): use ListButton
This commit is contained in:
parent
8d7bcab258
commit
c423ad1bfc
2 changed files with 23 additions and 13 deletions
|
|
@ -1,8 +1,9 @@
|
|||
use crate::{
|
||||
Apply, Element, fl,
|
||||
iced::{Alignment, Length},
|
||||
widget::{self, space},
|
||||
widget::{self, list},
|
||||
};
|
||||
use std::rc::Rc;
|
||||
|
||||
#[derive(Debug, Default, Clone, derive_setters::Setters)]
|
||||
#[setters(into, strip_option)]
|
||||
|
|
@ -104,19 +105,23 @@ pub fn about<'a, Message: Clone + 'static>(
|
|||
space_xxs, space_m, ..
|
||||
} = crate::theme::spacing();
|
||||
|
||||
let section_button = |name: &'a str, url: &'a str| -> Element<'a, Message> {
|
||||
widget::row::with_capacity(3)
|
||||
.push(widget::text(name))
|
||||
.push(space::horizontal())
|
||||
let svg_accent = Rc::new(|theme: &crate::Theme| widget::svg::Style {
|
||||
color: Some(theme.cosmic().accent_text_color().into()),
|
||||
});
|
||||
|
||||
let section_button = |name: &'a str, url: &'a str| -> list::ListButton<'a, Message> {
|
||||
widget::row::with_capacity(2)
|
||||
.push(widget::text::body(name).width(Length::Fill))
|
||||
.push_maybe(
|
||||
(!url.is_empty()).then_some(crate::widget::icon::from_name("link-symbolic").icon()),
|
||||
(!url.is_empty()).then_some(
|
||||
widget::icon::from_name("link-symbolic")
|
||||
.icon()
|
||||
.class(crate::theme::Svg::Custom(svg_accent.clone())),
|
||||
),
|
||||
)
|
||||
.align_y(Alignment::Center)
|
||||
.apply(widget::button::custom)
|
||||
.class(crate::theme::Button::Link)
|
||||
.apply(list::button)
|
||||
.on_press(on_url_press(url))
|
||||
.width(Length::Fill)
|
||||
.into()
|
||||
};
|
||||
|
||||
let section = |list: &'a Vec<(String, String)>, title: String| {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
use crate::Element;
|
||||
use crate::widget::list_column::IntoListItem;
|
||||
use crate::widget::{ListColumn, column, text};
|
||||
use crate::widget::{ListColumn, column, list_column, text};
|
||||
use std::borrow::Cow;
|
||||
|
||||
/// A section within a settings view column.
|
||||
|
|
@ -11,6 +11,11 @@ pub fn section<'a, Message: Clone + 'static>() -> Section<'a, Message> {
|
|||
with_column(ListColumn::default())
|
||||
}
|
||||
|
||||
/// A section with a pre-defined list column of a given capacity.
|
||||
pub fn with_capacity<'a, Message: Clone + 'static>(capacity: usize) -> Section<'a, Message> {
|
||||
with_column(list_column::with_capacity(capacity))
|
||||
}
|
||||
|
||||
/// A section with a pre-defined list column.
|
||||
pub fn with_column<Message: Clone + 'static>(
|
||||
children: ListColumn<'_, Message>,
|
||||
|
|
@ -47,7 +52,7 @@ impl<'a, Message: Clone + 'static> Section<'a, Message> {
|
|||
}
|
||||
|
||||
/// Add a child element to the section's list column, if `Some`.
|
||||
pub fn add_maybe(self, item: Option<impl Into<Element<'a, Message>>>) -> Self {
|
||||
pub fn add_maybe(self, item: Option<impl IntoListItem<'a, Message>>) -> Self {
|
||||
if let Some(item) = item {
|
||||
self.add(item)
|
||||
} else {
|
||||
|
|
@ -58,7 +63,7 @@ impl<'a, Message: Clone + 'static> Section<'a, Message> {
|
|||
/// Extends the [`Section`] with the given children.
|
||||
pub fn extend(
|
||||
self,
|
||||
children: impl IntoIterator<Item = impl Into<Element<'a, Message>>>,
|
||||
children: impl IntoIterator<Item = impl IntoListItem<'a, Message>>,
|
||||
) -> Self {
|
||||
children.into_iter().fold(self, Self::add)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue