Compare commits

...
39 Commits
Author SHA1 Message Date
github-actions[bot] 1e1ed45f98 Update CHANGELOG for v0.1.78 2026-09-07 22:43:21 +00:00
github-actions[bot] d15ee43112 release: bump version to v0.1.78 2026-09-07 22:40:57 +00:00
waozi f217b6b9c0 Add multiline TextArea page navigation 2026-09-07 19:30:48 -03:00
github-actions[bot] 1a8a4b20db Update CHANGELOG for v0.1.77 2026-09-07 21:55:49 +00:00
github-actions[bot] 48c8aaeeaf release: bump version to v0.1.77 2026-09-07 21:53:12 +00:00
waozi eff4ba2a51 Restore premultiplied paint layer compositing 2026-09-07 18:42:52 -03:00
waozi dd49b16e8e Make tab capacity audit resilient to dropped clicks 2026-09-07 18:32:46 -03:00
waozi 950f1c8213 Clean up default button rendering 2026-09-07 17:53:35 -03:00
waozi a1c250d8fa Open numeric editors on double click 2026-09-07 17:41:48 -03:00
github-actions[bot] 3390e82f26 Update CHANGELOG for v0.1.76 2026-09-07 20:03:45 +00:00
waozi e8927a64e2 release: bump version to v0.1.76 2026-09-07 17:01:09 -03:00
waozi 1d3f6e8970 Add temporary input to numeric controls 2026-09-07 17:00:38 -03:00
github-actions[bot] 0a7ed6f644 Update CHANGELOG for v0.1.75 2026-09-07 19:19:48 +00:00
github-actions[bot] ed4f6beb35 release: bump version to v0.1.75 2026-09-07 19:17:22 +00:00
waozi 48ca968449 Merge branch 'master' of github.com:kryonlabs/kryon 2026-09-07 16:05:13 -03:00
waozi 25a11d5c7d Enforce premultiplied paint layer output 2026-09-07 16:05:03 -03:00
waozi 656be6175f Highlight Kry directives in text areas 2026-09-07 15:56:13 -03:00
github-actions[bot] 69b6de9d18 Update CHANGELOG for v0.1.74 2026-09-07 18:54:02 +00:00
github-actions[bot] 3296f967d4 release: bump version to v0.1.74 2026-09-07 18:51:33 +00:00
waozi cc20902756 Keep paint layer text on straight alpha 2026-09-07 15:43:16 -03:00
waozi 262af24d23 Track single profile icon atlas 2026-09-07 15:39:34 -03:00
waozi 25b75816bf Use single transparent profile picture atlas 2026-09-07 15:37:43 -03:00
waozi ac45d64dd2 Merge remote-tracking branch 'origin/master' 2026-09-07 15:36:03 -03:00
waozi 88535c82a1 Keep paint layers premultiplied 2026-09-07 15:35:48 -03:00
waozi ac6f407f9d Use rounded profile picture tiles 2026-09-07 15:29:06 -03:00
github-actions[bot] be29262efc Update CHANGELOG for v0.1.73 2026-09-07 18:25:12 +00:00
github-actions[bot] b481104d5c release: bump version to v0.1.73 2026-09-07 18:22:52 +00:00
waozi 07746879d1 Use normal alpha for paint layer compositing 2026-09-07 15:22:04 -03:00
waozi 3e131a95b2 Preserve synthetic tap activation 2026-09-07 15:11:33 -03:00
waozi a680050571 Suppress control activation after drag 2026-09-07 15:07:12 -03:00
waozi b391120310 Fix translucent paint layer compositing 2026-09-07 15:04:39 -03:00
waozi d9361cdd53 Harden modern bottom navigation tests 2026-09-07 14:48:44 -03:00
waozi 0db7e10e3c Keep disabled bottom nav icons visible 2026-09-07 14:45:18 -03:00
waozi 1455aa124c Use normal alpha for paint layer compositing 2026-09-07 14:42:01 -03:00
waozi b16462f2b6 Preserve retro style tokens 2026-09-07 14:32:07 -03:00
waozi c7a00eb361 Merge remote-tracking branch 'origin/master' 2026-09-07 14:23:26 -03:00
waozi 69c032eeb6 Remove stale locale dropdown compatibility 2026-09-07 14:23:19 -03:00
waozi 7eb440e964 Expose locale dropdown controls 2026-09-07 14:22:23 -03:00
waozi b79044e726 Modernize default nav styling 2026-09-07 14:17:50 -03:00
30 changed files with 5830 additions and 17024 deletions

No files matched your search

