Paint the translate property as a move of the whole box
StyleBoxData carries the CSS translate property (StyleBoxTranslate), which the paint transform pass applies after rotate, scale and transform, so translate: 0 -2px lifts a box as on the web and eases with the other transform fields. The widget part metric that used the name is -kryon-content-offset in the CSS package; StyleContentOffset keeps its meaning.
This commit is contained in:
1 parent
6bb0da2d2e
commit
2f9b5db29b
4 files changed
+32
-21
No files matched your search
@@ -234,15 +234,15 @@ Parse once per stylesheet in a running app. The example reparses to show the com
|
||||
- Focus ring: `outline` (`[width] [solid | auto | none] [color]`), `outline-color`, `outline-width` (`px`, `rem`, `thin`, `medium`, `thick`) and `outline-offset` (signed) size the ring Button, ConfirmButton, Selectable and Radio draw on keyboard focus, from their `:focus-visible` rules. Keyboard focus always keeps a ring, so `outline: none` changes nothing (`css_tool check` says so).
|
||||
- Borders & shape: `border` (`width` or `thin`/`medium`/`thick`, `solid` or `none`, `color`), `border-width`, `border-style` (`solid` | `none`), `border-radius`, `opacity` (unitless number or clamped `0%`–`100%`).
|
||||
- Per-side borders on `Row`, `Column` and `Grid`: `border-top|right|bottom|left` and the logical `border-block-start|end` and `border-inline-start|end`, each with `-width`, `-color` and `-style`, for dividers, accent bars and tab underlines. A side without its own width or color takes the uniform `border`, and a uniform border later in the same rule clears earlier sides. The sides paint as square bands inside the box; with a `border-radius` the box paints only its uniform border, and `css_tool check` reports it.
|
||||
- Spacing & sizing: `padding` (1–4 values; top/bottom and left/right must be equal), `padding-inline`, `padding-block`, `gap` (one value for both axes or two values in `row column` order), `row-gap`, `column-gap` (`Row` reads `column-gap`, `Column` reads `row-gap`, uniform-gap controls read the first `gap` value; accepts `normal` = 0 or nonnegative `px`/`rem`), `min-height`, `min-block-size` (logical alias for `min-height`; a percentage only on `Row`, `Column` and `Grid`), `translate` (`x [y]`).
|
||||
- Spacing & sizing: `padding` (1–4 values; top/bottom and left/right must be equal), `padding-inline`, `padding-block`, `gap` (one value for both axes or two values in `row column` order), `row-gap`, `column-gap` (`Row` reads `column-gap`, `Column` reads `row-gap`, uniform-gap controls read the first `gap` value; accepts `normal` = 0 or nonnegative `px`/`rem`), `min-height`, `min-block-size` (logical alias for `min-height`; a percentage only on `Row`, `Column` and `Grid`).
|
||||
- Retained `Row`, `Column` and `Grid` also accept `width` and `height` as positive `px` or `rem` lengths, a percentage, or `auto`. Other size expressions pass through to the browser.
|
||||
- Percentages refer to the parent's content box (a grid child's track for widths), as in CSS: `width: 50%` is half the parent's inner width, and a percent height in a parent that sizes to its content computes to `auto`. `flex-basis` percentages share a measured flex row's inner width. A percentage mixed with other units in `calc()`, `min()`, `max()` or `clamp()` stays in the browser; write `width: 100%` with a `max-width`, or `flex: 1`, instead.
|
||||
- Box: `Row`, `Column` and `Grid` read `min-width`/`min-inline-size`, `max-width`/`max-inline-size` and `max-height`/`max-block-size` (`px`, `rem`, `0`, a percentage, or `none` for maxima), `margin` (1–4 values), `margin-top|right|bottom|left`, `margin-inline`, `margin-block`, `margin-inline-start|end` (`px`, `rem`, `0` or `auto`; `auto` inline margins share the free width, so `margin: 0 auto` centers), and `overflow` (`visible`, or `hidden`/`clip` to clip descendants). A container placed at explicit `x`/`y` ignores margins. Negative and percentage margins and `overflow: auto|scroll` stay in the browser; use `Scroll.Draw` for native scrolling.
|
||||
- Transforms: `transform` (`translate()`, `scale()`, `rotate()` and their X and Y forms, in any order that does not shear), `scale`, `rotate` and `transform-origin` (the box center unless set). They apply when Kryon paints, on every host, to `Row`, `Column`, `Grid`, `Button`, `Card`, `Text`, `Heading`, `Link` and `Image` nodes and to everything inside them; layout and pointer hit areas keep the untransformed box. `:hover` and `:active` follow the pointer, so `.card:hover { transform: translateY(-2px) }` works, and `transition: transform 150ms` (or `all`) eases the change. A transform rule matches its node by type, class, id and state; an ancestor or `:first-child` in its selector does not apply. A whole-pixel translation paints exactly as without it. A scale or rotation draws boxes as triangles, text at the nearest whole font size, and images scaled and turned; a widget that rasterizes by itself (a Scene, a custom emitter) ignores it. Transforms are opt-in paint code: an app whose styles set one imports `kryon/paint_transform` and calls `PaintTransformInstall()` once before its first frame, and installing a sheet with a transform without it fails with that instruction. An app that never calls it links none of the code.
|
||||
- Transforms: `transform` (`translate()`, `scale()`, `rotate()` and their X and Y forms, in any order that does not shear), `translate` (`x [y]`, which moves the whole box after the others), `scale`, `rotate` and `transform-origin` (the box center unless set). They apply when Kryon paints, on every host, to `Row`, `Column`, `Grid`, `Button`, `Card`, `Text`, `Heading`, `Link` and `Image` nodes and to everything inside them; layout and pointer hit areas keep the untransformed box. `:hover` and `:active` follow the pointer, so `.card:hover { translate: 0 -2px }` works, and `transition: translate 150ms` (or `transform`, or `all`) eases the change. A transform rule matches its node by type, class, id and state; an ancestor or `:first-child` in its selector does not apply. A whole-pixel translation paints exactly as without it. A scale or rotation draws boxes as triangles, text at the nearest whole font size, and images scaled and turned; a widget that rasterizes by itself (a Scene, a custom emitter) ignores it. Transforms are opt-in paint code: an app whose styles set one imports `kryon/paint_transform` and calls `PaintTransformInstall()` once before its first frame, and installing a sheet with a transform without it fails with that instruction. An app that never calls it links none of the code.
|
||||
- Text: `text-align` (`start`/`left`, `center`, `end`/`right`) on `Text`, `Heading`, `ParagraphText` and `Link`; an explicit `Text.Props.align` wins.
|
||||
- Use `border-color: var(--line)` and `border-width` for typed border variables.
|
||||
- Typography: `font-size`, `font-family`; native `Text`, `Heading`, and `ParagraphText` read `font-weight` (`normal` = 400, `bold` = 700, or `1`–`1000`), `font-style` (`normal` | `italic` | `oblique` without angle), and `letter-spacing` (`normal` or signed `px` / `rem`); `Text` and `Button` accept `line-height` (`normal`, nonnegative unitless factor, `%` of font size, or nonnegative `px` / `rem`).
|
||||
- Kryon extensions: `-kryon-material` (`lightfield` | `flat` | `glass`), `-kryon-icon-size`, `-kryon-font-role` (`inherit` | `control` | `body` | `heading` | `code`), `-kryon-elevation` (`none` | `rest` | `raised` | `floating`), `-kryon-motion-duration`, `-kryon-motion-multiplier`, `-kryon-motion-easing` (`inherit` | `standard` | `linear` | `instant`), `-kryon-motion-reduced` (`reduce` | `no-preference`).
|
||||
- Kryon extensions: `-kryon-material` (`lightfield` | `flat` | `glass`), `-kryon-icon-size`, `-kryon-content-offset` (`x [y]`: a widget part's offset or metric, such as a NavigationBar panel's width), `-kryon-font-role` (`inherit` | `control` | `body` | `heading` | `code`), `-kryon-elevation` (`none` | `rest` | `raised` | `floating`), `-kryon-motion-duration`, `-kryon-motion-multiplier`, `-kryon-motion-easing` (`inherit` | `standard` | `linear` | `instant`), `-kryon-motion-reduced` (`reduce` | `no-preference`).
|
||||
- **Units & values**: hex (`#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`), CSS named colors, `rgb()`, `rgba()`, `hsl()`, `hsla()`, `hwb(hue white% black% [/ alpha])`, hue angle units (`deg`, `rad`, `grad`, `turn`), `px`, `rem` (`16px`), `s`, `ms`, `em` (the rule's font-size, else 16px), `vw`, `vh`, `calc()`, `min()`, `max()`, `clamp()`, `:root` custom properties (`--token: ...;`) with `var(--token, fallback)` whose fallback may be one more `var()`, and `var(--kryon-surface)`-style theme colors (`background`, `surface`, `text`, `muted`, `border`, `accent`, `success`, `warning`, `danger` and more). `%` sizes as above; other `%` lengths are refused. The full property table is generated from the parser in the CSS package README.
|
||||
- **At-rules**: `@import` (before rules), `@layer`, `@keyframes`, `@media` (`prefers-color-scheme`, `prefers-contrast`, `prefers-reduced-motion`, `pointer`, `width`, `min-width`, `max-width`, `-kryon-theme`, `-kryon-density`, `-kryon-pointer`, `-kryon-platform`).
|
||||
- **Browser-only layout and paint** includes grid declarations outside the native track subset, radial, conic and repeating gradients (Kryon backends have no such paint primitive), skew, `matrix()` and 3D transforms, `text-decoration`, `text-transform`, `white-space`, `cursor`, `z-index` and `visibility`. A plain `CssSheetParse` refuses them; read a sheet shared with the browser export through `CssSheetParseWithDiagnostics`, which reports them. CSS `display` maps to an authored native flex or grid container. `wrap-reverse`, intrinsic flex bases, baseline alignment, and cross-line distribution remain browser-only.
|
||||
|
||||
@@ -22,11 +22,11 @@ PaintMatrix :: struct {
|
||||
// A node's CSS transform about its origin. `values` holds the translation,
|
||||
// rotation (degrees) and x and y scale of `transform`, applied to a point
|
||||
// scale first, then the rotation and x and y scale of the `rotate` and
|
||||
// `scale` properties. A percent origin is a percentage of the node's box.
|
||||
// `scale` properties, then the x and y of the `translate` property. A percent origin is a percentage of the node's box.
|
||||
// With `seconds` above zero a change of values eases over that time along
|
||||
// the cubic-bezier `timing` (all zero is linear).
|
||||
NodeTransform :: struct {
|
||||
values: [8]float32
|
||||
values: [10]float32
|
||||
origin: Vector2
|
||||
origin_percent_x: bool
|
||||
origin_percent_y: bool
|
||||
|
||||
+17
-10
@@ -33,7 +33,7 @@ TransformEntry :: struct {
|
||||
origin: Vector2
|
||||
origin_percent_x: bool
|
||||
origin_percent_y: bool
|
||||
values: [8]float32
|
||||
values: [10]float32
|
||||
}
|
||||
|
||||
TransformNodeLimit :: 32
|
||||
@@ -50,8 +50,8 @@ TransformFrame :: struct {
|
||||
|
||||
// The easing of one node's values from where they were to their target.
|
||||
TransformRow :: struct {
|
||||
from: [8]float32
|
||||
target: [8]float32
|
||||
from: [10]float32
|
||||
target: [10]float32
|
||||
started: float64
|
||||
seconds: float64
|
||||
timing: Motion.Timing
|
||||
@@ -68,7 +68,7 @@ TransformAbs :: (value: float32) -> float32 {
|
||||
return ifx value < 0.0 then -value else value
|
||||
}
|
||||
|
||||
TransformSample :: (row: *TransformRow, now: float64) -> [8]float32 {
|
||||
TransformSample :: (row: *TransformRow, now: float64) -> [10]float32 {
|
||||
if !row.running { return row.target }
|
||||
progress: float32 = 1.0
|
||||
if row.seconds > 0.0 { progress = cast(float32)((now - row.started) / row.seconds) }
|
||||
@@ -78,14 +78,14 @@ TransformSample :: (row: *TransformRow, now: float64) -> [8]float32 {
|
||||
}
|
||||
if progress < 0.0 { progress = 0.0 }
|
||||
eased := Motion.Progress(row.timing, progress)
|
||||
result: [8]float32
|
||||
for index: 0..7 { result[index] = row.from[index] + (row.target[index] - row.from[index]) * eased }
|
||||
result: [10]float32
|
||||
for index: 0..9 { result[index] = row.from[index] + (row.target[index] - row.from[index]) * eased }
|
||||
return result
|
||||
}
|
||||
|
||||
// The values to paint this frame: the target, or a point on the way to it
|
||||
// while the node's transition runs.
|
||||
TransformEase :: (session: Session, node: s32, value: NodeTransform) -> [8]float32 {
|
||||
TransformEase :: (session: Session, node: s32, value: NodeTransform) -> [10]float32 {
|
||||
target := value.values
|
||||
identity := TreeSubmittedIdentity(session, node)
|
||||
if identity == 0 { return target }
|
||||
@@ -98,7 +98,7 @@ TransformEase :: (session: Session, node: s32, value: NodeTransform) -> [8]float
|
||||
if MotionHistoryRead(history, identity, *row) {
|
||||
current = TransformSample(*row, now)
|
||||
changed := false
|
||||
for index: 0..7 {
|
||||
for index: 0..9 {
|
||||
if row.target[index] != target[index] { changed = true }
|
||||
}
|
||||
if changed {
|
||||
@@ -128,7 +128,7 @@ PaintTransformSet :: (session: Session, node: s32, value: NodeTransform) {
|
||||
frame := *transform_frames[SessionIndex(session)]
|
||||
values := TransformEase(session, node, value)
|
||||
if values[0] == 0.0 && values[1] == 0.0 && values[2] == 0.0 && values[3] == 1.0 && values[4] == 1.0 &&
|
||||
values[5] == 0.0 && values[6] == 1.0 && values[7] == 1.0 { return }
|
||||
values[5] == 0.0 && values[6] == 1.0 && values[7] == 1.0 && values[8] == 0.0 && values[9] == 0.0 { return }
|
||||
if frame.count >= TransformNodeLimit { return }
|
||||
if frame.count == 0 || node < frame.first { frame.first = node }
|
||||
frame.entries[frame.count] = .{.node = node, .origin = value.origin,
|
||||
@@ -180,6 +180,9 @@ TransformNodeMatrix :: (session: Session, entry: TransformEntry) -> TransformMap
|
||||
// About the origin: bring it to zero, map, and bring it back.
|
||||
map.matrix.tx += ox - (map.matrix.a * ox + map.matrix.c * oy)
|
||||
map.matrix.ty += oy - (map.matrix.b * ox + map.matrix.d * oy)
|
||||
// The translate property moves the result; the origin does not matter.
|
||||
map.matrix.tx += entry.values[8]
|
||||
map.matrix.ty += entry.values[9]
|
||||
return map
|
||||
}
|
||||
|
||||
@@ -342,7 +345,7 @@ TransformNodes :: (session: Session) {
|
||||
*box, cast(u32)StyleBoxTransformFields)
|
||||
if (box.fields & cast(u32)StyleBoxTransformFields) == 0 { continue }
|
||||
value: NodeTransform
|
||||
value.values = float32.[0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0]
|
||||
value.values = float32.[0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0]
|
||||
if (box.fields & cast(u32)StyleBoxTransform) != 0 {
|
||||
for part: 0..4 { value.values[part] = box.transform[part] }
|
||||
}
|
||||
@@ -351,6 +354,10 @@ TransformNodes :: (session: Session) {
|
||||
value.values[6] = box.scale[0]
|
||||
value.values[7] = box.scale[1]
|
||||
}
|
||||
if (box.fields & cast(u32)StyleBoxTranslate) != 0 {
|
||||
value.values[8] = box.translate[0]
|
||||
value.values[9] = box.translate[1]
|
||||
}
|
||||
value.origin = .{50.0, 50.0}
|
||||
value.origin_percent_x = true
|
||||
value.origin_percent_y = true
|
||||
|
||||
+10
-6
@@ -439,13 +439,15 @@ StyleBoxField :: enum {
|
||||
// corner, stops and middle colors (the face holds the first and last).
|
||||
StyleBoxGradient :: 524288
|
||||
// CSS transform, the rotate and scale properties, the transform origin
|
||||
// on each axis, and the transition a change of them eases over.
|
||||
// on each axis, the transition a change of them eases over, and the
|
||||
// translate property.
|
||||
StyleBoxTransform :: 1048576
|
||||
StyleBoxRotate :: 2097152
|
||||
StyleBoxScale :: 4194304
|
||||
StyleBoxOriginX :: 8388608
|
||||
StyleBoxOriginY :: 16777216
|
||||
StyleBoxTransformMotion :: 33554432
|
||||
StyleBoxTranslate :: 67108864
|
||||
}
|
||||
using StyleBoxField;
|
||||
|
||||
@@ -485,7 +487,7 @@ StyleBoxData :: struct {
|
||||
gradient_colors: [4]u32
|
||||
// `transform` as a translation, a rotation in degrees and an x and y
|
||||
// scale, applied to a point scale first; then the `rotate` and `scale`
|
||||
// properties. The origin is in logical pixels, or with its percent bit
|
||||
// properties, then the `translate` property's x and y. The origin is in logical pixels, or with its percent bit
|
||||
// a percentage of the box (50% of each side when unset). The paint
|
||||
// transform pass (paint_transform) reads these for each node; layout
|
||||
// never does.
|
||||
@@ -497,14 +499,15 @@ StyleBoxData :: struct {
|
||||
// cubic-bezier curve, in hundredths; all zero is linear.
|
||||
transform_seconds: float32
|
||||
transform_timing: [4]u8
|
||||
translate: [2]float32
|
||||
}
|
||||
|
||||
// Every box field but text-align, which only Text reads.
|
||||
StyleBoxContainerFields :: 655343
|
||||
// Transform, rotate, scale, their origin and their transition; then only
|
||||
// the three that set a transform.
|
||||
StyleBoxTransformFields :: 66060288
|
||||
StyleBoxTransformSets :: 7340032
|
||||
// Transform, rotate, scale, translate, their origin and their transition;
|
||||
// then only the four that set a transform.
|
||||
StyleBoxTransformFields :: 133169152
|
||||
StyleBoxTransformSets :: 74448896
|
||||
// The per-side border widths and colors.
|
||||
StyleBoxBorderSides :: 130560
|
||||
StyleBoxOutlineFields :: 393216
|
||||
@@ -1347,6 +1350,7 @@ ApplyBoxFields :: (target: *StyleBoxData, value: *StyleBoxData, fields: u32) {
|
||||
if (fields & cast(u32)StyleBoxTransform) != 0 { target.transform = value.transform }
|
||||
if (fields & cast(u32)StyleBoxRotate) != 0 { target.rotate = value.rotate }
|
||||
if (fields & cast(u32)StyleBoxScale) != 0 { target.scale = value.scale }
|
||||
if (fields & cast(u32)StyleBoxTranslate) != 0 { target.translate = value.translate }
|
||||
if (fields & cast(u32)StyleBoxOriginX) != 0 { target.transform_origin[0] = value.transform_origin[0] }
|
||||
if (fields & cast(u32)StyleBoxOriginY) != 0 { target.transform_origin[1] = value.transform_origin[1] }
|
||||
if (fields & cast(u32)StyleBoxTransformMotion) != 0 {
|
||||
|
||||
Reference in new issue
Block a user