feat(ui): flex-shrink, text that wraps beside its siblings, calc(), order, and 0 as a size
- flex-shrink: a line whose children want more room than it has takes it back from those that shrink, in proportion to shrink times size and never below a min size, a fixed size or the content. A scroll box shrinks (and scrolls), and a box in a column shrinks as far as the scroll boxes inside it let it, so a list in a column takes the room its siblings leave with no height. `flex: grow shrink`, and `flex-shrink` by name. - A row wider than its room measures its texts (and boxes without a width) again in the room the rest leave them, so a line wraps beside an icon. - calc() with + - * / and brackets over px, %, em, rem, vw, vh, plain numbers and var(); a width or height keeps its percentage, taken of the room it is given. Lengths lists (padding, margin) keep a calc()'s spaces. - `order` places a box's children without touching the tree. - width: 0 and height: 0 are 0: an unset size is UI_AUTO now, not 0. - A component root that is itself a component takes each user's class, style and id in turn (the outermost's id wins), and the rules of all their sheets are weighed by specificity together; a user's rule wins a tie. The parent's sheet used to override the child's whatever its specificity, and a middle component's sheet was lost. - The default sheet lays .ui-track out as a row, so a range's fill is as tall as its track and a checked box's knob goes right; a range's thumb is centred on the fill's end. - ui_boxes.ludic. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
9ad6347044
commit
7d8f34de17
23 changed files with 609 additions and 94 deletions
69
packages/ludic.ui/calc.ludic
Normal file
69
packages/ludic.ui/calc.ludic
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
# calc.ludic - CSS's calc(): + - * / and brackets over lengths (px, em, rem, vw, vh, or a bare
|
||||
# number, which is px as everywhere here), percentages and plain numbers; var() is already read by
|
||||
# then. A width or height keeps its percentage apart (w_pct plus an offset) to be taken of the room
|
||||
# the element is given; anywhere else a percentage in calc() has nothing to be a share of.
|
||||
var ca_s: string = ""
|
||||
var ca_i: int = 0
|
||||
var ca_bad: string = ""
|
||||
var ca_px: float = 0.0 # the result: its lengths, its percentage, and whether it had units
|
||||
var ca_pct: float = 0.0
|
||||
function ca_is(s: string) -> bool { return len(s) > 5 and s[0..5] == "calc(" }
|
||||
# calc(...) worked out into ca_px and ca_pct; false (with the reason said) when it cannot be
|
||||
function ca_eval(s: string) -> bool {
|
||||
ca_s = s[5..len(s)]
|
||||
ca_i = 0
|
||||
ca_bad = ""
|
||||
let v = ca_sum()
|
||||
ca_ws()
|
||||
if ca_bad == "" and (ca_i >= len(ca_s) or ca_s[ca_i] != 41) { ca_bad = "a closing )" }
|
||||
if ca_bad != "" {
|
||||
ui_err(`{s}: calc() expected {ca_bad}`)
|
||||
return false
|
||||
}
|
||||
ca_px = v.px
|
||||
ca_pct = v.pct
|
||||
if v.bare { ca_px = ui_px(v.n) }
|
||||
return true
|
||||
}
|
||||
property CaVal {
|
||||
px: float = 0.0
|
||||
pct: float = 0.0
|
||||
n: float = 0.0
|
||||
bare: bool = true # a plain number, which may scale a length
|
||||
}
|
||||
function ca_ws() -> void {
|
||||
while ca_i < len(ca_s) and (ca_s[ca_i] == 32 or ca_s[ca_i] == 9 or ca_s[ca_i] == 10) { ca_i += 1 }
|
||||
}
|
||||
function ca_sum() -> CaVal {
|
||||
var a = ca_product()
|
||||
while ca_bad == "" {
|
||||
ca_ws()
|
||||
if ca_i >= len(ca_s) or (ca_s[ca_i] != 43 and ca_s[ca_i] != 45) { return a }
|
||||
let minus = ca_s[ca_i] == 45
|
||||
ca_i += 1
|
||||
let b = ca_product()
|
||||
a = ca_add(a, b, minus)
|
||||
}
|
||||
return a
|
||||
}
|
||||
function ca_add(a: CaVal, b: CaVal, minus: bool) -> CaVal {
|
||||
var sign = 1.0
|
||||
if minus { sign = -1.0 }
|
||||
let r = new CaVal
|
||||
if a.bare and b.bare {
|
||||
r.n = a.n + sign * b.n
|
||||
return r
|
||||
}
|
||||
r.bare = false
|
||||
r.px = ca_len(a).px + sign * ca_len(b).px
|
||||
r.pct = a.pct + sign * b.pct
|
||||
return r
|
||||
}
|
||||
# a bare number beside a length is a length in px
|
||||
function ca_len(a: CaVal) -> CaVal {
|
||||
if not a.bare { return a }
|
||||
let r = new CaVal
|
||||
r.bare = false
|
||||
r.px = ui_px(a.n)
|
||||
return r
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue