20 static constexpr int32_t
kAuto = -1;
21 static constexpr int32_t
kUnbounded = std::numeric_limits<int32_t>::max();
39 template<
class PxFn>
constexpr void ResolveCss(
const PxFn& px)
51 constexpr int32_t
Clamp(int32_t s)
const {
return std::clamp(s,
min,
max); }
106 return { .type =
PositionType::Anchored, .anchorPlacement = placement, .autoFlip = flip, .anchorTarget = target, .near = offset };
223 #define TACHYON_LO_BUILDER(name, body) \
224 LayoutOverride& name & { body return *this; } \
225 LayoutOverride&& name && { body return std::move(*this); }
281 TACHYON_LO_BUILDER(
Anchored(
ID target,
AnchorPlacement pl, const
int2& off = {},
AutoFlipMode af =
AutoFlipMode::None),
x =
PositionConstraintAxis::Anchored(target,
GetHorizontalAxis(pl), int16_t(off.x), af);
y =
PositionConstraintAxis::Anchored(target,
GetVerticalAxis(pl), int16_t(off.y), af);)
282 TACHYON_LO_BUILDER(
Anchored(
ID target,
AnchorPlacement pl, int32_t ox, int32_t oy,
AutoFlipMode af =
AutoFlipMode::None),
x =
PositionConstraintAxis::Anchored(target,
GetHorizontalAxis(pl), int16_t(ox), af);
y =
PositionConstraintAxis::Anchored(target,
GetVerticalAxis(pl), int16_t(oy), af);)
283 TACHYON_LO_BUILDER(
Anchored(
ID target,
AnchorPlacementAxis px, int32_t ox,
AnchorPlacementAxis py, int32_t oy,
AutoFlipMode af =
AutoFlipMode::None),
x =
PositionConstraintAxis::Anchored(target, px, int16_t(ox), af);
y =
PositionConstraintAxis::Anchored(target, py, int16_t(oy), af);)
@ None
Definition gui_element_flags.h:19
AutoFlipMode
What an anchored element does when its placement would leave the work area.
Definition gui_constraints.h:66
AnchorPlacement FlipHorizontal(AnchorPlacement p)
Mirrors the horizontal part of a placement (e.g. right-of becomes left-of); vertical is kept.
AnchorPlacement FlipVertical(AnchorPlacement p)
Mirrors the vertical part of a placement (e.g. below becomes above); horizontal is kept.
TriState
Default defers to the element's style.
Definition gui_constraints.h:126
@ FlipAvoidTarget
Flip, then shrink to avoid overlapping the anchor target.
Definition gui_constraints.h:69
@ None
Keep the placement as given.
Definition gui_constraints.h:67
@ Flip
Flip placement, then clamp to workArea.
Definition gui_constraints.h:68
@ Default
Definition gui_constraints.h:126
@ True
Definition gui_constraints.h:126
@ False
Definition gui_constraints.h:126
constexpr AnchorPlacementAxis GetVerticalAxis(AnchorPlacement p)
Vertical part of an AnchorPlacement.
Definition gui_style.h:333
BreakBehavior
Line breaks around an item in a wrapping flex container (CSS: break-after).
Definition gui_style.h:465
constexpr AnchorPlacementAxis GetHorizontalAxis(AnchorPlacement p)
Horizontal part of an AnchorPlacement.
Definition gui_style.h:331
AnchorPlacement
Where an anchored element sits relative to its target: one horizontal and one vertical AnchorPlacemen...
Definition gui_style.h:262
PositionType
How an element is positioned; modeled on CSS position, but set in code, not CSS.
Definition gui_style.h:215
IconSide
Where an element's icon sits relative to its text (CSS: -tachyon-icon-side).
Definition gui_style.h:249
AnchorPlacementAxis
Anchor placement along one axis; the 4-bit value of one AnchorPlacement nibble.
Definition gui_style.h:304
@ Auto
No forced breaks, no keep-with-next.
Definition gui_style.h:466
@ Always
Force a line break after this element (CSS: always / right).
Definition gui_style.h:467
@ Before
Force a line break before this element (CSS: left).
Definition gui_style.h:468
@ Avoid
Prevent a line break between this and the next element (CSS: avoid).
Definition gui_style.h:469
@ Relative
in flow, offset from its natural position
Definition gui_style.h:216
@ Fixed
out of flow in overlay space; doesn't scroll with the parent
Definition gui_style.h:219
@ Absolute
out of flow in content space; scrolls with the parent
Definition gui_style.h:218
@ Anchored
placed relative to another element (AnchorPlacement)
Definition gui_style.h:217
@ Sticky
in flow like Relative, clamped to the parent's scroll viewport edge
Definition gui_style.h:221
@ Centered
centered in the parent
Definition gui_style.h:220
@ None
Definition gui_style.h:250
@ Left
Definition gui_style.h:252
@ None
Definition gui_style.h:305
#define TACHYON_LO_BUILDER(name, body)
Definition gui_constraints.h:223
Definition gui_logging.h:24
A size in CSS px.
Definition gui_units.h:18
int32_t value
Definition gui_units.h:19
Per-side offsets of a positioned element (CSS: top, right, bottom, left), in pixels.
Definition gui_style.h:136
static constexpr int16_t kAuto
"Not set". Insets can be negative, so the sentinel is the lowest int16_t.
Definition gui_style.h:138
kDefault = use style value, >= 0 = override.
Definition gui_constraints.h:130
constexpr bool HasShrink() const
Definition gui_constraints.h:137
int16_t shrink
flex-shrink override
Definition gui_constraints.h:134
bool operator==(const FlexOverride &) const noexcept=default
constexpr bool HasGrow() const
Definition gui_constraints.h:136
static constexpr int16_t kDefault
Use the style's value.
Definition gui_constraints.h:131
int16_t grow
flex-grow override
Definition gui_constraints.h:133
uint16_t flexShrink
CSS: flex-shrink (whole numbers).
Definition gui_style.h:353
uint16_t flexGrow
CSS: flex-grow (whole numbers).
Definition gui_style.h:352
A grid item's placement and track request along one axis, plus the container's gap.
Definition gui_style.h:407
int16_t start
first track the item covers; kAuto = auto-place
Definition gui_style.h:414
GridTrack track
Size the item asks for its column / row; across the items in a track, Fixed beats Fractional beats Au...
Definition gui_style.h:412
int16_t span
tracks the item covers
Definition gui_style.h:415
Grid container and item properties.
Definition gui_style.h:423
GridAxisProperties column
CSS: grid-column, column-gap.
Definition gui_style.h:424
GridAxisProperties row
CSS: grid-row, row-gap.
Definition gui_style.h:425
Size of one grid column or row (CSS: -tachyon-grid-column-track / -row-track).
Definition gui_style.h:373
@ Default
defers to the element's style (only valid in LayoutOverride)
Definition gui_style.h:380
static constexpr GridTrack Default()
Defers to the element's style (LayoutOverride only).
Definition gui_style.h:396
A 64-bit element ID whose bit layout depends on its IDMode.
Definition gui_id.h:23
static constexpr ID Invalid()
The "no element" ID (all bits zero); also the default for optional ID parameters.
Definition gui_id.h:66
Definition gui_base_types.h:407
GridProperties grid
used when display is Grid (and by grid items)
Definition gui_style.h:444
FlexProperties flex
used when display is Flex (and by flex items)
Definition gui_style.h:443
GridAxisProperties column
int16_t iconTextGapOverride
Icon layout overrides (-1 = use style).
Definition gui_constraints.h:165
constexpr bool HasFixedWidth() const
Whether an explicit width / height is set; axis 0 = width, 1 = height.
Definition gui_constraints.h:194
LayoutOverride & PositionX(PositionConstraintAxis ax) &
Sets one axis's constraint, or only its PositionType.
Definition gui_constraints.h:292
static LayoutOverride FixedHeight(Pixels h)
Definition gui_constraints.h:190
PositionConstraintAxis x
Definition gui_constraints.h:153
constexpr bool HasFixedAxis(int axis) const
Definition gui_constraints.h:196
LayoutOverride & NoShrink() &
Shorthands for FlexGrow(0) / FlexShrink(0).
Definition gui_constraints.h:323
LayoutOverride & Height(CssPx h) &
Size, min and max size, in CSS px (scaled by the UI scale) or Pixels (as they are).
Definition gui_constraints.h:234
LayoutOverride & KeepWithNext(bool v=true) &
Forces a line break after / before this element, or keeps it on the same line as the next one.
Definition gui_constraints.h:312
void ApplyHorizontal(IntRect &rect, const IntRect &targetRect) const
Positions rect on one axis against targetRect (the parent, or the anchor target).
Definition gui_constraints.h:219
int32_t ApplyHeight(int32_t s) const
Definition gui_constraints.h:209
bool GetKeepWithNext(const LayoutStyle *ls) const
Definition gui_constraints.h:367
LayoutOverride & ColumnTrack(GridTrack t) &
Overrides the style's column / row track size.
Definition gui_constraints.h:337
static LayoutOverride FixedWidth(Pixels w)
Definition gui_constraints.h:188
LayoutOverride & Anchored(ID target, AnchorPlacementAxis px, int32_t ox, AnchorPlacementAxis py, int32_t oy, AutoFlipMode af=AutoFlipMode::None) &
Placed next to / inside the target element per the placement, plus an offset in pixels.
Definition gui_constraints.h:283
uint32_t GetFlexShrink(const LayoutStyle *ls) const
Definition gui_constraints.h:356
LayoutOverride & Overhang(const int2 &o) &
After Anchored: how far past the work area the element may reach on each axis, for see-through room a...
Definition gui_constraints.h:287
constexpr bool IsInFlow() const
Definition gui_constraints.h:215
LayoutOverride & FlexShrink(int16_t v) &
Overrides the style's flex-grow / flex-shrink.
Definition gui_constraints.h:318
uint8_t breakBehaviorOverride
0 = use style, otherwise BreakBehavior + 1
Definition gui_constraints.h:169
void ApplyVertical(IntRect &rect, const IntRect &targetRect) const
Definition gui_constraints.h:220
TriState clampScroll
Override of the style's scroll clamping.
Definition gui_constraints.h:170
LayoutOverride & Size(CssPx w, CssPx h) &
Size, min and max size, in CSS px (scaled by the UI scale) or Pixels (as they are).
Definition gui_constraints.h:229
LayoutOverride & PositionY(PositionConstraintAxis ay) &
Sets one axis's constraint, or only its PositionType.
Definition gui_constraints.h:293
int2 ApplySize(int2 s) const
The explicit size where set, else s clamped to min / max.
Definition gui_constraints.h:207
bool GetBreakBefore(const LayoutStyle *ls) const
Definition gui_constraints.h:365
bool GetClampScroll(const LayoutStyle *ls) const
Definition gui_constraints.h:368
FlexOverride flex
flex-grow / flex-shrink overrides
Definition gui_constraints.h:155
LayoutOverride & Anchored(ID target, AnchorPlacement pl, int32_t ox, int32_t oy, AutoFlipMode af=AutoFlipMode::None) &
Placed next to / inside the target element per the placement, plus an offset in pixels.
Definition gui_constraints.h:282
IconSide iconSideOverride
None = use style.
Definition gui_constraints.h:166
bool outOfFlow
Set by ElementStorage::Add for display:none / visibility:collapsed; such elements take no space in th...
Definition gui_constraints.h:174
IconSide GetIconSide(const LayoutStyle *ls) const
Definition gui_constraints.h:370
constexpr int32_t ClampHeight(int32_t h) const
Definition gui_constraints.h:202
PositionConstraintAxis y
Position constraints; set with the position builders.
Definition gui_constraints.h:153
LayoutOverride & Centered() &
Centered in the parent on both axes.
Definition gui_constraints.h:259
static LayoutOverride FixedWidth(CssPx w)
Definition gui_constraints.h:187
LayoutOverride & GridColumn(int16_t start, int16_t span=1) &
Explicit grid placement: start cell and span.
Definition gui_constraints.h:342
static LayoutOverride FixedSize(CssPx w, CssPx h)
Sizes in CSS px (scaled by the UI scale) or in Pixels (as they are); see gui_units....
Definition gui_constraints.h:184
LayoutOverride & RowTrack(GridTrack t) &
Overrides the style's column / row track size.
Definition gui_constraints.h:338
SizeConstraintAxis height
Size constraints; set with the size builders.
Definition gui_constraints.h:151
static LayoutOverride FixedSize(Pixels w, Pixels h)
Definition gui_constraints.h:185
LayoutOverride & MaxHeight(CssPx h) &
Size, min and max size, in CSS px (scaled by the UI scale) or Pixels (as they are).
Definition gui_constraints.h:242
LayoutOverride & Width(Pixels w) &
Size, min and max size, in CSS px (scaled by the UI scale) or Pixels (as they are).
Definition gui_constraints.h:233
LayoutOverride & Width(CssPx w) &
Size, min and max size, in CSS px (scaled by the UI scale) or Pixels (as they are).
Definition gui_constraints.h:232
LayoutOverride & IconTextGap(int16_t gap) &
Overrides the style's icon side / icon-text gap (pixels).
Definition gui_constraints.h:329
GridProperties GetGridItem(const LayoutStyle *layoutStyle) const
Style values with non-Default overrides applied.
Definition gui_constraints.h:374
constexpr bool IsInFlowX() const
True when the element takes part in the parent's flow on that axis (see PositionConstraintAxis::IsInF...
Definition gui_constraints.h:213
SizeConstraintAxis width
Definition gui_constraints.h:151
uint16_t GetIconTextGap(const LayoutStyle *ls) const
Definition gui_constraints.h:371
LayoutOverride & MinWidth(CssPx w) &
Size, min and max size, in CSS px (scaled by the UI scale) or Pixels (as they are).
Definition gui_constraints.h:236
constexpr bool IsInFlowAxis(int axis) const
Definition gui_constraints.h:216
static LayoutOverride FixedSize(int2 pixels)
Definition gui_constraints.h:186
LayoutOverride & FlexGrow(int16_t v) &
Overrides the style's flex-grow / flex-shrink.
Definition gui_constraints.h:317
LayoutOverride & MaxWidth(CssPx w) &
Size, min and max size, in CSS px (scaled by the UI scale) or Pixels (as they are).
Definition gui_constraints.h:240
constexpr bool HasFixedHeight() const
Definition gui_constraints.h:195
LayoutOverride & Relative() &
In flow, shifted by the given offsets from the laid-out position.
Definition gui_constraints.h:263
LayoutOverride & GridRow(int16_t start, int16_t span=1) &
Explicit grid placement: start cell and span.
Definition gui_constraints.h:343
LayoutOverride & BreakBefore(bool v=true) &
Forces a line break after / before this element, or keeps it on the same line as the next one.
Definition gui_constraints.h:311
LayoutOverride & ClampScroll(bool v=true) &
Overrides the style's scroll clamping (false = unclamped / infinite scroll).
Definition gui_constraints.h:333
LayoutOverride & StickyY(int16_t threshold=0) &
See PositionConstraintAxis::Sticky.
Definition gui_constraints.h:301
static LayoutOverride FixedHeight(CssPx h)
Definition gui_constraints.h:189
struct tachyon::LayoutOverride::@257370144021133224045361232375113354134033247007 grid
BreakBehavior GetBreakBehavior(const LayoutStyle *ls) const
Definition gui_constraints.h:364
LayoutOverride & StickyX(int16_t threshold=0) &
See PositionConstraintAxis::Sticky.
Definition gui_constraints.h:300
LayoutOverride & WithTypeY(PositionType t) &
Sets one axis's constraint, or only its PositionType.
Definition gui_constraints.h:295
int32_t ApplyWidth(int32_t s) const
Definition gui_constraints.h:208
constexpr bool IsInFlowY() const
Definition gui_constraints.h:214
LayoutOverride & Sticky(int16_t thresholdX=0, int16_t thresholdY=0) &
See PositionConstraintAxis::Sticky.
Definition gui_constraints.h:304
uint32_t GetFlexGrow(const LayoutStyle *ls) const
Resolvers take the element's layout style (may be null) and return the effective value.
Definition gui_constraints.h:351
int2 Size() const
The explicit sizes; kAuto on axes without one.
Definition gui_constraints.h:205
bool GetBreakAfter(const LayoutStyle *ls) const
Definition gui_constraints.h:366
LayoutOverride & WithTypeX(PositionType t) &
Sets one axis's constraint, or only its PositionType.
Definition gui_constraints.h:294
LayoutOverride & NoGrow() &
Shorthands for FlexGrow(0) / FlexShrink(0).
Definition gui_constraints.h:322
static LayoutOverride Auto()
No overrides: everything comes from the style.
Definition gui_constraints.h:182
void ResolveCss(const PxFn &px)
CSS px to pixels; ElementStorage::Add does it with the style manager's Px.
Definition gui_constraints.h:247
LayoutOverride & Absolute(const EdgeInset &i) &
Out of flow, inset from the parent's edges; scrolls with the parent's content.
Definition gui_constraints.h:272
LayoutOverride & Anchored(ID target, AnchorPlacement pl, const int2 &off={}, AutoFlipMode af=AutoFlipMode::None) &
Placed next to / inside the target element per the placement, plus an offset in pixels.
Definition gui_constraints.h:281
LayoutOverride & BreakAfter(bool v=true) &
Forces a line break after / before this element, or keeps it on the same line as the next one.
Definition gui_constraints.h:310
constexpr bool IsFullyConstrained() const
Both width and height are explicit.
Definition gui_constraints.h:198
LayoutOverride & Position(int2 p) &
Position builders, in pixels (near = left/top, far = right/bottom).
Definition gui_constraints.h:252
LayoutOverride & MinHeight(CssPx h) &
Size, min and max size, in CSS px (scaled by the UI scale) or Pixels (as they are).
Definition gui_constraints.h:238
LayoutOverride & SetIconSide(IconSide s) &
Overrides the style's icon side / icon-text gap (pixels).
Definition gui_constraints.h:328
constexpr int32_t ClampWidth(int32_t w) const
Clamps a size to the min / max constraints, ignoring the explicit size.
Definition gui_constraints.h:201
The layout part of a registered Style, in pixels; shared by every style with the same values.
Definition gui_style.h:755
IconSide iconSide
see Style::iconSide
Definition gui_style.h:774
LayoutData layoutData
flex, grid and size properties, in pixels
Definition gui_style.h:762
bool clampScroll
see Style::clampScroll
Definition gui_style.h:777
uint16_t iconTextGap
space between icon and text, pixels
Definition gui_style.h:765
BreakBehavior breakBehavior
see Style::breakBehavior
Definition gui_style.h:776
A size in device pixels, used as is (not scaled by the UI scale).
Definition gui_units.h:28
int32_t value
Definition gui_units.h:29
Where an element goes on one axis: in the parent's flow (Relative, Centered, Sticky) or out of it (Ab...
Definition gui_constraints.h:75
AnchorPlacementAxis anchorPlacement
Anchored only: where along the target.
Definition gui_constraints.h:79
static constexpr PositionConstraintAxis Relative()
In flow, shifted by near (or back by far when near is unset).
Definition gui_constraints.h:94
constexpr PositionConstraintAxis & WithType(PositionType t)
Changes only the position type, keeping the insets.
Definition gui_constraints.h:117
constexpr bool IsInFlow() const
Relative, Centered and Sticky take part in the parent's flex/grid flow.
Definition gui_constraints.h:86
ID anchorTarget
Anchored only: the element to anchor to.
Definition gui_constraints.h:81
static constexpr PositionConstraintAxis Fixed(int16_t nearVal=kAuto, int16_t farVal=kAuto)
Like Absolute, but in overlay space: not moved by the parent's scroll.
Definition gui_constraints.h:101
static constexpr int16_t kAuto
Inset not set.
Definition gui_constraints.h:76
static constexpr PositionConstraintAxis Absolute(int16_t nearVal=kAuto, int16_t farVal=kAuto)
Out of flow, inset near from the parent's start or far from its end; scrolls with the parent.
Definition gui_constraints.h:99
AutoFlipMode autoFlip
Anchored only.
Definition gui_constraints.h:80
static constexpr PositionConstraintAxis Sticky(int16_t threshold=0)
In flow, but scrolling doesn't move it past threshold pixels inside the parent's padding box,...
Definition gui_constraints.h:111
static constexpr PositionConstraintAxis Relative(int16_t nearVal, int16_t farVal)
Definition gui_constraints.h:96
static constexpr PositionConstraintAxis Centered()
Centered in the parent.
Definition gui_constraints.h:91
static constexpr PositionConstraintAxis Auto()
Default: relative, no offset.
Definition gui_constraints.h:89
int16_t far
right/bottom inset; anchored: how far it may reach past the work area
Definition gui_constraints.h:83
int16_t near
left/top inset, or anchor offset (pixels)
Definition gui_constraints.h:82
static constexpr PositionConstraintAxis Relative(int16_t nearVal)
Definition gui_constraints.h:95
void Apply(IntRect &rect, int axis, const IntRect &targetRect) const
Positions rect on axis (0 = x, 1 = y) against targetRect (the parent's, or the anchor's).
PositionType type
Definition gui_constraints.h:78
bool operator==(const PositionConstraintAxis &) const noexcept=default
static constexpr PositionConstraintAxis Anchored(ID target, AnchorPlacementAxis placement, int16_t offset=0, AutoFlipMode flip=AutoFlipMode::None)
Placed relative to the target element's rect, plus offset pixels.
Definition gui_constraints.h:104
Per-axis size constraint: an explicit size, or a min / max clamp on the content-driven size.
Definition gui_constraints.h:19
constexpr void ResolveCss(const PxFn &px)
CSS px to pixels, with px (the style manager's Px).
Definition gui_constraints.h:39
constexpr void SetMax(CssPx v)
Definition gui_constraints.h:35
static constexpr uint8_t kValueCss
Definition gui_constraints.h:28
uint8_t cssMask
Which of value / min / max are CSS px, scaled to pixels when the element is added.
Definition gui_constraints.h:27
int32_t value
Explicit size (kAuto = content-driven).
Definition gui_constraints.h:23
static constexpr uint8_t kMinCss
Definition gui_constraints.h:28
int32_t min
Lower clamp for the content-driven size.
Definition gui_constraints.h:24
static constexpr int32_t kUnbounded
No maximum.
Definition gui_constraints.h:21
constexpr void SetMin(CssPx v)
Definition gui_constraints.h:33
constexpr void SetMax(Pixels v)
Definition gui_constraints.h:36
constexpr void SetMin(Pixels v)
Definition gui_constraints.h:34
int32_t max
Upper clamp for the content-driven size.
Definition gui_constraints.h:25
bool operator==(const SizeConstraintAxis &) const noexcept=default
static constexpr uint8_t kMaxCss
Definition gui_constraints.h:28
constexpr void SetValue(CssPx v)
Setters take CSS px (scaled when the element is added) or Pixels (used as is).
Definition gui_constraints.h:31
constexpr void SetValue(Pixels v)
Definition gui_constraints.h:32
constexpr bool HasFixed() const
True when an explicit size is set.
Definition gui_constraints.h:48
constexpr int32_t Clamp(int32_t s) const
Clamps s to [min, max].
Definition gui_constraints.h:51
static constexpr int32_t kAuto
No explicit size.
Definition gui_constraints.h:20
constexpr int32_t Apply(int32_t s) const
The explicit size if set, else s clamped to [min, max].
Definition gui_constraints.h:54
Integer 2D vector.
Definition gui_base_types.h:19
int32_t x
Definition gui_base_types.h:20
int32_t y
Definition gui_base_types.h:20