feat(widget): add text function with Cow<str> input

This commit is contained in:
Michael Aaron Murphy 2023-01-23 22:48:06 +01:00 committed by Michael Murphy
parent f81a06bc4a
commit b3a3c9c29a
6 changed files with 37 additions and 14 deletions

View file

@ -1,18 +1,21 @@
// Copyright 2022 System76 <info@system76.com>
// SPDX-License-Identifier: MPL-2.0
use crate::{Element, Renderer};
use std::borrow::Cow;
use crate::{widget::text, Element, Renderer};
use iced::widget::{horizontal_space, row, Row};
/// A setting within a settings view section.
#[must_use]
#[allow(clippy::module_name_repetitions)]
pub fn item<'a, Message: 'static>(
title: impl ToString,
title: impl Into<Cow<'a, str>>,
widget: impl Into<Element<'a, Message>>,
) -> iced::widget::Row<'a, Message, Renderer> {
) -> Row<'a, Message, Renderer> {
item_row(vec![
iced::widget::text(title).into(),
iced::widget::horizontal_space(iced::Length::Fill).into(),
text(title).into(),
horizontal_space(iced::Length::Fill).into(),
widget.into(),
])
}
@ -20,8 +23,8 @@ pub fn item<'a, Message: 'static>(
/// A settings item aligned in a row
#[must_use]
#[allow(clippy::module_name_repetitions)]
pub fn item_row<Message>(children: Vec<Element<Message>>) -> iced::widget::Row<Message, Renderer> {
iced::widget::row(children)
pub fn item_row<Message>(children: Vec<Element<Message>>) -> Row<Message, Renderer> {
row(children)
.align_items(iced::Alignment::Center)
.padding([0, 18])
.spacing(12)