Radish alpha
r
Radicle terminal user interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
lib: Move column type to parent UI module
Erik Kundt committed 1 year ago
commit d32b4e15b56be470058e88dc62a69bd08af248b2
parent 30788cf7988dce8a3eddd51b1c71f703fd9c9e19
7 files changed +93 -88
modified examples/basic.rs
@@ -7,10 +7,11 @@ use ratatui::layout::Constraint;
use radicle_tui as tui;

use tui::store;
-
use tui::ui::rm::widget::container::{Column, Container, Header, HeaderProps};
+
use tui::ui::rm::widget::container::{Container, Header, HeaderProps};
use tui::ui::rm::widget::input::{TextView, TextViewProps, TextViewState};
use tui::ui::rm::widget::window::{Page, Shortcuts, ShortcutsProps, Window, WindowProps};
use tui::ui::rm::widget::ToWidget;
+
use tui::ui::Column;
use tui::{BoxedAny, Channel, Exit};

const CONTENT: &str = r#"
modified src/ui.rs
@@ -4,3 +4,89 @@ pub mod layout;
pub mod rm;
pub mod span;
pub mod theme;
+

+
use ratatui::layout::Constraint;
+
use ratatui::text::Text;
+

+
pub const RENDER_WIDTH_XSMALL: usize = 50;
+
pub const RENDER_WIDTH_SMALL: usize = 70;
+
pub const RENDER_WIDTH_MEDIUM: usize = 150;
+
pub const RENDER_WIDTH_LARGE: usize = usize::MAX;
+

+
#[derive(Clone, Debug, Default)]
+
pub struct ColumnView {
+
    small: bool,
+
    medium: bool,
+
    large: bool,
+
}
+

+
impl ColumnView {
+
    pub fn all() -> Self {
+
        Self {
+
            small: true,
+
            medium: true,
+
            large: true,
+
        }
+
    }
+

+
    pub fn small(mut self) -> Self {
+
        self.small = true;
+
        self
+
    }
+

+
    pub fn medium(mut self) -> Self {
+
        self.medium = true;
+
        self
+
    }
+

+
    pub fn large(mut self) -> Self {
+
        self.large = true;
+
        self
+
    }
+
}
+

+
#[derive(Clone, Debug)]
+
pub struct Column<'a> {
+
    pub text: Text<'a>,
+
    pub width: Constraint,
+
    pub skip: bool,
+
    pub view: ColumnView,
+
}
+

+
impl<'a> Column<'a> {
+
    pub fn new(text: impl Into<Text<'a>>, width: Constraint) -> Self {
+
        Self {
+
            text: text.into(),
+
            width,
+
            skip: false,
+
            view: ColumnView::all(),
+
        }
+
    }
+

+
    pub fn skip(mut self, skip: bool) -> Self {
+
        self.skip = skip;
+
        self
+
    }
+

+
    pub fn hide_small(mut self) -> Self {
+
        self.view = ColumnView::default().medium().large();
+
        self
+
    }
+

+
    pub fn hide_medium(mut self) -> Self {
+
        self.view = ColumnView::default().large();
+
        self
+
    }
+

+
    pub fn displayed(&self, area_width: usize) -> bool {
+
        if area_width < RENDER_WIDTH_SMALL {
+
            self.view.small
+
        } else if area_width < RENDER_WIDTH_MEDIUM {
+
            self.view.medium
+
        } else if area_width < RENDER_WIDTH_LARGE {
+
            self.view.large
+
        } else {
+
            true
+
        }
+
    }
+
}
modified src/ui/im.rs
@@ -20,9 +20,9 @@ use crate::event::Event;
use crate::store::State;
use crate::task::Interrupted;
use crate::terminal;
-
use crate::ui::rm::widget::container::Column;
use crate::ui::rm::widget::list::ToRow;
use crate::ui::theme::Theme;
+
use crate::ui::Column;

use crate::ui::im::widget::{HeaderedTable, Widget};

modified src/ui/im/widget.rs
@@ -9,9 +9,9 @@ use ratatui::{layout::Constraint, widgets::Paragraph};
use termion::event::Key;

use crate::ui::ext::{FooterBlock, FooterBlockType, HeaderBlock};
-
use crate::ui::rm::widget::container::Column;
use crate::ui::rm::widget::list::ToRow;
use crate::ui::theme::style;
+
use crate::ui::Column;
use crate::ui::{layout, span};

use super::{Borders, Context, InnerResponse, Response, Ui};
modified src/ui/rm.rs
@@ -16,11 +16,6 @@ use crate::ui::rm::widget::Widget;
const RENDERING_TICK_RATE: Duration = Duration::from_millis(250);
const INLINE_HEIGHT: usize = 20;

-
pub const RENDER_WIDTH_XSMALL: usize = 50;
-
pub const RENDER_WIDTH_SMALL: usize = 70;
-
pub const RENDER_WIDTH_MEDIUM: usize = 150;
-
pub const RENDER_WIDTH_LARGE: usize = usize::MAX;
-

/// The `Frontend` runs an applications' view concurrently. It handles
/// terminal events as well as state updates and renders the view accordingly.
///
modified src/ui/rm/widget/container.rs
@@ -8,88 +8,10 @@ use ratatui::widgets::{Block, BorderType, Borders, Row};

use crate::ui::ext::{FooterBlock, FooterBlockType, HeaderBlock};
use crate::ui::theme::{style, Theme};
-
use crate::ui::rm::{RENDER_WIDTH_LARGE, RENDER_WIDTH_MEDIUM, RENDER_WIDTH_SMALL};
+
use crate::ui::Column;

use super::{PredefinedLayout, RenderProps, View, ViewProps, ViewState, Widget};

-
#[derive(Clone, Debug, Default)]
-
pub struct ColumnView {
-
    small: bool,
-
    medium: bool,
-
    large: bool,
-
}
-

-
impl ColumnView {
-
    pub fn all() -> Self {
-
        Self {
-
            small: true,
-
            medium: true,
-
            large: true,
-
        }
-
    }
-

-
    pub fn small(mut self) -> Self {
-
        self.small = true;
-
        self
-
    }
-

-
    pub fn medium(mut self) -> Self {
-
        self.medium = true;
-
        self
-
    }
-

-
    pub fn large(mut self) -> Self {
-
        self.large = true;
-
        self
-
    }
-
}
-

-
#[derive(Clone, Debug)]
-
pub struct Column<'a> {
-
    pub text: Text<'a>,
-
    pub width: Constraint,
-
    pub skip: bool,
-
    pub view: ColumnView,
-
}
-

-
impl<'a> Column<'a> {
-
    pub fn new(text: impl Into<Text<'a>>, width: Constraint) -> Self {
-
        Self {
-
            text: text.into(),
-
            width,
-
            skip: false,
-
            view: ColumnView::all(),
-
        }
-
    }
-

-
    pub fn skip(mut self, skip: bool) -> Self {
-
        self.skip = skip;
-
        self
-
    }
-

-
    pub fn hide_small(mut self) -> Self {
-
        self.view = ColumnView::default().medium().large();
-
        self
-
    }
-

-
    pub fn hide_medium(mut self) -> Self {
-
        self.view = ColumnView::default().large();
-
        self
-
    }
-

-
    pub fn displayed(&self, area_width: usize) -> bool {
-
        if area_width < RENDER_WIDTH_SMALL {
-
            self.view.small
-
        } else if area_width < RENDER_WIDTH_MEDIUM {
-
            self.view.medium
-
        } else if area_width < RENDER_WIDTH_LARGE {
-
            self.view.large
-
        } else {
-
            true
-
        }
-
    }
-
}
-

#[derive(Clone, Debug)]
pub struct HeaderProps<'a> {
    pub columns: Vec<Column<'a>>,
modified src/ui/rm/widget/list.rs
@@ -18,10 +18,11 @@ use ratatui::Frame;
use tui_tree_widget::{TreeItem, TreeState};

use crate::ui::theme::style;
+
use crate::ui::Column;
use crate::ui::{layout, span};

-
use super::{container::Column, RenderProps, View};
use super::{utils, ViewProps, ViewState};
+
use super::{RenderProps, View};

/// Needs to be implemented for items that are supposed to be rendered in tables.
pub trait ToRow<const W: usize> {