Skip to content

Commit a8030a8

Browse files
committed
Added abs positions
1 parent 142be78 commit a8030a8

30 files changed

Lines changed: 1717 additions & 250 deletions

docs/wiki/Visual-Position.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# position Property Visual Reference
2+
3+
The `position` property controls how an element is positioned within its container. FlexRender supports three positioning modes matching CSS behavior: `static` (default), `relative`, and `absolute`.
4+
5+
## Position Modes
6+
7+
### static (default)
8+
Element follows normal flex flow. No offset properties are applied.
9+
10+
### relative
11+
Element is offset from its normal flow position. Siblings are not affected.
12+
13+
| Example | Description | Visual |
14+
|---------|-------------|--------|
15+
| Offset | Middle box shifted with `top: 15, left: 20` from normal position | ![relative offset](../../examples/visual-docs/output/position-relative-offset.png) |
16+
17+
### absolute
18+
Element is removed from flex flow and positioned relative to its containing flex parent's padding box.
19+
20+
| Example | Description | Visual |
21+
|---------|-------------|--------|
22+
| Top/Left | Box pinned to `top: 10, left: 10` | ![absolute top-left](../../examples/visual-docs/output/position-absolute-top-left.png) |
23+
| Bottom/Right | Box pinned to `bottom: 10, right: 10` | ![absolute bottom-right](../../examples/visual-docs/output/position-absolute-bottom-right.png) |
24+
| Centered | Box centered via equal insets on all sides | ![absolute centered](../../examples/visual-docs/output/position-absolute-center.png) |
25+
| Flow Exclusion | Absolute elements excluded from flex flow — A, C, D stack normally | ![flow exclusion](../../examples/visual-docs/output/position-flow-exclusion.png) |
26+
| Inset Sizing | Width/height computed from opposing insets (no explicit size) | ![inset sizing](../../examples/visual-docs/output/position-inset-sizing.png) |
27+
28+
## Practical Patterns
29+
30+
| Pattern | Description | Visual |
31+
|---------|-------------|--------|
32+
| Badge | Star badge overlaid on product card with `top: 8, right: 8` | ![badge](../../examples/visual-docs/output/position-badge.png) |
33+
| Text Overlay | Dark bar with text at bottom of image using `bottom: 0, left: 0, right: 0` | ![overlay](../../examples/visual-docs/output/position-overlay.png) |
34+
| Floating Label | Input label floats above border with `top: -8, left: 12` | ![floating label](../../examples/visual-docs/output/position-floating-label.png) |
35+
36+
## Code Examples
37+
38+
### YAML Template
39+
40+
```yaml
41+
# Badge pattern — star overlay on card
42+
- type: flex
43+
overflow: hidden
44+
children:
45+
- type: image
46+
src: "product.png"
47+
fit: cover
48+
- type: image
49+
position: absolute
50+
top: "8"
51+
right: "8"
52+
src: "star-badge.png"
53+
width: "24"
54+
height: "24"
55+
```
56+
57+
### AST (C# Code)
58+
59+
```csharp
60+
using FlexRender.Layout;
61+
using FlexRender.Parsing.Ast;
62+
63+
var container = new FlexElement
64+
{
65+
Width = "300", Height = "200",
66+
Overflow = Overflow.Hidden
67+
};
68+
69+
// Absolute badge in top-right corner
70+
container.AddChild(new FlexElement
71+
{
72+
Position = Position.Absolute,
73+
Top = "8", Right = "8",
74+
Width = "24", Height = "24",
75+
Background = "#e74c3c"
76+
});
77+
```
78+
79+
## Inset Properties
80+
81+
| Property | Type | Description |
82+
|----------|------|-------------|
83+
| `top` | string | Offset from top edge of containing block's padding box |
84+
| `right` | string | Offset from right edge |
85+
| `bottom` | string | Offset from bottom edge |
86+
| `left` | string | Offset from left edge |
87+
88+
**Priority rules:**
89+
- `left` takes priority over `right` when both are specified (for `position: relative`)
90+
- `top` takes priority over `bottom` when both are specified (for `position: relative`)
91+
- For `position: absolute`, opposing insets (`left` + `right` or `top` + `bottom`) without explicit size compute the element's width/height (inset sizing)
92+
93+
## Notes
94+
95+
- Absolute elements are excluded from flex flow — siblings layout as if the absolute element doesn't exist
96+
- Absolute elements are excluded from intrinsic measurement — parent sizing ignores them
97+
- Relative positioning does not affect sibling positions — space is reserved at the original position
98+
- When no insets are specified on an absolute element, it defaults to `justify-content` (main axis) and `align-items` (cross axis) fallback positioning
99+
- Inset values support pixels, percentages, and em units
100+
- Use `overflow: hidden` on the parent to clip overflowing absolute elements
101+
102+
## See Also
103+
104+
- [[Flexbox-Layout]] - Complete flexbox layout reference
105+
- [[Element-Reference]] - All element types and properties
106+
- [[Visual-Reference]] - Index of all visual documentation pages

