Skip to content

Commit fa8070b

Browse files
author
Stephan Dilly
committed
new popup paragraph helper
1 parent 4caf8dd commit fa8070b

File tree

3 files changed

+33
-24
lines changed

3 files changed

+33
-24
lines changed

src/components/mod.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use tui::{
3030
backend::Backend,
3131
layout::Alignment,
3232
layout::Rect,
33-
widgets::{Block, Borders, Paragraph, Text},
33+
widgets::{Block, BorderType, Borders, Paragraph, Text},
3434
Frame,
3535
};
3636

@@ -165,3 +165,20 @@ where
165165
.block(Block::default().title(title).borders(Borders::ALL))
166166
.alignment(Alignment::Left)
167167
}
168+
169+
fn popup_paragraph<'a, 't, T>(
170+
title: &'a str,
171+
content: T,
172+
) -> Paragraph<'a, 't, T>
173+
where
174+
T: Iterator<Item = &'t Text<'t>>,
175+
{
176+
Paragraph::new(content)
177+
.block(
178+
Block::default()
179+
.title(title)
180+
.borders(Borders::ALL)
181+
.border_type(BorderType::Thick),
182+
)
183+
.alignment(Alignment::Left)
184+
}

src/components/reset.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
use super::{
2-
visibility_blocking, CommandBlocking, CommandInfo, Component,
3-
DrawableComponent,
4-
};
51
use crate::{
6-
components::dialog_paragraph,
2+
components::{
3+
popup_paragraph, visibility_blocking, CommandBlocking,
4+
CommandInfo, Component, DrawableComponent,
5+
},
76
queue::{Action, InternalEvent, Queue},
87
strings, ui,
98
ui::style::Theme,
@@ -43,10 +42,7 @@ impl DrawableComponent for ResetComponent {
4342

4443
let area = ui::centered_rect(30, 20, f.size());
4544
f.render_widget(Clear, area);
46-
f.render_widget(
47-
dialog_paragraph(title, txt.iter()),
48-
area,
49-
);
45+
f.render_widget(popup_paragraph(title, txt.iter()), area);
5046
}
5147

5248
Ok(())

src/components/textinput.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
use super::{
2-
visibility_blocking, CommandBlocking, CommandInfo, Component,
3-
DrawableComponent,
1+
use crate::{
2+
components::{
3+
popup_paragraph, visibility_blocking, CommandBlocking,
4+
CommandInfo, Component, DrawableComponent,
5+
},
6+
strings, ui,
7+
ui::style::Theme,
48
};
5-
use crate::{strings, ui, ui::style::Theme};
69
use anyhow::Result;
710
use crossterm::event::{Event, KeyCode};
811
use std::borrow::Cow;
912
use strings::commands;
1013
use tui::{
1114
backend::Backend,
12-
layout::{Alignment, Rect},
15+
layout::Rect,
1316
style::Style,
14-
widgets::{Block, BorderType, Borders, Clear, Paragraph, Text},
17+
widgets::{Clear, Text},
1518
Frame,
1619
};
1720

@@ -73,14 +76,7 @@ impl DrawableComponent for TextInputComponent {
7376
let area = ui::centered_rect(60, 20, f.size());
7477
f.render_widget(Clear, area);
7578
f.render_widget(
76-
Paragraph::new(txt.iter())
77-
.block(
78-
Block::default()
79-
.title(self.title.as_str())
80-
.borders(Borders::ALL)
81-
.border_type(BorderType::Thick),
82-
)
83-
.alignment(Alignment::Left),
79+
popup_paragraph(self.title.as_str(), txt.iter()),
8480
area,
8581
);
8682
}

0 commit comments

Comments
 (0)