Began the Great Widget Refactor of 2024 and introduced custom widgets for buttons, checkboxes, and input boxes. Up next: loading and table widgets

This commit is contained in:
2024-02-09 16:36:54 -07:00
parent 9b0c272e76
commit 68de986c48
11 changed files with 667 additions and 627 deletions
+1 -37
View File
@@ -1,9 +1,9 @@
use crate::ui::styles::ManagarrStyle;
use ratatui::layout::{Alignment, Constraint, Layout, Rect};
use ratatui::style::{Color, Style, Stylize};
use ratatui::symbols;
use ratatui::text::{Line, Span, Text};
use ratatui::widgets::{Block, BorderType, Borders, LineGauge, Paragraph, Wrap};
use ratatui::{symbols, Frame};
pub const COLOR_TEAL: Color = Color::Rgb(35, 50, 55);
@@ -37,28 +37,6 @@ pub fn layout_block_bottom_border<'a>() -> Block<'a> {
Block::new().borders(Borders::BOTTOM)
}
pub fn layout_button_paragraph(
is_selected: bool,
label: &str,
alignment: Alignment,
) -> Paragraph<'_> {
Paragraph::new(Text::from(label))
.block(layout_block())
.alignment(alignment)
.style(style_block_highlight(is_selected))
}
pub fn layout_button_paragraph_borderless(
is_selected: bool,
label: &str,
alignment: Alignment,
) -> Paragraph<'_> {
Paragraph::new(Text::from(label))
.block(borderless_block())
.alignment(alignment)
.style(style_block_highlight(is_selected))
}
pub fn layout_paragraph_borderless(string: &str) -> Paragraph<'_> {
Paragraph::new(Text::from(string))
.block(borderless_block())
@@ -135,20 +113,6 @@ pub fn line_gauge_with_label(title: &str, ratio: f64) -> LineGauge<'_> {
.label(Line::from(format!("{title}: {:.0}%", ratio * 100.0)))
}
pub fn show_cursor(
f: &mut Frame<'_>,
area: Rect,
offset: usize,
string: &str,
cursor_after_string: bool,
) {
if cursor_after_string {
f.set_cursor(area.x + (string.len() - offset) as u16 + 1, area.y + 1);
} else {
f.set_cursor(area.x + 1u16, area.y + 1);
}
}
pub fn get_width_from_percentage(area: Rect, percentage: u16) -> usize {
(area.width as f64 * (percentage as f64 / 100.0)) as usize
}