Add popup toggle to settings view

Introduce `show_popup` flag in SettingsState, toggle it with the Space
key, and
render a yellow test popup in the settings view when the flag is true.
This commit is contained in:
2026-03-14 20:35:03 +01:00
parent 3d0aa42d7d
commit acc6ba08f3
3 changed files with 30 additions and 2 deletions
+2
View File
@@ -39,6 +39,7 @@ pub struct SettingsState {
pub id: usize,
pub name: &'static str,
pub selected_setting: usize,
pub show_popup: bool,
}
impl GameStates {
@@ -67,6 +68,7 @@ impl GameStates {
id: 4,
name: "Settings",
selected_setting: 0,
show_popup: false,
},
}
}
+4
View File
@@ -10,6 +10,10 @@ pub fn settings_keybindings(app: &mut App, key_event: &KeyEvent) {
Action::Quit => app.exit = true,
Action::Quit2 => app.exit = true,
Action::Esc => app.view = View::MainMenu,
Action::Space => {
app.game_states.settings_state.show_popup =
!app.game_states.settings_state.show_popup
}
_ => (),
}
}
+24 -2
View File
@@ -6,8 +6,8 @@ use crate::app::{
use ratatui::{
buffer::Buffer,
layout::{Alignment, Constraint, Layout, Rect},
style::Stylize,
widgets::{Block, Borders, Padding, Paragraph, Widget},
style::{Style, Stylize},
widgets::{Block, Borders, Padding, Paragraph, Widget, Wrap},
};
pub fn settings_view(app: &App, area: Rect, buf: &mut Buffer) {
@@ -41,6 +41,28 @@ pub fn settings_view(app: &App, area: Rect, buf: &mut Buffer) {
)
.render(main_area, buf);
let popup_area = Rect {
x: main_area.width / 4,
y: main_area.height / 3,
width: main_area.width / 2,
height: main_area.height / 3,
};
let popup = Paragraph::new("Test popup")
.wrap(Wrap { trim: true })
.style(Style::default().yellow())
.block(
Block::new()
.title("Insert value")
.title_style(Style::default().green())
.borders(Borders::ALL)
.border_style(Style::default().blue()),
);
if app.game_states.settings_state.show_popup {
popup.render(popup_area, buf);
}
{
let keybindings: Vec<Option<&'static KeyBinding>> = vec![
binding_for(Action::Up),