Skip to main content

Crate egui_nonogram

Crate egui_nonogram 

Source
Expand description

§egui-nonogram

crates.io docs.rs deps.rs CI Rust version License Changelog Live demo

A self-contained Nonogram (picross) puzzle game library for egui.

§Features

  • Pure game logic struct (NonogramGame) with no egui dependency — usable headlessly or with any renderer
  • Ready-to-use egui Widget (NonogramWidget) that renders an interactive board with row/column clues
  • Two ways to build a puzzle: NonogramGame::from_grid (supply your own picture) and NonogramGame::random (procedural, seeded)
  • Monochrome only — cells are filled or empty, clues are plain run-length numbers
  • Left-click fills a cell, right-click crosses it out; crossed cells are a player aid only and never need to match the solution
  • Click-and-drag paints (or erases) a whole stroke of cells in one gesture
  • Solved rows/columns dim and strike through their clue as a solving hint
  • Optional read-only progress preview thumbnail beside the board
  • Undo/redo history
  • No losing state — every action is reversible

§Usage

Add the dependency:

[dependencies]
egui-nonogram = "0.1"

Then use it in your egui app:

ⓘ
use egui_nonogram::{NonogramGame, NonogramWidget};

// A curated puzzle from an explicit picture:
let grid = vec![
    vec![false, true, false],
    vec![true, true, true],
    vec![false, true, false],
];
let mut game = NonogramGame::from_grid(grid);

// Or a procedural puzzle, reproducible via a seed:
let mut game = NonogramGame::random(10, 10, 0.45, 42);

// Inside your egui update/UI closure:
ui.add(NonogramWidget::new(&mut game));

After each frame you can inspect game.status to check for a win:

ⓘ
use egui_nonogram::GameStatus;

match game.status {
    GameStatus::Playing => {}
    GameStatus::Won => println!("Solved!"),
}

To start over on the same puzzle:

ⓘ
game.reset();

§egui version compatibility

egui-nonogramegui
0.10.35

§License

Licensed under either of MIT or Apache-2.0 at your option.

Structs§

NonogramGame
The nonogram game state: board dimensions, the hidden solution, the player’s grid, derived clues, and undo/redo history.
NonogramWidget
An egui widget that renders a nonogram board with its row/column clues.

Enums§

CellState
The player-visible state of a single cell.
GameStatus
The current status of the game.
TapMode
Which action a plain (primary) tap performs. Desktop users always have both actions available (left-click fills, right-click crosses); this only matters for touch input, which has no secondary-tap gesture — a toolbar toggle can flip it so mobile players can reach both actions.

Functions§

content_size
The total footprint NonogramWidget will occupy for game at a given cell_size, including the clue gutters and (if enabled) the progress preview column. Lets a caller pre-size a container (e.g. egui::Scene) before laying the widget out.
fit_cell_size
The cell size (in logical pixels) that fits game’s board into available space — the same auto-sizing formula NonogramWidget uses internally when no explicit cell_size is set. Lets a caller pre-compute that fit (e.g. to size a Scene before laying the widget out inside it) instead of duplicating the formula.
gutter_size
Row gutter width and column gutter height for a given game’s clues.
is_logically_solvable
Check whether the puzzle defined by its clues can be solved using line-solving only (no guessing/backtracking). Returns true if iterative single-line deduction can determine every cell’s state.

Type Aliases§

Clue
A single row or column clue: run-lengths of consecutive filled cells, e.g. [3, 1] for a line shaped ###.#. An all-empty line’s clue is [0], never an empty vec, so it can be compared directly against a freshly-computed clue from the player’s current grid.