docs/wiki/Visual-Reference.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ These pages demonstrate the core flexbox layout properties with visual examples:
1818
- [[Visual-Align]] - `align` property alignment (5 values: stretch, start, center, end, baseline)
1919
- [[Visual-Direction]] - `direction` property main axis control (4 values: row, column, row-reverse, column-reverse)
2020
- [[Visual-Wrap]] - `wrap` property wrapping behavior (3 values: nowrap, wrap, wrap-reverse)
21+
- [[Visual-Position]] - `position` property (3 values: static, relative, absolute) with inset placement and practical patterns
2122

2223
### Element Types
2324

Lines changed: 2 additions & 2 deletions
Loading

examples/receipt-dynamic.yaml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -131,37 +131,37 @@ layout:
131131
color: "#cccccc"
132132
thickness: 1
133133

134-
# Total with star badge (if total > 10)
134+
# Total with star badge overlay (if total > 10)
135135
- type: flex
136136
direction: row
137137
justify: space-between
138138
align: center
139139
children:
140-
- type: flex
141-
direction: row
142-
gap: 4
143-
align: center
144-
children:
145-
- type: text
146-
content: "TOTAL"
147-
font: bold
148-
size: 1.2em
149-
color: "#1a1a1a"
150-
- type: if
151-
condition: totalNumber
152-
greaterThan: 10
153-
then:
154-
- type: image
155-
src: "assets/placeholder/star-badge.png"
156-
width: "16"
157-
height: "16"
158-
fit: contain
140+
- type: text
141+
content: "TOTAL"
142+
font: bold
143+
size: 1.2em
144+
color: "#1a1a1a"
159145
- type: text
160146
content: "{{total}} $"
161147
font: bold
162148
size: 1.2em
163149
color: "#1a1a1a"
164150
align: right
151+
# Star badge as absolute overlay on TOTAL text
152+
- type: if
153+
condition: totalNumber
154+
greaterThan: 10
155+
then:
156+
- type: image
157+
position: absolute
158+
top: "-8"
159+
left: "36"
160+
rotate: 30
161+
src: "assets/placeholder/star-badge.png"
162+
width: "24"
163+
height: "24"
164+
fit: contain
165165

166166
- type: separator
167167
style: dotted

examples/visual-docs/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,10 @@ After making changes to visual docs:
213213

214214
## Current Statistics
215215

216-
- **Total YAML templates:** 42
217-
- **Total PNG outputs:** 42 (1:1 mapping)
218-
- **Categories:** 10 (align, barcode, canvas, direction, image, justify, qr, separator, text, wrap)
219-
- **Wiki pages:** 11 (includes Visual-Reference.md)
216+
- **Total YAML templates:** 51
217+
- **Total PNG outputs:** 51 (1:1 mapping)
218+
- **Categories:** 11 (align, barcode, canvas, direction, image, justify, position, qr, separator, text, wrap)
219+
- **Wiki pages:** 12 (includes Visual-Reference.md)
220220

221221
Last updated: February 2026
222222

Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)