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::subgridhas its own local coordinates and coverage check. Parent paint does not reach into it. GridPlacer::carve_rows,GridPlacer::carve_colsandGridPlacer::restare cursor-computed subgrids. One carve axis per scope. Nest to switch axes.
ModulesΒ§
- sealed π
StructsΒ§
- Abs π
- A
Rectresolved against a concrete scope: absolute coordinates, concrete extent. - ColSpan
- A
Rectwith only its columns given. Complete it withrows. - Frame π
- One grid scope: the whole grid, or a sub-area inside a subgrid or carve.
- Grid
Placer - Places rectangles on a grid scope. Created by
MenuBuilder::grid. - Grid
State π - Grid-wide state shared by all nested
GridPlacerscopes. - Placement π
- One container-backed placement, in absolute grid coordinates.
- Placement
Builder - A pending placement, applied only when
regionorresultis 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
Rectwith only its rows given. Complete it withcols.
EnumsΒ§
- Axis π
- Cell π
- What one grid cell resolved to.
- Placement
Kind π - Slot
Mapping π - Maps a placementβs row-major cell index to a container slot index.
ConstantsΒ§
- GRID_
WIDTH π
TraitsΒ§
- Span
Bounds - A column or row selection for
Rect::cols/Rect::rows: any range or a bare index.
FunctionsΒ§
- to_span π
- Lowers a
SpanBoundsto(start, length). ANonelength means the scopeβs edge.