mirror of
https://seed.radicle.dev/rad:z39mP9rQAaGmERfUMPULfPUi473tY.git
synced 2026-11-22 02:50:45 +08:00
lib: Move label builders to widget module
This commit is contained in:
@@ -14,13 +14,11 @@ use widget::container::{
|
||||
VerticalLine,
|
||||
};
|
||||
use widget::context::{Shortcut, Shortcuts};
|
||||
use widget::label::{Label, Textarea};
|
||||
use widget::label::{self, Label, Textarea};
|
||||
use widget::list::{ColumnWidth, Property, PropertyList, PropertyTable};
|
||||
|
||||
use widget::Widget;
|
||||
|
||||
use self::theme::{style, Theme};
|
||||
use self::widget::label::LabelGroup;
|
||||
use theme::{style, Theme};
|
||||
|
||||
use super::context::Context;
|
||||
|
||||
@@ -28,35 +26,6 @@ pub fn global_listener() -> Widget<GlobalListener> {
|
||||
Widget::new(GlobalListener::default())
|
||||
}
|
||||
|
||||
pub fn label(content: &str) -> Widget<Label> {
|
||||
// TODO: Remove when size constraints are implemented
|
||||
let width = content.chars().count() as u16;
|
||||
|
||||
Widget::new(Label)
|
||||
.content(AttrValue::String(content.to_string()))
|
||||
.height(1)
|
||||
.width(width)
|
||||
}
|
||||
|
||||
pub fn label_group(labels: &[Widget<Label>]) -> Widget<LabelGroup> {
|
||||
let group = LabelGroup::new(labels);
|
||||
let width = labels.iter().fold(0, |total, label| {
|
||||
total
|
||||
+ label
|
||||
.query(Attribute::Width)
|
||||
.unwrap_or(AttrValue::Size(0))
|
||||
.unwrap_size()
|
||||
});
|
||||
|
||||
Widget::new(group).width(width)
|
||||
}
|
||||
|
||||
pub fn reversable_label(content: &str) -> Widget<Label> {
|
||||
let content = &format!(" {content} ");
|
||||
|
||||
label(content)
|
||||
}
|
||||
|
||||
pub fn container_header(theme: &Theme, label: Widget<Label>) -> Widget<Header<1>> {
|
||||
let header = Header::new([label], [ColumnWidth::Grow], theme.clone());
|
||||
|
||||
@@ -73,16 +42,19 @@ pub fn labeled_container(
|
||||
title: &str,
|
||||
component: Box<dyn MockComponent>,
|
||||
) -> Widget<LabeledContainer> {
|
||||
let header = container_header(theme, label(&format!(" {title} ")).style(style::reset()));
|
||||
let header = container_header(
|
||||
theme,
|
||||
label::default(&format!(" {title} ")).style(style::reset()),
|
||||
);
|
||||
let container = LabeledContainer::new(header, component, theme.clone());
|
||||
|
||||
Widget::new(container)
|
||||
}
|
||||
|
||||
pub fn shortcut(theme: &Theme, short: &str, long: &str) -> Widget<Shortcut> {
|
||||
let short = label(short).style(style::gray());
|
||||
let long = label(long).style(style::gray_dim());
|
||||
let divider = label(&theme.icons.whitespace.to_string());
|
||||
let short = label::default(short).style(style::gray());
|
||||
let long = label::default(long).style(style::gray_dim());
|
||||
let divider = label::default(&theme.icons.whitespace.to_string());
|
||||
|
||||
// TODO: Remove when size constraints are implemented
|
||||
let short_w = short.query(Attribute::Width).unwrap().unwrap_size();
|
||||
@@ -96,16 +68,17 @@ pub fn shortcut(theme: &Theme, short: &str, long: &str) -> Widget<Shortcut> {
|
||||
}
|
||||
|
||||
pub fn shortcuts(theme: &Theme, shortcuts: Vec<Widget<Shortcut>>) -> Widget<Shortcuts> {
|
||||
let divider = label(&format!(" {} ", theme.icons.shortcutbar_divider)).style(style::gray_dim());
|
||||
let divider =
|
||||
label::default(&format!(" {} ", theme.icons.shortcutbar_divider)).style(style::gray_dim());
|
||||
let shortcut_bar = Shortcuts::new(shortcuts, divider);
|
||||
|
||||
Widget::new(shortcut_bar).height(1)
|
||||
}
|
||||
|
||||
pub fn property(theme: &Theme, name: &str, value: &str) -> Widget<Property> {
|
||||
let name = label(name).style(style::cyan());
|
||||
let divider = label(&format!(" {} ", theme.icons.property_divider));
|
||||
let value = label(value).style(style::reset());
|
||||
let name = label::default(name).style(style::cyan());
|
||||
let divider = label::default(&format!(" {} ", theme.icons.property_divider));
|
||||
let value = label::default(value).style(style::reset());
|
||||
|
||||
// TODO: Remove when size constraints are implemented
|
||||
let name_w = name.query(Attribute::Width).unwrap().unwrap_size();
|
||||
@@ -137,8 +110,8 @@ pub fn tabs(_theme: &Theme, tabs: Vec<Widget<Label>>) -> Widget<Tabs> {
|
||||
}
|
||||
|
||||
pub fn app_info(context: &Context) -> Widget<AppInfo> {
|
||||
let project = label(context.project().name()).style(style::cyan());
|
||||
let rid = label(&format!(" ({})", context.id())).style(style::yellow());
|
||||
let project = label::default(context.project().name()).style(style::cyan());
|
||||
let rid = label::default(&format!(" ({})", context.id())).style(style::yellow());
|
||||
|
||||
let project_w = project
|
||||
.query(Attribute::Width)
|
||||
@@ -158,7 +131,7 @@ pub fn app_header(
|
||||
theme: &Theme,
|
||||
nav: Option<Widget<Tabs>>,
|
||||
) -> Widget<AppHeader> {
|
||||
let line = label(&theme.icons.tab_overline.to_string()).style(style::magenta());
|
||||
let line = label::default(&theme.icons.tab_overline.to_string()).style(style::magenta());
|
||||
let line = Widget::new(VerticalLine::new(line));
|
||||
let info = app_info(context);
|
||||
let header = AppHeader::new(nav, info, line);
|
||||
|
||||
Reference in New Issue
Block a user