Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1e1ed45f98 | ||
|
|
d15ee43112 | ||
|
|
f217b6b9c0 | ||
|
|
1a8a4b20db | ||
|
|
48c8aaeeaf | ||
|
|
eff4ba2a51 | ||
|
|
dd49b16e8e | ||
|
|
950f1c8213 | ||
|
|
a1c250d8fa | ||
|
|
3390e82f26 | ||
|
|
e8927a64e2 | ||
|
|
1d3f6e8970 | ||
|
|
0a7ed6f644 | ||
|
|
ed4f6beb35 | ||
|
|
48ca968449 | ||
|
|
25a11d5c7d | ||
|
|
656be6175f | ||
|
|
cc20902756 |
No files matched your search
@@ -1,4 +1,37 @@
|
||||
# Changelog
|
||||
## v0.1.78 - 2026-09-07
|
||||
|
||||
### Changed
|
||||
|
||||
- Release: bump version to v0.1.78
|
||||
- Add multiline TextArea page navigation
|
||||
|
||||
## v0.1.77 - 2026-09-07
|
||||
|
||||
### Changed
|
||||
|
||||
- Release: bump version to v0.1.77
|
||||
- Restore premultiplied paint layer compositing
|
||||
- Make tab capacity audit resilient to dropped clicks
|
||||
- Clean up default button rendering
|
||||
- Open numeric editors on double click
|
||||
|
||||
## v0.1.76 - 2026-09-07
|
||||
|
||||
### Changed
|
||||
|
||||
- Release: bump version to v0.1.76
|
||||
- Add temporary input to numeric controls
|
||||
|
||||
## v0.1.75 - 2026-09-07
|
||||
|
||||
### Changed
|
||||
|
||||
- Release: bump version to v0.1.75
|
||||
- Enforce premultiplied paint layer output
|
||||
- Highlight Kry directives in text areas
|
||||
- Keep paint layer text on straight alpha
|
||||
|
||||
## v0.1.74 - 2026-09-07
|
||||
|
||||
### Changed
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
This audit compares Kryon's clean native widget surface with Dear ImGui
|
||||
`imgui.h` at commit
|
||||
[`53d421955fdb658e75b039b8210841ad691dafd1`](https://github.com/ocornut/imgui/commit/53d421955fdb658e75b039b8210841ad691dafd1)
|
||||
(`IMGUI_VERSION_NUM` 19295, `1.93.0 WIP`). It tracks widget behavior rather
|
||||
[`334f484892a1fa881d2a927c2aff222c15458b8f`](https://github.com/ocornut/imgui/commit/334f484892a1fa881d2a927c2aff222c15458b8f)
|
||||
(`IMGUI_VERSION_NUM` 19296, `1.93.0 WIP`). It tracks widget behavior rather
|
||||
than copying overload names: Kryon's counted value arrays cover the ImGui
|
||||
`*2`, `*3`, `*4`, `Scalar`, and `ScalarN` fronts without adding aliases.
|
||||
|
||||
@@ -20,8 +20,8 @@ implemented combo scope and its remaining lifecycle/backend gaps.
|
||||
| Progress and links | `Progress`, `Href` | covered; `Href` represents both clickable text and open-URL links |
|
||||
| Images | `Picture`, `ImageWithBg`, `ImageButton` | covered; `ImageButton` shares ordinary focus and keyboard activation |
|
||||
| Combo boxes | `Combobox`, `Dropdown`, `Selectable`, `BeginCombo` / `EndCombo` / `CloseCombo` | option-list helper plus a native arbitrary-child scope with explicit close and presentation flags |
|
||||
| Drag values | `DragFloat`, `DragInt`, `DragFloatRange2`, `DragIntRange2` | covered, including counted N-component values, component focus/Tab traversal, Left/Right adjustment, Home/End bounds, and Shift/Alt step modifiers |
|
||||
| Sliders | `SliderFloat`, `SliderInt`, `VSliderFloat`, `VSliderInt`, `SliderAngle` | counted N-component values, component focus, arrow/Home/End keyboard adjustment, and slow/fast modifiers are covered |
|
||||
| Drag values | `DragFloat`, `DragInt`, `DragFloatRange2`, `DragIntRange2` | covered, including counted N-component values, component focus/Tab traversal, Left/Right adjustment, Home/End bounds, Shift/Alt step modifiers, and Ctrl-click/double-click temporary keyboard entry |
|
||||
| Sliders | `SliderFloat`, `SliderInt`, `VSliderFloat`, `VSliderInt`, `SliderAngle` | counted N-component values, component focus, arrow/Home/End keyboard adjustment, slow/fast modifiers, and Ctrl-click/double-click temporary keyboard entry are covered |
|
||||
| Keyboard inputs | `TextField`, `TextArea`, `InputFloat`, `InputInt`, `InputDouble` | covered, including hints and counted N-component values |
|
||||
| Color editors and pickers | `ColorEdit3`, `ColorEdit4`, `ColorPicker3`, `ColorPicker4`, `ColorButton` | covered; `ColorButton` shares ordinary focus and keyboard activation |
|
||||
| Trees and collapsing headers | `TreeView`, `Collapsible` | `Collapsible` supports tree styling, depth indentation, leaves, selected/disabled state, optional close/visibility state, arbitrary nested children, keyboard expansion, and directional header/parent/child focus traversal |
|
||||
@@ -79,6 +79,11 @@ gates keyboard input, and the focused component receives the ordinary focus
|
||||
presentation. Matching native tests cover component Tab traversal and the
|
||||
generated `plots.kry` fixture verifies horizontal float and vertical integer
|
||||
adjustment through k2c and k2go.
|
||||
Ctrl-clicking or double-clicking a drag or slider component temporarily
|
||||
replaces that component with the canonical text editor in native C and Go. Valid edits update live,
|
||||
Enter returns to the numeric control, and typed values remain unclamped like
|
||||
Dear ImGui's default temporary-input behavior. The generated `plots.kry`
|
||||
fixture exercises Ctrl-click and double-click entry through k2c and k2go.
|
||||
|
||||
Native Go now constrains and flips long dropdowns using the same placement
|
||||
rules as C, reusing its ordinary scroll container for clipping, wheel input and
|
||||
@@ -253,6 +258,13 @@ deletion and IME commits cannot mutate buffers. C retained mutation paths now
|
||||
enforce the property; Go text props expose ReadOnly and retain focus styling
|
||||
while suppressing the insertion caret. Go tests cover preedit cancellation,
|
||||
buffer preservation, rejected-input expiry and fresh editing after re-enabling.
|
||||
Multiline TextArea navigation now handles Up/Down and PageUp/PageDown in native
|
||||
C and Go, with page movement derived from the visible editor height. The C
|
||||
immediate and retained paths share the same internal line/page movement helpers,
|
||||
so generated code no longer loses vertical navigation when submitted through
|
||||
the retained tree. Enter inserts a newline in Go TextArea instead of following
|
||||
the single-line commit path. Direct runtime tests and the generated composition
|
||||
fixture exercise these behaviors through k2c and k2go.
|
||||
|
||||
Native C and Go list boxes now register with ordinary Tab focus, expose a
|
||||
visible focus presentation, and move selection with Up/Down/Home/End while
|
||||
|
||||
@@ -1004,6 +1004,93 @@ func TestNativeDragScalars(t *testing.T) {
|
||||
r.EndFrame()
|
||||
}
|
||||
|
||||
func TestNumericDragAndSliderCtrlClickEditing(t *testing.T) {
|
||||
r := New(AppConfig{Width: 480, Height: 240}).(*runtime)
|
||||
floats := []float32{2.5}
|
||||
drag := DragFloatProps{Bounds: NewRectangle(10, 10, 120, 30), ID: 520,
|
||||
Values: floats, ValueCount: 1, Speed: 0.1, Min: 0, Max: 10}
|
||||
|
||||
r.QueueKey(KeyLeftControl)
|
||||
r.QueueTap(40, 20)
|
||||
r.BeginFrame()
|
||||
if r.DragFloat(drag) || floats[0] != 2.5 {
|
||||
t.Fatalf("Ctrl-click changed drag value before editing: %v", floats)
|
||||
}
|
||||
r.EndFrame()
|
||||
foundEditor := false
|
||||
for _, op := range r.FrameOps() {
|
||||
if op.Kind == FrameOpTextField && op.FocusID == 520 && op.Focused {
|
||||
foundEditor = true
|
||||
}
|
||||
}
|
||||
if !foundEditor {
|
||||
t.Fatal("Ctrl-click did not replace drag cell with a focused editor")
|
||||
}
|
||||
|
||||
r.QueueShortcut(KeyA)
|
||||
r.QueueText("7.25")
|
||||
r.BeginFrame()
|
||||
if !r.DragFloat(drag) || floats[0] != 7.25 {
|
||||
t.Fatalf("edited drag value=%v, want 7.25", floats)
|
||||
}
|
||||
r.EndFrame()
|
||||
r.QueueKey(KeyEnter)
|
||||
r.BeginFrame()
|
||||
r.DragFloat(drag)
|
||||
r.EndFrame()
|
||||
if r.numericInputs[numericInputKey{kind: numericEditDragFloat, widgetID: 520}].focused {
|
||||
t.Fatal("Enter did not finish drag keyboard entry")
|
||||
}
|
||||
|
||||
ints := []int32{4}
|
||||
slider := SliderIntProps{Bounds: NewRectangle(10, 60, 120, 30), ID: 521,
|
||||
Values: ints, ValueCount: 1, Min: 0, Max: 10}
|
||||
r.QueueKey(KeyLeftControl)
|
||||
r.QueueTap(40, 70)
|
||||
r.BeginFrame()
|
||||
r.SliderInt(slider)
|
||||
r.EndFrame()
|
||||
r.QueueShortcut(KeyA)
|
||||
r.QueueText("19")
|
||||
r.BeginFrame()
|
||||
if !r.SliderInt(slider) || ints[0] != 19 {
|
||||
t.Fatalf("temporary slider input should be unclamped: %v", ints)
|
||||
}
|
||||
r.EndFrame()
|
||||
|
||||
disabled := []int32{3}
|
||||
r.QueueKey(KeyLeftControl)
|
||||
r.QueueTap(40, 110)
|
||||
r.BeginFrame()
|
||||
r.DragInt(DragIntProps{Bounds: NewRectangle(10, 100, 120, 30), ID: 522,
|
||||
Values: disabled, ValueCount: 1, Min: 0, Max: 10, Disabled: true})
|
||||
r.EndFrame()
|
||||
state := r.numericInputs[numericInputKey{kind: numericEditDragInt, widgetID: 522}]
|
||||
if state != nil && state.focused {
|
||||
t.Fatal("disabled drag accepted Ctrl-click keyboard entry")
|
||||
}
|
||||
|
||||
doubleRuntime := New(AppConfig{Width: 240, Height: 120}).(*runtime)
|
||||
doubleValues := []int32{6}
|
||||
doubleDrag := DragIntProps{Bounds: NewRectangle(10, 10, 120, 30), ID: 523,
|
||||
Values: doubleValues, ValueCount: 1, Speed: 1, Min: 0, Max: 10}
|
||||
doubleRuntime.QueueTap(40, 20)
|
||||
doubleRuntime.BeginFrame()
|
||||
doubleRuntime.DragInt(doubleDrag)
|
||||
doubleRuntime.EndFrame()
|
||||
if state := doubleRuntime.numericInputs[numericInputKey{kind: numericEditDragInt, widgetID: 523}]; state != nil {
|
||||
t.Fatal("single click created a temporary drag editor")
|
||||
}
|
||||
doubleRuntime.QueueTap(40, 20)
|
||||
doubleRuntime.BeginFrame()
|
||||
doubleRuntime.DragInt(doubleDrag)
|
||||
doubleRuntime.EndFrame()
|
||||
state = doubleRuntime.numericInputs[numericInputKey{kind: numericEditDragInt, widgetID: 523}]
|
||||
if state == nil || !state.focused {
|
||||
t.Fatal("double-click did not open temporary drag editor")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNativeDragKeyboardNavigation(t *testing.T) {
|
||||
r := New(AppConfig{Width: 480, Height: 240}).(*runtime)
|
||||
floats := []float32{2, 5}
|
||||
|
||||
+261
-20
@@ -74,6 +74,8 @@ const (
|
||||
KeyLeft int32 = 263
|
||||
KeyDown int32 = 264
|
||||
KeyUp int32 = 265
|
||||
KeyPageUp int32 = 266
|
||||
KeyPageDown int32 = 267
|
||||
KeyHome int32 = 268
|
||||
KeyEnd int32 = 269
|
||||
KeyF2 int32 = 291
|
||||
@@ -1485,6 +1487,7 @@ type runtime struct {
|
||||
tableDrag tableDrag
|
||||
tableResize tableResize
|
||||
lastTabClick tabClick
|
||||
lastNumericClick numericClick
|
||||
tabDrag tabDrag
|
||||
tabScroll map[int32]int32
|
||||
tabBarsSeen map[int32]bool
|
||||
@@ -1608,6 +1611,12 @@ type tabClick struct {
|
||||
bounds Rectangle
|
||||
}
|
||||
|
||||
type numericClick struct {
|
||||
key numericInputKey
|
||||
x, y float32
|
||||
when time.Time
|
||||
}
|
||||
|
||||
type tabDrag struct {
|
||||
active bool
|
||||
id int32
|
||||
@@ -1633,6 +1642,13 @@ type numericInputState struct {
|
||||
focused bool
|
||||
}
|
||||
|
||||
const (
|
||||
numericEditDragFloat int32 = 3 + iota
|
||||
numericEditDragInt
|
||||
numericEditSliderFloat
|
||||
numericEditSliderInt
|
||||
)
|
||||
|
||||
type dragDropState struct {
|
||||
active bool
|
||||
sourceID int32
|
||||
@@ -2017,7 +2033,7 @@ func (r *runtime) textWithFont(props TextProps, fontID uint32) {
|
||||
}
|
||||
}
|
||||
func (r *runtime) TextFormat(format string, args ...any) string { return fmt.Sprintf(format, args...) }
|
||||
func (r *runtime) Scale(px int32) int32 { return px }
|
||||
func (r *runtime) Scale(px int32) int32 { return px }
|
||||
func (r *runtime) GetScreenWidth() int32 { return int32(r.config.Width) }
|
||||
func (r *runtime) GetScreenHeight() int32 { return int32(r.config.Height) }
|
||||
func (r *runtime) GetThemeBackground() Color { return r.theme().background }
|
||||
@@ -3163,6 +3179,15 @@ func (r *runtime) DragFloat(props DragFloatProps) bool {
|
||||
enabled := !props.Disabled && !r.contentDisabled()
|
||||
if enabled {
|
||||
r.registerField(focusID)
|
||||
}
|
||||
edited, editing := r.numericTempFloat(cell,
|
||||
numericInputKey{kind: numericEditDragFloat, widgetID: props.ID, component: int32(i)},
|
||||
focusID, props.Values, i, props.Format, props.Disabled)
|
||||
changed = changed || edited
|
||||
if editing {
|
||||
continue
|
||||
}
|
||||
if enabled {
|
||||
if next, keyboardChanged := r.dragFloatKeyboard(focusID, speed, props.Min, props.Max, props.Values[i]); keyboardChanged {
|
||||
props.Values[i] = next
|
||||
changed = true
|
||||
@@ -3212,6 +3237,15 @@ func (r *runtime) DragInt(props DragIntProps) bool {
|
||||
enabled := !props.Disabled && !r.contentDisabled()
|
||||
if enabled {
|
||||
r.registerField(focusID)
|
||||
}
|
||||
edited, editing := r.numericTempInt(cell,
|
||||
numericInputKey{kind: numericEditDragInt, widgetID: props.ID, component: int32(i)},
|
||||
focusID, props.Values, i, props.Format, props.Disabled)
|
||||
changed = changed || edited
|
||||
if editing {
|
||||
continue
|
||||
}
|
||||
if enabled {
|
||||
if next, keyboardChanged := r.dragIntKeyboard(focusID, speed, props.Min, props.Max, props.Values[i]); keyboardChanged {
|
||||
props.Values[i] = next
|
||||
changed = true
|
||||
@@ -3382,6 +3416,86 @@ func (r *runtime) drawDragLabel(bounds Rectangle, label string) {
|
||||
r.record(FrameOp{Kind: FrameOpText, Bounds: Rectangle{X: bounds.X + 6, Y: bounds.Y - 18, Width: bounds.Width - 12, Height: 16}, Text: label, Color: r.theme().text, FontSize: Text14})
|
||||
}
|
||||
|
||||
func (r *runtime) numericTempEdit(bounds Rectangle, key numericInputKey, focusID int32, formatted string, disabled bool) (*numericInputState, bool, bool) {
|
||||
enabled := !disabled && !r.contentDisabled()
|
||||
control := r.keyDown[KeyLeftControl] || r.keyDown[KeyRightControl]
|
||||
pressed := enabled && r.mousePressed[MouseButtonLeft] && r.hasTap(bounds)
|
||||
now := time.Now()
|
||||
dx := r.mousePos.X - r.lastNumericClick.x
|
||||
dy := r.mousePos.Y - r.lastNumericClick.y
|
||||
doubleClick := pressed && r.lastNumericClick.key == key &&
|
||||
now.Sub(r.lastNumericClick.when) <= 300*time.Millisecond &&
|
||||
dx >= -6 && dx <= 6 && dy >= -6 && dy <= 6
|
||||
activate := pressed && (control || doubleClick) && r.consumeTap(bounds)
|
||||
if pressed {
|
||||
r.lastNumericClick = numericClick{key: key, x: r.mousePos.X, y: r.mousePos.Y, when: now}
|
||||
if activate {
|
||||
r.lastNumericClick = numericClick{}
|
||||
}
|
||||
}
|
||||
state := r.numericInputs[key]
|
||||
if state == nil && !activate {
|
||||
return nil, false, false
|
||||
}
|
||||
if state == nil {
|
||||
state = r.numericInputState(key, formatted)
|
||||
}
|
||||
if !enabled && state.focused {
|
||||
state.focused = false
|
||||
if r.focusID == focusID {
|
||||
r.setFocus(0)
|
||||
}
|
||||
}
|
||||
if activate {
|
||||
r.setNumericInputText(key, formatted)
|
||||
state.focused = true
|
||||
r.setFocus(focusID)
|
||||
r.drag = scalarDrag{}
|
||||
r.slider = scalarDrag{}
|
||||
}
|
||||
if !state.focused {
|
||||
return state, false, false
|
||||
}
|
||||
commit := false
|
||||
textChanged := r.editText(bounds, state.text, &state.cursor, &state.focused, &commit, focusID, textEditOptions{maxCodepoints: 63})
|
||||
r.recordTextInput(FrameOpTextField, bounds, state.text, &state.cursor, &state.focused, focusID, Text14, false, false)
|
||||
if commit {
|
||||
state.focused = false
|
||||
r.setFocus(focusID)
|
||||
}
|
||||
return state, textChanged, state.focused
|
||||
}
|
||||
|
||||
func (r *runtime) numericTempFloat(bounds Rectangle, key numericInputKey, focusID int32, values []float32, index int, format string, disabled bool) (bool, bool) {
|
||||
if format == "" {
|
||||
format = "%.3f"
|
||||
}
|
||||
state, textChanged, editing := r.numericTempEdit(bounds, key, focusID, fmt.Sprintf(format, values[index]), disabled)
|
||||
if textChanged {
|
||||
text := string(state.text[:zeroIndex(state.text)])
|
||||
if parsed, err := strconv.ParseFloat(text, 32); err == nil && !math.IsInf(parsed, 0) && !math.IsNaN(parsed) && values[index] != float32(parsed) {
|
||||
values[index] = float32(parsed)
|
||||
return true, editing
|
||||
}
|
||||
}
|
||||
return false, editing
|
||||
}
|
||||
|
||||
func (r *runtime) numericTempInt(bounds Rectangle, key numericInputKey, focusID int32, values []int32, index int, format string, disabled bool) (bool, bool) {
|
||||
if format == "" {
|
||||
format = "%d"
|
||||
}
|
||||
state, textChanged, editing := r.numericTempEdit(bounds, key, focusID, fmt.Sprintf(format, values[index]), disabled)
|
||||
if textChanged {
|
||||
text := string(state.text[:zeroIndex(state.text)])
|
||||
if parsed, err := strconv.ParseInt(text, 0, 32); err == nil && values[index] != int32(parsed) {
|
||||
values[index] = int32(parsed)
|
||||
return true, editing
|
||||
}
|
||||
}
|
||||
return false, editing
|
||||
}
|
||||
|
||||
func (r *runtime) sliderRatio(token, focusID int32, bounds Rectangle, disabled, vertical bool) (float32, bool) {
|
||||
disabled = disabled || r.contentDisabled()
|
||||
if r.slider.active && r.popupInputOwnerCaptures(r.slider.owner) {
|
||||
@@ -3585,6 +3699,13 @@ func (r *runtime) sliderFloat(props SliderFloatProps, vertical bool) bool {
|
||||
if enabled {
|
||||
r.registerField(focusID)
|
||||
}
|
||||
edited, editing := r.numericTempFloat(cell,
|
||||
numericInputKey{kind: numericEditSliderFloat, widgetID: props.ID, component: int32(i)},
|
||||
focusID, props.Values, i, props.Format, props.Disabled)
|
||||
changed = changed || edited
|
||||
if editing {
|
||||
continue
|
||||
}
|
||||
ratio := float32(0)
|
||||
if rangeValue > 0 {
|
||||
ratio = (props.Values[i] - props.Min) / rangeValue
|
||||
@@ -3636,6 +3757,13 @@ func (r *runtime) sliderInt(props SliderIntProps, vertical bool) bool {
|
||||
if enabled {
|
||||
r.registerField(focusID)
|
||||
}
|
||||
edited, editing := r.numericTempInt(cell,
|
||||
numericInputKey{kind: numericEditSliderInt, widgetID: props.ID, component: int32(i)},
|
||||
focusID, props.Values, i, props.Format, props.Disabled)
|
||||
changed = changed || edited
|
||||
if editing {
|
||||
continue
|
||||
}
|
||||
ratio := float32(0)
|
||||
if rangeValue > 0 {
|
||||
ratio = float32(float64(int64(props.Values[i])-int64(props.Min)) / float64(rangeValue))
|
||||
@@ -3739,7 +3867,7 @@ func (r *runtime) numericInputCell(bounds Rectangle, key numericInputKey, format
|
||||
state.focused = false
|
||||
} else {
|
||||
var commit bool
|
||||
textChanged = r.editText(field, state.text, &state.cursor, &state.focused, &commit, token, 63, false, false)
|
||||
textChanged = r.editText(field, state.text, &state.cursor, &state.focused, &commit, token, textEditOptions{maxCodepoints: 63})
|
||||
}
|
||||
r.recordTextInput(FrameOpTextField, field, state.text, &state.cursor, &state.focused, token, Text14, false, false)
|
||||
if step == 0 {
|
||||
@@ -5170,10 +5298,37 @@ func (r *runtime) recordToast() {
|
||||
}
|
||||
func (r *runtime) TextArea(props TextAreaProps) bool {
|
||||
props.Bounds = r.layoutRect(props.Bounds)
|
||||
changed := r.editText(props.Bounds, props.Text, props.CursorPosition, props.Focused, nil, props.FocusID, props.MaxCodepoints, false, props.ReadOnly)
|
||||
changed := r.editText(props.Bounds, props.Text, props.CursorPosition, props.Focused, nil, props.FocusID, textEditOptions{
|
||||
maxCodepoints: props.MaxCodepoints,
|
||||
pageRows: textAreaPageRows(props),
|
||||
readOnly: props.ReadOnly,
|
||||
multiline: true,
|
||||
})
|
||||
r.recordTextInput(FrameOpTextArea, props.Bounds, props.Text, props.CursorPosition, props.Focused, props.FocusID, props.Font, false, props.ReadOnly)
|
||||
return changed
|
||||
}
|
||||
|
||||
func textAreaPageRows(props TextAreaProps) int {
|
||||
font := props.Font
|
||||
if font <= 0 {
|
||||
font = Text16
|
||||
}
|
||||
lineGap := props.LineGap
|
||||
if lineGap < 0 {
|
||||
lineGap = 6
|
||||
}
|
||||
paddingY := props.Style.PaddingY
|
||||
if paddingY <= 0 {
|
||||
paddingY = 8
|
||||
}
|
||||
lineHeight := font + lineGap
|
||||
visibleHeight := int32(props.Bounds.Height) - paddingY*2
|
||||
if lineHeight <= 0 || visibleHeight < lineHeight {
|
||||
return 1
|
||||
}
|
||||
return int(visibleHeight / lineHeight)
|
||||
}
|
||||
|
||||
func (r *runtime) Radio(props RadioButtonProps) int32 {
|
||||
props.Bounds = r.layoutRect(props.Bounds)
|
||||
pressed, focused := r.focusablePress(props.Bounds, props.ID, props.Disabled)
|
||||
@@ -5943,7 +6098,7 @@ func (r *runtime) PromptDialog(props PromptDialogProps) int32 {
|
||||
result, field := r.drawActionModal(props.Title, "", []string{props.CancelLabel, props.ConfirmLabel}, 38)
|
||||
commit := false
|
||||
if props.Text != nil && props.Cursor != nil && props.Focused != nil {
|
||||
r.editText(field, props.Text, props.Cursor, props.Focused, &commit, 7301, int32(len(props.Text)-1), false, false)
|
||||
r.editText(field, props.Text, props.Cursor, props.Focused, &commit, 7301, textEditOptions{maxCodepoints: int32(len(props.Text) - 1)})
|
||||
r.recordTextInput(FrameOpTextField, field, props.Text, props.Cursor, props.Focused, 7301, Text16, false, false)
|
||||
}
|
||||
if result == 0 && commit {
|
||||
@@ -6215,7 +6370,11 @@ func ThemeSettings(props ThemeSettingsProps, state *UIThemeSettingsState, result
|
||||
|
||||
func (r *runtime) TextField(props TextFieldProps) {
|
||||
props.Bounds = r.layoutRect(props.Bounds)
|
||||
r.editText(props.Bounds, props.Text, props.CursorPosition, props.Focused, props.CommitPressed, props.FocusID, props.MaxCodepoints, props.Secure, props.ReadOnly)
|
||||
r.editText(props.Bounds, props.Text, props.CursorPosition, props.Focused, props.CommitPressed, props.FocusID, textEditOptions{
|
||||
maxCodepoints: props.MaxCodepoints,
|
||||
secure: props.Secure,
|
||||
readOnly: props.ReadOnly,
|
||||
})
|
||||
r.recordTextInput(FrameOpTextField, props.Bounds, props.Text, props.CursorPosition, props.Focused, props.FocusID, props.Font, props.Secure, props.ReadOnly)
|
||||
}
|
||||
|
||||
@@ -6446,8 +6605,16 @@ func pageBoundsOrView(bounds Rectangle, viewWidth, viewHeight int32) Rectangle {
|
||||
return bounds
|
||||
}
|
||||
|
||||
func (r *runtime) editText(bounds Rectangle, buf []byte, cursor *int32, focused *bool, commit *bool, focusID int32, maxCodepoints int32, secure, readOnly bool) bool {
|
||||
if readOnly {
|
||||
type textEditOptions struct {
|
||||
maxCodepoints int32
|
||||
pageRows int
|
||||
secure bool
|
||||
readOnly bool
|
||||
multiline bool
|
||||
}
|
||||
|
||||
func (r *runtime) editText(bounds Rectangle, buf []byte, cursor *int32, focused *bool, commit *bool, focusID int32, options textEditOptions) bool {
|
||||
if options.readOnly {
|
||||
delete(r.preedit, focusID)
|
||||
}
|
||||
if len(buf) == 0 {
|
||||
@@ -6494,11 +6661,11 @@ func (r *runtime) editText(bounds Rectangle, buf []byte, cursor *int32, focused
|
||||
changed := false
|
||||
for _, event := range r.inputEvents {
|
||||
if event.text != "" {
|
||||
if readOnly {
|
||||
if options.readOnly {
|
||||
continue
|
||||
}
|
||||
var inserted bool
|
||||
text, pos, inserted = insertText(text, pos, sel, event.text, textLimit(buf, maxCodepoints))
|
||||
text, pos, inserted = insertText(text, pos, sel, event.text, textLimit(buf, options.maxCodepoints))
|
||||
if inserted {
|
||||
changed = true
|
||||
sel = selection{Anchor: pos, Cursor: pos}
|
||||
@@ -6510,15 +6677,15 @@ func (r *runtime) editText(bounds Rectangle, buf []byte, cursor *int32, focused
|
||||
case KeyA:
|
||||
sel = selection{Anchor: 0, Cursor: len(text)}
|
||||
case KeyC:
|
||||
if !secure && sel.Anchor != sel.Cursor {
|
||||
if !options.secure && sel.Anchor != sel.Cursor {
|
||||
start, end := selectionRange(sel)
|
||||
r.clipboard = text[start:end]
|
||||
}
|
||||
case KeyX:
|
||||
if readOnly {
|
||||
if options.readOnly {
|
||||
continue
|
||||
}
|
||||
if !secure && sel.Anchor != sel.Cursor {
|
||||
if !options.secure && sel.Anchor != sel.Cursor {
|
||||
start, end := selectionRange(sel)
|
||||
r.clipboard = text[start:end]
|
||||
text = text[:start] + text[end:]
|
||||
@@ -6527,11 +6694,11 @@ func (r *runtime) editText(bounds Rectangle, buf []byte, cursor *int32, focused
|
||||
changed = true
|
||||
}
|
||||
case KeyV:
|
||||
if readOnly {
|
||||
if options.readOnly {
|
||||
continue
|
||||
}
|
||||
var inserted bool
|
||||
text, pos, inserted = insertText(text, pos, sel, r.clipboard, textLimit(buf, maxCodepoints))
|
||||
text, pos, inserted = insertText(text, pos, sel, r.clipboard, textLimit(buf, options.maxCodepoints))
|
||||
if inserted {
|
||||
changed = true
|
||||
sel = selection{Anchor: pos, Cursor: pos}
|
||||
@@ -6555,8 +6722,20 @@ func (r *runtime) editText(bounds Rectangle, buf []byte, cursor *int32, focused
|
||||
case KeyEnd:
|
||||
pos = len(text)
|
||||
sel = selection{Anchor: pos, Cursor: pos}
|
||||
case KeyUp, KeyDown, KeyPageUp, KeyPageDown:
|
||||
if options.multiline {
|
||||
direction, rows := -1, 1
|
||||
if event.key == KeyDown || event.key == KeyPageDown {
|
||||
direction = 1
|
||||
}
|
||||
if event.key == KeyPageUp || event.key == KeyPageDown {
|
||||
rows = max(1, options.pageRows)
|
||||
}
|
||||
pos = textMoveVertical(text, pos, direction, rows)
|
||||
sel = selection{Anchor: pos, Cursor: pos}
|
||||
}
|
||||
case KeyBackspace:
|
||||
if readOnly {
|
||||
if options.readOnly {
|
||||
continue
|
||||
}
|
||||
if sel.Anchor != sel.Cursor {
|
||||
@@ -6573,7 +6752,7 @@ func (r *runtime) editText(bounds Rectangle, buf []byte, cursor *int32, focused
|
||||
}
|
||||
sel = selection{Anchor: pos, Cursor: pos}
|
||||
case KeyDelete:
|
||||
if readOnly {
|
||||
if options.readOnly {
|
||||
continue
|
||||
}
|
||||
if sel.Anchor != sel.Cursor {
|
||||
@@ -6589,7 +6768,12 @@ func (r *runtime) editText(bounds Rectangle, buf []byte, cursor *int32, focused
|
||||
}
|
||||
sel = selection{Anchor: pos, Cursor: pos}
|
||||
case KeyEnter:
|
||||
if commit != nil {
|
||||
if options.multiline && !options.readOnly {
|
||||
var inserted bool
|
||||
text, pos, inserted = insertText(text, pos, sel, "\n", textLimit(buf, options.maxCodepoints))
|
||||
changed = changed || inserted
|
||||
sel = selection{Anchor: pos, Cursor: pos}
|
||||
} else if commit != nil {
|
||||
*commit = true
|
||||
}
|
||||
}
|
||||
@@ -6598,13 +6782,13 @@ func (r *runtime) editText(bounds Rectangle, buf []byte, cursor *int32, focused
|
||||
r.inputEvents = nil
|
||||
}
|
||||
var composed bool
|
||||
if readOnly {
|
||||
if options.readOnly {
|
||||
r.ClearTextComposition()
|
||||
} else {
|
||||
text, pos, sel, composed = r.editComposition(focusID, text, pos, sel, textLimit(buf, maxCodepoints))
|
||||
text, pos, sel, composed = r.editComposition(focusID, text, pos, sel, textLimit(buf, options.maxCodepoints))
|
||||
}
|
||||
changed = changed || composed
|
||||
if !readOnly {
|
||||
if !options.readOnly {
|
||||
clear(buf)
|
||||
copy(buf, text)
|
||||
}
|
||||
@@ -6626,6 +6810,20 @@ func (r *runtime) pointerCanReach(bounds Rectangle) bool {
|
||||
pointInRect(r.mousePos.X, r.mousePos.Y, r.scrollClip(bounds))
|
||||
}
|
||||
|
||||
func (r *runtime) hasTap(bounds Rectangle) bool {
|
||||
bounds = r.scrollClip(bounds)
|
||||
if r.contentDisabled() {
|
||||
return false
|
||||
}
|
||||
for i := range r.taps {
|
||||
if !r.taps[i].consumed && !r.popupCaptures(r.taps[i].x, r.taps[i].y) &&
|
||||
pointInRect(r.taps[i].x, r.taps[i].y, bounds) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (r *runtime) consumeTapPoint(bounds Rectangle) (float32, bool) {
|
||||
bounds = r.scrollClip(bounds)
|
||||
if r.contentDisabled() {
|
||||
@@ -6979,6 +7177,49 @@ func nextRune(text string, pos int) int {
|
||||
return pos + size
|
||||
}
|
||||
|
||||
func textLineStart(text string, pos int) int {
|
||||
pos = clampCursor(text, pos)
|
||||
if start := strings.LastIndexByte(text[:pos], '\n'); start >= 0 {
|
||||
return start + 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func textLineEnd(text string, pos int) int {
|
||||
pos = clampCursor(text, pos)
|
||||
if end := strings.IndexByte(text[pos:], '\n'); end >= 0 {
|
||||
return pos + end
|
||||
}
|
||||
return len(text)
|
||||
}
|
||||
|
||||
func textMoveVertical(text string, pos, direction, rows int) int {
|
||||
start := textLineStart(text, pos)
|
||||
column := utf8.RuneCountInString(text[start:clampCursor(text, pos)])
|
||||
for step := 0; step < max(1, rows); step++ {
|
||||
if direction < 0 {
|
||||
if start == 0 {
|
||||
break
|
||||
}
|
||||
pos = start - 1
|
||||
start = textLineStart(text, pos)
|
||||
} else {
|
||||
end := textLineEnd(text, start)
|
||||
if end == len(text) {
|
||||
break
|
||||
}
|
||||
start = end + 1
|
||||
}
|
||||
}
|
||||
pos = start
|
||||
end := textLineEnd(text, start)
|
||||
for column > 0 && pos < end {
|
||||
pos = nextRune(text, pos)
|
||||
column--
|
||||
}
|
||||
return pos
|
||||
}
|
||||
|
||||
func cellW(grid Grid) float32 {
|
||||
return (grid.Bounds.Width - float32(grid.PadX*2) - float32(max32(0, grid.Cols-1)*grid.GapX)) / float32(grid.Cols)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package kryon
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestTextAreaMultilineNavigation(t *testing.T) {
|
||||
r := New(AppConfig{Width: 240, Height: 160}).(*runtime)
|
||||
text := make([]byte, 64)
|
||||
copy(text, "a0\nb1\nc2\nd3\ne4\nf5")
|
||||
cursor := int32(4)
|
||||
focused := true
|
||||
props := TextAreaProps{
|
||||
Bounds: NewRectangle(10, 10, 160, 60), Text: text,
|
||||
CursorPosition: &cursor, Focused: &focused, FocusID: 32100, Font: Text16, LineGap: 4,
|
||||
}
|
||||
draw := func(key int32) {
|
||||
if key != 0 {
|
||||
r.QueueKey(key)
|
||||
}
|
||||
r.BeginFrame()
|
||||
r.TextArea(props)
|
||||
r.EndFrame()
|
||||
}
|
||||
|
||||
r.SetFocus(props.FocusID)
|
||||
draw(KeyDown)
|
||||
if cursor != 7 {
|
||||
t.Fatalf("Down cursor = %d, want 7", cursor)
|
||||
}
|
||||
draw(KeyPageDown)
|
||||
if cursor != 13 {
|
||||
t.Fatalf("PageDown cursor = %d, want 13", cursor)
|
||||
}
|
||||
draw(KeyPageUp)
|
||||
if cursor != 7 {
|
||||
t.Fatalf("PageUp cursor = %d, want 7", cursor)
|
||||
}
|
||||
draw(KeyEnter)
|
||||
if got := CString(text); got != "a0\nb1\nc\n2\nd3\ne4\nf5" {
|
||||
t.Fatalf("multiline Enter text = %q", got)
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#define KRYON_VERSION_MAJOR 0
|
||||
#define KRYON_VERSION_MINOR 1
|
||||
#define KRYON_VERSION_PATCH 74
|
||||
#define KRYON_VERSION_STRING "v0.1.74"
|
||||
#define KRYON_VERSION_PATCH 78
|
||||
#define KRYON_VERSION_STRING "v0.1.78"
|
||||
|
||||
#endif /* KRYON_VERSION_H */
|
||||
+6
-23
@@ -205,13 +205,6 @@ ui_render_button(ButtonSpec button, int handle_input, int paint,
|
||||
ui_draw_termi_button_outline(draw_bounds, draw_border, hovered,
|
||||
retained_pressed,
|
||||
button.disabled);
|
||||
if(cues && hovered && button.bounds.width > 4 && button.bounds.height > 4) {
|
||||
Color cue = LightenUIColor(draw_background, 42);
|
||||
cue.a = cue.a > 170 ? 170 : cue.a;
|
||||
DrawRectangle((int)draw_bounds.x + 2, (int)draw_bounds.y + 1,
|
||||
(int)button.bounds.width - 4, Scale(1), cue);
|
||||
}
|
||||
|
||||
if(focused) {
|
||||
SetUIFocusTextInputActive(0);
|
||||
DrawUIFocus(draw_bounds);
|
||||
@@ -353,12 +346,6 @@ DrawUIIconButton(IconButtonProps button)
|
||||
hovered &&
|
||||
IsMouseButtonDown(MOUSE_BUTTON_LEFT),
|
||||
button.disabled);
|
||||
if(cues && hovered && button.bounds.width > 4 && button.bounds.height > 4) {
|
||||
Color cue = LightenUIColor(draw_background, 42);
|
||||
cue.a = cue.a > 170 ? 170 : cue.a;
|
||||
DrawRectangle((int)button.bounds.x + 2, (int)button.bounds.y + 1,
|
||||
(int)button.bounds.width - 4, Scale(1), cue);
|
||||
}
|
||||
if(focused) {
|
||||
SetUIFocusTextInputActive(0);
|
||||
DrawUIFocus(button.bounds);
|
||||
@@ -448,10 +435,16 @@ RenderTextButton(int x, int y, const char *label, int *hover)
|
||||
const char *text = label != NULL ? label : "";
|
||||
int w = (int)TextWidth(text, font) + Scale(16);
|
||||
int h = TextLineHeight(font) + Scale(8);
|
||||
int min_w = Scale(34);
|
||||
int min_h = Scale(34);
|
||||
Rectangle bounds;
|
||||
int hovered;
|
||||
ButtonSpec spec;
|
||||
|
||||
if(w < min_w)
|
||||
w = min_w;
|
||||
if(h < min_h)
|
||||
h = min_h;
|
||||
x = x - w / 2;
|
||||
bounds.x = (float)x;
|
||||
bounds.y = (float)y;
|
||||
@@ -600,16 +593,6 @@ RenderStyledButton(int x, int y, int w, int h, const char *label,
|
||||
ui_material_scheme().outline);
|
||||
}
|
||||
|
||||
if(!ui_material_style() && UITransitionCuesEnabled() &&
|
||||
style == ButtonStyleTabSelected &&
|
||||
!disabled && w > Scale(18)) {
|
||||
int cue_h = Scale(2);
|
||||
if(cue_h < 1)
|
||||
cue_h = 1;
|
||||
DrawRectangle(x + Scale(9), y + h - cue_h, w - Scale(18),
|
||||
cue_h, LightenUIColor(c_button_hover, 18));
|
||||
}
|
||||
|
||||
return clicked;
|
||||
}
|
||||
|
||||
|
||||
+39
-4
@@ -2240,7 +2240,7 @@ ui_text_cursor_from_line_x(const char *text, int start, int end, int font, int t
|
||||
return end;
|
||||
}
|
||||
|
||||
static int
|
||||
int
|
||||
ui_text_move_vertical(const char *text, int cursor, int font, int dir)
|
||||
{
|
||||
int start;
|
||||
@@ -2269,6 +2269,24 @@ ui_text_move_vertical(const char *text, int cursor, int font, int dir)
|
||||
return ui_text_cursor_from_line_x(text, other_start, other_end, font, target_x);
|
||||
}
|
||||
|
||||
int
|
||||
ui_text_area_move_page(TextAreaProps area, int cursor, int direction)
|
||||
{
|
||||
int font = area.font > 0 ? area.font : GetFontSize();
|
||||
int line_gap = area.line_gap >= 0 ? area.line_gap : Scale(6);
|
||||
int padding_y = area.style.padding_y > 0
|
||||
? area.style.padding_y : Scale(8);
|
||||
int line_h = TextLineHeight(font) + line_gap;
|
||||
int page_rows = line_h > 0
|
||||
? ((int)area.bounds.height - padding_y * 2) / line_h : 1;
|
||||
|
||||
if(page_rows < 1)
|
||||
page_rows = 1;
|
||||
for(int row = 0; row < page_rows; row++)
|
||||
cursor = ui_text_move_vertical(area.text, cursor, font, direction);
|
||||
return cursor;
|
||||
}
|
||||
|
||||
static int
|
||||
ui_text_area_line_font(const char *text, int start, int end, int base_font)
|
||||
{
|
||||
@@ -2518,6 +2536,8 @@ static int
|
||||
ui_syntax_kry_keyword(const char *text, int len)
|
||||
{
|
||||
static const char *keywords[] = {
|
||||
"#defined", "#else", "#enum", "#extern", "#export", "#global", "#if",
|
||||
"#import", "#module", "#private", "#type", "#ui",
|
||||
"app", "args", "background", "button", "c", "c_rect", "call",
|
||||
"cimport", "clamp_max", "clamp_min", "do", "draw", "else", "endraw",
|
||||
"event", "fn", "font", "for", "fps", "global", "goto", "guard", "icon_button", "if",
|
||||
@@ -2581,7 +2601,8 @@ ui_syntax_token_color(SyntaxMode syntax, const char *text, int len,
|
||||
if(len <= 0)
|
||||
return style.text;
|
||||
if((syntax == SyntaxKry || syntax == SyntaxMake) &&
|
||||
first_token && text[0] == '#')
|
||||
first_token && text[0] == '#' &&
|
||||
!(syntax == SyntaxKry && ui_syntax_kry_keyword(text, len)))
|
||||
return comment;
|
||||
if(text[0] == '"')
|
||||
return string;
|
||||
@@ -2617,6 +2638,13 @@ ui_syntax_token_len(const char *line, int len, int index, SyntaxMode syntax,
|
||||
i++;
|
||||
return i - index;
|
||||
}
|
||||
if(syntax == SyntaxKry && first_token && line[i] == '#' &&
|
||||
ui_syntax_is_ident_start(line[i + 1])) {
|
||||
i++;
|
||||
while(i < len && ui_syntax_is_ident(line[i]))
|
||||
i++;
|
||||
return i - index;
|
||||
}
|
||||
if((syntax == SyntaxKry || syntax == SyntaxMake) &&
|
||||
first_token && line[i] == '#')
|
||||
return len - index;
|
||||
@@ -3580,9 +3608,15 @@ RenderTextArea(TextAreaProps area)
|
||||
*area.cursor_position = ui_text_move_vertical(area.text, *area.cursor_position, font, -1);
|
||||
if(IsKeyPressed(KEY_DOWN))
|
||||
*area.cursor_position = ui_text_move_vertical(area.text, *area.cursor_position, font, 1);
|
||||
if(IsKeyPressed(KEY_PAGE_UP) || IsKeyPressed(KEY_PAGE_DOWN)) {
|
||||
int direction = IsKeyPressed(KEY_PAGE_UP) ? -1 : 1;
|
||||
*area.cursor_position = ui_text_area_move_page(
|
||||
area, *area.cursor_position, direction);
|
||||
}
|
||||
if(changed || IsKeyPressed(KEY_LEFT) || IsKeyPressed(KEY_RIGHT) ||
|
||||
IsKeyPressed(KEY_HOME) || IsKeyPressed(KEY_END) ||
|
||||
IsKeyPressed(KEY_UP) || IsKeyPressed(KEY_DOWN)) {
|
||||
IsKeyPressed(KEY_UP) || IsKeyPressed(KEY_DOWN) ||
|
||||
IsKeyPressed(KEY_PAGE_UP) || IsKeyPressed(KEY_PAGE_DOWN)) {
|
||||
if(!g_ui_text_area_selection.dragging) {
|
||||
ui_text_selection_set(&g_ui_text_area_selection, drag_id,
|
||||
area.focused, *area.cursor_position,
|
||||
@@ -3614,7 +3648,8 @@ RenderTextArea(TextAreaProps area)
|
||||
reveal_cursor = focused &&
|
||||
(changed || IsKeyPressed(KEY_LEFT) || IsKeyPressed(KEY_RIGHT) ||
|
||||
IsKeyPressed(KEY_HOME) || IsKeyPressed(KEY_END) ||
|
||||
IsKeyPressed(KEY_UP) || IsKeyPressed(KEY_DOWN));
|
||||
IsKeyPressed(KEY_UP) || IsKeyPressed(KEY_DOWN) ||
|
||||
IsKeyPressed(KEY_PAGE_UP) || IsKeyPressed(KEY_PAGE_DOWN));
|
||||
if(reveal_cursor) {
|
||||
int cursor_h = TextLineHeight(font);
|
||||
int cursor_y = ui_text_area_cursor_y(
|
||||
|
||||
@@ -120,6 +120,8 @@ int ui_paragraph_modal_height(ParagraphModalMeasureProps measure);
|
||||
int ui_title_bar_height(void);
|
||||
int ui_paragraph_height(ParagraphSpec paragraph);
|
||||
void DrawUIText(const char *text, int x, int y, int font_size, Color color);
|
||||
int ui_text_move_vertical(const char *text, int cursor, int font, int direction);
|
||||
int ui_text_area_move_page(TextAreaProps area, int cursor, int direction);
|
||||
void DrawUITextEx(const char *text, int x, int y, int font_size, Color color,
|
||||
int selectable);
|
||||
void DrawUITextStyled(const char *text, int x, int y, TextStyle style);
|
||||
|
||||
@@ -287,8 +287,9 @@ void ui_paint_layers_composite(UIPaintLayers *layers)
|
||||
rlSetMatrixModelview(layers->modelview);
|
||||
}
|
||||
ResetUIClip();
|
||||
/* Capture stores source-over RGB premultiplied by alpha. Compositing it
|
||||
* with ordinary alpha would multiply translucent pixels a second time. */
|
||||
/* Inputs such as font atlases may use straight alpha, but capture applies
|
||||
* source-over and stores the resulting layer premultiplied. Ordinary alpha
|
||||
* here would multiply every translucent pixel a second time. */
|
||||
BeginBlendMode(BLEND_ALPHA_PREMULTIPLY);
|
||||
for(int i = 0; i < layers->count; i++) {
|
||||
UIPaintLayer *layer = &layers->items[i];
|
||||
|
||||
+179
-2
@@ -25,6 +25,15 @@ static float g_drag_last_x = 0.0f;
|
||||
static UIPopupInputOwner g_drag_owner = {0};
|
||||
static int g_slider_active = 0;
|
||||
static UIPopupInputOwner g_slider_owner = {0};
|
||||
typedef struct UINumericClickState {
|
||||
int valid;
|
||||
int kind;
|
||||
int widget_id;
|
||||
int component;
|
||||
Vector2 position;
|
||||
double time;
|
||||
} UINumericClickState;
|
||||
static UINumericClickState g_numeric_click = {0};
|
||||
typedef struct UIDragDropState {
|
||||
int active;
|
||||
int source_id;
|
||||
@@ -1608,6 +1617,122 @@ ui_numeric_focus_id(int id, int component, int integer)
|
||||
}
|
||||
|
||||
static int ui_slider_keyboard_direction(int vertical);
|
||||
static int ui_numeric_input_filter(int codepoint, void *user_data);
|
||||
static UINumericInputState *ui_numeric_input_find(int kind, int widget_id,
|
||||
int component);
|
||||
|
||||
enum {
|
||||
UI_NUMERIC_EDIT_DRAG_FLOAT = 3,
|
||||
UI_NUMERIC_EDIT_DRAG_INT,
|
||||
UI_NUMERIC_EDIT_SLIDER_FLOAT,
|
||||
UI_NUMERIC_EDIT_SLIDER_INT
|
||||
};
|
||||
|
||||
static int
|
||||
ui_numeric_temp_edit(Rectangle bounds, int kind, int widget_id, int component,
|
||||
int focus_id, void *value, const char *format,
|
||||
int disabled, int integer, int *editing)
|
||||
{
|
||||
int enabled = !disabled && !UIContentDisabled();
|
||||
int control = IsKeyDown(KEY_LEFT_CONTROL) ||
|
||||
IsKeyDown(KEY_RIGHT_CONTROL);
|
||||
int pressed = enabled && IsMouseButtonPressed(MOUSE_BUTTON_LEFT) &&
|
||||
ui_hot(bounds);
|
||||
Vector2 mouse = ui_mouse_world();
|
||||
double now = GetTime();
|
||||
int slop = Scale(6);
|
||||
float dx = mouse.x - g_numeric_click.position.x;
|
||||
float dy = mouse.y - g_numeric_click.position.y;
|
||||
int double_click = pressed && g_numeric_click.valid &&
|
||||
g_numeric_click.kind == kind &&
|
||||
g_numeric_click.widget_id == widget_id &&
|
||||
g_numeric_click.component == component &&
|
||||
now - g_numeric_click.time <= 0.30 &&
|
||||
dx >= -slop && dx <= slop && dy >= -slop && dy <= slop;
|
||||
int activate = pressed && (control || double_click);
|
||||
UINumericInputState *state =
|
||||
ui_numeric_input_find(kind, widget_id, component);
|
||||
int commit = 0;
|
||||
int changed = 0;
|
||||
|
||||
if(pressed) {
|
||||
g_numeric_click = (UINumericClickState){
|
||||
1, kind, widget_id, component, mouse, now
|
||||
};
|
||||
if(activate)
|
||||
g_numeric_click.valid = 0;
|
||||
}
|
||||
|
||||
if(state == NULL && !activate) {
|
||||
*editing = 0;
|
||||
return 0;
|
||||
}
|
||||
if(state == NULL)
|
||||
state = ui_numeric_input_state(kind, widget_id, component);
|
||||
if(!enabled && state->focused) {
|
||||
state->focused = 0;
|
||||
ClearTextInputFocus();
|
||||
}
|
||||
if(activate) {
|
||||
if(integer)
|
||||
snprintf(state->text, sizeof(state->text),
|
||||
format != NULL ? format : "%d", *(int *)value);
|
||||
else
|
||||
snprintf(state->text, sizeof(state->text),
|
||||
format != NULL ? format : "%.3f", *(float *)value);
|
||||
state->cursor = (int)strlen(state->text);
|
||||
state->focused = 1;
|
||||
SetUIFocus(focus_id);
|
||||
g_drag_active = 0;
|
||||
g_slider_active = 0;
|
||||
}
|
||||
if(!state->focused) {
|
||||
*editing = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
BeginDisabled(!enabled);
|
||||
if(RenderTextField((TextFieldProps){
|
||||
.bounds = bounds,
|
||||
.text = state->text,
|
||||
.text_size = sizeof(state->text),
|
||||
.cursor_position = &state->cursor,
|
||||
.focused = &state->focused,
|
||||
.max_codepoints = 63,
|
||||
.font = GetSmallFontSize(),
|
||||
.focus_id = focus_id,
|
||||
.style = kryon_zero_text_input_style,
|
||||
.filter = ui_numeric_input_filter,
|
||||
.commit_pressed = &commit,
|
||||
.read_only = !enabled
|
||||
})) {
|
||||
char *end = NULL;
|
||||
if(integer) {
|
||||
long parsed = strtol(state->text, &end, 0);
|
||||
if(end != state->text && *end == '\0' &&
|
||||
parsed >= INT_MIN && parsed <= INT_MAX &&
|
||||
*(int *)value != (int)parsed) {
|
||||
*(int *)value = (int)parsed;
|
||||
changed = 1;
|
||||
}
|
||||
} else {
|
||||
float parsed = strtof(state->text, &end);
|
||||
if(end != state->text && *end == '\0' &&
|
||||
isfinite(parsed) && *(float *)value != parsed) {
|
||||
*(float *)value = parsed;
|
||||
changed = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
EndDisabled();
|
||||
if(commit) {
|
||||
state->focused = 0;
|
||||
ClearTextInputFocus();
|
||||
SetUIFocus(focus_id);
|
||||
}
|
||||
*editing = state->focused;
|
||||
return changed;
|
||||
}
|
||||
|
||||
static int
|
||||
ui_drag_delta(int token, int focus_id, Rectangle bounds, int disabled,
|
||||
@@ -1719,7 +1844,13 @@ ui_update_drag_float(DragFloatProps drag)
|
||||
drag.bounds.height};
|
||||
float delta;
|
||||
int enabled = !drag.disabled && !UIContentDisabled();
|
||||
int editing = 0;
|
||||
if(enabled && focus_id > 0) RegisterUIFocus(focus_id,cell);
|
||||
changed |= ui_numeric_temp_edit(cell, UI_NUMERIC_EDIT_DRAG_FLOAT,
|
||||
drag.id, i, focus_id, &drag.values[i], drag.format,
|
||||
drag.disabled, 0, &editing);
|
||||
if(editing)
|
||||
continue;
|
||||
if(enabled && ui_update_drag_float_keyboard(focus_id,speed,
|
||||
drag.min,drag.max,&drag.values[i]))
|
||||
changed = 1;
|
||||
@@ -1756,7 +1887,13 @@ ui_update_drag_int(DragIntProps drag)
|
||||
drag.bounds.height};
|
||||
float delta;
|
||||
int enabled = !drag.disabled && !UIContentDisabled();
|
||||
int editing = 0;
|
||||
if(enabled && focus_id > 0) RegisterUIFocus(focus_id,cell);
|
||||
changed |= ui_numeric_temp_edit(cell, UI_NUMERIC_EDIT_DRAG_INT,
|
||||
drag.id, i, focus_id, &drag.values[i], drag.format,
|
||||
drag.disabled, 1, &editing);
|
||||
if(editing)
|
||||
continue;
|
||||
if(enabled && ui_update_drag_int_keyboard(focus_id,speed,
|
||||
drag.min,drag.max,&drag.values[i]))
|
||||
changed = 1;
|
||||
@@ -1810,7 +1947,11 @@ ui_paint_drag_float(DragFloatProps drag)
|
||||
drag.bounds.height};
|
||||
char text[64];
|
||||
int focus_id = ui_numeric_focus_id(drag.id,i,0);
|
||||
UINumericInputState *state = ui_numeric_input_find(
|
||||
UI_NUMERIC_EDIT_DRAG_FLOAT, drag.id, i);
|
||||
int disabled = drag.disabled || UIContentDisabled();
|
||||
if(state != NULL && state->focused)
|
||||
continue;
|
||||
int focused = !disabled && focus_id > 0 && IsUIFocusActive(focus_id) &&
|
||||
!ui_popup_input_focus_captures(focus_id);
|
||||
snprintf(text, sizeof(text), drag.format != NULL ? drag.format : "%.3f",
|
||||
@@ -1831,7 +1972,11 @@ ui_paint_drag_int(DragIntProps drag)
|
||||
drag.bounds.height};
|
||||
char text[64];
|
||||
int focus_id = ui_numeric_focus_id(drag.id,i,1);
|
||||
UINumericInputState *state = ui_numeric_input_find(
|
||||
UI_NUMERIC_EDIT_DRAG_INT, drag.id, i);
|
||||
int disabled = drag.disabled || UIContentDisabled();
|
||||
if(state != NULL && state->focused)
|
||||
continue;
|
||||
int focused = !disabled && focus_id > 0 && IsUIFocusActive(focus_id) &&
|
||||
!ui_popup_input_focus_captures(focus_id);
|
||||
snprintf(text, sizeof(text), drag.format != NULL ? drag.format : "%d",
|
||||
@@ -2010,8 +2155,14 @@ ui_update_slider_float(SliderFloatProps slider, int vertical)
|
||||
slider.bounds.height};
|
||||
float ratio = range > 0.0f ? (slider.values[i] - slider.min) / range : 0.0f;
|
||||
int enabled = !slider.disabled && !UIContentDisabled();
|
||||
int editing = 0;
|
||||
if(enabled && focus_id > 0)
|
||||
RegisterUIFocus(focus_id,cell);
|
||||
changed |= ui_numeric_temp_edit(cell, UI_NUMERIC_EDIT_SLIDER_FLOAT,
|
||||
slider.id, i, focus_id, &slider.values[i], slider.format,
|
||||
slider.disabled, 0, &editing);
|
||||
if(editing)
|
||||
continue;
|
||||
if(enabled && ui_update_slider_float_keyboard(focus_id,vertical,
|
||||
slider.min,slider.max,&slider.values[i])) {
|
||||
ratio = (slider.values[i] - slider.min) / range;
|
||||
@@ -2050,8 +2201,14 @@ ui_update_slider_int(SliderIntProps slider, int vertical)
|
||||
float ratio = range > 0 ?
|
||||
(float)(((long long)slider.values[i] - slider.min) / (double)range) : 0.0f;
|
||||
int enabled = !slider.disabled && !UIContentDisabled();
|
||||
int editing = 0;
|
||||
if(enabled && focus_id > 0)
|
||||
RegisterUIFocus(focus_id,cell);
|
||||
changed |= ui_numeric_temp_edit(cell, UI_NUMERIC_EDIT_SLIDER_INT,
|
||||
slider.id, i, focus_id, &slider.values[i], slider.format,
|
||||
slider.disabled, 1, &editing);
|
||||
if(editing)
|
||||
continue;
|
||||
if(enabled && ui_update_slider_int_keyboard(focus_id,vertical,
|
||||
slider.min,slider.max,&slider.values[i])) {
|
||||
ratio = (float)(((long long)slider.values[i] - slider.min) /
|
||||
@@ -2090,6 +2247,10 @@ ui_paint_slider_float(SliderFloatProps slider, int vertical)
|
||||
if(ratio > 1) ratio = 1;
|
||||
char text[64];
|
||||
int focus_id = ui_numeric_focus_id(slider.id,i,0);
|
||||
UINumericInputState *state = ui_numeric_input_find(
|
||||
UI_NUMERIC_EDIT_SLIDER_FLOAT, slider.id, i);
|
||||
if(state != NULL && state->focused)
|
||||
continue;
|
||||
int focused = !slider.disabled && focus_id > 0 &&
|
||||
IsUIFocusActive(focus_id) &&
|
||||
!ui_popup_input_focus_captures(focus_id);
|
||||
@@ -2114,6 +2275,10 @@ ui_paint_slider_int(SliderIntProps slider, int vertical)
|
||||
if(ratio > 1) ratio = 1;
|
||||
char text[64];
|
||||
int focus_id = ui_numeric_focus_id(slider.id,i,1);
|
||||
UINumericInputState *state = ui_numeric_input_find(
|
||||
UI_NUMERIC_EDIT_SLIDER_INT, slider.id, i);
|
||||
if(state != NULL && state->focused)
|
||||
continue;
|
||||
int focused = !slider.disabled && focus_id > 0 &&
|
||||
IsUIFocusActive(focus_id) &&
|
||||
!ui_popup_input_focus_captures(focus_id);
|
||||
@@ -2170,8 +2335,8 @@ ui_paint_slider_angle(SliderAngleProps slider)
|
||||
static UINumericInputState *g_numeric_inputs[UI_NUMERIC_INPUT_BUCKETS];
|
||||
static int g_numeric_next_token = 0x60000000;
|
||||
|
||||
UINumericInputState *
|
||||
ui_numeric_input_state(int kind, int widget_id, int component)
|
||||
static UINumericInputState *
|
||||
ui_numeric_input_find(int kind, int widget_id, int component)
|
||||
{
|
||||
unsigned bucket = ((unsigned)widget_id * 31u + (unsigned)component * 17u +
|
||||
(unsigned)kind) % UI_NUMERIC_INPUT_BUCKETS;
|
||||
@@ -2180,6 +2345,18 @@ ui_numeric_input_state(int kind, int widget_id, int component)
|
||||
if(state->kind == kind && state->widget_id == widget_id &&
|
||||
state->component == component)
|
||||
return state;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
UINumericInputState *
|
||||
ui_numeric_input_state(int kind, int widget_id, int component)
|
||||
{
|
||||
unsigned bucket = ((unsigned)widget_id * 31u + (unsigned)component * 17u +
|
||||
(unsigned)kind) % UI_NUMERIC_INPUT_BUCKETS;
|
||||
UINumericInputState *existing =
|
||||
ui_numeric_input_find(kind, widget_id, component);
|
||||
if(existing != NULL)
|
||||
return existing;
|
||||
|
||||
UINumericInputState *state = calloc(1, sizeof(*state));
|
||||
if(state == NULL)
|
||||
|
||||
@@ -1453,6 +1453,28 @@ RouteInput(void)
|
||||
end = state->anchor > state->cursor
|
||||
? state->anchor : state->cursor;
|
||||
}
|
||||
if(node->kind == UI_WIDGET_TEXT_AREA_NODE &&
|
||||
(IsKeyPressed(KEY_UP) || IsKeyPressed(KEY_DOWN) ||
|
||||
IsKeyPressed(KEY_PAGE_UP) || IsKeyPressed(KEY_PAGE_DOWN))) {
|
||||
int shift = IsKeyDown(KEY_LEFT_SHIFT) || IsKeyDown(KEY_RIGHT_SHIFT);
|
||||
int direction = (IsKeyPressed(KEY_UP) || IsKeyPressed(KEY_PAGE_UP))
|
||||
? -1 : 1;
|
||||
int font = field->font > 0 ? field->font : GetFontSize();
|
||||
|
||||
if(IsKeyPressed(KEY_PAGE_UP) || IsKeyPressed(KEY_PAGE_DOWN))
|
||||
state->cursor = ui_text_area_move_page(
|
||||
node->data.text_area, state->cursor, direction);
|
||||
else
|
||||
state->cursor = ui_text_move_vertical(
|
||||
field->text, state->cursor, font, direction);
|
||||
if(!shift)
|
||||
state->anchor = state->cursor;
|
||||
selection_changed = 1;
|
||||
start = state->anchor < state->cursor
|
||||
? state->anchor : state->cursor;
|
||||
end = state->anchor > state->cursor
|
||||
? state->anchor : state->cursor;
|
||||
}
|
||||
codepoint = GetCharPressed();
|
||||
while(codepoint > 0) {
|
||||
if(field->read_only) { codepoint = GetCharPressed(); continue; }
|
||||
|
||||
@@ -78,6 +78,7 @@ import (
|
||||
"fmt"
|
||||
"image/color"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
kryon "github.com/waozixyz/kryon/go/kryon"
|
||||
)
|
||||
@@ -772,6 +773,19 @@ func main() {
|
||||
}
|
||||
}
|
||||
CompositionStateValue.CompositionReadOnly = false
|
||||
driver.SetFocus(26102)
|
||||
driver.QueueKey(kryon.KeyDown); drawComposition()
|
||||
if CompositionStateValue.CompositionPageCursor <= 4 { panic("generated TextArea Down did not move") }
|
||||
beforePage := CompositionStateValue.CompositionPageCursor
|
||||
driver.QueueKey(kryon.KeyPageDown); drawComposition()
|
||||
if CompositionStateValue.CompositionPageCursor < beforePage+4 { panic("generated TextArea PageDown did not move a page") }
|
||||
beforePage = CompositionStateValue.CompositionPageCursor
|
||||
driver.QueueKey(kryon.KeyPageUp); drawComposition()
|
||||
if CompositionStateValue.CompositionPageCursor > beforePage-4 { panic("generated TextArea PageUp did not move a page") }
|
||||
pageTextBefore := text64(CompositionStateValue.CompositionPageArea)
|
||||
driver.QueueKey(kryon.KeyEnter); drawComposition()
|
||||
pageTextAfter := text64(CompositionStateValue.CompositionPageArea)
|
||||
if len(pageTextAfter) != len(pageTextBefore)+1 || strings.Count(pageTextAfter, "\n") != strings.Count(pageTextBefore, "\n")+1 { panic("generated TextArea Enter did not insert newline") }
|
||||
fields := FieldsStateValue
|
||||
focus := FocusStateValue
|
||||
buttons := ButtonsLayoutStateValue
|
||||
@@ -1082,6 +1096,38 @@ func main() {
|
||||
if value := PlotsStateValue.SliderInts[0]; value != 3 {
|
||||
panic(fmt.Sprintf("generated vertical int slider keyboard value=%d, want 3", value))
|
||||
}
|
||||
driver.QueueKey(kryon.KeyLeftControl)
|
||||
driver.QueueTap(30, 190)
|
||||
drawPlots()
|
||||
driver.QueueShortcut(kryon.KeyA)
|
||||
driver.QueueText("12.5")
|
||||
drawPlots()
|
||||
if value := PlotsStateValue.DragFloats[0]; value != 12.5 {
|
||||
panic(fmt.Sprintf("generated float drag temporary input=%v, want 12.5", value))
|
||||
}
|
||||
driver.QueueKey(kryon.KeyEnter)
|
||||
drawPlots()
|
||||
driver.QueueTap(145, 190)
|
||||
drawPlots()
|
||||
driver.QueueTap(145, 190)
|
||||
drawPlots()
|
||||
driver.QueueShortcut(kryon.KeyA)
|
||||
driver.QueueText("17")
|
||||
drawPlots()
|
||||
if value := PlotsStateValue.DragInts[0]; value != 17 {
|
||||
panic(fmt.Sprintf("generated int drag double-click input=%d, want 17", value))
|
||||
}
|
||||
driver.QueueKey(kryon.KeyEnter)
|
||||
drawPlots()
|
||||
driver.QueueKey(kryon.KeyLeftControl)
|
||||
driver.QueueTap(150, 246)
|
||||
drawPlots()
|
||||
driver.QueueShortcut(kryon.KeyA)
|
||||
driver.QueueText("19")
|
||||
drawPlots()
|
||||
if value := PlotsStateValue.SliderInts[0]; value != 19 {
|
||||
panic(fmt.Sprintf("generated int slider temporary input=%d, want 19", value))
|
||||
}
|
||||
driver.SetFocus(0x60000008)
|
||||
driver.QueueKey(kryon.KeySpace)
|
||||
drawPlots()
|
||||
@@ -1521,6 +1567,28 @@ int main(void)
|
||||
InjectReset();
|
||||
}
|
||||
composition_read_only = 0;
|
||||
SetUIFocus(26102);
|
||||
InjectKeyTap(KEY_DOWN); InjectPump(); draw_composition();
|
||||
if(composition_page_cursor <= 4) {
|
||||
fprintf(stderr,"generated TextArea Down did not move\n"); return 1;
|
||||
}
|
||||
int composition_before_page = composition_page_cursor;
|
||||
InjectKeyTap(KEY_PAGE_DOWN); InjectPump(); draw_composition();
|
||||
if(composition_page_cursor < composition_before_page + 4) {
|
||||
fprintf(stderr,"generated TextArea PageDown did not move a page\n"); return 1;
|
||||
}
|
||||
composition_before_page = composition_page_cursor;
|
||||
InjectKeyTap(KEY_PAGE_UP); InjectPump(); draw_composition();
|
||||
if(composition_page_cursor > composition_before_page - 4) {
|
||||
fprintf(stderr,"generated TextArea PageUp did not move a page\n"); return 1;
|
||||
}
|
||||
int composition_page_length = (int)strlen(composition_page_area);
|
||||
int composition_page_lines = TextBufferLineCount(composition_page_area);
|
||||
InjectKeyTap(KEY_ENTER); InjectPump(); draw_composition();
|
||||
if((int)strlen(composition_page_area) != composition_page_length + 1 ||
|
||||
TextBufferLineCount(composition_page_area) != composition_page_lines + 1) {
|
||||
fprintf(stderr,"generated TextArea Enter did not insert newline\n"); return 1;
|
||||
}
|
||||
InjectMousePosition(20,20);
|
||||
InjectMouseButton(MOUSE_BUTTON_LEFT,1);
|
||||
InjectPump(); draw_ui(drag_drop_frame);
|
||||
@@ -2070,6 +2138,49 @@ int main(void)
|
||||
slider_ints[0]);
|
||||
return 1;
|
||||
}
|
||||
InjectMousePosition(30,190); InjectKey(KEY_LEFT_CONTROL,1);
|
||||
InjectMouseButton(MOUSE_BUTTON_LEFT,1); InjectPump(); draw_plots();
|
||||
InjectMouseButton(MOUSE_BUTTON_LEFT,0); InjectKey(KEY_LEFT_CONTROL,0);
|
||||
InjectPump(); draw_plots();
|
||||
InjectKey(KEY_LEFT_CONTROL,1); InjectKeyTap(KEY_A);
|
||||
InjectPump(); draw_plots();
|
||||
InjectKey(KEY_LEFT_CONTROL,0); InjectText("12.5");
|
||||
InjectPump(); draw_plots();
|
||||
if(drag_floats[0] != 12.5f) {
|
||||
fprintf(stderr,"generated float drag temporary input=%f, want 12.5\n",
|
||||
drag_floats[0]);
|
||||
return 1;
|
||||
}
|
||||
InjectKeyTap(KEY_ENTER); InjectPump(); draw_plots();
|
||||
InjectMousePosition(145,190);
|
||||
InjectMouseButton(MOUSE_BUTTON_LEFT,1); InjectPump(); draw_plots();
|
||||
InjectMouseButton(MOUSE_BUTTON_LEFT,0); InjectPump(); draw_plots();
|
||||
InjectMousePosition(145,190);
|
||||
InjectMouseButton(MOUSE_BUTTON_LEFT,1); InjectPump(); draw_plots();
|
||||
InjectMouseButton(MOUSE_BUTTON_LEFT,0); InjectPump(); draw_plots();
|
||||
InjectKey(KEY_LEFT_CONTROL,1); InjectKeyTap(KEY_A);
|
||||
InjectPump(); draw_plots();
|
||||
InjectKey(KEY_LEFT_CONTROL,0); InjectText("17");
|
||||
InjectPump(); draw_plots();
|
||||
if(drag_ints[0] != 17) {
|
||||
fprintf(stderr,"generated int drag double-click input=%d, want 17\n",
|
||||
drag_ints[0]);
|
||||
return 1;
|
||||
}
|
||||
InjectKeyTap(KEY_ENTER); InjectPump(); draw_plots();
|
||||
InjectMousePosition(150,246); InjectKey(KEY_LEFT_CONTROL,1);
|
||||
InjectMouseButton(MOUSE_BUTTON_LEFT,1); InjectPump(); draw_plots();
|
||||
InjectMouseButton(MOUSE_BUTTON_LEFT,0); InjectKey(KEY_LEFT_CONTROL,0);
|
||||
InjectPump(); draw_plots();
|
||||
InjectKey(KEY_LEFT_CONTROL,1); InjectKeyTap(KEY_A);
|
||||
InjectPump(); draw_plots();
|
||||
InjectKey(KEY_LEFT_CONTROL,0); InjectText("19");
|
||||
InjectPump(); draw_plots();
|
||||
if(slider_ints[0] != 19) {
|
||||
fprintf(stderr,"generated int slider temporary input=%d, want 19\n",
|
||||
slider_ints[0]);
|
||||
return 1;
|
||||
}
|
||||
SetUIFocus(0x60000008); InjectKeyTap(KEY_SPACE); InjectPump(); draw_plots();
|
||||
if(input_ints[0] != 5) {
|
||||
fprintf(stderr,"generated input step keyboard value=%d, want 5\n",
|
||||
|
||||
@@ -10,6 +10,8 @@ state {
|
||||
composition_cursor: int = 4
|
||||
composition_area: [64] char = "area"
|
||||
composition_area_cursor: int = 4
|
||||
composition_page_area: [64] char = "a0\nb1\nc2\nd3\ne4\nf5"
|
||||
composition_page_cursor: int = 4
|
||||
composition_read_only: bool = false
|
||||
}
|
||||
|
||||
@@ -17,5 +19,6 @@ composition_frame :: () #ui {
|
||||
Screen root: {
|
||||
TextField((TextFieldProps){.bounds = {20,20,220,32}, .text = composition_text, .text_size = sizeof(composition_text), .cursor_position = &composition_cursor, .focus_id = 26100, .read_only = composition_read_only})
|
||||
TextArea((TextAreaProps){.bounds = {20,70,220,80}, .text = composition_area, .text_size = sizeof(composition_area), .cursor_position = &composition_area_cursor, .focus_id = 26101, .read_only = composition_read_only})
|
||||
TextArea((TextAreaProps){.bounds = {20,70,160,60}, .text = composition_page_area, .text_size = sizeof(composition_page_area), .cursor_position = &composition_page_cursor, .focus_id = 26102, .font = Text16, .line_gap = 4})
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,9 @@ static int check_window_readback;
|
||||
static int window_readbacks;
|
||||
static const char *expected_dropdown_text;
|
||||
static int full_dropdown_text_draws;
|
||||
static int syntax_directive_tokens;
|
||||
static int syntax_string_tokens;
|
||||
static int syntax_comment_lines;
|
||||
|
||||
static void check_invalid_layer_end(UIPaintLayerToken token, const char *label)
|
||||
{
|
||||
@@ -53,6 +56,13 @@ void __wrap_DrawUIText(const char *text, int x, int y, int font, Color color)
|
||||
if(expected_dropdown_text != NULL && text != NULL &&
|
||||
strcmp(text, expected_dropdown_text) == 0)
|
||||
full_dropdown_text_draws++;
|
||||
if(text != NULL && strcmp(text, "#import") == 0)
|
||||
syntax_directive_tokens++;
|
||||
if(text != NULL && strcmp(text, "\"kryon.h\"") == 0)
|
||||
syntax_string_tokens++;
|
||||
if(text != NULL && strcmp(text, "# a comment") == 0)
|
||||
syntax_comment_lines++;
|
||||
(void)color;
|
||||
__real_DrawUIText(text, x, y, font, color);
|
||||
}
|
||||
|
||||
@@ -134,6 +144,34 @@ int main(void)
|
||||
check_pixel(c,1,1,MAGENTA,"leaf independent target");
|
||||
UnloadImage(a); UnloadImage(b); UnloadImage(c);
|
||||
|
||||
char syntax_text[] = "#import \"kryon.h\"\n# a comment\n";
|
||||
int syntax_cursor = 0;
|
||||
int syntax_focused = 0;
|
||||
int syntax_scroll = 0;
|
||||
BeginTextureMode(outer);
|
||||
ClearBackground(BLACK);
|
||||
TextArea((TextAreaProps){
|
||||
.bounds = {0, 0, 64, 48},
|
||||
.text = syntax_text,
|
||||
.text_size = sizeof(syntax_text),
|
||||
.cursor_position = &syntax_cursor,
|
||||
.focused = &syntax_focused,
|
||||
.scroll_y = &syntax_scroll,
|
||||
.max_codepoints = 128,
|
||||
.font = 16,
|
||||
.line_gap = 0,
|
||||
.focus_id = 7771,
|
||||
.syntax = SyntaxKry,
|
||||
.style = (TextInputStyle){BLACK, BLACK, WHITE, WHITE, WHITE, 0, 0, 0}
|
||||
});
|
||||
EndTextureMode();
|
||||
if(syntax_directive_tokens == 0 || syntax_string_tokens == 0 ||
|
||||
syntax_comment_lines == 0) {
|
||||
fprintf(stderr,
|
||||
"kry syntax highlighting did not split directive/string/comment tokens\n");
|
||||
failures++;
|
||||
}
|
||||
|
||||
/* Ordinary source-alpha blending also multiplies the alpha channel by
|
||||
* source alpha on this backend. Transparent layer capture instead needs
|
||||
* separate RGB/alpha factors, followed by premultiplied compositing. */
|
||||
|
||||
@@ -221,6 +221,111 @@ test_drag_keyboard_navigation(void)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
draw_numeric_temporary_inputs(DragFloatProps drag, SliderIntProps slider)
|
||||
{
|
||||
BeginUIFrame(320,160,1);
|
||||
(void)DragFloat(drag);
|
||||
(void)SliderInt(slider);
|
||||
EndUIFrame();
|
||||
}
|
||||
|
||||
static void
|
||||
test_numeric_ctrl_click_editing(void)
|
||||
{
|
||||
float drag_value = 1.25f;
|
||||
int slider_value = 4;
|
||||
DragFloatProps drag = {.bounds={10,10,140,30},.id=634,
|
||||
.values=&drag_value,.value_count=1,.speed=0.1f,.min=0,.max=10};
|
||||
SliderIntProps slider = {.bounds={10,60,140,30},.id=635,
|
||||
.values=&slider_value,.value_count=1,.min=0,.max=10};
|
||||
|
||||
InjectReset();
|
||||
ClearTextInputFocus();
|
||||
draw_numeric_temporary_inputs(drag,slider);
|
||||
|
||||
InjectMousePosition(30,20);
|
||||
InjectKey(KEY_LEFT_CONTROL,1);
|
||||
InjectMouseButton(MOUSE_BUTTON_LEFT,1);
|
||||
InjectPump();
|
||||
draw_numeric_temporary_inputs(drag,slider);
|
||||
InjectMouseButton(MOUSE_BUTTON_LEFT,0);
|
||||
InjectKey(KEY_LEFT_CONTROL,0);
|
||||
InjectPump();
|
||||
draw_numeric_temporary_inputs(drag,slider);
|
||||
InjectKey(KEY_LEFT_CONTROL,1);
|
||||
InjectKeyTap(KEY_A);
|
||||
InjectPump();
|
||||
draw_numeric_temporary_inputs(drag,slider);
|
||||
InjectKey(KEY_LEFT_CONTROL,0);
|
||||
InjectText("7.25");
|
||||
InjectPump();
|
||||
draw_numeric_temporary_inputs(drag,slider);
|
||||
check_int("drag temporary input",(int)(drag_value*100),725);
|
||||
InjectKeyTap(KEY_ENTER);
|
||||
InjectPump();
|
||||
draw_numeric_temporary_inputs(drag,slider);
|
||||
|
||||
InjectMousePosition(30,20);
|
||||
InjectMouseButton(MOUSE_BUTTON_LEFT,1);
|
||||
InjectPump();
|
||||
draw_numeric_temporary_inputs(drag,slider);
|
||||
check_int("single click has no temporary input",
|
||||
ui_numeric_input_state(3,634,0)->focused,0);
|
||||
InjectMouseButton(MOUSE_BUTTON_LEFT,0);
|
||||
InjectPump();
|
||||
draw_numeric_temporary_inputs(drag,slider);
|
||||
InjectMousePosition(30,20);
|
||||
InjectMouseButton(MOUSE_BUTTON_LEFT,1);
|
||||
InjectPump();
|
||||
draw_numeric_temporary_inputs(drag,slider);
|
||||
check_int("double-click opens temporary input",
|
||||
ui_numeric_input_state(3,634,0)->focused,1);
|
||||
InjectMouseButton(MOUSE_BUTTON_LEFT,0);
|
||||
InjectPump();
|
||||
draw_numeric_temporary_inputs(drag,slider);
|
||||
InjectKeyTap(KEY_ENTER);
|
||||
InjectPump();
|
||||
draw_numeric_temporary_inputs(drag,slider);
|
||||
|
||||
InjectMousePosition(30,70);
|
||||
InjectKey(KEY_LEFT_CONTROL,1);
|
||||
InjectMouseButton(MOUSE_BUTTON_LEFT,1);
|
||||
InjectPump();
|
||||
draw_numeric_temporary_inputs(drag,slider);
|
||||
InjectMouseButton(MOUSE_BUTTON_LEFT,0);
|
||||
InjectKey(KEY_LEFT_CONTROL,0);
|
||||
InjectPump();
|
||||
draw_numeric_temporary_inputs(drag,slider);
|
||||
InjectKey(KEY_LEFT_CONTROL,1);
|
||||
InjectKeyTap(KEY_A);
|
||||
InjectPump();
|
||||
draw_numeric_temporary_inputs(drag,slider);
|
||||
InjectKey(KEY_LEFT_CONTROL,0);
|
||||
InjectText("19");
|
||||
InjectPump();
|
||||
draw_numeric_temporary_inputs(drag,slider);
|
||||
check_int("slider temporary input is unclamped",slider_value,19);
|
||||
|
||||
slider.disabled = 1;
|
||||
InjectKeyTap(KEY_ENTER);
|
||||
InjectPump();
|
||||
draw_numeric_temporary_inputs(drag,slider);
|
||||
InjectMousePosition(30,70);
|
||||
InjectKey(KEY_LEFT_CONTROL,1);
|
||||
InjectMouseButton(MOUSE_BUTTON_LEFT,1);
|
||||
InjectPump();
|
||||
draw_numeric_temporary_inputs(drag,slider);
|
||||
InjectMouseButton(MOUSE_BUTTON_LEFT,0);
|
||||
InjectKey(KEY_LEFT_CONTROL,0);
|
||||
InjectPump();
|
||||
draw_numeric_temporary_inputs(drag,slider);
|
||||
InjectText("8");
|
||||
InjectPump();
|
||||
draw_numeric_temporary_inputs(drag,slider);
|
||||
check_int("disabled slider temporary input",slider_value,19);
|
||||
}
|
||||
|
||||
static void
|
||||
test_tab_bar_keyboard_navigation(void)
|
||||
{
|
||||
@@ -1611,6 +1716,37 @@ test_popup_text_keyboard_ownership(void)
|
||||
InjectReset();
|
||||
}
|
||||
|
||||
static void
|
||||
test_text_area_page_navigation(void)
|
||||
{
|
||||
char text[64] = "a0\nb1\nc2\nd3\ne4\nf5";
|
||||
int cursor = 4;
|
||||
int focused = 1;
|
||||
TextAreaProps area = {
|
||||
.bounds = {10,10,160,60}, .text = text, .text_size = sizeof(text),
|
||||
.cursor_position = &cursor, .focused = &focused,
|
||||
.focus_id = 25510, .font = Text16
|
||||
};
|
||||
|
||||
InjectReset();
|
||||
SetUIFocus(area.focus_id);
|
||||
InjectKeyTap(KEY_DOWN); InjectPump();
|
||||
BeginUIFrame(240,160,1); TextArea(area); EndUIFrame();
|
||||
check_int("TextArea Down advances one line",cursor > 4,1);
|
||||
|
||||
int before_page = cursor;
|
||||
InjectKeyTap(KEY_PAGE_DOWN); InjectPump();
|
||||
BeginUIFrame(240,160,1); TextArea(area); EndUIFrame();
|
||||
check_int("TextArea PageDown moves more than one line",cursor >= before_page + 4,1);
|
||||
|
||||
before_page = cursor;
|
||||
InjectKeyTap(KEY_PAGE_UP); InjectPump();
|
||||
BeginUIFrame(240,160,1); TextArea(area); EndUIFrame();
|
||||
check_int("TextArea PageUp moves more than one line",cursor <= before_page - 4,1);
|
||||
ClearTextInputFocus();
|
||||
InjectReset();
|
||||
}
|
||||
|
||||
static void
|
||||
test_composed_combo_scope(void)
|
||||
{
|
||||
@@ -3279,6 +3415,7 @@ main(void)
|
||||
|
||||
check_int("topmost hit", CanvasHitTest((Vector2){15, 15}, hits, 3), 1);
|
||||
check_int("miss", CanvasHitTest((Vector2){80, 80}, hits, 3), -1);
|
||||
test_numeric_ctrl_click_editing();
|
||||
test_menu_bar_switches_while_popup_captures_input();
|
||||
test_menu_keyboard_navigation();
|
||||
test_popup_menu_keyboard_navigation();
|
||||
@@ -3319,6 +3456,7 @@ main(void)
|
||||
test_composed_popup_focus_lifecycle();
|
||||
test_popup_active_drag_ownership();
|
||||
test_popup_text_keyboard_ownership();
|
||||
test_text_area_page_navigation();
|
||||
test_popup_tab_ownership();
|
||||
test_popup_button_keyboard_ownership();
|
||||
test_popup_choice_keyboard_ownership();
|
||||
|
||||
@@ -263,10 +263,31 @@ def run_tab_limits():
|
||||
category(4)
|
||||
check("Close first tab","tabs",lambda:click(612,352),1)
|
||||
check("Close last tab","tabs",lambda:click(992,352),0)
|
||||
check("Reopen empty tab bar","tabs",lambda:click(730,410),1)
|
||||
|
||||
def add_tab(name, expected):
|
||||
before=state()["tabs"]
|
||||
after=before
|
||||
# Xvfb can occasionally drop an injected click while llvmpipe is busy.
|
||||
# Retry only while the button had no effect; never click again after the
|
||||
# count changes, so a real double-add or capacity error still fails.
|
||||
for _ in range(3):
|
||||
click(730,410)
|
||||
after=state()["tabs"]
|
||||
if after != before:
|
||||
break
|
||||
results.append(dict(widget=name, passed=after == expected, key="tabs",
|
||||
before=before, after=after))
|
||||
|
||||
add_tab("Reopen empty tab bar",1)
|
||||
for count in range(2,9):
|
||||
check(f"Add tab {count}","tabs",lambda:click(730,410),count)
|
||||
check("Tab capacity disables add","tabs",lambda:click(730,410),8)
|
||||
add_tab(f"Add tab {count}",count)
|
||||
before=state()["tabs"]
|
||||
for _ in range(3):
|
||||
click(730,410)
|
||||
after=state()["tabs"]
|
||||
results.append(dict(widget="Tab capacity disables add",
|
||||
passed=before == 8 and after == 8, key="tabs",
|
||||
before=before, after=after))
|
||||
capture("full-tab-bar")
|
||||
|
||||
def run_settings():
|
||||
|
||||
Reference in new issue
Block a user