feat(ui): number and key fields, notes, anchored popovers, text-shadow, and pictures as painted
- <input type="number" min max step>: typed digits replace its value (a minus when min allows one, a point when step has a fraction), Enter or leaving the field commits them held between min and max, the left and right arrows step it. - <input type="key">: Enter or a click starts it listening and the next key is its value, Tab, the arrows and Enter included; Esc stops it listening, Backspace clears it, `shown` names the value, and ui_capturing() tells the host to leave its keys alone (through the frame that ended it). - note="..." under any control's label (.ui-labels > .ui-label + .ui-note); a range's (or number's) value with decimals, format="percent" and a unit. - A popover with `anchor="id"` (the nearest element of that id) or a bare `anchor` (the element before it) sits beside it by `placement` (right, left, bottom, top), its margin the gap, opens to the other side where it would leave the screen, and is kept on it. - A tooltip's title splits into lines at a newline or a written \n. - text-shadow, inherited, drawn sharp under the text. - ui_opacity(): the group opacity a native's draw is at. - border-image is drawn as painted with no background colour, tinted by one, and not at all when that colour is transparent (it drew a white nine-slice). - A picture file is drawn untinted, as a browser draws one; an atlas cell (prefix:name) still takes the color around it, and an <img> with its own color is tinted by it. - The render3d backend loads a picture again when its file changes or appears (a failed load was kept for ever), and at once after ui_image_reload(path); takes a path with a drive letter (C:/...) as a path rather than an atlas; and slices a nine-slice by its texture's own width and height. - ui_inputs.ludic and ui_look.ludic; LANGUAGE.md and the changeset say all of it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
7d8f34de17
commit
9f59000f5b
39 changed files with 732 additions and 75 deletions
|
|
@ -1,8 +1,7 @@
|
|||
# controls.ludic - what a control does: a button (or anything with on-click) is pressed, a checkbox
|
||||
# flips, a radio chooses its value, a select steps through its options, a range moves by its step
|
||||
# (or to where the pointer is on its track), a text field takes what is typed, a key field the next
|
||||
# key. Each says so with on-change and event.value, after the frame is drawn.
|
||||
var ct_capture: string = ""
|
||||
# (or to where the pointer is on its track), a text field takes what is typed, a number field its
|
||||
# digits, a key field the next key. Each says so with on-change and event.value, after the frame is drawn.
|
||||
function ct_type(n: UiNode) -> string {
|
||||
if n.tag == "select" { return "select" }
|
||||
if n.tag != "input" { return "" }
|
||||
|
|
@ -10,7 +9,7 @@ function ct_type(n: UiNode) -> string {
|
|||
if t == "" { return "text" }
|
||||
return t
|
||||
}
|
||||
function ct_takes_arrows(n: UiNode) -> bool { return ct_type(n) == "range" or ct_type(n) == "select" }
|
||||
function ct_takes_arrows(n: UiNode) -> bool { return ct_type(n) == "range" or ct_type(n) == "select" or ct_type(n) == "number" }
|
||||
function ct_takes_space(n: UiNode) -> bool { return ct_type(n) == "text" }
|
||||
function ct_change(n: UiNode, v: Val) -> void {
|
||||
ui_sound(ct_sound(n))
|
||||
|
|
@ -24,7 +23,7 @@ function ct_sound(n: UiNode) -> string {
|
|||
function ct_activate(n: UiNode) -> void {
|
||||
if not n.enabled { return }
|
||||
let t = ct_type(n)
|
||||
if t == "checkbox" { ct_change(n, vl_bool(not ui_attr_on(n, "checked"))) } else if t == "radio" { ct_change(n, ui_attr(n, "value")) } else if t == "select" { ct_step(n, 1) } else if t == "key" { ct_capture = n.key } else if t == "" {
|
||||
if t == "checkbox" { ct_change(n, vl_bool(not ui_attr_on(n, "checked"))) } else if t == "radio" { ct_change(n, ui_attr(n, "value")) } else if t == "select" { ct_step(n, 1) } else if t == "key" { ct_key_start(n) } else if t == "number" { ct_num_commit(n) } else if t == "" {
|
||||
ui_sound(ct_sound(n))
|
||||
ui_fire(n, "press", Value.null())
|
||||
}
|
||||
|
|
@ -36,6 +35,7 @@ function ct_step(n: UiNode, d: int) -> void {
|
|||
let ov = ui_attr(n.opts[at], "value")
|
||||
if Value.kind(ov) == 0 { ct_change(n, Value.int(at)) } else { ct_change(n, ov) }
|
||||
}
|
||||
if t == "number" { ct_num_step(n, d) }
|
||||
if t == "range" {
|
||||
var step = Value.as_float(ui_attr(n, "step"))
|
||||
if step <= 0.0 { step = 1.0 }
|
||||
|
|
@ -70,11 +70,8 @@ function ct_drag(root: UiNode, key: string, x: float, y: float) -> void {
|
|||
# typing into a focused text field, or the key a key field is waiting for
|
||||
function ct_typed(n: UiNode) -> void {
|
||||
let t = ct_type(n)
|
||||
if t == "key" and ct_capture == n.key and in_now.key != 0 and not in_now.enter {
|
||||
ct_capture = ""
|
||||
ct_change(n, Value.int(in_now.key))
|
||||
return
|
||||
}
|
||||
if t == "key" { ct_key_typed(n) }
|
||||
if t == "number" { ct_num_typed(n) }
|
||||
if t != "text" or (in_now.typed == "" and not in_now.backspace) { return }
|
||||
var s = ui_attr_text(n, "value")
|
||||
if in_now.backspace and len(s) > 0 { s = s[0..ct_char_start(s)] }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue