diff --git a/radicle-tui/src/app.rs b/radicle-tui/src/app.rs index c2a82523..cdde6d9c 100644 --- a/radicle-tui/src/app.rs +++ b/radicle-tui/src/app.rs @@ -13,9 +13,10 @@ use tuirealm::{ }; use radicle_tui::ui; -use radicle_tui::ui::components::{ - GlobalListener, LabeledContainer, PropertyList, ShortcutBar, Workspaces, -}; +use radicle_tui::ui::components::container::{GlobalListener, LabeledContainer}; +use radicle_tui::ui::components::context::Shortcuts; +use radicle_tui::ui::components::list::PropertyList; +use radicle_tui::ui::components::workspace::Workspaces; use radicle_tui::ui::theme; use radicle_tui::ui::widget::Widget; @@ -100,7 +101,7 @@ impl Tui for App { app.mount( ComponentId::Shortcuts, - ui::shortcut_bar( + ui::shortcuts( &theme, vec![ ui::shortcut(&theme, "tab", "section"), @@ -217,7 +218,7 @@ impl Component for Widget { } } -impl Component for Widget { +impl Component for Widget { fn on(&mut self, _event: Event) -> Option { None } diff --git a/radicle-tui/src/ui.rs b/radicle-tui/src/ui.rs index c7829a95..90de1aa6 100644 --- a/radicle-tui/src/ui.rs +++ b/radicle-tui/src/ui.rs @@ -1,16 +1,17 @@ pub mod components; pub mod layout; -mod state; +pub mod state; pub mod theme; pub mod widget; use tuirealm::props::Attribute; use tuirealm::{MockComponent, StateValue}; -use components::{ - ContainerHeader, GlobalListener, Label, LabeledContainer, Property, PropertyList, Shortcut, - ShortcutBar, Tabs, Workspaces, WorkspacesHeader, -}; +use components::container::{GlobalListener, LabeledContainer, Tabs}; +use components::context::{Shortcut, Shortcuts}; +use components::label::Label; +use components::list::{Property, PropertyList}; +use components::workspace::Workspaces; use widget::Widget; pub fn global_listener() -> Widget { @@ -33,9 +34,7 @@ pub fn labeled_container( let title = label(&format!(" {title} ")) .foreground(theme.colors.default_fg) .background(theme.colors.labeled_container_bg); - let spacer = label(""); - let header = Widget::new(ContainerHeader::new(title, spacer)); - let container = LabeledContainer::new(header, component); + let container = LabeledContainer::new(title, component); Widget::new(container).background(theme.colors.labeled_container_bg) } @@ -56,10 +55,10 @@ pub fn shortcut(theme: &theme::Theme, short: &str, long: &str) -> Widget>) -> Widget { +pub fn shortcuts(theme: &theme::Theme, shortcuts: Vec>) -> Widget { let divider = label(&format!(" {} ", theme.icons.shortcutbar_divider)) .foreground(theme.colors.shortcutbar_divider_fg); - let shortcut_bar = ShortcutBar::new(shortcuts, divider); + let shortcut_bar = Shortcuts::new(shortcuts, divider); Widget::new(shortcut_bar).height(1) } @@ -106,8 +105,7 @@ pub fn workspaces( children: Vec>, ) -> Widget { let info = label(info).foreground(theme.colors.workspaces_info_fg); - let header = Widget::new(WorkspacesHeader::new(tabs, info)); - let workspaces = Workspaces::new(header, children); + let workspaces = Workspaces::new(tabs, info, children); Widget::new(workspaces) } diff --git a/radicle-tui/src/ui/components.rs b/radicle-tui/src/ui/components.rs index 5882a700..deef1684 100644 --- a/radicle-tui/src/ui/components.rs +++ b/radicle-tui/src/ui/components.rs @@ -1,568 +1,5 @@ -use tui_realm_stdlib::Phantom; - -use tuirealm::command::{Cmd, CmdResult}; -use tuirealm::props::{AttrValue, Attribute, Color, Props, Style}; -use tuirealm::tui::layout::{Constraint, Direction, Layout, Rect}; -use tuirealm::tui::text::{Span, Spans}; -use tuirealm::tui::widgets::{Block, Tabs as TuiTabs}; -use tuirealm::{Frame, MockComponent, State, StateValue}; - -use super::layout; -use super::state::TabState; -use super::widget::{Widget, WidgetComponent}; - -/// Some user events need to be handled globally (e.g. user presses key `q` to quit -/// the application). This component can be used in conjunction with SubEventClause -/// to handle those events. -#[derive(Default)] -pub struct GlobalListener {} - -impl WidgetComponent for GlobalListener { - fn view(&mut self, _properties: &Props, _frame: &mut Frame, _area: Rect) {} - - fn state(&self) -> State { - State::None - } - - fn perform(&mut self, _cmd: Cmd) -> CmdResult { - CmdResult::None - } -} - -/// Some user events need to be handled globally (e.g. user presses key `q` to quit -/// the application). This component can be used in conjunction with SubEventClause -/// to handle those events. -#[derive(Default, MockComponent)] -pub struct GlobalPhantom { - component: Phantom, -} - -/// A label that can be styled using a foreground color and text modifiers. -/// Its height is fixed, its width depends on the length of the text it displays. -#[derive(Clone)] -pub struct Label { - content: StateValue, -} - -impl Label { - pub fn new(content: StateValue) -> Self { - Self { content } - } -} - -impl WidgetComponent for Label { - fn view(&mut self, properties: &Props, frame: &mut Frame, area: Rect) { - use tui_realm_stdlib::Label; - - let display = properties - .get_or(Attribute::Display, AttrValue::Flag(true)) - .unwrap_flag(); - let foreground = properties - .get_or(Attribute::Foreground, AttrValue::Color(Color::Reset)) - .unwrap_color(); - let background = properties - .get_or(Attribute::Background, AttrValue::Color(Color::Reset)) - .unwrap_color(); - - if display { - let mut label = match properties.get(Attribute::TextProps) { - Some(modifiers) => Label::default() - .foreground(foreground) - .background(background) - .modifiers(modifiers.unwrap_text_modifiers()) - .text(self.content.clone().unwrap_string()), - None => Label::default() - .foreground(foreground) - .background(background) - .text(self.content.clone().unwrap_string()), - }; - - label.view(frame, area); - } - } - - fn state(&self) -> State { - State::One(self.content.clone()) - } - - fn perform(&mut self, _cmd: Cmd) -> CmdResult { - CmdResult::None - } -} - -impl From<&Widget