+60
View File
@@ -1,4 +1,64 @@
# 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
- Release: bump version to v0.1.74
- Track single profile icon atlas
- Use single transparent profile picture atlas
- Keep paint layers premultiplied
- Use rounded profile picture tiles
- Use normal alpha for paint layer compositing
## v0.1.73 - 2026-09-07
### Changed
- Release: bump version to v0.1.73
- Preserve synthetic tap activation
- Suppress control activation after drag
- Fix translucent paint layer compositing
- Harden modern bottom navigation tests
- Keep disabled bottom nav icons visible
- Use normal alpha for paint layer compositing
- Preserve retro style tokens
- Remove stale locale dropdown compatibility
- Expose locale dropdown controls
- Modernize default nav styling
## v0.1.72 - 2026-09-07
### Changed
+2
View File
@@ -896,6 +896,8 @@ $(BOTTOM_NAV_ICON_COLOR_TEST): tests/bottom_nav_icon_color_test.c $(LIB) $(KRYON
-Wl,--wrap=DrawTexturePro \
-Wl,--wrap=DrawRectangleRec \
-Wl,--wrap=DrawRectangleRounded \
-Wl,--wrap=DrawRectangleGradientV \
-Wl,--wrap=DrawRectangleRoundedLinesEx \
-Wl,--wrap=SetMouseCursor \
-Wl,--wrap=GetMousePosition \
-Wl,--wrap=IsMouseButtonReleased \
+16 -4
View File
@@ -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
+87
View File
@@ -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
View File
@@ -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)
}
+41
View File
@@ -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)
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 173 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 179 KiB

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 173 KiB

After

Width:  |  Height:  |  Size: 142 KiB

