Class CSSGridTracks
columns, rows, autoColumns and autoRows properties of CSSGridLayout.The property itself is a plain StringProp holding CSS text, e.g. "200px 1fr minmax(120px,2fr)". The Browser receives that text verbatim as grid-template-columns (or -rows, grid-auto-columns, grid-auto-rows), so the grammar accepted here is a subset of CSS and nothing else: every track the parser accepts is resolved natively by the Browser, with no measurement in JavaScript. This class is the single source of truth for validation in the Designer (the property sheet marker and the track dialog) and for any later editing of one track.
The accepted grammar (CSS Grid Layout Level 1, without line names and without subgrid, which are out of scope):
template list := ( track-size | repeat(N, track-size+) )+
with at most one repeat(auto-fill|auto-fit, fixed-size+), in which
case every other track must have a fixed size
auto list := track-size+ (grid-auto-columns / -rows)
track-size := breadth | minmax(inflexible, breadth) | fit-content(length)
breadth := length | flex | auto | min-content | max-content
inflexible := length | auto | min-content | max-content
fixed-size := length | minmax(length, breadth) | minmax(inflexible, length)
length := number px|%|em|rem|vw|vh, or a unitless 0
flex := number fr
Numbers are non-negative decimals. Keywords, function names and units are case-insensitive and are written lower case by toString(). A blank string is a valid, empty list ("no explicit tracks").IIZI units are not accepted (dlg, dpx, dpr, the neighbor units, formulas): they would have to be computed in JavaScript, which is what this layout exists to avoid. % here is the CSS % of the grid container's content box, not IIZI's %.
Instances are immutable.
- Author:
- Christopher Mindus
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe kind of one track or track function.static final classOne track, track function or repetition.Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe repeat count ofrepeat(auto-fill,...).static final intThe repeat count ofrepeat(auto-fit,...).static final CSSGridTracksThe empty list.The units accepted for a length, in the order they are listed in messages.static final intThe largest integer repeat count accepted (the Browsers clamp the total track count near this value anyway).Method Summary
Modifier and TypeMethodDescriptionbooleanTwo lists are equal when their canonical CSS texts are equal.intReturns the number of explicit tracks.Returns the tracks.booleanReturns if the list holdsrepeat(auto-fill,...)orrepeat(auto-fit,...).inthashCode()Hash code of the canonical CSS text.booleanisEmpty()Returns if the list is empty.booleanReturns if any track grows with a flexible lengthfr.static CSSGridTracksof(List<CSSGridTracks.Track> tracks, boolean auto) Creates a list from tracks, validating it against the template grammar or the auto grammar.static CSSGridTracksParses a track template (grid-template-columns/-rows).static CSSGridTracksParses an implicit track list (grid-auto-columns/-rows): one or more track sizes, norepeat().toString()Returns the CSS text in canonical form: tracks separated by one space, functions written without spaces after their commas, numbers without redundant zeros, everything lower case.static StringValidates a text.
Field Details
LENGTH_UNITS
AUTO_FILL
public static final int AUTO_FILLThe repeat count ofrepeat(auto-fill,...).- See Also:
AUTO_FIT
public static final int AUTO_FITThe repeat count ofrepeat(auto-fit,...).- See Also:
MAX_REPEAT
public static final int MAX_REPEATThe largest integer repeat count accepted (the Browsers clamp the total track count near this value anyway).- See Also:
EMPTY
The empty list.
Method Details
of
Creates a list from tracks, validating it against the template grammar or the auto grammar.- Parameters:
tracks- The tracks.auto- true for thegrid-auto-columns/-rowsgrammar (norepeat()).- Returns:
- The list.
- Throws:
IllegalArgumentException- When the combination is not valid CSS.
parse
Parses a track template (grid-template-columns/-rows).- Parameters:
text- The CSS text, null or blank for an empty list.- Returns:
- The parsed list.
- Throws:
ParseException- When the text is not in the accepted grammar; the error offset is the index intextwhere the problem was found.
parseAuto
Parses an implicit track list (grid-auto-columns/-rows): one or more track sizes, norepeat().- Parameters:
text- The CSS text, null or blank for an empty list (the CSS initial valueauto).- Returns:
- The parsed list.
- Throws:
ParseException- When the text is not in the accepted grammar.
validate
getTracks
isEmpty
public boolean isEmpty()Returns if the list is empty.- Returns:
- true for no tracks.
getTrackCount
public int getTrackCount()Returns the number of explicit tracks.- Returns:
- The count, or -1 when it depends on the container size (auto-fill, auto-fit).
isFlexible
public boolean isFlexible()Returns if any track grows with a flexible lengthfr.- Returns:
- true when flexible.
hasAutoRepeat
public boolean hasAutoRepeat()Returns if the list holdsrepeat(auto-fill,...)orrepeat(auto-fit,...).- Returns:
- true for an automatic repetition.
toString
equals
hashCode