Simplify: extract paint_glyph, drop unused param and redundant comments
- Add paint_glyph(painter, rect, glyph) to render.rs; draw_glyph now delegates to it, eliminating the duplicated rect_filled+text pattern that appeared in four places across editor.rs and glyph_picker.rs - Remove unused _board param from show_editor_panel and its call site - Drop redundant section-header comments in glyph_picker.rs (the ui.label() calls immediately below already name each section) - Remove extracted fg/bg/cur_ch locals in the char grid loop now that paint_glyph accepts a Glyph directly - Fix CLAUDE.md update phase description (stale from pre-refactor) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+11
-7
@@ -49,11 +49,17 @@ pub(crate) const MIN_WINDOW_W: f32 = CELL_W * 10.0 + 2.0 * PANEL_MARGIN;
|
||||
/// Minimum window height: enough room for 5 cells plus menu and margins.
|
||||
pub(crate) const MIN_WINDOW_H: f32 = CELL_H * 5.0 + MENU_H + 2.0 * PANEL_MARGIN;
|
||||
|
||||
/// Draws a single cell at grid position `(x, y)` using the given glyph.
|
||||
/// Paints a glyph into an already-allocated `rect`.
|
||||
///
|
||||
/// Each cell is rendered as two layers:
|
||||
/// 1. A filled rectangle in `glyph.bg` covering the full cell area.
|
||||
/// 2. A monospace character (`glyph.ch`) in `glyph.fg`, centered in the cell.
|
||||
/// Unlike [`draw_glyph`], this does not compute the rect from grid coordinates —
|
||||
/// the caller owns the rect (typically from [`egui::Ui::allocate_exact_size`])
|
||||
/// and handles interaction. Use this when you need the click [`egui::Response`].
|
||||
pub(crate) fn paint_glyph(painter: &egui::Painter, rect: Rect, glyph: &Glyph) {
|
||||
painter.rect_filled(rect, 0.0, glyph.bg);
|
||||
painter.text(rect.center(), Align2::CENTER_CENTER, glyph.ch, FontId::monospace(CELL_H), glyph.fg);
|
||||
}
|
||||
|
||||
/// Draws a single cell at grid position `(x, y)` using the given glyph.
|
||||
///
|
||||
/// `origin` is the pixel position of cell `(0, 0)` — the top-left corner of
|
||||
/// the board within the panel. Cell positions are computed from `origin` using
|
||||
@@ -61,9 +67,7 @@ pub(crate) const MIN_WINDOW_H: f32 = CELL_H * 5.0 + MENU_H + 2.0 * PANEL_MARGIN;
|
||||
pub(crate) fn draw_glyph(painter: &egui::Painter, origin: Pos2, x: usize, y: usize, glyph: &Glyph) {
|
||||
let tl = origin + vec2(x as f32 * CELL_W, y as f32 * CELL_H);
|
||||
let rect = Rect::from_min_size(tl, vec2(CELL_W, CELL_H));
|
||||
let center = rect.center();
|
||||
painter.rect_filled(rect, 0.0, glyph.bg);
|
||||
painter.text(center, Align2::CENTER_CENTER, glyph.ch, FontId::monospace(CELL_H), glyph.fg);
|
||||
paint_glyph(painter, rect, glyph);
|
||||
}
|
||||
|
||||
/// Draws all board cells then the player overlay at `origin`.
|
||||
|
||||
Reference in New Issue
Block a user