Skip to content

Commit

Permalink
reorganized layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
boldandbrad committed Mar 18, 2024
1 parent 7b84b77 commit b6a8257
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 49 deletions.
1 change: 0 additions & 1 deletion src/interface/components/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pub mod ascii_text;
pub mod cards;
pub mod inputs;
pub mod layouts;
pub mod popups;
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,6 @@ use ratatui::{
Frame,
};

pub struct MenuLayout {
pub header_area: Rect,
pub sub_header_area: Rect,
pub menu_area: Rect,
pub menu_option_areas: Vec<Rect>,
}

impl MenuLayout {
pub fn new(frame: &mut Frame, num_menu_options: usize) -> Self {
let layout_base = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Fill(1),
Constraint::Length(5),
Constraint::Fill(4),
])
.split(frame.size());
let layout_bottom = Layout::default()
.direction(Direction::Horizontal)
.constraints([
Constraint::Fill(1),
Constraint::Length(42),
Constraint::Fill(1),
])
.split(layout_base[2]);
let layout_menu = Layout::default()
.direction(Direction::Vertical)
.constraints([Constraint::Length(3), Constraint::Fill(1)])
.split(layout_bottom[1]);
let layout_menu_options = Layout::default()
.direction(Direction::Vertical)
.constraints([Constraint::Length(3)].repeat(num_menu_options))
.split(layout_menu[1]);
Self {
header_area: layout_base[1],
sub_header_area: layout_menu[0],
menu_area: layout_menu[1],
menu_option_areas: layout_menu_options.to_vec(),
}
}
}

pub struct PlayerLayout {
pub name_area: Rect,
pub hand_area: Rect,
Expand Down Expand Up @@ -124,4 +82,3 @@ impl GameLayout {

// TODO: implement GameTableLayout
// TODO: implement ScoreBoardLayout
// TODO: implement PlayerAreaLayout(s)
46 changes: 46 additions & 0 deletions src/interface/layouts/menu.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use ratatui::{
layout::{Constraint, Direction, Layout, Rect},
Frame,
};

pub struct MenuLayout {
pub header_area: Rect,
pub sub_header_area: Rect,
pub menu_area: Rect,
pub menu_option_areas: Vec<Rect>,
}

impl MenuLayout {
pub fn new(frame: &mut Frame, num_menu_options: usize) -> Self {
let layout_base = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Fill(1),
Constraint::Length(5),
Constraint::Fill(4),
])
.split(frame.size());
let layout_bottom = Layout::default()
.direction(Direction::Horizontal)
.constraints([
Constraint::Fill(1),
Constraint::Length(42),
Constraint::Fill(1),
])
.split(layout_base[2]);
let layout_menu = Layout::default()
.direction(Direction::Vertical)
.constraints([Constraint::Length(3), Constraint::Fill(1)])
.split(layout_bottom[1]);
let layout_menu_options = Layout::default()
.direction(Direction::Vertical)
.constraints([Constraint::Length(3)].repeat(num_menu_options))
.split(layout_menu[1]);
Self {
header_area: layout_base[1],
sub_header_area: layout_menu[0],
menu_area: layout_menu[1],
menu_option_areas: layout_menu_options.to_vec(),
}
}
}
2 changes: 2 additions & 0 deletions src/interface/layouts/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod game;
pub mod menu;
1 change: 1 addition & 0 deletions src/interface/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod components;
pub mod interface_callback;
pub mod layouts;
pub mod screens;

use crate::interface::{
Expand Down
5 changes: 2 additions & 3 deletions src/interface/screens/game_screen.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::interface::{
components::{layouts::GameLayout, popups::centered_popup_area},
interface_callback::InterfaceCallback,
screens::Screen,
components::popups::centered_popup_area, interface_callback::InterfaceCallback,
layouts::game::GameLayout, screens::Screen,
};
use crate::{
engine::{
Expand Down
3 changes: 2 additions & 1 deletion src/interface/screens/setup_screen.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::engine::game::Game;
use crate::interface::{
components::{ascii_text::SETUP_HEADER, inputs::InputStyle, layouts::MenuLayout},
components::{ascii_text::SETUP_HEADER, inputs::InputStyle},
interface_callback::InterfaceCallback,
layouts::menu::MenuLayout,
screens::{paragraph_from_multiline_string, Screen},
};
use crossterm::event::{KeyCode, KeyEvent, KeyEventKind};
Expand Down
3 changes: 2 additions & 1 deletion src/interface/screens/splash_screen.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::interface::{
components::{ascii_text::*, layouts::MenuLayout},
components::ascii_text::*,
interface_callback::InterfaceCallback,
layouts::menu::MenuLayout,
screens::{paragraph_from_multiline_string, Screen},
};
use crossterm::event::{KeyCode, KeyEventKind};
Expand Down

0 comments on commit b6a8257

Please sign in to comment.