Skip to content

Commit

Permalink
feat: popup during add or start service
Browse files Browse the repository at this point in the history
  • Loading branch information
RolandSherwin authored and jacderida committed May 1, 2024
1 parent e722b63 commit 0e19f34
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions node-tui/src/components/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ impl Component for Home {
[Constraint::Max(1), Constraint::Min(5), Constraint::Min(3), Constraint::Max(3)],
)
.split(area);
let popup_area = Self::centered_rect(25, 25, area);

// top section
//
Expand Down Expand Up @@ -215,6 +216,18 @@ impl Component for Home {
.block(Block::default().title(" Key commands ").borders(Borders::ALL)),
layer_zero[3],
);

// popup
if self.lock_registry {
f.render_widget(Clear, popup_area);
f.render_widget(
Paragraph::new("Adding/Starting Node.. Please wait...")
.alignment(Alignment::Center)
.block(Block::default().borders(Borders::ALL).style(Style::default().bg(Color::Reset))),
popup_area,
);
}

Ok(())
}
}
Expand Down Expand Up @@ -264,4 +277,21 @@ impl Home {
fn unselect_table_item(&mut self) {
self.node_table_state.select(None);
}

/// helper function to create a centered rect using up certain percentage of the available rect `r`
fn centered_rect(percent_x: u16, percent_y: u16, r: Rect) -> Rect {
let popup_layout = Layout::vertical([
Constraint::Percentage((100 - percent_y) / 2),
Constraint::Percentage(percent_y),
Constraint::Percentage((100 - percent_y) / 2),
])
.split(r);

Layout::horizontal([
Constraint::Percentage((100 - percent_x) / 2),
Constraint::Percentage(percent_x),
Constraint::Percentage((100 - percent_x) / 2),
])
.split(popup_layout[1])[1]
}
}

0 comments on commit 0e19f34

Please sign in to comment.