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:
2026-05-18 22:01:21 -05:00
parent f3bbfbb169
commit 12ebe77932
5 changed files with 30 additions and 53 deletions
+6 -22
View File
@@ -1,8 +1,8 @@
use eframe::egui;
use egui::{Align2, FontId, Sense, vec2};
use egui::{Sense, vec2};
use crate::game::{Archetype, Board, Glyph, ALL_ARCHETYPES};
use crate::render::{CELL_H, CELL_W, PALETTE_PANEL_W};
use crate::game::{Archetype, Glyph, ALL_ARCHETYPES};
use crate::render::{CELL_H, CELL_W, PALETTE_PANEL_W, paint_glyph};
/// Which tab is active in the editor side panel.
#[derive(Copy, Clone, PartialEq, Eq)]
@@ -43,12 +43,11 @@ impl EditorState {
///
/// Shows tab bar (Palette / Board / World) and, on the Palette tab, the
/// scrollable archetype list and current-glyph preview button.
pub(crate) fn show_editor_panel(ctx: &egui::Context, editor: &mut EditorState, _board: &Board) {
pub(crate) fn show_editor_panel(ctx: &egui::Context, editor: &mut EditorState) {
egui::SidePanel::right("palette_panel")
.resizable(true)
.default_width(PALETTE_PANEL_W)
.show(ctx, |ui| {
// Tab bar
ui.horizontal(|ui| {
ui.selectable_value(&mut editor.tab, EditorTab::Palette, "Palette");
ui.selectable_value(&mut editor.tab, EditorTab::Board, "Board");
@@ -72,12 +71,7 @@ pub(crate) fn show_editor_panel(ctx: &egui::Context, editor: &mut EditorState, _
ui.horizontal(|ui| {
let (r, cell_resp) = ui.allocate_exact_size(
vec2(CELL_W, CELL_H), Sense::click());
{
let p = ui.painter();
p.rect_filled(r, 0.0, glyph.bg);
p.text(r.center(), Align2::CENTER_CENTER,
glyph.ch, FontId::monospace(CELL_H), glyph.fg);
}
paint_glyph(ui.painter(), r, &glyph);
let label_resp =
ui.selectable_label(is_selected, archetype.name());
if cell_resp.clicked() || label_resp.clicked() {
@@ -94,17 +88,7 @@ pub(crate) fn show_editor_panel(ctx: &egui::Context, editor: &mut EditorState, _
// Paint a preview cell showing the current glyph, sized like a board cell.
let (cell_rect, glyph_btn) =
ui.allocate_exact_size(vec2(CELL_W, CELL_H), Sense::click());
{
let p = ui.painter();
p.rect_filled(cell_rect, 0.0, editor.glyph.bg);
p.text(
cell_rect.center(),
Align2::CENTER_CENTER,
editor.glyph.ch,
FontId::monospace(CELL_H),
editor.glyph.fg,
);
}
paint_glyph(ui.painter(), cell_rect, &editor.glyph);
if glyph_btn.clicked() {
editor.glyph_picker_open = true;
}