feat(widget): Add SpinButtonModel
Enables convenient handling of spin messages, and specifying steppings, minimum, and maximum values
This commit is contained in:
parent
200784b6c1
commit
ef71f7f027
7 changed files with 277 additions and 134 deletions
|
|
@ -6,11 +6,14 @@ use crate::{Element, Renderer};
|
|||
/// A setting within a settings view section.
|
||||
#[must_use]
|
||||
#[allow(clippy::module_name_repetitions)]
|
||||
pub fn item<'a, Message: 'static>(title: &'a str, widget: impl Into<Element<'a, Message>>) -> iced::widget::Row<'a, Message, Renderer> {
|
||||
pub fn item<'a, Message: 'static>(
|
||||
title: impl ToString,
|
||||
widget: impl Into<Element<'a, Message>>,
|
||||
) -> iced::widget::Row<'a, Message, Renderer> {
|
||||
item_row(vec![
|
||||
iced::widget::text(title).into(),
|
||||
iced::widget::horizontal_space(iced::Length::Fill).into(),
|
||||
widget.into()
|
||||
widget.into(),
|
||||
])
|
||||
}
|
||||
|
||||
|
|
@ -23,4 +26,3 @@ pub fn item_row<Message>(children: Vec<Element<Message>>) -> iced::widget::Row<M
|
|||
.padding([0, 8])
|
||||
.spacing(12)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,10 +5,10 @@ mod item;
|
|||
mod section;
|
||||
|
||||
pub use self::item::{item, item_row};
|
||||
pub use self::section::{Section, view_section};
|
||||
pub use self::section::{view_section, Section};
|
||||
|
||||
use crate::{Element, Renderer};
|
||||
use iced::widget::{Column, column};
|
||||
use iced::widget::{column, Column};
|
||||
|
||||
/// A column with a predefined style for creating a settings panel
|
||||
#[must_use]
|
||||
|
|
|
|||
|
|
@ -1,21 +1,23 @@
|
|||
// Copyright 2022 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use crate::{Element};
|
||||
use crate::widget::{ListColumn};
|
||||
use crate::widget::ListColumn;
|
||||
use crate::Element;
|
||||
use iced::widget::{column, text};
|
||||
use std::borrow::Cow;
|
||||
|
||||
/// A section within a settings view column.
|
||||
#[must_use]
|
||||
pub fn view_section<Message: 'static>(
|
||||
title: &str,
|
||||
) -> Section<Message> {
|
||||
Section { title, children: ListColumn::default() }
|
||||
pub fn view_section<'a, Message: 'static>(title: impl Into<Cow<'a, str>>) -> Section<'a, Message> {
|
||||
Section {
|
||||
title: title.into(),
|
||||
children: ListColumn::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Section<'a, Message> {
|
||||
title: &'a str,
|
||||
children: ListColumn<'a, Message>
|
||||
title: Cow<'a, str>,
|
||||
children: ListColumn<'a, Message>,
|
||||
}
|
||||
|
||||
impl<'a, Message: 'static> Section<'a, Message> {
|
||||
|
|
@ -28,12 +30,10 @@ impl<'a, Message: 'static> Section<'a, Message> {
|
|||
|
||||
impl<'a, Message: 'static> From<Section<'a, Message>> for Element<'a, Message> {
|
||||
fn from(data: Section<'a, Message>) -> Self {
|
||||
let title = text(data.title)
|
||||
.font(crate::font::FONT_SEMIBOLD)
|
||||
.into();
|
||||
let title = text(data.title).font(crate::font::FONT_SEMIBOLD).into();
|
||||
|
||||
column(vec![title, data.children.into_element()])
|
||||
.spacing(8)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue