Added 'save password' tab to auth activity when saving bookmarks

This commit is contained in:
ChristianVisintin
2020-12-16 17:01:11 +01:00
parent 344bf8604f
commit 335bfc8460
4 changed files with 66 additions and 18 deletions

View File

@@ -126,7 +126,7 @@ impl AuthActivity {
let (width, height): (u16, u16) = match popup {
PopupType::Alert(_, _) => (50, 10),
PopupType::Help => (50, 70),
PopupType::Input(_, _) => (40, 10),
PopupType::SaveBookmark(_, _) => (40, 20),
PopupType::YesNo(_, _, _) => (30, 10),
};
let popup_area: Rect = self.draw_popup_area(f.size(), width, height);
@@ -137,12 +137,27 @@ impl AuthActivity {
popup_area,
),
PopupType::Help => f.render_widget(self.draw_popup_help(), popup_area),
PopupType::Input(txt, _) => {
f.render_widget(self.draw_popup_input(txt.clone()), popup_area);
PopupType::SaveBookmark(txt, _) => {
let popup_chunks = Layout::default()
.direction(Direction::Vertical)
.margin(1)
.constraints(
[
Constraint::Length(3), // Input form
Constraint::Length(2), // Yes/No
]
.as_ref(),
)
.split(popup_area);
let (input, yes_no): (Paragraph, Tabs) =
self.draw_popup_save_bookmark(txt.clone());
// Render parts
f.render_widget(input, popup_chunks[0]);
f.render_widget(yes_no, popup_chunks[1]);
// Set cursor
f.set_cursor(
popup_area.x + self.input_txt.width() as u16 + 1,
popup_area.y + 1,
popup_chunks[0].x + self.input_txt.width() as u16 + 1,
popup_chunks[0].y + 1,
)
}
PopupType::YesNo(txt, _, _) => {
@@ -414,10 +429,29 @@ impl AuthActivity {
/// ### draw_popup_input
///
/// Draw input popup
pub(super) fn draw_popup_input(&self, text: String) -> Paragraph {
Paragraph::new(self.input_txt.as_ref())
.style(Style::default().fg(Color::White))
.block(Block::default().borders(Borders::ALL).title(text))
pub(super) fn draw_popup_save_bookmark(&self, text: String) -> (Paragraph, Tabs) {
let input: Paragraph = Paragraph::new(self.input_txt.as_ref())
.style(Style::default().fg(Color::LightYellow))
.block(Block::default().borders(Borders::ALL).title(text));
let choices: Vec<Spans> = vec![Spans::from("Yes"), Spans::from("No")];
let index: usize = match self.choice_opt {
DialogYesNoOption::Yes => 0,
DialogYesNoOption::No => 1,
};
let tabs: Tabs = Tabs::new(choices)
.block(
Block::default()
.borders(Borders::ALL)
.title("Save password?"),
)
.select(index)
.style(Style::default())
.highlight_style(
Style::default()
.add_modifier(Modifier::BOLD)
.fg(Color::LightRed),
);
(input, tabs)
}
/// ### draw_popup_yesno