Skip to content
FutureBlitz

    Install

    Import std.term.region

    std.term.region

    Laying out a screen's cells in rows and columns.

    std.term's regions: a Region of a screen's cells, which splits into rows or columns by Constraints, as a full-screen app lays out its panes: a size that's Fixed, a Percent of what there is, at least a Min, or a share of what's left, Fill.

    std/term/region.fb

    Types

    Region struct

    Public Struct Region Implements Hashable, Printable

    A rectangle of a screen's cells: its top-left Column and Row, from 0, and its Width and Height.

    Examples

    Local screen = Region(0, 0, 80, 24)
    Local rows = screen.SplitRows(Constraint.Fixed(1), Constraint.Fill(), Constraint.Fixed(1))
    Expect(rows[0].Height == 1 && rows[1].Height == 22 && rows[2].Row == 23)
    Local columns = rows[1].SplitColumns(Constraint.Percent(25), Constraint.Fill())
    Expect(columns[0].Width == 20 && columns[1].Column == 20)

    std/term/region.fb, line 21

    • Public Field Column: Int field #

      Its left column, from 0.

    • Public Field Row: Int field #

      Its top row, from 0.

    • Public Field Width: Int field #

      How many columns wide it is.

    • Public Field Height: Int field #

      How many rows high it is.

    • Public Property Right: Int property #

      The column just past its right edge, and the row just past its bottom.

    • Public Property Bottom: Int property #

      The row just past its bottom.

    • Public Property IsEmpty: Bool property #

      Whether it has no cells.

    • Public Method Contains(column: Int, row: Int): Bool method #

      Whether the cell at column and row is in it.

    • Public Method Inner(margin: Int = 1): Region method #

      It without margin cells on each side, or empty where there aren't that many.

    • Public Method Inner(horizontal: Int, vertical: Int): Region method #

      It without horizontal cells on its left and right, and vertical ones on its top and bottom.

    • Public Method Intersect(other: Region): Region method #

      The cells it has in common with other, which may be none.

    • Public Method SplitRows(sizes: Constraint...): Region[] method #

      Its rows, top to bottom, as the sizes say, each its whole width.

    • Public Method SplitColumns(sizes: Constraint...): Region[] method #

      Its columns, left to right, as the sizes say, each its whole height.

    • Public Method ToString(): String method #

      Like "(3, 4) 20x10".

    ConstraintKind enum

    Public Enum ConstraintKind

    How a Constraint sizes its part.

    std/term/region.fb, line 99

    • FIXED enum member #

      A number of cells.

    • PERCENT enum member #

      A percent of the cells there are.

    • MIN enum member #

      At least a number of cells, and a share of what's left like a Fill of 1.

    • FILL enum member #

      A share of what's left by its weight, beside the other Fills'.

    Constraint struct

    Public Struct Constraint Implements Hashable, Printable

    How big one part of a split is: a Fixed number of cells, a Percent of the cells there are, at least a Min of them and a share of what's left like a Fill of 1, or a Fill, a share of what's left by its weight beside the other Fills'.

    Examples

    Expect("{Constraint.Fixed(3)}" == "Fixed(3)")
    Local parts = Region(0, 0, 10, 1).SplitColumns(Constraint.Min(2), Constraint.Fill(3))
    Expect(parts[0].Width + parts[1].Width == 10)

    std/term/region.fb, line 121

    • Public ReadOnly Field Kind: ConstraintKind field #

      What kind of constraint it is.

    • Public ReadOnly Field Value: Int field #

      Its cells, percent, or weight, as its Kind has it.

    • @PanicsAtCaller Public Static Method Fixed(size: Int): Constraint static method #

      size cells. Panics for a negative size.

    • @PanicsAtCaller Public Static Method Percent(percent: Int): Constraint static method #

      percent of the cells there are, rounded down. Panics for a percent below 0 or past 100.

    • @PanicsAtCaller Public Static Method Min(size: Int): Constraint static method #

      At least size cells, and a share of what's left, as a Fill of 1. Panics for a negative size.

    • @PanicsAtCaller Public Static Method Fill(weight: Int = 1): Constraint static method #

      A share of what's left, by weight beside the other Fills' weights: a Fill of 2 gets twice a Fill of 1's. Panics for a negative weight.

    • Public Method ToString(): String method #

      Like "Fixed(3)" or "Fill(1)".

    Report an issue with this page or with FutureBlitz on GitHub.