Compare commits

...
9 Commits
15 changed files with 482 additions and 59 deletions

No files matched your search

+17
View File
@@ -1,4 +1,21 @@
# 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
+12 -5
View File
@@ -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, Shift/Alt step modifiers, and Ctrl-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 temporary keyboard entry 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,11 +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 a drag or slider component temporarily replaces that component
with the canonical text editor in native C and Go. Valid edits update live,
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 float drag and integer slider entry through k2c and k2go.
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
@@ -258,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
+20
View File
@@ -1069,6 +1069,26 @@ func TestNumericDragAndSliderCtrlClickEditing(t *testing.T) {
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) {
+156 -21
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
@@ -3410,7 +3419,20 @@ func (r *runtime) drawDragLabel(bounds Rectangle, label string) {
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]
activate := enabled && control && r.mousePressed[MouseButtonLeft] && r.consumeTap(bounds)
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
@@ -3435,7 +3457,7 @@ func (r *runtime) numericTempEdit(bounds Rectangle, key numericInputKey, focusID
return state, false, false
}
commit := false
textChanged := r.editText(bounds, state.text, &state.cursor, &state.focused, &commit, focusID, 63, false, 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
@@ -3845,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 {
@@ -5276,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)
@@ -6049,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 {
@@ -6321,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)
}
@@ -6552,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 {
@@ -6600,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}
@@ -6616,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:]
@@ -6633,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}
@@ -6661,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 {
@@ -6679,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 {
@@ -6695,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
}
}
@@ -6704,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)
}
@@ -6732,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() {
@@ -7085,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)
}
}
+2 -2
View File
@@ -3,7 +3,7 @@
#define KRYON_VERSION_MAJOR 0
#define KRYON_VERSION_MINOR 1
#define KRYON_VERSION_PATCH 76
#define KRYON_VERSION_STRING "v0.1.76"
#define KRYON_VERSION_PATCH 78
#define KRYON_VERSION_STRING "v0.1.78"
#endif /* KRYON_VERSION_H */
+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;
}
+28 -3
View File
@@ -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)
{
@@ -3590,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,
@@ -3624,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(
+2
View File
@@ -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);
+31 -2
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;
@@ -1627,13 +1636,33 @@ ui_numeric_temp_edit(Rectangle bounds, int kind, int widget_id, int component,
int enabled = !disabled && !UIContentDisabled();
int control = IsKeyDown(KEY_LEFT_CONTROL) ||
IsKeyDown(KEY_RIGHT_CONTROL);
int activate = enabled && control &&
IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && ui_hot(bounds);
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;
+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; }
+64
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
@@ -1093,6 +1107,18 @@ func main() {
}
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()
@@ -1541,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);
@@ -2104,6 +2152,22 @@ int main(void)
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);
+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})
}
}
+54
View File
@@ -266,6 +266,28 @@ test_numeric_ctrl_click_editing(void)
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);
@@ -1694,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)
{
@@ -3403,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();
+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():