Skip to content

Commit

Permalink
fix: use fixed size popups
Browse files Browse the repository at this point in the history
  • Loading branch information
RolandSherwin authored and joshuef committed May 9, 2024
1 parent bbb5e6e commit 82ddedf
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
4 changes: 2 additions & 2 deletions node-launchpad/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ impl App {
tick_rate,
frame_rate,
components: vec![
Box::new(home),
Box::new(discord_username_input),
Box::new(tab),
Box::new(footer),
Box::new(home),
Box::new(discord_username_input),
],
should_quit: false,
should_suspend: false,
Expand Down
7 changes: 4 additions & 3 deletions node-launchpad/src/components/discord_username.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// KIND, either express or implied. Please review the Licences for the specific language governing
// permissions and limitations relating to use of the SAFE Network Software.

use super::{utils::centered_rect, Component};
use super::{utils::centered_rect_fixed, Component};
use crate::{
action::Action,
mode::{InputMode, Scene},
Expand Down Expand Up @@ -100,8 +100,7 @@ impl Component for DiscordUsernameInputBox {
return Ok(());
}

// todo: y should be set to a min value, so it doesnt become too small
let layer_zero = centered_rect(25, 15, area);
let layer_zero = centered_rect_fixed(40, 5, area);

let layer_one = Layout::new(
Direction::Vertical,
Expand All @@ -120,6 +119,8 @@ impl Component for DiscordUsernameInputBox {
let pop_up_border = Paragraph::new("").block(
Block::default()
.borders(Borders::ALL)
.border_type(BorderType::Double)
.border_style(Style::new().bold())
.title("Enter Discord Username"),
);
f.render_widget(Clear, layer_zero);
Expand Down
7 changes: 4 additions & 3 deletions node-launchpad/src/components/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// KIND, either express or implied. Please review the Licences for the specific language governing
// permissions and limitations relating to use of the SAFE Network Software.

use super::{utils::centered_rect, Component, Frame};
use super::{utils::centered_rect_fixed, Component, Frame};
use crate::{
action::{Action, HomeActions},
config::Config,
Expand Down Expand Up @@ -255,7 +255,7 @@ impl Component for Home {
],
)
.split(area);
let popup_area = centered_rect(25, 25, area);
let popup_area = centered_rect_fixed(25, 3, area);

// top section
//
Expand Down Expand Up @@ -317,7 +317,8 @@ impl Component for Home {
.block(
Block::default()
.borders(Borders::ALL)
.style(Style::default().bg(Color::Reset)),
.border_type(BorderType::Double)
.border_style(Style::new().bold()),
),
popup_area,
);
Expand Down
17 changes: 17 additions & 0 deletions node-launchpad/src/components/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,20 @@ pub fn centered_rect(percent_x: u16, percent_y: u16, r: Rect) -> Rect {
])
.split(popup_layout[1])[1]
}

/// Helper function to create a centered rect using a fixed x,y constraint.
pub fn centered_rect_fixed(x: u16, y: u16, r: Rect) -> Rect {
let popup_layout = Layout::vertical([
Constraint::Fill(1),
Constraint::Length(y),
Constraint::Fill(1),
])
.split(r);

Layout::horizontal([
Constraint::Fill(1),
Constraint::Length(x),
Constraint::Fill(1),
])
.split(popup_layout[1])[1]
}

0 comments on commit 82ddedf

Please sign in to comment.