Skip to main content

Module grid

Module grid 

Source
Expand description

Builds sections by placing rectangles on a canvas instead of placing sections by hand.

Only works with row-major menus, not ones with protocol-defined slot indices like anvils. Those still build through MenuBuilder’s normal placements.

use steel_registry::{vanilla_items, vanilla_menu_types};
use steel_core::inventory::menu::kinds::BasicKind;
use steel_core::player::player_inventory::PlayerInventory;

use steel_core::inventory::prelude::*;

fn example(container_id: u8, inventory: Shared<PlayerInventory>) -> Menu {
    let mut b = MenuBuilder::new(&vanilla_menu_types::GENERIC_9X3, container_id);

    let storage = SimpleContainer::new(3).into_shared();

    let items = b.grid(3, |g| {
        let items = g.place(Rect::cols(3..6).rows(1), storage).section();
        g.paint_all(&vanilla_items::GRAY_STAINED_GLASS_PANE);
        items
    });

    let player = b.player_inventory(&inventory);
    b.route(items, player.all(), FillDirection::Backward);
    b.route(player.all(), items, FillDirection::Forward);
    b.build(BasicKind)
}

Β§Rules

  • Placements never overlap. A cell belongs to at most one placement. A second claim panics.
  • Paint is decoration. It layers freely (last paint wins) and placements always mask it. Painted cells become locked display slots of one auto-sized filler container.
  • Every cell must be placed or painted when a scope closes, else panic.
  • Subgrids are self-contained. GridPlacer::subgrid has its own local coordinates and coverage check. Parent paint does not reach into it.
  • GridPlacer::carve_rows, GridPlacer::carve_cols and GridPlacer::rest are cursor-computed subgrids. One carve axis per scope. Nest to switch axes.

ModulesΒ§

sealed πŸ”’

StructsΒ§

Abs πŸ”’
A Rect resolved against a concrete scope: absolute coordinates, concrete extent.
ColSpan
A Rect with only its columns given. Complete it with rows.
Frame πŸ”’
One grid scope: the whole grid, or a sub-area inside a subgrid or carve.
GridPlacer
Places rectangles on a grid scope. Created by MenuBuilder::grid.
GridState πŸ”’
Grid-wide state shared by all nested GridPlacer scopes.
Placement πŸ”’
One container-backed placement, in absolute grid coordinates.
PlacementBuilder
A pending placement, applied only when region or result is called.
Rect
A rectangle of grid cells, selected by column and row ranges. Coordinates are 0-based from the top-left of the scope the rect is used in.
Region
The sections created by a grid placement.
RowSpan
A Rect with only its rows given. Complete it with cols.

EnumsΒ§

Axis πŸ”’
Cell πŸ”’
What one grid cell resolved to.
PlacementKind πŸ”’
SlotMapping πŸ”’
Maps a placement’s row-major cell index to a container slot index.

ConstantsΒ§

GRID_WIDTH πŸ”’

TraitsΒ§

SpanBounds
A column or row selection for Rect::cols / Rect::rows: any range or a bare index.

FunctionsΒ§

to_span πŸ”’
Lowers a SpanBounds to (start, length). A None length means the scope’s edge.