spinners and fmt
This commit is contained in:
+65
-21
@@ -235,7 +235,11 @@ impl<Ctx> GlyphDialog<Ctx> {
|
||||
}
|
||||
let i = stops.iter().position(|f| *f == self.focus).unwrap_or(0);
|
||||
let n = stops.len();
|
||||
let j = if forward { (i + 1) % n } else { (i + n - 1) % n };
|
||||
let j = if forward {
|
||||
(i + 1) % n
|
||||
} else {
|
||||
(i + n - 1) % n
|
||||
};
|
||||
self.focus = stops[j];
|
||||
DialogResult::Continue
|
||||
}
|
||||
@@ -248,7 +252,11 @@ impl<Ctx> GlyphDialog<Ctx> {
|
||||
KeyCode::Left => picker.move_select(-1),
|
||||
KeyCode::Right => picker.move_select(1),
|
||||
KeyCode::Down if picker.is_custom() => {
|
||||
self.focus = if is_fg { Focus::FgField } else { Focus::BgField };
|
||||
self.focus = if is_fg {
|
||||
Focus::FgField
|
||||
} else {
|
||||
Focus::BgField
|
||||
};
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@@ -258,7 +266,11 @@ impl<Ctx> GlyphDialog<Ctx> {
|
||||
/// edits the field.
|
||||
fn handle_field(&mut self, key: ratatui::crossterm::event::KeyEvent, is_fg: bool) {
|
||||
if matches!(key.code, KeyCode::Up) {
|
||||
self.focus = if is_fg { Focus::FgStrip } else { Focus::BgStrip };
|
||||
self.focus = if is_fg {
|
||||
Focus::FgStrip
|
||||
} else {
|
||||
Focus::BgStrip
|
||||
};
|
||||
return;
|
||||
}
|
||||
let picker = if is_fg { &mut self.fg } else { &mut self.bg };
|
||||
@@ -315,7 +327,14 @@ impl<Ctx> GlyphDialog<Ctx> {
|
||||
/// Draws a color strip into `area`: a focusable label, then a solid swatch per named
|
||||
/// color plus a final custom slot. The selected slot is marked with `●`; the custom
|
||||
/// slot is otherwise marked `+`.
|
||||
fn draw_strip(&self, buf: &mut Buffer, area: Rect, label: &str, picker: &ColorPicker, focused: bool) {
|
||||
fn draw_strip(
|
||||
&self,
|
||||
buf: &mut Buffer,
|
||||
area: Rect,
|
||||
label: &str,
|
||||
picker: &ColorPicker,
|
||||
focused: bool,
|
||||
) {
|
||||
draw_label(buf, area.x, area.y, label, focused);
|
||||
let sx = area.x + 3;
|
||||
let y = area.y;
|
||||
@@ -374,7 +393,12 @@ impl<Ctx> GlyphDialog<Ctx> {
|
||||
Style::default().fg(Color::White).bg(INVALID_BG)
|
||||
};
|
||||
let box_x = x + 1;
|
||||
buf.set_string(box_x, y, format!("{val:<width$}", width = w as usize), style);
|
||||
buf.set_string(
|
||||
box_x,
|
||||
y,
|
||||
format!("{val:<width$}", width = w as usize),
|
||||
style,
|
||||
);
|
||||
focused.then(|| {
|
||||
let cur = box_x + (picker.field.display_cursor() as u16).min(w.saturating_sub(1));
|
||||
Position::new(cur, y)
|
||||
@@ -444,27 +468,37 @@ impl<Ctx> CursorOverlay for GlyphDialog<Ctx> {
|
||||
block.render(rect, buf);
|
||||
|
||||
// Stack: grid, gap, fg strip + hex, bg strip + hex, filler, footer.
|
||||
let [grid_area, _gap, fg_strip, fg_field, bg_strip, bg_field, _filler, footer_area] =
|
||||
Layout::vertical([
|
||||
Constraint::Length(GRID_ROWS as u16),
|
||||
Constraint::Length(1),
|
||||
Constraint::Length(1),
|
||||
Constraint::Length(1),
|
||||
Constraint::Length(1),
|
||||
Constraint::Length(1),
|
||||
Constraint::Min(0),
|
||||
Constraint::Length(1),
|
||||
])
|
||||
.areas(inner);
|
||||
let [
|
||||
grid_area,
|
||||
_gap,
|
||||
fg_strip,
|
||||
fg_field,
|
||||
bg_strip,
|
||||
bg_field,
|
||||
_filler,
|
||||
footer_area,
|
||||
] = Layout::vertical([
|
||||
Constraint::Length(GRID_ROWS as u16),
|
||||
Constraint::Length(1),
|
||||
Constraint::Length(1),
|
||||
Constraint::Length(1),
|
||||
Constraint::Length(1),
|
||||
Constraint::Length(1),
|
||||
Constraint::Min(0),
|
||||
Constraint::Length(1),
|
||||
])
|
||||
.areas(inner);
|
||||
|
||||
// Both colors must resolve for the grid to preview them; otherwise gray-on-black.
|
||||
let colors = self.fg.color().zip(self.bg.color());
|
||||
self.draw_grid(buf, grid_area, colors);
|
||||
|
||||
self.draw_strip(buf, fg_strip, "fg ", &self.fg, self.focus == Focus::FgStrip);
|
||||
let fg_cursor = self.draw_color_field(buf, fg_field, &self.fg, self.focus == Focus::FgField);
|
||||
let fg_cursor =
|
||||
self.draw_color_field(buf, fg_field, &self.fg, self.focus == Focus::FgField);
|
||||
self.draw_strip(buf, bg_strip, "bg ", &self.bg, self.focus == Focus::BgStrip);
|
||||
let bg_cursor = self.draw_color_field(buf, bg_field, &self.bg, self.focus == Focus::BgField);
|
||||
let bg_cursor =
|
||||
self.draw_color_field(buf, bg_field, &self.bg, self.focus == Focus::BgField);
|
||||
|
||||
self.draw_footer(buf, footer_area);
|
||||
|
||||
@@ -536,8 +570,18 @@ mod tests {
|
||||
fn sample() -> Glyph {
|
||||
Glyph {
|
||||
tile: 5,
|
||||
fg: Rgba8 { r: 0xFF, g: 0x00, b: 0x00, a: 255 }, // not a named color
|
||||
bg: Rgba8 { r: 0x00, g: 0x00, b: 0xFF, a: 255 }, // not a named color
|
||||
fg: Rgba8 {
|
||||
r: 0xFF,
|
||||
g: 0x00,
|
||||
b: 0x00,
|
||||
a: 255,
|
||||
}, // not a named color
|
||||
bg: Rgba8 {
|
||||
r: 0x00,
|
||||
g: 0x00,
|
||||
b: 0xFF,
|
||||
a: 255,
|
||||
}, // not a named color
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user