Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3390e82f26 | ||
|
|
e8927a64e2 | ||
|
|
1d3f6e8970 | ||
|
|
0a7ed6f644 | ||
|
|
ed4f6beb35 | ||
|
|
48ca968449 | ||
|
|
25a11d5c7d | ||
|
|
656be6175f | ||
|
|
cc20902756 |
No files matched your search
@@ -1,4 +1,20 @@
|
||||
# Changelog
|
||||
## v0.1.76 - 2026-09-07
|
||||
|
||||
### Changed
|
||||
|
||||
- Release: bump version to v0.1.76
|
||||
- Add temporary input to numeric controls
|
||||
|
||||
## v0.1.75 - 2026-09-07
|
||||
|
||||
### Changed
|
||||
|
||||
- Release: bump version to v0.1.75
|
||||
- Enforce premultiplied paint layer output
|
||||
- Highlight Kry directives in text areas
|
||||
- Keep paint layer text on straight alpha
|
||||
|
||||
## v0.1.74 - 2026-09-07
|
||||
|
||||
### Changed
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
This audit compares Kryon's clean native widget surface with Dear ImGui
|
||||
`imgui.h` at commit
|
||||
[`53d421955fdb658e75b039b8210841ad691dafd1`](https://github.com/ocornut/imgui/commit/53d421955fdb658e75b039b8210841ad691dafd1)
|
||||
(`IMGUI_VERSION_NUM` 19295, `1.93.0 WIP`). It tracks widget behavior rather
|
||||
[`334f484892a1fa881d2a927c2aff222c15458b8f`](https://github.com/ocornut/imgui/commit/334f484892a1fa881d2a927c2aff222c15458b8f)
|
||||
(`IMGUI_VERSION_NUM` 19296, `1.93.0 WIP`). It tracks widget behavior rather
|
||||
than copying overload names: Kryon's counted value arrays cover the ImGui
|
||||
`*2`, `*3`, `*4`, `Scalar`, and `ScalarN` fronts without adding aliases.
|
||||
|
||||
@@ -20,8 +20,8 @@ implemented combo scope and its remaining lifecycle/backend gaps.
|
||||
| Progress and links | `Progress`, `Href` | covered; `Href` represents both clickable text and open-URL links |
|
||||
| Images | `Picture`, `ImageWithBg`, `ImageButton` | covered; `ImageButton` shares ordinary focus and keyboard activation |
|
||||
| Combo boxes | `Combobox`, `Dropdown`, `Selectable`, `BeginCombo` / `EndCombo` / `CloseCombo` | option-list helper plus a native arbitrary-child scope with explicit close and presentation flags |
|
||||
| Drag values | `DragFloat`, `DragInt`, `DragFloatRange2`, `DragIntRange2` | covered, including counted N-component values, component focus/Tab traversal, Left/Right adjustment, Home/End bounds, and Shift/Alt step modifiers |
|
||||
| Sliders | `SliderFloat`, `SliderInt`, `VSliderFloat`, `VSliderInt`, `SliderAngle` | counted N-component values, component focus, arrow/Home/End keyboard adjustment, and slow/fast modifiers are covered |
|
||||
| Drag values | `DragFloat`, `DragInt`, `DragFloatRange2`, `DragIntRange2` | covered, including counted N-component values, component focus/Tab traversal, Left/Right adjustment, Home/End bounds, Shift/Alt step modifiers, and Ctrl-click 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 |
|
||||
| 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 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.
|
||||
|
||||
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
|
||||
|
||||
@@ -1004,6 +1004,73 @@ 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")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNativeDragKeyboardNavigation(t *testing.T) {
|
||||
r := New(AppConfig{Width: 480, Height: 240}).(*runtime)
|
||||
floats := []float32{2, 5}
|
||||
|
||||
+107
-1
@@ -1633,6 +1633,13 @@ type numericInputState struct {
|
||||
focused bool
|
||||
}
|
||||
|
||||
const (
|
||||
numericEditDragFloat int32 = 3 + iota
|
||||
numericEditDragInt
|
||||
numericEditSliderFloat
|
||||
numericEditSliderInt
|
||||
)
|
||||
|
||||
type dragDropState struct {
|
||||
active bool
|
||||
sourceID int32
|
||||
@@ -2017,7 +2024,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 +3170,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 +3228,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 +3407,73 @@ 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]
|
||||
activate := enabled && control && r.mousePressed[MouseButtonLeft] && r.consumeTap(bounds)
|
||||
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, 63, false, false)
|
||||
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 +3677,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 +3735,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))
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#define KRYON_VERSION_MAJOR 0
|
||||
#define KRYON_VERSION_MINOR 1
|
||||
#define KRYON_VERSION_PATCH 74
|
||||
#define KRYON_VERSION_STRING "v0.1.74"
|
||||
#define KRYON_VERSION_PATCH 76
|
||||
#define KRYON_VERSION_STRING "v0.1.76"
|
||||
|
||||
#endif /* KRYON_VERSION_H */
|
||||
+11
-1
@@ -2518,6 +2518,8 @@ static int
|
||||
ui_syntax_kry_keyword(const char *text, int len)
|
||||
{
|
||||
static const char *keywords[] = {
|
||||
"#defined", "#else", "#enum", "#extern", "#export", "#global", "#if",
|
||||
"#import", "#module", "#private", "#type", "#ui",
|
||||
"app", "args", "background", "button", "c", "c_rect", "call",
|
||||
"cimport", "clamp_max", "clamp_min", "do", "draw", "else", "endraw",
|
||||
"event", "fn", "font", "for", "fps", "global", "goto", "guard", "icon_button", "if",
|
||||
@@ -2581,7 +2583,8 @@ ui_syntax_token_color(SyntaxMode syntax, const char *text, int len,
|
||||
if(len <= 0)
|
||||
return style.text;
|
||||
if((syntax == SyntaxKry || syntax == SyntaxMake) &&
|
||||
first_token && text[0] == '#')
|
||||
first_token && text[0] == '#' &&
|
||||
!(syntax == SyntaxKry && ui_syntax_kry_keyword(text, len)))
|
||||
return comment;
|
||||
if(text[0] == '"')
|
||||
return string;
|
||||
@@ -2617,6 +2620,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;
|
||||
|
||||
@@ -287,8 +287,9 @@ void ui_paint_layers_composite(UIPaintLayers *layers)
|
||||
rlSetMatrixModelview(layers->modelview);
|
||||
}
|
||||
ResetUIClip();
|
||||
/* Capture stores source-over RGB premultiplied by alpha. Compositing it
|
||||
* with ordinary alpha would multiply translucent pixels a second time. */
|
||||
/* Inputs such as font atlases may use straight alpha, but capture applies
|
||||
* source-over and stores the resulting layer premultiplied. Ordinary alpha
|
||||
* here would multiply every translucent pixel a second time. */
|
||||
BeginBlendMode(BLEND_ALPHA_PREMULTIPLY);
|
||||
for(int i = 0; i < layers->count; i++) {
|
||||
UIPaintLayer *layer = &layers->items[i];
|
||||
|
||||
+150
-2
@@ -1608,6 +1608,102 @@ 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 activate = enabled && control &&
|
||||
IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && ui_hot(bounds);
|
||||
UINumericInputState *state =
|
||||
ui_numeric_input_find(kind, widget_id, component);
|
||||
int commit = 0;
|
||||
int changed = 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 +1815,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 +1858,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 +1918,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 +1943,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 +2126,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 +2172,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 +2218,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 +2246,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 +2306,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 +2316,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)
|
||||
|
||||
@@ -1082,6 +1082,26 @@ 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.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()
|
||||
@@ -2070,6 +2090,33 @@ 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(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",
|
||||
|
||||
@@ -18,6 +18,9 @@ static int check_window_readback;
|
||||
static int window_readbacks;
|
||||
static const char *expected_dropdown_text;
|
||||
static int full_dropdown_text_draws;
|
||||
static int syntax_directive_tokens;
|
||||
static int syntax_string_tokens;
|
||||
static int syntax_comment_lines;
|
||||
|
||||
static void check_invalid_layer_end(UIPaintLayerToken token, const char *label)
|
||||
{
|
||||
@@ -53,6 +56,13 @@ void __wrap_DrawUIText(const char *text, int x, int y, int font, Color color)
|
||||
if(expected_dropdown_text != NULL && text != NULL &&
|
||||
strcmp(text, expected_dropdown_text) == 0)
|
||||
full_dropdown_text_draws++;
|
||||
if(text != NULL && strcmp(text, "#import") == 0)
|
||||
syntax_directive_tokens++;
|
||||
if(text != NULL && strcmp(text, "\"kryon.h\"") == 0)
|
||||
syntax_string_tokens++;
|
||||
if(text != NULL && strcmp(text, "# a comment") == 0)
|
||||
syntax_comment_lines++;
|
||||
(void)color;
|
||||
__real_DrawUIText(text, x, y, font, color);
|
||||
}
|
||||
|
||||
@@ -134,6 +144,34 @@ int main(void)
|
||||
check_pixel(c,1,1,MAGENTA,"leaf independent target");
|
||||
UnloadImage(a); UnloadImage(b); UnloadImage(c);
|
||||
|
||||
char syntax_text[] = "#import \"kryon.h\"\n# a comment\n";
|
||||
int syntax_cursor = 0;
|
||||
int syntax_focused = 0;
|
||||
int syntax_scroll = 0;
|
||||
BeginTextureMode(outer);
|
||||
ClearBackground(BLACK);
|
||||
TextArea((TextAreaProps){
|
||||
.bounds = {0, 0, 64, 48},
|
||||
.text = syntax_text,
|
||||
.text_size = sizeof(syntax_text),
|
||||
.cursor_position = &syntax_cursor,
|
||||
.focused = &syntax_focused,
|
||||
.scroll_y = &syntax_scroll,
|
||||
.max_codepoints = 128,
|
||||
.font = 16,
|
||||
.line_gap = 0,
|
||||
.focus_id = 7771,
|
||||
.syntax = SyntaxKry,
|
||||
.style = (TextInputStyle){BLACK, BLACK, WHITE, WHITE, WHITE, 0, 0, 0}
|
||||
});
|
||||
EndTextureMode();
|
||||
if(syntax_directive_tokens == 0 || syntax_string_tokens == 0 ||
|
||||
syntax_comment_lines == 0) {
|
||||
fprintf(stderr,
|
||||
"kry syntax highlighting did not split directive/string/comment tokens\n");
|
||||
failures++;
|
||||
}
|
||||
|
||||
/* Ordinary source-alpha blending also multiplies the alpha channel by
|
||||
* source alpha on this backend. Transparent layer capture instead needs
|
||||
* separate RGB/alpha factors, followed by premultiplied compositing. */
|
||||
|
||||
@@ -221,6 +221,89 @@ 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,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)
|
||||
{
|
||||
@@ -3279,6 +3362,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();
|
||||
|
||||
Reference in new issue
Block a user