generated from GarandPLG/rust-flake-template
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:
@@ -39,6 +39,7 @@ pub struct SettingsState {
|
|||||||
pub id: usize,
|
pub id: usize,
|
||||||
pub name: &'static str,
|
pub name: &'static str,
|
||||||
pub selected_setting: usize,
|
pub selected_setting: usize,
|
||||||
|
pub show_popup: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GameStates {
|
impl GameStates {
|
||||||
@@ -67,6 +68,7 @@ impl GameStates {
|
|||||||
id: 4,
|
id: 4,
|
||||||
name: "Settings",
|
name: "Settings",
|
||||||
selected_setting: 0,
|
selected_setting: 0,
|
||||||
|
show_popup: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,10 @@ pub fn settings_keybindings(app: &mut App, key_event: &KeyEvent) {
|
|||||||
Action::Quit => app.exit = true,
|
Action::Quit => app.exit = true,
|
||||||
Action::Quit2 => app.exit = true,
|
Action::Quit2 => app.exit = true,
|
||||||
Action::Esc => app.view = View::MainMenu,
|
Action::Esc => app.view = View::MainMenu,
|
||||||
|
Action::Space => {
|
||||||
|
app.game_states.settings_state.show_popup =
|
||||||
|
!app.game_states.settings_state.show_popup
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ use crate::app::{
|
|||||||
use ratatui::{
|
use ratatui::{
|
||||||
buffer::Buffer,
|
buffer::Buffer,
|
||||||
layout::{Alignment, Constraint, Layout, Rect},
|
layout::{Alignment, Constraint, Layout, Rect},
|
||||||
style::Stylize,
|
style::{Style, Stylize},
|
||||||
widgets::{Block, Borders, Padding, Paragraph, Widget},
|
widgets::{Block, Borders, Padding, Paragraph, Widget, Wrap},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn settings_view(app: &App, area: Rect, buf: &mut Buffer) {
|
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);
|
.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![
|
let keybindings: Vec<Option<&'static KeyBinding>> = vec![
|
||||||
binding_for(Action::Up),
|
binding_for(Action::Up),
|
||||||
|
|||||||
Reference in New Issue
Block a user