//! 共用小件:带底色的容器、容忍域的标题、逐条列表。 //! //! 三个都在两个以上地方用到,所以单独一个文件——不是为了行数好看,是因为 //! 「容忍域长什么样」只有一处定义,改颜色/图标才不用找第二个副本。 use iced::widget::{column, container, row}; use iced::{Alignment, Background, Border, Element, Length}; use unlucky_design::color::Role; use unlucky_design::icons::IconKind; use unlucky_design::shape::ShapeScale; use unlucky_design::spacing::Space; use unlucky_design::typography::TypeRole; use unlucky_i18n::Catalog; use crate::pages::frame; use crate::pages::Message as PageMessage; use crate::theme::Ui; use super::super::model::Row; /// 带底色的容器(探测块与致命块共用;颜色由调用方给)。 pub(super) fn marker_box<'a>( ui: &'a Ui, role: Role, content: impl Into>, ) -> Element<'a, PageMessage> { let role = ui.color(role); container(content.into()) .width(Length::Fill) .padding(ui.space(Space::X3)) .style(move |_theme| container::Style { background: Some(Background::Color(role)), border: Border { radius: ui.radius_dp(ShapeScale::Large), ..Border::default() }, ..container::Style::default() }) .into() } pub(super) fn tolerable_title<'a>( ui: &'a Ui, catalog: Catalog, title: &'a str, ) -> Element<'a, PageMessage> { let _ = catalog; row![ frame::glyph(IconKind::Warn, ui.color(Role::Tertiary), frame::ICON_PX), frame::text_role( ui, TypeRole::LabelLarge, true, title, ui.color(Role::Tertiary), ), ] .spacing(ui.space(Space::X2)) .align_y(Alignment::Center) .into() } pub(super) fn rows_block<'a>( ui: &'a Ui, catalog: Catalog, rows: &'a [Row], ) -> Element<'a, PageMessage> { let _ = catalog; column( rows.iter() .map(|row| { row![ frame::text_role( ui, TypeRole::BodySmall, false, row.path.as_str(), ui.color(Role::OnSurface), ), frame::text_role( ui, TypeRole::BodySmall, false, row.note.as_str(), ui.color(Role::OnSurfaceVariant), ), ] .spacing(ui.space(Space::X2)) .width(Length::Fill) .into() }) .collect::>(), ) .spacing(ui.space(Space::X1)) .width(Length::Fill) .into() }