From 97e07e01bab5d6db240afd058dc52068935e6d87 Mon Sep 17 00:00:00 2001 From: Cutieguwu Date: Thu, 10 Apr 2025 21:04:05 -0400 Subject: [PATCH] Build interface layout blocks. --- miller/Cargo.lock | 2 +- miller/src/tui.rs | 107 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 105 insertions(+), 4 deletions(-) diff --git a/miller/Cargo.lock b/miller/Cargo.lock index 67d8745..6498b4b 100644 --- a/miller/Cargo.lock +++ b/miller/Cargo.lock @@ -205,7 +205,7 @@ checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" [[package]] name = "gamelog" -version = "0.6.0" +version = "0.6.1" dependencies = [ "ron", "semver", diff --git a/miller/src/tui.rs b/miller/src/tui.rs index 08326e2..72a5bb7 100644 --- a/miller/src/tui.rs +++ b/miller/src/tui.rs @@ -6,9 +6,11 @@ use ratatui::{ self, event::{KeyCode, KeyEventKind}, }, - layout::Layout, + layout::{Constraint, Layout}, style::Color as Colour, - widgets::Widget, + symbols::border, + text::Line, + widgets::{Block, Widget}, }; pub enum Event { @@ -52,12 +54,111 @@ impl App { } } +// impl on ref to avoid accidentally mutating the struct. impl Widget for &App { fn render(self, area: ratatui::prelude::Rect, buf: &mut ratatui::prelude::Buffer) where Self: Sized, { - let layout: Layout; + let [teams_area, main_area, instruction_area] = + Layout::vertical([Constraint::Max(3), Constraint::Fill(1), Constraint::Max(1)]) + .areas(area); + + let [left_area, right_area] = + Layout::horizontal([Constraint::Percentage(50), Constraint::Percentage(50)]) + .areas(main_area); + + let [upper_left_area, common_play_area, common_config_area] = Layout::vertical([ + Constraint::Percentage(60), + Constraint::Percentage(20), + Constraint::Percentage(20), + ]) + .areas(left_area); + + let [quicks_area, pattern_area] = + Layout::horizontal([Constraint::Percentage(60), Constraint::Percentage(40)]) + .areas(upper_left_area); + + let [trends_area, graph_area, lower_right_area] = Layout::vertical([ + Constraint::Percentage(20), + Constraint::Percentage(55), + Constraint::Percentage(25), + ]) + .areas(right_area); + + let [legend_area, _, right_lower_right_area] = Layout::horizontal([ + Constraint::Percentage(40), + Constraint::Percentage(30), + Constraint::Percentage(30), + ]) + .areas(lower_right_area); + + let [_, compare_area] = + Layout::vertical([Constraint::Percentage(50), Constraint::Percentage(50)]) + .areas(right_lower_right_area); + + let teams_block = Block::bordered() + .title(Line::from(" Teams ")) + .border_set(border::THICK); + teams_block.render(teams_area, buf); + + let instructions = Line::from(vec![ + " ".into(), + "Quit ".into(), + " | ".into(), + "Function ".into(), + " | ".into(), + "Function ".into(), + " | ".into(), + "Function ".into(), + " | ".into(), + "Function ".into(), + " | ".into(), + "Function ".into(), + " | ".into(), + "Function ".into(), + " | ".into(), + "Function ".into(), + ]); + instructions.render(instruction_area, buf); + + let quicks_block = Block::bordered() + .title(" Quicks ") + .border_set(border::THICK); + quicks_block.render(quicks_area, buf); + + let pattern_block = Block::bordered() + .title(" Pattern ") + .border_set(border::THICK); + pattern_block.render(pattern_area, buf); + + let common_play_block = Block::bordered() + .title(" Most Freq. Play ") + .border_set(border::THICK); + common_play_block.render(common_play_area, buf); + + let common_config_block = Block::bordered() + .title(" Most Freq. Configuration ") + .border_set(border::THICK); + common_config_block.render(common_config_area, buf); + + let trends_block = Block::bordered() + .title(" Trends ") + .border_set(border::THICK); + trends_block.render(trends_area, buf); + + let graph_block = Block::bordered().title(" Graph ").border_set(border::THICK); + graph_block.render(graph_area, buf); + + let legend_block = Block::bordered() + .title(" Legend ") + .border_set(border::THICK); + legend_block.render(legend_area, buf); + + let compare_block = Block::bordered() + .title(" Compare ") + .border_set(border::THICK); + compare_block.render(compare_area, buf); } }