From 08c482ad5b37b07b3373613c4b7eb9d32470d8fe Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Tue, 4 Jun 2024 17:07:50 +0200 Subject: [PATCH] lib: Rename paragraph to textarea --- examples/basic.rs | 6 +++--- examples/hello.rs | 6 +++--- src/ui/widget/text.rs | 28 ++++++++++++++-------------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/examples/basic.rs b/examples/basic.rs index cc0d0a3e..bbbbdc52 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -8,7 +8,7 @@ use radicle_tui as tui; use tui::store; use tui::ui::widget::container::{Column, Container, Header, HeaderProps}; -use tui::ui::widget::text::{Paragraph, ParagraphProps}; +use tui::ui::widget::text::{TextArea, TextAreaProps}; use tui::ui::widget::window::{Page, Shortcuts, ShortcutsProps, Window, WindowProps}; use tui::ui::widget::ToWidget; use tui::{BoxedAny, Channel, Exit}; @@ -72,9 +72,9 @@ pub async fn main() -> Result<()> { .to_boxed_any() .into() })) - .content(Paragraph::default().to_widget(sender.clone()).on_update( + .content(TextArea::default().to_widget(sender.clone()).on_update( |state: &State| { - ParagraphProps::default() + TextAreaProps::default() .text(&state.content.clone().into()) .can_scroll(false) .to_boxed_any() diff --git a/examples/hello.rs b/examples/hello.rs index 174f29c4..dcd99e49 100644 --- a/examples/hello.rs +++ b/examples/hello.rs @@ -8,7 +8,7 @@ use ratatui::text::Text; use radicle_tui as tui; use tui::store; -use tui::ui::widget::text::{Paragraph, ParagraphProps}; +use tui::ui::widget::text::{TextArea, TextAreaProps}; use tui::ui::widget::ToWidget; use tui::{BoxedAny, Channel, Exit}; @@ -56,14 +56,14 @@ pub async fn main() -> Result<()> { alien: ALIEN.to_string(), }; - let scene = Paragraph::default() + let scene = TextArea::default() .to_widget(sender.clone()) .on_event(|key, _, _| match key { Key::Char('q') => Some(Message::Quit), _ => None, }) .on_update(|state: &State| { - ParagraphProps::default() + TextAreaProps::default() .text(&Text::styled(state.alien.clone(), Color::Rgb(85, 85, 255))) .to_boxed_any() .into() diff --git a/src/ui/widget/text.rs b/src/ui/widget/text.rs index fe261140..812e25ec 100644 --- a/src/ui/widget/text.rs +++ b/src/ui/widget/text.rs @@ -8,7 +8,7 @@ use termion::event::Key; use super::{RenderProps, View, ViewProps, ViewState}; #[derive(Clone)] -pub struct ParagraphProps<'a> { +pub struct TextAreaProps<'a> { pub content: Text<'a>, pub has_header: bool, pub has_footer: bool, @@ -17,7 +17,7 @@ pub struct ParagraphProps<'a> { pub can_scroll: bool, } -impl<'a> ParagraphProps<'a> { +impl<'a> TextAreaProps<'a> { pub fn page_size(mut self, page_size: usize) -> Self { self.page_size = page_size; self @@ -34,7 +34,7 @@ impl<'a> ParagraphProps<'a> { } } -impl<'a> Default for ParagraphProps<'a> { +impl<'a> Default for TextAreaProps<'a> { fn default() -> Self { Self { content: Text::raw(""), @@ -48,24 +48,24 @@ impl<'a> Default for ParagraphProps<'a> { } #[derive(Clone)] -struct ParagraphState { +struct TextAreaState { /// Internal offset pub offset: usize, /// Internal progress pub progress: usize, } -pub struct Paragraph { +pub struct TextArea { /// Internal state - state: ParagraphState, + state: TextAreaState, /// Phantom phantom: PhantomData<(S, M)>, } -impl Default for Paragraph { +impl Default for TextArea { fn default() -> Self { Self { - state: ParagraphState { + state: TextAreaState { offset: 0, progress: 0, }, @@ -74,7 +74,7 @@ impl Default for Paragraph { } } -impl Paragraph { +impl TextArea { fn scroll(&self) -> (u16, u16) { (self.state.offset as u16, 0) } @@ -134,7 +134,7 @@ impl Paragraph { } } -impl View for Paragraph +impl View for TextArea where S: 'static, M: 'static, @@ -143,9 +143,9 @@ where type State = S; fn handle_event(&mut self, props: Option<&ViewProps>, key: Key) -> Option { - let default = ParagraphProps::default(); + let default = TextAreaProps::default(); let props = props - .and_then(|props| props.inner_ref::()) + .and_then(|props| props.inner_ref::()) .unwrap_or(&default); let len = props.content.lines.len() + 1; @@ -179,9 +179,9 @@ where } fn render(&self, props: Option<&ViewProps>, render: RenderProps, frame: &mut Frame) { - let default = ParagraphProps::default(); + let default = TextAreaProps::default(); let props = props - .and_then(|props| props.inner_ref::()) + .and_then(|props| props.inner_ref::()) .unwrap_or(&default); let [content_area] = Layout::horizontal([Constraint::Min(1)])