refactor layout code a lil
This commit is contained in:
parent
74bf702219
commit
33cb9c7f97
2 changed files with 29 additions and 37 deletions
|
|
@ -1,7 +1,7 @@
|
|||
use bevy::prelude::*;
|
||||
use bevy_ratatui::RatatuiContext;
|
||||
use ratatui::{
|
||||
layout::{Constraint, Layout, Margin},
|
||||
layout::{Constraint, Flex, Layout, Margin},
|
||||
prelude::Rect,
|
||||
};
|
||||
|
||||
|
|
@ -12,15 +12,19 @@ pub(crate) struct Overlays {
|
|||
|
||||
pub(crate) enum Overlay {}
|
||||
|
||||
#[derive(Resource, Clone, Copy)]
|
||||
#[derive(Resource, Clone)]
|
||||
pub(crate) struct HandLayouts {
|
||||
pub(crate) left_pond: Rect,
|
||||
pub(crate) cross_pond: Rect,
|
||||
pub(crate) right_pond: Rect,
|
||||
pub(crate) this_pond: Rect,
|
||||
pub(crate) left_hand: Rect,
|
||||
|
||||
pub(crate) cross_pond: Rect,
|
||||
pub(crate) cross_hand: Rect,
|
||||
|
||||
pub(crate) right_pond: Rect,
|
||||
pub(crate) right_hand: Rect,
|
||||
|
||||
pub(crate) this_pond: Rect,
|
||||
pub(crate) this_pond_slots: Vec<Rect>,
|
||||
pub(crate) this_hand: Rect,
|
||||
}
|
||||
|
||||
|
|
@ -69,14 +73,28 @@ fn tiles_areas(term_area: Rect) -> HandLayouts {
|
|||
right_pond.height = cross_pond.height;
|
||||
right_pond.y += cross_pond.height / 2;
|
||||
|
||||
let this_pond_row_constraints = [Constraint::Max(4); 3];
|
||||
let this_pond_col_constraints = [Constraint::Max(5); 6];
|
||||
let this_pond_row_layouts = Layout::vertical(this_pond_row_constraints).flex(Flex::Start);
|
||||
let this_pond_col_layouts = Layout::horizontal(this_pond_col_constraints).flex(Flex::Start);
|
||||
let mut this_pond_rows = this_pond_row_layouts.areas::<3>(this_pond);
|
||||
let this_pond_slots: Vec<_> = this_pond_rows
|
||||
.iter()
|
||||
.flat_map(|row| this_pond_col_layouts.areas::<6>(*row))
|
||||
.collect();
|
||||
|
||||
HandLayouts {
|
||||
left_pond,
|
||||
cross_pond,
|
||||
right_pond,
|
||||
this_pond,
|
||||
left_hand,
|
||||
|
||||
cross_pond,
|
||||
cross_hand,
|
||||
|
||||
right_pond,
|
||||
right_hand,
|
||||
|
||||
this_pond,
|
||||
this_hand,
|
||||
this_pond_slots,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,21 +93,6 @@ pub(crate) fn render(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn query_tester(
|
||||
mut commands: Commands,
|
||||
mut tui: ResMut<RatatuiContext>,
|
||||
|
||||
hovered: Query<Entity, With<Hovered>>,
|
||||
layouts: Res<HandLayouts>,
|
||||
|
||||
tiles: Query<&jong_types::Tile>,
|
||||
// main_player: Single<(&Player, Entity /* , &Wind */), With<MainPlayer>>,
|
||||
hand: Single<(&Children, Entity), With<Hand>>,
|
||||
drawn_tile: Option<Single<Entity, With<Drawn>>>,
|
||||
) {
|
||||
trace!("owo")
|
||||
}
|
||||
|
||||
// FIXME we don't care about other players atm
|
||||
#[allow(clippy::too_many_arguments, clippy::type_complexity)]
|
||||
pub(crate) fn render_hand(
|
||||
|
|
@ -123,7 +108,7 @@ pub(crate) fn render_hand(
|
|||
drawn_tile: Option<Single<Entity, With<Drawn>>>,
|
||||
) -> Result {
|
||||
let mut frame = tui.get_frame();
|
||||
debug_blocks(*layouts, &mut frame);
|
||||
debug_blocks(layouts.clone(), &mut frame);
|
||||
|
||||
let hand: Vec<_> = hand
|
||||
.0
|
||||
|
|
@ -234,19 +219,8 @@ pub(crate) fn render_pond(
|
|||
})
|
||||
.collect::<Result<_>>()?;
|
||||
|
||||
let mut this_pond = layouts.this_pond;
|
||||
let row_constraints = [Constraint::Max(4); 3];
|
||||
let col_constraints = [Constraint::Max(5); 6];
|
||||
let row_layouts = Layout::vertical(row_constraints).flex(Flex::Start);
|
||||
let col_layouts = Layout::horizontal(col_constraints).flex(Flex::Start);
|
||||
let mut rows = row_layouts.areas::<3>(this_pond);
|
||||
|
||||
for (rect, (_, tile)) in rows
|
||||
.iter()
|
||||
.flat_map(|row| col_layouts.areas::<6>(*row))
|
||||
.zip(pond)
|
||||
{
|
||||
frame.render_widget(tile, rect);
|
||||
for (rect, (_, tile)) in layouts.this_pond_slots.iter().zip(pond) {
|
||||
frame.render_widget(tile, *rect);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue