generated from GarandPLG/rust-flake-template
Add rustfmt configuration and reformat code
- Document new Rust formatting standards in AGENTS, CODE_MAP, and PROGRESS. - Add rustfmt.toml with style 2024, 2‑space indents, 100‑char width, LF endings. - Apply consistent 2‑space indentation and ordering across source files. - Minor clean‑up of imports and whitespace to match the new style.
This commit is contained in:
1 parent
9e09aaf75e
commit
c4313b4117
60 files changed
+3632
-3610
No files matched your search
@@ -1,108 +1,108 @@
|
||||
use crate::app::{
|
||||
helpers::block_single_title_helper,
|
||||
states::skirmish_states::{
|
||||
structures::{Structure, Structures},
|
||||
units::{Unit, Units},
|
||||
},
|
||||
helpers::block_single_title_helper,
|
||||
states::skirmish_states::{
|
||||
structures::{Structure, Structures},
|
||||
units::{Unit, Units},
|
||||
},
|
||||
};
|
||||
use ratatui::{
|
||||
buffer::Buffer,
|
||||
layout::{Alignment, Constraint, Layout, Margin, Rect},
|
||||
style::Color,
|
||||
widgets::{Block, BorderType, Borders, Padding, Paragraph, Widget},
|
||||
buffer::Buffer,
|
||||
layout::{Alignment, Constraint, Layout, Margin, Rect},
|
||||
style::Color,
|
||||
widgets::{Block, BorderType, Borders, Padding, Paragraph, Widget},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct SidePanelWidget<'a> {
|
||||
coords: (usize, usize),
|
||||
structure: &'a Structures,
|
||||
unit: &'a Option<Units>,
|
||||
is_unit_marked: bool,
|
||||
}
|
||||
|
||||
impl<'a> SidePanelWidget<'a> {
|
||||
pub fn new(
|
||||
coords: (usize, usize),
|
||||
structure: &'a Structures,
|
||||
unit: &'a Option<Units>,
|
||||
is_unit_marked: bool,
|
||||
}
|
||||
) -> Self {
|
||||
Self {
|
||||
coords,
|
||||
structure,
|
||||
unit,
|
||||
is_unit_marked,
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SidePanelWidget<'a> {
|
||||
pub fn new(
|
||||
coords: (usize, usize),
|
||||
structure: &'a Structures,
|
||||
unit: &'a Option<Units>,
|
||||
is_unit_marked: bool,
|
||||
) -> Self {
|
||||
Self {
|
||||
coords,
|
||||
structure,
|
||||
unit,
|
||||
is_unit_marked,
|
||||
}
|
||||
fn col_to_letters(&self) -> String {
|
||||
let mut col: usize = self.coords.1 + 1;
|
||||
let mut letters: Vec<char> = Vec::new();
|
||||
|
||||
while col > 0 {
|
||||
letters.push((b'A' + ((col - 1) % 26) as u8) as char);
|
||||
col = (col - 1) / 26;
|
||||
}
|
||||
|
||||
fn col_to_letters(&self) -> String {
|
||||
let mut col: usize = self.coords.1 + 1;
|
||||
let mut letters: Vec<char> = Vec::new();
|
||||
letters.iter().rev().collect()
|
||||
}
|
||||
|
||||
while col > 0 {
|
||||
letters.push((b'A' + ((col - 1) % 26) as u8) as char);
|
||||
col = (col - 1) / 26;
|
||||
}
|
||||
fn get_outer_block(&self) -> Block<'_> {
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Double)
|
||||
.title(block_single_title_helper(
|
||||
format!("{}{}", self.col_to_letters(), self.coords.0),
|
||||
Color::Yellow,
|
||||
))
|
||||
.title_alignment(Alignment::Center)
|
||||
}
|
||||
|
||||
letters.iter().rev().collect()
|
||||
}
|
||||
fn get_inner_block<'b>(&self, title: String, color: Color) -> Block<'b> {
|
||||
Block::default()
|
||||
.borders(Borders::TOP)
|
||||
.title(block_single_title_helper(title, color))
|
||||
.title_alignment(Alignment::Center)
|
||||
.padding(Padding::symmetric(1, 1))
|
||||
}
|
||||
|
||||
fn get_outer_block(&self) -> Block<'_> {
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Double)
|
||||
.title(block_single_title_helper(
|
||||
format!("{}{}", self.col_to_letters(), self.coords.0),
|
||||
Color::Yellow,
|
||||
))
|
||||
.title_alignment(Alignment::Center)
|
||||
}
|
||||
|
||||
fn get_inner_block<'b>(&self, title: String, color: Color) -> Block<'b> {
|
||||
Block::default()
|
||||
.borders(Borders::TOP)
|
||||
.title(block_single_title_helper(title, color))
|
||||
.title_alignment(Alignment::Center)
|
||||
.padding(Padding::symmetric(1, 1))
|
||||
}
|
||||
|
||||
fn get_area_constraints(&self) -> [Constraint; 2] {
|
||||
if self.unit.is_unit() {
|
||||
[Constraint::Percentage(50), Constraint::Percentage(50)]
|
||||
} else {
|
||||
[Constraint::Percentage(100), Constraint::Percentage(0)]
|
||||
}
|
||||
fn get_area_constraints(&self) -> [Constraint; 2] {
|
||||
if self.unit.is_unit() {
|
||||
[Constraint::Percentage(50), Constraint::Percentage(50)]
|
||||
} else {
|
||||
[Constraint::Percentage(100), Constraint::Percentage(0)]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Widget for SidePanelWidget<'_> {
|
||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||
let block: Block<'_> = self.get_outer_block();
|
||||
let inner_area: Rect = block.inner(area).inner(Margin {
|
||||
horizontal: 2,
|
||||
vertical: 1,
|
||||
});
|
||||
block.render(area, buf);
|
||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||
let block: Block<'_> = self.get_outer_block();
|
||||
let inner_area: Rect = block.inner(area).inner(Margin {
|
||||
horizontal: 2,
|
||||
vertical: 1,
|
||||
});
|
||||
block.render(area, buf);
|
||||
|
||||
let [structure_area, unit_area] =
|
||||
Layout::vertical(self.get_area_constraints()).areas(inner_area);
|
||||
let [structure_area, unit_area] =
|
||||
Layout::vertical(self.get_area_constraints()).areas(inner_area);
|
||||
|
||||
Paragraph::new(self.structure.text())
|
||||
.alignment(Alignment::Left)
|
||||
.block(self.get_inner_block(self.structure.get_name().to_string(), Color::Cyan))
|
||||
.render(structure_area, buf);
|
||||
Paragraph::new(self.structure.text())
|
||||
.alignment(Alignment::Left)
|
||||
.block(self.get_inner_block(self.structure.get_name().to_string(), Color::Cyan))
|
||||
.render(structure_area, buf);
|
||||
|
||||
if self.unit.is_unit() {
|
||||
let mut unit_name: String = self.unit.get_name().to_string();
|
||||
if self.unit.is_unit() {
|
||||
let mut unit_name: String = self.unit.get_name().to_string();
|
||||
|
||||
if self.is_unit_marked {
|
||||
unit_name = format!("> {} <", unit_name);
|
||||
}
|
||||
if self.is_unit_marked {
|
||||
unit_name = format!("> {} <", unit_name);
|
||||
}
|
||||
|
||||
Paragraph::new(self.unit.text())
|
||||
.alignment(Alignment::Left)
|
||||
.block(self.get_inner_block(unit_name, Color::Green))
|
||||
.render(unit_area, buf);
|
||||
}
|
||||
Paragraph::new(self.unit.text())
|
||||
.alignment(Alignment::Left)
|
||||
.block(self.get_inner_block(unit_name, Color::Green))
|
||||
.render(unit_area, buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user