Skip to content

Commit

Permalink
fixes and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 committed Oct 22, 2023
1 parent 00455d0 commit d6e548f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
17 changes: 9 additions & 8 deletions book/src/guides/layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

Learn how the layout attributes work.

- [`width & height`](#width_&_height)
- [`min_width & min_height`](#min_width_&_min_height)
- [`max_width & max_height`](#max_width_&_max_height)
- [`width & height`](#width--height)
- [`min_width & min_height`](#min_width--min_height)
- [`max_width & max_height`](#max_width--max_height)
- [`Size units`](#size_units)
- [`Logical pixels`](#logical-pixels)
- [`Percentages`](#percentages)
- [`calc()`](#calc)
- [`direction`](#direction)
- [`padding`](#padding)
- [`margin`](#margin)
- [`main_alignment & cross_alignment`](#main_alignment_&_cross_alignment)
- [`main_align & cross_align`](#main_align--cross_align)

> ⚠️ Freya's layout is still somewhat limited.
Expand Down Expand Up @@ -168,16 +168,17 @@ fn app(cx: Scope) -> Element {
```

### main_alignment & cross_alignment
### main_align & cross_align

Control how the inner elements are positioned inside the element. You can combine it with the `direction` attribute to create complex flows.
Possible values for both are:

Possible values for both attributes are:
- `start` (default): At the begining of the axis
- `center`: At the center of the axis
- `end`: At the end of the axis

When using the `vertical` direction, `main_alignment` will be the Y axis and `cross_alignment` will be the X axis. But when using the `horizontal` direction, the
`main_alignment` will be the X axis and the `cross_alignment` will be the Y axis.
When using the `vertical` direction, `main_align` will be the Y axis and `cross_align` will be the X axis. But when using the `horizontal` direction, the
`main_align` will be the X axis and the `cross_align` will be the Y axis.

Example on how to center the inner elements in both axis:

Expand Down
4 changes: 2 additions & 2 deletions crates/state/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ impl State<CustomAttributeValues> for LayoutState {
"direction",
"offset_y",
"offset_x",
"main_alignment",
"cross_alignment",
"main_align",
"cross_align",
"reference",
"margin",
]))
Expand Down
17 changes: 14 additions & 3 deletions examples/alignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,20 @@ fn app(cx: Scope) -> Element {
background: "green"
}
rect {
width: "50",
height: "50",
background: "orange"
main_align: "center",
cross_align: "center",
background: "orange",
padding: "15",
rect {
width: "20",
height: "20",
background: "black"
}
rect {
width: "20",
height: "20",
background: "white"
}
}
}
rect {
Expand Down

0 comments on commit d6e548f

Please sign in to comment.