add: playing with base TUI

This commit is contained in:
Charles
2024-11-11 21:43:34 -08:00
commit 20c48e3cc4
5 changed files with 658 additions and 0 deletions
+72
View File
@@ -0,0 +1,72 @@
use ratatui::prelude::*;
use ratatui::widgets::{Block, Widget};
pub struct CharacterWidget {}
impl StatefulWidget for CharacterWidget {
type State = Character;
fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) {
let title = Line::from(format!("{}", state.handle)).centered();
let b = Block::bordered()
.title(title);
RoleWidget{}.render(b.inner(area), buf, state);
b.render(area, buf);
}
}
pub struct RoleWidget {}
impl StatefulWidget for RoleWidget {
type State = Character;
fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) {
Line::from(format!("{}: {}", state.role.as_str(), state.role_ability)).render(area, buf);
}
}
pub struct Character {
skills: Vec<Skill>,
handle: String,
role: String,
role_ability: i32,
notes: String,
int: i32,
r#ref: i32,
dex: i32,
tech: i32,
cool: i32,
will: i32,
luck: i32,
r#move: i32,
body: i32,
emp: i32,
}
impl Character {
pub fn new() -> Self {
Self{
skills: vec!(),
handle: String::from("My handle"),
role: String::from("Rocker Boy"),
role_ability: 1,
notes: String::from("These are notes"),
int: 2,
r#ref: 2,
dex: 2,
tech: 2,
cool: 2,
will: 2,
luck: 2,
r#move: 2,
body: 2,
emp: 2,
}
}
}
pub struct Skill {
name: String,
level: i32,
category: String,
}
+25
View File
@@ -0,0 +1,25 @@
use character_sheet::Character;
use crossterm::event::{self, Event};
use ratatui::{text::Text, Frame};
mod character_sheet;
fn main() {
let mut terminal = ratatui::init();
loop {
terminal.draw(draw).expect("failed to draw frame");
if matches!(event::read().expect("failed to read event"), Event::Key(_)) {
break;
}
}
ratatui::restore();
}
fn draw(frame: &mut Frame) {
let text = Text::raw("Hello World!");
frame.render_stateful_widget(
character_sheet::CharacterWidget{},
frame.area(),
&mut Character::new(),
);
}