From fa8070b1ba6a58fb04e1085fb6b39675272c4c41 Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Mon, 8 Jun 2020 23:50:46 +0200 Subject: [PATCH] new popup paragraph helper --- src/components/mod.rs | 19 ++++++++++++++++++- src/components/reset.rs | 14 +++++--------- src/components/textinput.rs | 24 ++++++++++-------------- 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/src/components/mod.rs b/src/components/mod.rs index 8c4d398b..165ea269 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -30,7 +30,7 @@ use tui::{ backend::Backend, layout::Alignment, layout::Rect, - widgets::{Block, Borders, Paragraph, Text}, + widgets::{Block, BorderType, Borders, Paragraph, Text}, Frame, }; @@ -165,3 +165,20 @@ where .block(Block::default().title(title).borders(Borders::ALL)) .alignment(Alignment::Left) } + +fn popup_paragraph<'a, 't, T>( + title: &'a str, + content: T, +) -> Paragraph<'a, 't, T> +where + T: Iterator>, +{ + Paragraph::new(content) + .block( + Block::default() + .title(title) + .borders(Borders::ALL) + .border_type(BorderType::Thick), + ) + .alignment(Alignment::Left) +} diff --git a/src/components/reset.rs b/src/components/reset.rs index fff1307e..70b56519 100644 --- a/src/components/reset.rs +++ b/src/components/reset.rs @@ -1,9 +1,8 @@ -use super::{ - visibility_blocking, CommandBlocking, CommandInfo, Component, - DrawableComponent, -}; use crate::{ - components::dialog_paragraph, + components::{ + popup_paragraph, visibility_blocking, CommandBlocking, + CommandInfo, Component, DrawableComponent, + }, queue::{Action, InternalEvent, Queue}, strings, ui, ui::style::Theme, @@ -43,10 +42,7 @@ impl DrawableComponent for ResetComponent { let area = ui::centered_rect(30, 20, f.size()); f.render_widget(Clear, area); - f.render_widget( - dialog_paragraph(title, txt.iter()), - area, - ); + f.render_widget(popup_paragraph(title, txt.iter()), area); } Ok(()) diff --git a/src/components/textinput.rs b/src/components/textinput.rs index a1027b67..0efbdfc2 100644 --- a/src/components/textinput.rs +++ b/src/components/textinput.rs @@ -1,17 +1,20 @@ -use super::{ - visibility_blocking, CommandBlocking, CommandInfo, Component, - DrawableComponent, +use crate::{ + components::{ + popup_paragraph, visibility_blocking, CommandBlocking, + CommandInfo, Component, DrawableComponent, + }, + strings, ui, + ui::style::Theme, }; -use crate::{strings, ui, ui::style::Theme}; use anyhow::Result; use crossterm::event::{Event, KeyCode}; use std::borrow::Cow; use strings::commands; use tui::{ backend::Backend, - layout::{Alignment, Rect}, + layout::Rect, style::Style, - widgets::{Block, BorderType, Borders, Clear, Paragraph, Text}, + widgets::{Clear, Text}, Frame, }; @@ -73,14 +76,7 @@ impl DrawableComponent for TextInputComponent { let area = ui::centered_rect(60, 20, f.size()); f.render_widget(Clear, area); f.render_widget( - Paragraph::new(txt.iter()) - .block( - Block::default() - .title(self.title.as_str()) - .borders(Borders::ALL) - .border_type(BorderType::Thick), - ) - .alignment(Alignment::Left), + popup_paragraph(self.title.as_str(), txt.iter()), area, ); }