tui: Reorganize component modules

This commit is contained in:
Erik Kundt 2023-04-20 11:02:11 +02:00 committed by Alexis Sellier
parent a2da673c31
commit fed4e84dd7
No known key found for this signature in database
14 changed files with 288 additions and 268 deletions

View File

@ -5,12 +5,12 @@ use tuirealm::command::{Cmd, CmdResult, Direction as MoveDirection};
use tuirealm::event::{Event, Key, KeyEvent};
use tuirealm::{MockComponent, NoUserEvent, State, StateValue};
use radicle_tui::ui::components::container::{GlobalListener, LabeledContainer, Tabs};
use radicle_tui::ui::components::context::{ContextBar, Shortcuts};
use radicle_tui::ui::components::list::PropertyList;
use radicle_tui::ui::components::workspace::{
Browser, Dashboard, IssueBrowser, PatchActivity, PatchFiles,
};
use radicle_tui::ui::components::common::container::{GlobalListener, LabeledContainer, Tabs};
use radicle_tui::ui::components::common::context::{ContextBar, Shortcuts};
use radicle_tui::ui::components::common::list::PropertyList;
use radicle_tui::ui::components::common::Browser;
use radicle_tui::ui::components::home::{Dashboard, IssueBrowser};
use radicle_tui::ui::components::patch;
use radicle_tui::ui::widget::Widget;
@ -86,7 +86,7 @@ impl tuirealm::Component<Message, NoUserEvent> for Widget<IssueBrowser> {
}
}
impl tuirealm::Component<Message, NoUserEvent> for Widget<PatchActivity> {
impl tuirealm::Component<Message, NoUserEvent> for Widget<patch::Activity> {
fn on(&mut self, event: Event<NoUserEvent>) -> Option<Message> {
match event {
Event::Keyboard(KeyEvent { code: Key::Esc, .. }) => {
@ -97,7 +97,7 @@ impl tuirealm::Component<Message, NoUserEvent> for Widget<PatchActivity> {
}
}
impl tuirealm::Component<Message, NoUserEvent> for Widget<PatchFiles> {
impl tuirealm::Component<Message, NoUserEvent> for Widget<patch::Files> {
fn on(&mut self, event: Event<NoUserEvent>) -> Option<Message> {
match event {
Event::Keyboard(KeyEvent { code: Key::Esc, .. }) => {

View File

@ -7,7 +7,7 @@ use radicle::cob::patch::{Patch, PatchId};
use tuirealm::props::{Color, TextSpan};
use crate::ui::components::list::List;
use crate::ui::components::common::list::List;
use crate::ui::theme::Theme;
pub fn format_status(_patch: &Patch) -> String {

View File

@ -1,5 +1,3 @@
pub mod container;
pub mod context;
pub mod label;
pub mod list;
pub mod workspace;
pub mod common;
pub mod home;
pub mod patch;

View File

@ -0,0 +1,55 @@
pub mod container;
pub mod context;
pub mod label;
pub mod list;
use std::marker::PhantomData;
use tuirealm::command::{Cmd, CmdResult};
use tuirealm::props::Props;
use tuirealm::tui::layout::Rect;
use tuirealm::{AttrValue, Attribute, Frame, MockComponent, State};
use crate::ui::layout;
use crate::ui::widget::{Widget, WidgetComponent};
use context::Shortcuts;
use list::{List, Table};
pub struct Browser<T> {
list: Widget<Table>,
shortcuts: Widget<Shortcuts>,
phantom: PhantomData<T>,
}
impl<T: List> Browser<T> {
pub fn new(list: Widget<Table>, shortcuts: Widget<Shortcuts>) -> Self {
Self {
list,
shortcuts,
phantom: PhantomData,
}
}
}
impl<T: List> WidgetComponent for Browser<T> {
fn view(&mut self, _properties: &Props, frame: &mut Frame, area: Rect) {
let shortcuts_h = self
.shortcuts
.query(Attribute::Height)
.unwrap_or(AttrValue::Size(0))
.unwrap_size();
let layout = layout::root_component(area, shortcuts_h);
self.list.view(frame, layout[0]);
self.shortcuts.view(frame, layout[1]);
}
fn state(&self) -> State {
State::None
}
fn perform(&mut self, _properties: &Props, cmd: Cmd) -> CmdResult {
self.list.perform(cmd)
}
}

View File

@ -7,7 +7,7 @@ use tuirealm::tui::text::{Span, Spans};
use tuirealm::tui::widgets::Block;
use tuirealm::{Frame, MockComponent, State, StateValue};
use crate::ui::components::label::Label;
use crate::ui::components::common::label::Label;
use crate::ui::layout;
use crate::ui::state::TabState;
use crate::ui::widget::{Widget, WidgetComponent};

View File

@ -3,7 +3,7 @@ use tuirealm::props::{AttrValue, Attribute, Props};
use tuirealm::tui::layout::Rect;
use tuirealm::{Frame, MockComponent, State};
use crate::ui::components::label::Label;
use crate::ui::components::common::label::Label;
use crate::ui::layout;
use crate::ui::widget::{Widget, WidgetComponent};

View File

@ -7,7 +7,7 @@ use tuirealm::tui::layout::{Constraint, Rect};
use tuirealm::tui::widgets::{Cell, Row, TableState};
use tuirealm::{Frame, MockComponent, State, StateValue};
use crate::ui::components::label::Label;
use crate::ui::components::common::label::Label;
use crate::ui::layout;
use crate::ui::theme::Theme;
use crate::ui::widget::{Widget, WidgetComponent};

View File

@ -0,0 +1,83 @@
use tuirealm::command::{Cmd, CmdResult};
use tuirealm::props::Props;
use tuirealm::tui::layout::Rect;
use tuirealm::{AttrValue, Attribute, Frame, MockComponent, State};
use crate::ui::layout;
use crate::ui::widget::{Widget, WidgetComponent};
use super::common::container::LabeledContainer;
use super::common::context::Shortcuts;
use super::common::label::Label;
pub struct Dashboard {
about: Widget<LabeledContainer>,
shortcuts: Widget<Shortcuts>,
}
impl Dashboard {
pub fn new(about: Widget<LabeledContainer>, shortcuts: Widget<Shortcuts>) -> Self {
Self { about, shortcuts }
}
}
impl WidgetComponent for Dashboard {
fn view(&mut self, _properties: &Props, frame: &mut Frame, area: Rect) {
let shortcuts_h = self
.shortcuts
.query(Attribute::Height)
.unwrap_or(AttrValue::Size(0))
.unwrap_size();
let layout = layout::root_component(area, shortcuts_h);
self.about.view(frame, layout[0]);
self.shortcuts.view(frame, layout[1]);
}
fn state(&self) -> State {
State::None
}
fn perform(&mut self, _properties: &Props, _cmd: Cmd) -> CmdResult {
CmdResult::None
}
}
pub struct IssueBrowser {
label: Widget<Label>,
shortcuts: Widget<Shortcuts>,
}
impl IssueBrowser {
pub fn new(label: Widget<Label>, shortcuts: Widget<Shortcuts>) -> Self {
Self { label, shortcuts }
}
}
impl WidgetComponent for IssueBrowser {
fn view(&mut self, _properties: &Props, frame: &mut Frame, area: Rect) {
let label_w = self
.label
.query(Attribute::Width)
.unwrap_or(AttrValue::Size(1))
.unwrap_size();
let shortcuts_h = self
.shortcuts
.query(Attribute::Height)
.unwrap_or(AttrValue::Size(0))
.unwrap_size();
let layout = layout::root_component(area, shortcuts_h);
self.label
.view(frame, layout::centered_label(label_w, layout[0]));
self.shortcuts.view(frame, layout[1])
}
fn state(&self) -> State {
State::None
}
fn perform(&mut self, _properties: &Props, _cmd: Cmd) -> CmdResult {
CmdResult::None
}
}

View File

@ -0,0 +1,118 @@
use tuirealm::command::{Cmd, CmdResult};
use tuirealm::props::Props;
use tuirealm::tui::layout::Rect;
use tuirealm::{AttrValue, Attribute, Frame, MockComponent, State};
use crate::ui::layout;
use crate::ui::widget::{Widget, WidgetComponent};
use super::common::context::{ContextBar, Shortcuts};
use super::common::label::Label;
pub struct Activity {
label: Widget<Label>,
context: Widget<ContextBar>,
shortcuts: Widget<Shortcuts>,
}
impl Activity {
pub fn new(
label: Widget<Label>,
context: Widget<ContextBar>,
shortcuts: Widget<Shortcuts>,
) -> Self {
Self {
label,
context,
shortcuts,
}
}
}
impl WidgetComponent for Activity {
fn view(&mut self, _properties: &Props, frame: &mut Frame, area: Rect) {
let label_w = self
.label
.query(Attribute::Width)
.unwrap_or(AttrValue::Size(1))
.unwrap_size();
let context_h = self
.context
.query(Attribute::Height)
.unwrap_or(AttrValue::Size(0))
.unwrap_size();
let shortcuts_h = self
.shortcuts
.query(Attribute::Height)
.unwrap_or(AttrValue::Size(0))
.unwrap_size();
let layout = layout::root_component_with_context(area, context_h, shortcuts_h);
self.label
.view(frame, layout::centered_label(label_w, layout[0]));
self.context.view(frame, layout[1]);
self.shortcuts.view(frame, layout[2]);
}
fn state(&self) -> State {
State::None
}
fn perform(&mut self, _properties: &Props, _cmd: Cmd) -> CmdResult {
CmdResult::None
}
}
pub struct Files {
label: Widget<Label>,
context: Widget<ContextBar>,
shortcuts: Widget<Shortcuts>,
}
impl Files {
pub fn new(
label: Widget<Label>,
context: Widget<ContextBar>,
shortcuts: Widget<Shortcuts>,
) -> Self {
Self {
label,
context,
shortcuts,
}
}
}
impl WidgetComponent for Files {
fn view(&mut self, _properties: &Props, frame: &mut Frame, area: Rect) {
let label_w = self
.label
.query(Attribute::Width)
.unwrap_or(AttrValue::Size(1))
.unwrap_size();
let context_h = self
.context
.query(Attribute::Height)
.unwrap_or(AttrValue::Size(0))
.unwrap_size();
let shortcuts_h = self
.shortcuts
.query(Attribute::Height)
.unwrap_or(AttrValue::Size(0))
.unwrap_size();
let layout = layout::root_component_with_context(area, context_h, shortcuts_h);
self.label
.view(frame, layout::centered_label(label_w, layout[0]));
self.context.view(frame, layout[1]);
self.shortcuts.view(frame, layout[2]);
}
fn state(&self) -> State {
State::None
}
fn perform(&mut self, _properties: &Props, _cmd: Cmd) -> CmdResult {
CmdResult::None
}
}

View File

@ -1,231 +0,0 @@
use std::marker::PhantomData;
use tuirealm::command::{Cmd, CmdResult};
use tuirealm::props::Props;
use tuirealm::tui::layout::Rect;
use tuirealm::{AttrValue, Attribute, Frame, MockComponent, State};
use crate::ui::layout;
use crate::ui::widget::{Widget, WidgetComponent};
use super::container::LabeledContainer;
use super::context::{ContextBar, Shortcuts};
use super::label::Label;
use super::list::{List, Table};
pub struct Browser<T> {
list: Widget<Table>,
shortcuts: Widget<Shortcuts>,
phantom: PhantomData<T>,
}
impl<T: List> Browser<T> {
pub fn new(list: Widget<Table>, shortcuts: Widget<Shortcuts>) -> Self {
Self {
list,
shortcuts,
phantom: PhantomData,
}
}
}
impl<T: List> WidgetComponent for Browser<T> {
fn view(&mut self, _properties: &Props, frame: &mut Frame, area: Rect) {
let shortcuts_h = self
.shortcuts
.query(Attribute::Height)
.unwrap_or(AttrValue::Size(0))
.unwrap_size();
let layout = layout::root_component(area, shortcuts_h);
self.list.view(frame, layout[0]);
self.shortcuts.view(frame, layout[1]);
}
fn state(&self) -> State {
State::None
}
fn perform(&mut self, _properties: &Props, cmd: Cmd) -> CmdResult {
self.list.perform(cmd)
}
}
pub struct Dashboard {
about: Widget<LabeledContainer>,
shortcuts: Widget<Shortcuts>,
}
impl Dashboard {
pub fn new(about: Widget<LabeledContainer>, shortcuts: Widget<Shortcuts>) -> Self {
Self { about, shortcuts }
}
}
impl WidgetComponent for Dashboard {
fn view(&mut self, _properties: &Props, frame: &mut Frame, area: Rect) {
let shortcuts_h = self
.shortcuts
.query(Attribute::Height)
.unwrap_or(AttrValue::Size(0))
.unwrap_size();
let layout = layout::root_component(area, shortcuts_h);
self.about.view(frame, layout[0]);
self.shortcuts.view(frame, layout[1]);
}
fn state(&self) -> State {
State::None
}
fn perform(&mut self, _properties: &Props, _cmd: Cmd) -> CmdResult {
CmdResult::None
}
}
pub struct IssueBrowser {
label: Widget<Label>,
shortcuts: Widget<Shortcuts>,
}
impl IssueBrowser {
pub fn new(label: Widget<Label>, shortcuts: Widget<Shortcuts>) -> Self {
Self { label, shortcuts }
}
}
impl WidgetComponent for IssueBrowser {
fn view(&mut self, _properties: &Props, frame: &mut Frame, area: Rect) {
let label_w = self
.label
.query(Attribute::Width)
.unwrap_or(AttrValue::Size(1))
.unwrap_size();
let shortcuts_h = self
.shortcuts
.query(Attribute::Height)
.unwrap_or(AttrValue::Size(0))
.unwrap_size();
let layout = layout::root_component(area, shortcuts_h);
self.label
.view(frame, layout::centered_label(label_w, layout[0]));
self.shortcuts.view(frame, layout[1])
}
fn state(&self) -> State {
State::None
}
fn perform(&mut self, _properties: &Props, _cmd: Cmd) -> CmdResult {
CmdResult::None
}
}
pub struct PatchActivity {
label: Widget<Label>,
context: Widget<ContextBar>,
shortcuts: Widget<Shortcuts>,
}
impl PatchActivity {
pub fn new(
label: Widget<Label>,
context: Widget<ContextBar>,
shortcuts: Widget<Shortcuts>,
) -> Self {
Self {
label,
context,
shortcuts,
}
}
}
impl WidgetComponent for PatchActivity {
fn view(&mut self, _properties: &Props, frame: &mut Frame, area: Rect) {
let label_w = self
.label
.query(Attribute::Width)
.unwrap_or(AttrValue::Size(1))
.unwrap_size();
let context_h = self
.context
.query(Attribute::Height)
.unwrap_or(AttrValue::Size(0))
.unwrap_size();
let shortcuts_h = self
.shortcuts
.query(Attribute::Height)
.unwrap_or(AttrValue::Size(0))
.unwrap_size();
let layout = layout::root_component_with_context(area, context_h, shortcuts_h);
self.label
.view(frame, layout::centered_label(label_w, layout[0]));
self.context.view(frame, layout[1]);
self.shortcuts.view(frame, layout[2]);
}
fn state(&self) -> State {
State::None
}
fn perform(&mut self, _properties: &Props, _cmd: Cmd) -> CmdResult {
CmdResult::None
}
}
pub struct PatchFiles {
label: Widget<Label>,
context: Widget<ContextBar>,
shortcuts: Widget<Shortcuts>,
}
impl PatchFiles {
pub fn new(
label: Widget<Label>,
context: Widget<ContextBar>,
shortcuts: Widget<Shortcuts>,
) -> Self {
Self {
label,
context,
shortcuts,
}
}
}
impl WidgetComponent for PatchFiles {
fn view(&mut self, _properties: &Props, frame: &mut Frame, area: Rect) {
let label_w = self
.label
.query(Attribute::Width)
.unwrap_or(AttrValue::Size(1))
.unwrap_size();
let context_h = self
.context
.query(Attribute::Height)
.unwrap_or(AttrValue::Size(0))
.unwrap_size();
let shortcuts_h = self
.shortcuts
.query(Attribute::Height)
.unwrap_or(AttrValue::Size(0))
.unwrap_size();
let layout = layout::root_component_with_context(area, context_h, shortcuts_h);
self.label
.view(frame, layout::centered_label(label_w, layout[0]));
self.context.view(frame, layout[1]);
self.shortcuts.view(frame, layout[2]);
}
fn state(&self) -> State {
State::None
}
fn perform(&mut self, _properties: &Props, _cmd: Cmd) -> CmdResult {
CmdResult::None
}
}

View File

@ -2,16 +2,16 @@ use radicle::Profile;
use tuirealm::props::{AttrValue, Attribute};
use tuirealm::MockComponent;
use crate::ui::components::container::{GlobalListener, LabeledContainer, Tabs};
use crate::ui::components::context::{Shortcut, Shortcuts};
use crate::ui::components::label::Label;
use crate::ui::components::list::{Property, PropertyList};
use crate::ui;
use ui::components::common::container::{GlobalListener, LabeledContainer, Tabs};
use ui::components::common::context::{Shortcut, Shortcuts};
use ui::components::common::label::Label;
use ui::components::common::list::{List, Property, PropertyList, Table};
use ui::theme::Theme;
use super::Widget;
use crate::ui::components::list::{List, Table};
use crate::ui::theme::Theme;
pub fn global_listener() -> Widget<GlobalListener> {
Widget::new(GlobalListener::default())
}

View File

@ -4,8 +4,9 @@ use radicle::Profile;
use tuirealm::props::{PropPayload, PropValue, TextSpan};
use tuirealm::AttrValue;
use crate::ui::components::container::Tabs;
use crate::ui::components::workspace::{Browser, Dashboard, IssueBrowser};
use crate::ui::components::common::container::Tabs;
use crate::ui::components::common::Browser;
use crate::ui::components::home::{Dashboard, IssueBrowser};
use crate::ui::theme::Theme;
use super::{common, Widget};

View File

@ -7,9 +7,9 @@ use super::common;
use super::Widget;
use crate::ui::cob::patch;
use crate::ui::components::container::Tabs;
use crate::ui::components::context::ContextBar;
use crate::ui::components::workspace::{PatchActivity, PatchFiles};
use crate::ui::components::common::container::Tabs;
use crate::ui::components::common::context::ContextBar;
use crate::ui::components::patch::Activity;
use crate::ui::theme::Theme;
pub fn navigation(theme: &Theme) -> Widget<Tabs> {
@ -19,11 +19,7 @@ pub fn navigation(theme: &Theme) -> Widget<Tabs> {
)
}
pub fn activity(
theme: &Theme,
patch: (PatchId, &Patch),
profile: &Profile,
) -> Widget<PatchActivity> {
pub fn activity(theme: &Theme, patch: (PatchId, &Patch), profile: &Profile) -> Widget<Activity> {
let (id, patch) = patch;
let shortcuts = common::shortcuts(
theme,
@ -36,12 +32,12 @@ pub fn activity(
let context = context(theme, (id, patch), profile);
let not_implemented = common::label("not implemented").foreground(theme.colors.default_fg);
let activity = PatchActivity::new(not_implemented, context, shortcuts);
let activity = Activity::new(not_implemented, context, shortcuts);
Widget::new(activity)
}
pub fn files(theme: &Theme, patch: (PatchId, &Patch), profile: &Profile) -> Widget<PatchFiles> {
pub fn files(theme: &Theme, patch: (PatchId, &Patch), profile: &Profile) -> Widget<Activity> {
let (id, patch) = patch;
let shortcuts = common::shortcuts(
theme,
@ -54,7 +50,7 @@ pub fn files(theme: &Theme, patch: (PatchId, &Patch), profile: &Profile) -> Widg
let context = context(theme, (id, patch), profile);
let not_implemented = common::label("not implemented").foreground(theme.colors.default_fg);
let files = PatchFiles::new(not_implemented, context, shortcuts);
let files = Activity::new(not_implemented, context, shortcuts);
Widget::new(files)
}