+2 -2
View File
@@ -3,7 +3,7 @@
#define KRYON_VERSION_MAJOR 0
#define KRYON_VERSION_MINOR 1
#define KRYON_VERSION_PATCH 72
#define KRYON_VERSION_STRING "v0.1.72"
#define KRYON_VERSION_PATCH 78
#define KRYON_VERSION_STRING "v0.1.78"
#endif /* KRYON_VERSION_H */
-10
View File
@@ -18,12 +18,6 @@ SHEETS = (
("logos", "UI_ICON_SHEET_LOGOS", "ui_logos_atlas_png"),
)
EXTRA_PNGS = (
("pfp-dark.png", "ui_pfp_dark_atlas_png"),
("pfp-light.png", "ui_pfp_light_atlas_png"),
)
def enum_name(name: str) -> str:
return re.sub(r"[^A-Za-z0-9]", "_", name).upper()
@@ -59,10 +53,6 @@ def main() -> None:
arrays.append(byte_array(symbol, (icon_dir / manifest["image"]).read_bytes()))
for icon in manifest["icons"]:
records.append({**icon, "sheet": sheet_enum})
for filename, symbol in EXTRA_PNGS:
path = icon_dir / filename
if path.is_file():
arrays.append(byte_array(symbol, path.read_bytes()))
records.sort(key=lambda icon: icon["name"])
assets = [
+93 -105
View File
@@ -12,9 +12,9 @@ static const Vector2 kryon_zero_vector2;
int
ui_bottom_nav_height(void)
{
if(ui_material_style())
return Scale(80);
return Scale(40);
if(ui_retro_style())
return Scale(40);
return Scale(106);
}
static int
@@ -33,7 +33,7 @@ ui_bottom_nav_hit(Rectangle bounds, int disabled, int *hovered)
else
MarkUIClickable();
}
if(active && IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) {
if(mouse_release_activates_rect(bounds, mouse, active)) {
UIConsumeRelease();
return 1;
}
@@ -57,28 +57,48 @@ ui_draw_bottom_nav_icon(Texture2D icon, Rectangle dst, Color tint, unsigned char
DrawTexturePro(icon, src, dst, kryon_zero_vector2, 0, tint);
}
static Color
ui_bottom_nav_mix(Color a, Color b, float t)
{
if(t < 0.0f)
t = 0.0f;
if(t > 1.0f)
t = 1.0f;
return (Color){
(unsigned char)((float)a.r + ((float)b.r - (float)a.r) * t),
(unsigned char)((float)a.g + ((float)b.g - (float)a.g) * t),
(unsigned char)((float)a.b + ((float)b.b - (float)a.b) * t),
(unsigned char)((float)a.a + ((float)b.a - (float)a.a) * t)
};
}
BottomNavResult
DrawUIBottomNav(BottomNavProps nav)
{
BottomNavResult result = {-1, -1, 0, 0};
int count = nav.count;
int height = nav.height > 0 ? nav.height : ui_bottom_nav_height();
int bottom_margin = nav.bottom_margin > 0 ? nav.bottom_margin : 0;
int side_margin = nav.side_margin > 0 ? nav.side_margin : 0;
int icon_size = nav.icon_size > 0 ? nav.icon_size : Scale(24);
int bottom_margin = nav.bottom_margin > 0 ? nav.bottom_margin : Scale(12);
int side_margin = nav.side_margin > 0 ? nav.side_margin : Scale(14);
int icon_size = nav.icon_size > 0 ? nav.icon_size : Scale(28);
int y = nav.view_height - bottom_margin - height;
int available_w = nav.view_width - side_margin * 2;
int tab_w;
int group_w;
int start_x;
int cues = UITransitionCuesEnabled();
UIWidget widget;
Rectangle bounds;
UIMaterialScheme scheme;
Color bg = GetThemeBackground();
Color surface = c_surface.a != 0 ? c_surface : DarkenUIColor(bg, 5);
Color accent = c_button_hover.a != 0 ? c_button_hover : c_circle;
Color inactive = ui_bottom_nav_mix(c_text, bg, GetEffectiveThemeDarkMode() ? 0.30f : 0.46f);
Color glass_top = ui_bottom_nav_mix(surface, WHITE, GetEffectiveThemeDarkMode() ? 0.06f : 0.30f);
Color glass_bottom = ui_bottom_nav_mix(surface, BLACK, GetEffectiveThemeDarkMode() ? 0.28f : 0.04f);
Color border = ui_bottom_nav_mix(accent, WHITE, GetEffectiveThemeDarkMode() ? 0.34f : 0.12f);
int i;
Rectangle src;
Rectangle dst;
Rectangle rounded;
Rectangle bar;
result.y = y;
result.height = height;
@@ -105,16 +125,17 @@ DrawUIBottomNav(BottomNavProps nav)
UI_WIDGET_READONLY);
UIWidgetSetAction(&widget, "DrawUIBottomNav");
scheme = ui_material_scheme();
if(ui_material_style()) {
Rectangle bar = {0, (float)y, (float)nav.view_width, (float)height};
ui_material_elevation(bar, 0.0f, 2);
DrawRectangleRec(bar, scheme.surface_container);
} else {
DrawRectangle(0, y, nav.view_width, height, DarkenUIColor(c_bg, 10));
DrawLine(0, y, nav.view_width, y, DarkenUIColor(c_bg, 42));
}
bar.x = (float)side_margin;
bar.y = (float)(y + Scale(8));
bar.width = (float)available_w;
bar.height = (float)(height - Scale(16));
ui_material_elevation(bar, 0.38f, 3);
DrawRectangleRounded(bar, 0.38f, 18, ui_alpha(BLACK, GetEffectiveThemeDarkMode() ? 70 : 22));
DrawRectangleRounded(bar, 0.38f, 18, glass_bottom);
DrawRectangleGradientV((int)bar.x, (int)bar.y, (int)bar.width,
(int)(bar.height * 0.55f),
ui_alpha(glass_top, 210), ui_alpha(glass_top, 40));
DrawRectangleRoundedLinesEx(bar, 0.38f, 18, Scale(1), ui_alpha(border, 96));
for(i = 0; i < count; i++) {
const BottomNavItem *item = &nav.items[i];
@@ -123,98 +144,65 @@ DrawUIBottomNav(BottomNavProps nav)
int icon_x;
int icon_y;
int hover = 0;
ButtonStyle style = item->active
? ButtonStyleTabSelected
: ButtonStyleTab;
unsigned char icon_alpha = item->disabled ? 150 : 255;
Rectangle item_bounds = {(float)x, (float)y, (float)w, (float)height};
int label_font = GetSmallFontSize();
int label_h = TextLineHeight(label_font);
int label_gap = Scale(5);
int active_h = Scale(76);
int active_w = w - Scale(10);
int active_x = x + (w - active_w) / 2;
int active_y = y + Scale(8);
int content_y = y + Scale(19);
int label_y = content_y + icon_size + label_gap;
int label_pad = Scale(3);
Color text_tint = item->active ? LightenUIColor(accent, 42) : inactive;
Color icon_tint = item->active ? LightenUIColor(accent, 48) : inactive;
if(ui_material_style()) {
Rectangle item_bounds = {(float)x, (float)y, (float)w, (float)height};
int label_font = GetSmallFontSize();
int label_h = TextLineHeight(label_font);
int indicator_w = Scale(64);
int indicator_h = Scale(32);
int indicator_x = x + (w - indicator_w) / 2;
int label_gap = Scale(4);
int content_h = indicator_h + label_gap + label_h;
int indicator_y = y + (height - content_h) / 2;
int label_y = indicator_y + indicator_h + label_gap;
int label_pad = Scale(4);
Color text_tint = item->active ? scheme.on_surface :
scheme.on_surface_variant;
Color state_tint = item->active ? scheme.on_secondary :
scheme.on_surface_variant;
icon_size = nav.icon_size > 0 ? nav.icon_size : Scale(26);
if(indicator_y < y + Scale(4))
indicator_y = y + Scale(4);
label_y = indicator_y + indicator_h + label_gap;
icon_x = x + (w - icon_size) / 2;
icon_y = indicator_y + (indicator_h - icon_size) / 2;
if(item->disabled) {
text_tint = scheme.disabled_content;
state_tint = scheme.disabled_content;
}
if(ui_bottom_nav_hit(item_bounds, item->disabled, &hover)) {
result.clicked_index = i;
result.clicked_route = item->route;
}
if(hover)
ui_material_state_layer(item_bounds, state_tint, hover, 0,
hover && IsMouseButtonDown(MOUSE_BUTTON_LEFT));
if(item->active) {
rounded.x = (float)indicator_x;
rounded.y = (float)indicator_y;
rounded.width = (float)indicator_w;
rounded.height = (float)indicator_h;
DrawRectangleRounded(rounded, 0.50f, 12, scheme.secondary);
}
dst.x = (float)icon_x;
dst.y = (float)icon_y;
dst.width = (float)icon_size;
dst.height = (float)icon_size;
ui_draw_bottom_nav_icon(item->icon, dst, nav.icon_color, icon_alpha);
if(item->label != NULL && item->label[0] != '\0') {
Rectangle label_rect = {
(float)(x + label_pad),
(float)label_y,
(float)(w - label_pad * 2),
(float)label_h
};
DrawFittedTextInRect(item->label, label_rect, label_font,
Text8, text_tint);
}
continue;
if(item->disabled) {
text_tint = ui_alpha(inactive, 112);
}
icon_x = x + (w - icon_size) / 2;
icon_y = y + (height - icon_size) / 2;
if(RenderStyledButton(x, y, w, height, "", style,
item->disabled, &hover)) {
if(ui_bottom_nav_hit(item_bounds, item->disabled, &hover)) {
result.clicked_index = i;
result.clicked_route = item->route;
}
if(!ui_material_style() && cues && item->active &&
!item->disabled && w > Scale(20)) {
int cue_h = Scale(2);
if(cue_h < 1)
cue_h = 1;
DrawRectangle(x + Scale(10), y + height - cue_h,
w - Scale(20), cue_h,
LightenUIColor(c_button_hover, 18));
if(hover && !item->active) {
rounded.x = (float)(x + Scale(5));
rounded.y = (float)(y + Scale(14));
rounded.width = (float)(w - Scale(10));
rounded.height = (float)active_h;
DrawRectangleRounded(rounded, 0.24f, 14, ui_alpha(c_text, 22));
}
if(item->icon.id != 0) {
src.x = 0;
src.y = 0;
src.width = (float)item->icon.width;
src.height = (float)item->icon.height;
dst.x = (float)icon_x;
dst.y = (float)icon_y;
dst.width = (float)icon_size;
dst.height = (float)icon_size;
ui_draw_bottom_nav_icon(item->icon, dst, nav.icon_color, icon_alpha);
if(item->active) {
Color glow = LightenUIColor(accent, 30);
rounded.x = (float)active_x;
rounded.y = (float)active_y;
rounded.width = (float)active_w;
rounded.height = (float)active_h;
DrawRectangleRounded((Rectangle){rounded.x - Scale(2), rounded.y + Scale(4),
rounded.width + Scale(4), rounded.height},
0.24f, 16, ui_alpha(glow, 38));
DrawRectangleRounded(rounded, 0.24f, 16,
ui_alpha(ui_bottom_nav_mix(accent, surface, 0.56f), 174));
DrawRectangleRoundedLinesEx(rounded, 0.24f, 16, Scale(1),
ui_alpha(LightenUIColor(accent, 42), 150));
}
icon_x = x + (w - icon_size) / 2;
icon_y = content_y;
dst.x = (float)icon_x;
dst.y = (float)icon_y;
dst.width = (float)icon_size;
dst.height = (float)icon_size;
ui_draw_bottom_nav_icon(item->icon, dst, nav.icon_color.a == 0 ? icon_tint : nav.icon_color, icon_alpha);
if(item->label != NULL && item->label[0] != '\0') {
Rectangle label_rect = {
(float)(x + label_pad),
(float)label_y,
(float)(w - label_pad * 2),
(float)label_h
};
DrawFittedTextInRect(item->label, label_rect, label_font,
Text8, text_tint);
}
}
+6 -23
View File
@@ -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;
}
+21 -16
View File
@@ -175,6 +175,12 @@ ui_draw_pfp_texture_in_circle(Texture2D icon, int cx, int cy, int radius)
ui_draw_pfp_texture(icon, x, y, inner_size);
}
static void
ui_draw_avatar_tile(Rectangle bounds, Color background, Color outline)
{
ui_draw_control_background(bounds, background, outline, 0.22f);
}
static int
ui_profile_pictures_dark_mode(void)
{
@@ -262,19 +268,19 @@ DrawUISidebarAccountHeader(SidebarAccountHeaderProps header)
result.pfp_clicked = 1;
}
}
DrawCircle(avatar_x, avatar_y, (float)(avatar_r + Scale(3)), c_surface);
DrawCircle(avatar_x, avatar_y, (float)avatar_r,
LightenUIColor(c_surface, 12));
DrawCircleLines(avatar_x, avatar_y, (float)avatar_r,
DarkenUIColor(c_text, 38));
ui_draw_avatar_tile((Rectangle){(float)(avatar_x - avatar_r - Scale(3)),
(float)(avatar_y - avatar_r - Scale(3)),
(float)(avatar_size + Scale(6)),
(float)(avatar_size + Scale(6))},
c_surface, DarkenUIColor(c_surface, 18));
if(header.pfp_icon_type > UI_ICON_TYPE_NONE &&
header.pfp_icon_type < UI_ICON_TYPE_COUNT) {
Rectangle icon_bounds;
icon_bounds.x = (float)(avatar_x - avatar_r);
icon_bounds.y = (float)(avatar_y - avatar_r);
icon_bounds.width = (float)avatar_size;
icon_bounds.height = (float)avatar_size;
icon_bounds.x = (float)(avatar_x - avatar_r + Scale(3));
icon_bounds.y = (float)(avatar_y - avatar_r + Scale(3));
icon_bounds.width = (float)(avatar_size - Scale(6));
icon_bounds.height = (float)(avatar_size - Scale(6));
DrawProfilePictureIcon(header.pfp_icon_type, icon_bounds,
ui_profile_pictures_dark_mode());
} else if(pfp_icon.id != 0)
@@ -389,7 +395,7 @@ DrawUIProfilePicturePickerModal(ProfilePicturePickerProps modal)
scroll_view = BeginUIScrollContainer(scroll_area);
mouse = ui_mouse_world();
icon_inset = Scale(2);
icon_inset = Scale(6);
for(i = 0; i < count; i++) {
int row = i / columns;
int col = i % columns;
@@ -403,12 +409,11 @@ DrawUIProfilePicturePickerModal(ProfilePicturePickerProps modal)
!UIInputCapturesClick(mouse);
int active = type == selected;
DrawRectangleRounded(bounds, 0.12f, 8,
hovered ? LightenUIColor(c_surface, 10)
: c_surface);
DrawUIBevel(x, y, cell, cell,
LightenUIColor(c_surface, active ? 68 : 34),
DarkenUIColor(c_surface, active ? 68 : 34));
ui_draw_avatar_tile(bounds,
hovered ? LightenUIColor(c_surface, 10)
: c_surface,
active ? c_button_hover
: DarkenUIColor(c_surface, 22));
if(active)
DrawRectangleLinesEx(bounds, Scale(2), c_button_hover);
if(modal.icons != NULL && type > UI_ICON_TYPE_NONE &&
+98 -9
View File
@@ -13,6 +13,7 @@
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
/* zero constants: the native Plan 9 compiler rejects short
* compound literals like (Type){0}, and a copy of a zero
@@ -51,8 +52,9 @@ int g_ui_slider_active_id = 0;
static int g_ui_pointer_down = 0;
int g_ui_pointer_dragging = 0;
static int g_ui_pointer_dragged_this_click = 0;
static int g_ui_pointer_start_x = 0;
static int g_ui_pointer_start_y = 0;
static int g_ui_pointer_start_x = INT_MIN;
static int g_ui_pointer_start_y = INT_MIN;
static Vector2 g_ui_pointer_start_world = {0};
static int g_ui_transition_cues_enabled = 0;
static int g_ui_release_consumed = 0;
static int g_ui_keyboard_input_enabled = 1;
@@ -331,6 +333,14 @@ ui_mouse_world(void)
return GetScreenToWorld2D(GetMousePosition(), g_ui_camera);
}
static Vector2
screen_to_world_for_input(Vector2 screen)
{
if(g_ui_mouse_world_override_enabled)
return g_ui_mouse_world_override;
return GetScreenToWorld2D(screen, g_ui_camera);
}
void
SetUIMouseWorldOverride(int enabled, Vector2 position)
{
@@ -614,6 +624,7 @@ ui_update_pointer_gesture(void)
g_ui_pointer_owner = UI_POINTER_OWNER_NONE;
g_ui_pointer_start_x = mx;
g_ui_pointer_start_y = my;
g_ui_pointer_start_world = screen_to_world_for_input(mouse);
} else if(IsMouseButtonDown(MOUSE_BUTTON_LEFT) && g_ui_pointer_down) {
int dx = ui_pointer_dx();
int dy = ui_pointer_dy();
@@ -623,6 +634,13 @@ ui_update_pointer_gesture(void)
g_ui_pointer_dragged_this_click = 1;
}
} else if(IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) {
/* A complete injected tap can be pumped before a UI frame. In that
* case no press origin was observed, so activation falls back to the
* release point just as it did before origin tracking existed. */
if(!g_ui_pointer_down) {
g_ui_pointer_start_x = INT_MIN;
g_ui_pointer_start_y = INT_MIN;
}
g_ui_pointer_down = 0;
g_ui_pointer_dragging = 0;
g_ui_scroll_gesture_pending = 0;
@@ -634,6 +652,8 @@ ui_update_pointer_gesture(void)
g_ui_scroll_gesture_pending = 0;
g_ui_release_consumed = 0;
g_ui_pointer_owner = UI_POINTER_OWNER_NONE;
g_ui_pointer_start_x = INT_MIN;
g_ui_pointer_start_y = INT_MIN;
}
}
@@ -762,6 +782,35 @@ UIConsumePointerRelease(void)
UIConsumeRelease();
}
static int
press_started_inside(Rectangle bounds)
{
if(g_ui_pointer_start_x == INT_MIN && g_ui_pointer_start_y == INT_MIN)
return 1;
return CheckCollisionPointRec(g_ui_pointer_start_world, bounds);
}
static int
press_started_inside_circle(Vector2 center, float radius)
{
if(g_ui_pointer_start_x == INT_MIN && g_ui_pointer_start_y == INT_MIN)
return 1;
float dx = g_ui_pointer_start_world.x - center.x;
float dy = g_ui_pointer_start_world.y - center.y;
return dx * dx + dy * dy <= radius * radius;
}
int
mouse_release_activates_rect(Rectangle bounds, Vector2 mouse, int active)
{
return active &&
IsMouseButtonReleased(MOUSE_BUTTON_LEFT) &&
!g_ui_release_consumed &&
!UIInputCapturesClick(mouse) &&
press_started_inside(bounds);
}
int
UIPointerReleaseAvailable(Vector2 point)
{
@@ -783,8 +832,7 @@ UIHandleClick(Rectangle bounds, int disabled, int *hover)
MarkUIDisabled();
if(active)
MarkUIClickable();
if(active && IsMouseButtonReleased(MOUSE_BUTTON_LEFT) &&
!UIPointerReleaseConsumed()) {
if(mouse_release_activates_rect(bounds, mouse_world, active)) {
UIConsumeRelease();
return 1;
}
@@ -808,7 +856,9 @@ UIHandleCircleClick(Vector2 center, float radius, int disabled, int *hover)
if(active)
MarkUIClickable();
if(active && IsMouseButtonReleased(MOUSE_BUTTON_LEFT) &&
!UIPointerReleaseConsumed()) {
!g_ui_release_consumed &&
!UIInputCapturesClick(mouse_world) &&
press_started_inside_circle(center, radius)) {
UIConsumeRelease();
return 1;
}
@@ -2190,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;
@@ -2219,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)
{
@@ -2468,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",
@@ -2531,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;
@@ -2567,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;
@@ -3530,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,
@@ -3564,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(
@@ -4903,6 +4988,10 @@ RestoreUIFrameState(UIFrameState state)
g_ui_text_input_show_requested = state.text_input_show_requested;
g_ui_mouse_world_override_enabled = state.mouse_world_override_enabled;
g_ui_mouse_world_override = state.mouse_world_override;
if(g_ui_pointer_start_x != INT_MIN || g_ui_pointer_start_y != INT_MIN)
g_ui_pointer_start_world = screen_to_world_for_input(
(Vector2){(float)g_ui_pointer_start_x,
(float)g_ui_pointer_start_y});
g_ui_frame_serial = state.frame_serial;
SetUIScale(state.ui_scale);
ResetUIClip();
+4559 -16774
View File
File diff suppressed because it is too large. Load diff
+4 -33
View File
@@ -11,10 +11,6 @@ extern const unsigned char ui_icon_atlas_png[];
extern const unsigned int ui_icon_atlas_png_size;
extern const unsigned char ui_pfp_atlas_png[];
extern const unsigned int ui_pfp_atlas_png_size;
extern const unsigned char ui_pfp_dark_atlas_png[];
extern const unsigned int ui_pfp_dark_atlas_png_size;
extern const unsigned char ui_pfp_light_atlas_png[];
extern const unsigned int ui_pfp_light_atlas_png_size;
extern const unsigned char ui_platforms_atlas_png[];
extern const unsigned int ui_platforms_atlas_png_size;
extern const unsigned char ui_payments_atlas_png[];
@@ -27,7 +23,6 @@ extern const unsigned char ui_logos_atlas_png[];
extern const unsigned int ui_logos_atlas_png_size;
static Texture2D icon_sheets[UI_ICON_SHEET_COUNT];
static Texture2D pfp_theme_sheets[2];
static int
icon_sheet_png(UIIconSheet sheet, const unsigned char **png,
@@ -89,7 +84,7 @@ load_atlas(Texture2D *atlas, const unsigned char *png, unsigned int png_size)
*atlas = LoadTextureFromImage(image);
UnloadImage(image);
if(atlas->id != 0)
SetTextureFilter(*atlas, TEXTURE_FILTER_POINT);
SetTextureFilter(*atlas, TEXTURE_FILTER_BILINEAR);
return *atlas;
}
@@ -127,18 +122,6 @@ LoadIconSheet(UIIconSheet sheet)
return load_atlas(&icon_sheets[sheet], png, png_size);
}
static Texture2D
load_profile_picture_sheet(int dark_mode)
{
int index = dark_mode ? 1 : 0;
const unsigned char *png =
dark_mode ? ui_pfp_dark_atlas_png : ui_pfp_light_atlas_png;
unsigned int png_size =
dark_mode ? ui_pfp_dark_atlas_png_size : ui_pfp_light_atlas_png_size;
return load_atlas(&pfp_theme_sheets[index], png, png_size);
}
void
UnloadIconSheets(void)
{
@@ -146,12 +129,7 @@ UnloadIconSheets(void)
if(icon_sheets[sheet].id != 0)
UnloadTexture(icon_sheets[sheet]);
}
for(int sheet = 0; sheet < 2; sheet++) {
if(pfp_theme_sheets[sheet].id != 0)
UnloadTexture(pfp_theme_sheets[sheet]);
}
memset(icon_sheets, 0, sizeof(icon_sheets));
memset(pfp_theme_sheets, 0, sizeof(pfp_theme_sheets));
}
static void
@@ -187,18 +165,11 @@ void
DrawProfilePictureIcon(UIIconType type, Rectangle bounds, int dark_mode)
{
const UIIconAsset *asset = GetUIIconAsset(type);
Texture2D atlas;
(void)dark_mode;
if(asset == NULL || bounds.width <= 0 || bounds.height <= 0)
return;
if(asset->sheet != UI_ICON_SHEET_PFP) {
DrawIcon(type, bounds, WHITE);
return;
}
atlas = load_profile_picture_sheet(dark_mode);
if(atlas.id == 0)
return;
DrawTexturePro(atlas, asset->source, bounds, (Vector2){0}, 0.0f, WHITE);
DrawIcon(type, bounds, WHITE);
}
static Texture2D
@@ -257,7 +228,7 @@ load_icon_asset_texture(const UIIconAsset *asset)
texture = LoadTextureFromImage(image);
UnloadImage(image);
if(texture.id != 0)
SetTextureFilter(texture, TEXTURE_FILTER_POINT);
SetTextureFilter(texture, TEXTURE_FILTER_BILINEAR);
return texture;
}
+3
View File
@@ -57,6 +57,7 @@ int UIPointerReleaseConsumed(void);
void UIConsumePointerRelease(void);
int UIPointerReleaseAvailable(Vector2 point);
int UIPointerReleaseOutside(Rectangle bounds);
int mouse_release_activates_rect(Rectangle bounds, Vector2 mouse, int active);
void ClearTextInputFocus(void);
int UIHandleCircleClick(Vector2 center, float radius, int disabled, int *hover);
int ui_base_input_captures_click(Vector2 point, int include_pointer_drag);
@@ -119,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);
+3
View File
@@ -287,6 +287,9 @@ void ui_paint_layers_composite(UIPaintLayers *layers)
rlSetMatrixModelview(layers->modelview);
}
ResetUIClip();
/* 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];
+10 -8
View File
@@ -39,16 +39,18 @@ GetUIStyleTokensForThemeStyle(ThemeStyle style)
tokens.bevel_enabled = 1;
tokens.touch_target_min = 36;
tokens.shadow_offset_y = 0;
if(style == THEME_STYLE_MATERIAL) {
/* Fixed pixels: 4px control / 6px panel corners. Fractional
* radii read as pills on tall controls. */
tokens.control_radius = 4.0f;
tokens.panel_radius = 6.0f;
tokens.shadow_alpha = 36;
tokens.title_bar_alpha = 204;
if(style != THEME_STYLE_RETRO) {
tokens.control_radius = 12.0f;
tokens.panel_radius = 14.0f;
tokens.control_alpha = 222;
tokens.panel_alpha = 235;
tokens.title_bar_alpha = 222;
tokens.border_alpha = 118;
tokens.shadow_alpha = 44;
tokens.shine_alpha = 34;
tokens.bevel_enabled = 0;
tokens.touch_target_min = 48;
tokens.shadow_offset_y = 2;
tokens.shadow_offset_y = 3;
}
return tokens;
}
+180 -3
View File
@@ -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;
@@ -120,7 +129,7 @@ ui_focusable_pressed(Rectangle bounds, int id, int disabled, int *focused)
MarkUIClickable();
else if(inside && !captured && !enabled)
MarkUIDisabled();
if(hot && IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) {
if(mouse_release_activates_rect(bounds, mouse, hot)) {
UIConsumeRelease();
if(id > 0)
SetUIFocus(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)
+22
View File
@@ -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; }
+45 -9
View File
@@ -15,6 +15,15 @@ check_int(const char *name, int got, int want)
exit(1);
}
static void
check_true(const char *name, int value)
{
if(value)
return;
fprintf(stderr, "%s: false\n", name);
exit(1);
}
void
__wrap_DrawRectangleRec(Rectangle rec, Color color)
{
@@ -32,6 +41,30 @@ __wrap_DrawRectangleRounded(Rectangle rec, float roundness, int segments,
(void)color;
}
void
__wrap_DrawRectangleGradientV(int pos_x, int pos_y, int width, int height,
Color top, Color bottom)
{
(void)pos_x;
(void)pos_y;
(void)width;
(void)height;
(void)top;
(void)bottom;
}
void
__wrap_DrawRectangleRoundedLinesEx(Rectangle rec, float roundness,
int segments, float line_thick,
Color color)
{
(void)rec;
(void)roundness;
(void)segments;
(void)line_thick;
(void)color;
}
void
__wrap_SetMouseCursor(int cursor)
{
@@ -110,15 +143,18 @@ main(void)
check_int("bottom nav lower edge anchors to usable bottom",
result.y + result.height + 48, 720);
{
check_int("inactive bottom nav icon red", icon_tints[0].r, 255);
check_int("inactive bottom nav icon green", icon_tints[0].g, 255);
check_int("inactive bottom nav icon blue", icon_tints[0].b, 255);
check_int("active bottom nav icon red", icon_tints[1].r, 255);
check_int("active bottom nav icon green", icon_tints[1].g, 255);
check_int("active bottom nav icon blue", icon_tints[1].b, 255);
check_int("disabled bottom nav icon red", icon_tints[2].r, 255);
check_int("disabled bottom nav icon green", icon_tints[2].g, 255);
check_int("disabled bottom nav icon blue", icon_tints[2].b, 255);
check_int("inactive bottom nav icon alpha", icon_tints[0].a, 255);
check_int("active bottom nav icon alpha", icon_tints[1].a, 255);
check_true("active bottom nav icon has distinct theme color",
icon_tints[0].r != icon_tints[1].r ||
icon_tints[0].g != icon_tints[1].g ||
icon_tints[0].b != icon_tints[1].b);
check_int("disabled bottom nav icon red", icon_tints[2].r,
icon_tints[0].r);
check_int("disabled bottom nav icon green", icon_tints[2].g,
icon_tints[0].g);
check_int("disabled bottom nav icon blue", icon_tints[2].b,
icon_tints[0].b);
check_int("disabled bottom nav icon alpha", icon_tints[2].a, 150);
}
for(int dark = 0; dark <= 1; dark++) {
+2 -4
View File
@@ -29,8 +29,6 @@ require_first_line src/ui/ui_icon_names.c 'Generated by scripts/embed-icon-sheet
require_first_line src/ui/ui_icon_assets.c 'Generated by scripts/embed-icon-sheets\.py'
require_contains src/ui/ui_icon_assets.c 'const unsigned char ui_icon_atlas_png\[\]'
require_contains src/ui/ui_icon_assets.c 'const unsigned char ui_pfp_atlas_png\[\]'
require_contains src/ui/ui_icon_assets.c 'const unsigned char ui_pfp_dark_atlas_png\[\]'
require_contains src/ui/ui_icon_assets.c 'const unsigned char ui_pfp_light_atlas_png\[\]'
require_contains src/ui/ui_icon_assets.c 'const unsigned char ui_platforms_atlas_png\[\]'
require_contains src/ui/ui_icon_assets.c 'const unsigned char ui_payments_atlas_png\[\]'
require_contains src/ui/ui_icon_assets.c 'const unsigned char ui_language_atlas_png\[\]'
@@ -47,8 +45,8 @@ require_contains icons/ui.json '"upstream_revision"'
icon_png_count=$(find icons -mindepth 1 -maxdepth 1 -type f -name '*.png' | wc -l | tr -d ' ')
icon_manifest_count=$(find icons -mindepth 1 -maxdepth 1 -type f -name '*.json' | wc -l | tr -d ' ')
if [ "$icon_png_count" -ne 9 ] || [ "$icon_manifest_count" -ne 7 ]; then
echo "icons/ must contain exactly 9 atlases and 7 manifests" >&2
if [ "$icon_png_count" -ne 7 ] || [ "$icon_manifest_count" -ne 7 ]; then
echo "icons/ must contain exactly 7 atlases and 7 manifests" >&2
status=1
fi
require_first_line docs/PUBLIC_API_SNAPSHOT.txt 'Generated by scripts/public-api-snapshot\.py'
+111
View File
@@ -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",
+3
View File
@@ -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})
}
}
+38
View File
@@ -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. */
+138
View File
@@ -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();
+1 -1
View File
@@ -118,7 +118,7 @@ main(void)
SetThemeStyle(THEME_STYLE_MATERIAL);
check_int("material bottom nav",
GetNodeHeight(NodeBottomNav(nav)),
Scale(80));
Scale(106));
SetThemeStyle(THEME_STYLE_RETRO);
check_int("retro tab bar",
GetNodeHeight(NodeTabBar(tabs)),
+24 -3
View File
@@ -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():