Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1e1ed45f98 | ||
|
|
d15ee43112 | ||
|
|
f217b6b9c0 | ||
|
|
1a8a4b20db | ||
|
|
48c8aaeeaf | ||
|
|
eff4ba2a51 | ||
|
|
dd49b16e8e | ||
|
|
950f1c8213 | ||
|
|
a1c250d8fa | ||
|
|
3390e82f26 | ||
|
|
e8927a64e2 | ||
|
|
1d3f6e8970 | ||
|
|
0a7ed6f644 | ||
|
|
ed4f6beb35 | ||
|
|
48ca968449 | ||
|
|
25a11d5c7d | ||
|
|
656be6175f | ||
|
|
69b6de9d18 | ||
|
|
3296f967d4 | ||
|
|
cc20902756 | ||
|
|
262af24d23 | ||
|
|
25b75816bf | ||
|
|
ac45d64dd2 | ||
|
|
88535c82a1 | ||
|
|
ac6f407f9d | ||
|
|
be29262efc | ||
|
|
b481104d5c | ||
|
|
07746879d1 | ||
|
|
3e131a95b2 | ||
|
|
a680050571 | ||
|
|
b391120310 | ||
|
|
d9361cdd53 | ||
|
|
0db7e10e3c | ||
|
|
1455aa124c | ||
|
|
b16462f2b6 | ||
|
|
c7a00eb361 | ||
|
|
69c032eeb6 | ||
|
|
7eb440e964 | ||
|
|
b79044e726 | ||
|
|
186876cc2e | ||
|
|
a9231918e6 | ||
|
|
cab6851f29 | ||
|
|
fef273a2c8 | ||
|
|
0f4d54fd60 | ||
|
|
0854d09aa4 |
No files matched your search
@@ -1,4 +1,73 @@
|
||||
# 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
|
||||
|
||||
- Release: bump version to v0.1.72
|
||||
- Isolate and clean dropdown state
|
||||
- Modernize profile picture icons
|
||||
- Add text editor buffer helpers
|
||||
|
||||
## v0.1.71 - 2026-09-07
|
||||
|
||||
### Changed
|
||||
|
||||
@@ -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 \
|
||||
|
||||
@@ -85,7 +85,7 @@ li{margin:.25rem 0}
|
||||
<tr><td class="">TextField</td><td class="ok">✅</td><td class="ok">✅</td><td class="ok">✅</td><td class="ok">✅</td><td class="ok">✅ <code>kryon.TextField(kryon.TextFieldProps)</code> / <code>kryon.TextField("Name", &value)</code></td><td class="ok">✅ TEXTINPUT node</td></tr>
|
||||
<tr><td class="">Read-only text</td><td class="ok">✅</td><td class="ok">✅</td><td class="ok">✅</td><td class="ok">✅ via <code>Text</code></td><td class="ok">✅ <code>Text(TextProps)</code></td><td class="no">✗</td></tr>
|
||||
<tr><td class="">TextArea (selection, syntax highlight)</td><td class="ok">✅</td><td class="ok">✅</td><td class="ok">✅</td><td class="ok">✅</td><td class="ok">✅ <code>NewTextArea</code>/<code>TextArea</code></td><td class="no">✗</td></tr>
|
||||
<tr><td class="">Dropdown / DropdownEx</td><td class="ok">✅</td><td class="ok">✅</td><td class="ok">✅</td><td class="ok">✅ <code>Dropdown</code> (Ex needs rich option arrays)</td><td class="ok">✅ <code>Dropdown(Ex)</code></td><td class="ok">✅ DROPDOWN control</td></tr>
|
||||
<tr><td class="">Dropdown / DropdownOptions</td><td class="ok">✅</td><td class="ok">✅</td><td class="ok">✅</td><td class="ok">✅ <code>Dropdown</code> (rich option arrays are native C only)</td><td class="ok">✅ <code>Dropdown</code></td><td class="ok">✅ DROPDOWN control</td></tr>
|
||||
<tr><td class="">Slider</td><td class="ok">✅</td><td class="ok">✅</td><td class="ok">✅</td><td class="ok">✅</td><td class="ok">✅ <code>Slider</code>/<code>Slider</code></td><td class="ok">✅ SLIDER control</td></tr>
|
||||
<tr><td class="">Vertical sliders</td><td class="ok">✅</td><td class="ok">✅</td><td class="ok">✅</td><td class="ok">✅ <code>VSliderFloat</code> / <code>VSliderInt</code></td><td class="ok">✅</td><td class="ok">✅ VSLIDER control</td></tr>
|
||||
<tr><td class="">Toggle (switch)</td><td class="ok">✅</td><td class="ok">✅</td><td class="ok">✅</td><td class="ok">✅</td><td class="ok">✅ <code>Toggle</code></td><td class="ok">✅ node</td></tr>
|
||||
@@ -243,7 +243,7 @@ li{margin:.25rem 0}
|
||||
<ul>
|
||||
<li><code>k2go</code> targets native Go: the <code>Runtime</code> interface covers the widget</li>
|
||||
</ul>
|
||||
<p>whitelist plus the generated-code widget families in <code>go/kryon</code> (controls, Props widgets, dialogs, canvas, Tk layout helpers, toasts, theme control), with <code>.kry</code> array declarations lowering to Go slices at the use site. Remaining boundaries: a forward <code>goto</code> over declarations is a loud Go compile error, <code>DropdownEx</code>'s rich option arrays are not expressible from <code>.kry</code>, and C pointer/<code>Texture2D</code> values cannot be written (icons pass by <code>UIIconType</code>, option lists as joined strings or <code>[N]string</code>).</p>
|
||||
<p>whitelist plus the generated-code widget families in <code>go/kryon</code> (controls, Props widgets, dialogs, canvas, Tk layout helpers, toasts, theme control), with <code>.kry</code> array declarations lowering to Go slices at the use site. Remaining boundaries: a forward <code>goto</code> over declarations is a loud Go compile error, <code>DropdownOptions</code>' rich option arrays are not expressible from <code>.kry</code>, and C pointer/<code>Texture2D</code> values cannot be written (icons pass by <code>UIIconType</code>, option lists as joined strings or <code>[N]string</code>).</p>
|
||||
<ul>
|
||||
<li><code>k2js</code> emits ESM for the web recorder runtime. `make</li>
|
||||
</ul>
|
||||
|
||||
@@ -118,7 +118,7 @@ declaration pass (`src/ui/ui_tree.c`).
|
||||
| TextField | ✅ | ✅ | ✅ | ✅ | ✅ `kryon.TextField(kryon.TextFieldProps)` / `kryon.TextField("Name", &value)` | ✅ TEXTINPUT node |
|
||||
| Read-only text | ✅ | ✅ | ✅ | ✅ via `Text` | ✅ `Text(TextProps)` | ✗ |
|
||||
| TextArea (selection, syntax highlight) | ✅ | ✅ | ✅ | ✅ | ✅ `NewTextArea`/`TextArea` | ✗ |
|
||||
| Dropdown / DropdownEx | ✅ | ✅ | ✅ | ✅ `Dropdown` (Ex needs rich option arrays) | ✅ `Dropdown(Ex)` | ✅ DROPDOWN control |
|
||||
| Dropdown / DropdownOptions | ✅ | ✅ | ✅ | ✅ `Dropdown` (rich option arrays are native C only) | ✅ `Dropdown` | ✅ DROPDOWN control |
|
||||
| Slider | ✅ | ✅ | ✅ | ✅ | ✅ `Slider`/`Slider` | ✅ SLIDER control |
|
||||
| Vertical sliders | ✅ | ✅ | ✅ | ✅ `VSliderFloat` / `VSliderInt` | ✅ | ✅ VSLIDER control |
|
||||
| Toggle (switch) | ✅ | ✅ | ✅ | ✅ | ✅ `Toggle` | ✅ node |
|
||||
@@ -297,7 +297,7 @@ declaration pass (`src/ui/ui_tree.c`).
|
||||
Props widgets, dialogs, canvas, Tk layout helpers, toasts, theme control),
|
||||
with `.kry` array declarations lowering to Go slices at the use site.
|
||||
Remaining boundaries: a forward `goto` over declarations is a loud Go
|
||||
compile error, `DropdownEx`'s rich option arrays are not expressible from
|
||||
compile error, `DropdownOptions`' rich option arrays are not expressible from
|
||||
`.kry`, and C pointer/`Texture2D` values cannot be written (icons pass by
|
||||
`UIIconType`, option lists as joined strings or `[N]string`).
|
||||
- `k2js` emits ESM for the web recorder runtime. `make
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
This audit compares Kryon's clean native widget surface with Dear ImGui
|
||||
`imgui.h` at commit
|
||||
[`96b6eb7728d298decdc939d4c698502220190050`](https://github.com/ocornut/imgui/commit/96b6eb7728d298decdc939d4c698502220190050)
|
||||
(`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 |
|
||||
@@ -52,9 +52,10 @@ storage. Native tests select option 130, beyond the former 128-option cap.
|
||||
The C rendering test observes the real text renderer receiving a full owned
|
||||
512-byte overlay label after its caller buffer has been overwritten; Go checks
|
||||
the corresponding deferred text record. Visible-row painting avoids drawing
|
||||
every option in a large list. Process-global state in the option-list helper
|
||||
still needs consolidation; arbitrary popup composition uses the separate public
|
||||
combo scope.
|
||||
every option in a large list. The option-list helper's retained state is owned
|
||||
per render host; native C tests open the same numeric widget ID in independent
|
||||
stores and verify that popup visibility cannot cross windows. Arbitrary popup
|
||||
composition uses the separate public combo scope.
|
||||
|
||||
Open native C/Go dropdowns support Up/Down, Home/End and Enter, keeping the
|
||||
highlight separate from committed selection. Native tests navigate a 131-option
|
||||
@@ -78,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
|
||||
@@ -252,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
|
||||
|
||||
@@ -1381,9 +1381,14 @@ include/ui_controls.h function RenderStyledButton
|
||||
include/ui_controls.h function ScoreControl
|
||||
include/ui_controls.h function SegmentedControl
|
||||
include/ui_controls.h function SetTextAreaSelection
|
||||
include/ui_controls.h function SetUIDropdownClipBottom
|
||||
include/ui_controls.h function SetUIDropdownClipTop
|
||||
include/ui_controls.h function SetUIStyleTokens
|
||||
include/ui_controls.h function TextAreaGutter
|
||||
include/ui_controls.h function TextBufferBracketMatch
|
||||
include/ui_controls.h function TextBufferColumnAtCursor
|
||||
include/ui_controls.h function TextBufferIndentLine
|
||||
include/ui_controls.h function TextBufferLineAtCursor
|
||||
include/ui_controls.h function TextBufferLineCount
|
||||
include/ui_controls.h function TextBufferToggleLineComment
|
||||
include/ui_controls.h macro RICH_TEXT_TOOLS_DEFAULT
|
||||
include/ui_controls.h typedef TextInputFilter
|
||||
include/ui_controls.h typedef UIVerticalSliderMarkCallback
|
||||
@@ -1587,6 +1592,7 @@ include/ui_icons.h enum UI_ICON_SHEET_TILES
|
||||
include/ui_icons.h enum UI_ICON_SHEET_UI
|
||||
include/ui_icons.h function DrawIcon
|
||||
include/ui_icons.h function DrawIconByName
|
||||
include/ui_icons.h function DrawProfilePictureIcon
|
||||
include/ui_icons.h function GetUIIconAsset
|
||||
include/ui_icons.h function GetUIIconAssetByName
|
||||
include/ui_icons.h function LoadAllUIIconTextures
|
||||
@@ -1964,7 +1970,7 @@ include/ui_tree.h function DragFloatRange2
|
||||
include/ui_tree.h function DragInt
|
||||
include/ui_tree.h function DragIntRange2
|
||||
include/ui_tree.h function Dropdown
|
||||
include/ui_tree.h function DropdownEx
|
||||
include/ui_tree.h function DropdownOptions
|
||||
include/ui_tree.h function End
|
||||
include/ui_tree.h function EndCombo
|
||||
include/ui_tree.h function EndDisabled
|
||||
|
||||
@@ -1004,6 +1004,93 @@ func TestNativeDragScalars(t *testing.T) {
|
||||
r.EndFrame()
|
||||
}
|
||||
|
||||
func TestNumericDragAndSliderCtrlClickEditing(t *testing.T) {
|
||||
r := New(AppConfig{Width: 480, Height: 240}).(*runtime)
|
||||
floats := []float32{2.5}
|
||||
drag := DragFloatProps{Bounds: NewRectangle(10, 10, 120, 30), ID: 520,
|
||||
Values: floats, ValueCount: 1, Speed: 0.1, Min: 0, Max: 10}
|
||||
|
||||
r.QueueKey(KeyLeftControl)
|
||||
r.QueueTap(40, 20)
|
||||
r.BeginFrame()
|
||||
if r.DragFloat(drag) || floats[0] != 2.5 {
|
||||
t.Fatalf("Ctrl-click changed drag value before editing: %v", floats)
|
||||
}
|
||||
r.EndFrame()
|
||||
foundEditor := false
|
||||
for _, op := range r.FrameOps() {
|
||||
if op.Kind == FrameOpTextField && op.FocusID == 520 && op.Focused {
|
||||
foundEditor = true
|
||||
}
|
||||
}
|
||||
if !foundEditor {
|
||||
t.Fatal("Ctrl-click did not replace drag cell with a focused editor")
|
||||
}
|
||||
|
||||
r.QueueShortcut(KeyA)
|
||||
r.QueueText("7.25")
|
||||
r.BeginFrame()
|
||||
if !r.DragFloat(drag) || floats[0] != 7.25 {
|
||||
t.Fatalf("edited drag value=%v, want 7.25", floats)
|
||||
}
|
||||
r.EndFrame()
|
||||
r.QueueKey(KeyEnter)
|
||||
r.BeginFrame()
|
||||
r.DragFloat(drag)
|
||||
r.EndFrame()
|
||||
if r.numericInputs[numericInputKey{kind: numericEditDragFloat, widgetID: 520}].focused {
|
||||
t.Fatal("Enter did not finish drag keyboard entry")
|
||||
}
|
||||
|
||||
ints := []int32{4}
|
||||
slider := SliderIntProps{Bounds: NewRectangle(10, 60, 120, 30), ID: 521,
|
||||
Values: ints, ValueCount: 1, Min: 0, Max: 10}
|
||||
r.QueueKey(KeyLeftControl)
|
||||
r.QueueTap(40, 70)
|
||||
r.BeginFrame()
|
||||
r.SliderInt(slider)
|
||||
r.EndFrame()
|
||||
r.QueueShortcut(KeyA)
|
||||
r.QueueText("19")
|
||||
r.BeginFrame()
|
||||
if !r.SliderInt(slider) || ints[0] != 19 {
|
||||
t.Fatalf("temporary slider input should be unclamped: %v", ints)
|
||||
}
|
||||
r.EndFrame()
|
||||
|
||||
disabled := []int32{3}
|
||||
r.QueueKey(KeyLeftControl)
|
||||
r.QueueTap(40, 110)
|
||||
r.BeginFrame()
|
||||
r.DragInt(DragIntProps{Bounds: NewRectangle(10, 100, 120, 30), ID: 522,
|
||||
Values: disabled, ValueCount: 1, Min: 0, Max: 10, Disabled: true})
|
||||
r.EndFrame()
|
||||
state := r.numericInputs[numericInputKey{kind: numericEditDragInt, widgetID: 522}]
|
||||
if state != nil && state.focused {
|
||||
t.Fatal("disabled drag accepted Ctrl-click keyboard entry")
|
||||
}
|
||||
|
||||
doubleRuntime := New(AppConfig{Width: 240, Height: 120}).(*runtime)
|
||||
doubleValues := []int32{6}
|
||||
doubleDrag := DragIntProps{Bounds: NewRectangle(10, 10, 120, 30), ID: 523,
|
||||
Values: doubleValues, ValueCount: 1, Speed: 1, Min: 0, Max: 10}
|
||||
doubleRuntime.QueueTap(40, 20)
|
||||
doubleRuntime.BeginFrame()
|
||||
doubleRuntime.DragInt(doubleDrag)
|
||||
doubleRuntime.EndFrame()
|
||||
if state := doubleRuntime.numericInputs[numericInputKey{kind: numericEditDragInt, widgetID: 523}]; state != nil {
|
||||
t.Fatal("single click created a temporary drag editor")
|
||||
}
|
||||
doubleRuntime.QueueTap(40, 20)
|
||||
doubleRuntime.BeginFrame()
|
||||
doubleRuntime.DragInt(doubleDrag)
|
||||
doubleRuntime.EndFrame()
|
||||
state = doubleRuntime.numericInputs[numericInputKey{kind: numericEditDragInt, widgetID: 523}]
|
||||
if state == nil || !state.focused {
|
||||
t.Fatal("double-click did not open temporary drag editor")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNativeDragKeyboardNavigation(t *testing.T) {
|
||||
r := New(AppConfig{Width: 480, Height: 240}).(*runtime)
|
||||
floats := []float32{2, 5}
|
||||
|
||||
+261
-20
@@ -74,6 +74,8 @@ const (
|
||||
KeyLeft int32 = 263
|
||||
KeyDown int32 = 264
|
||||
KeyUp int32 = 265
|
||||
KeyPageUp int32 = 266
|
||||
KeyPageDown int32 = 267
|
||||
KeyHome int32 = 268
|
||||
KeyEnd int32 = 269
|
||||
KeyF2 int32 = 291
|
||||
@@ -1485,6 +1487,7 @@ type runtime struct {
|
||||
tableDrag tableDrag
|
||||
tableResize tableResize
|
||||
lastTabClick tabClick
|
||||
lastNumericClick numericClick
|
||||
tabDrag tabDrag
|
||||
tabScroll map[int32]int32
|
||||
tabBarsSeen map[int32]bool
|
||||
@@ -1608,6 +1611,12 @@ type tabClick struct {
|
||||
bounds Rectangle
|
||||
}
|
||||
|
||||
type numericClick struct {
|
||||
key numericInputKey
|
||||
x, y float32
|
||||
when time.Time
|
||||
}
|
||||
|
||||
type tabDrag struct {
|
||||
active bool
|
||||
id int32
|
||||
@@ -1633,6 +1642,13 @@ type numericInputState struct {
|
||||
focused bool
|
||||
}
|
||||
|
||||
const (
|
||||
numericEditDragFloat int32 = 3 + iota
|
||||
numericEditDragInt
|
||||
numericEditSliderFloat
|
||||
numericEditSliderInt
|
||||
)
|
||||
|
||||
type dragDropState struct {
|
||||
active bool
|
||||
sourceID int32
|
||||
@@ -2017,7 +2033,7 @@ func (r *runtime) textWithFont(props TextProps, fontID uint32) {
|
||||
}
|
||||
}
|
||||
func (r *runtime) TextFormat(format string, args ...any) string { return fmt.Sprintf(format, args...) }
|
||||
func (r *runtime) Scale(px int32) int32 { return px }
|
||||
func (r *runtime) Scale(px int32) int32 { return px }
|
||||
func (r *runtime) GetScreenWidth() int32 { return int32(r.config.Width) }
|
||||
func (r *runtime) GetScreenHeight() int32 { return int32(r.config.Height) }
|
||||
func (r *runtime) GetThemeBackground() Color { return r.theme().background }
|
||||
@@ -3163,6 +3179,15 @@ func (r *runtime) DragFloat(props DragFloatProps) bool {
|
||||
enabled := !props.Disabled && !r.contentDisabled()
|
||||
if enabled {
|
||||
r.registerField(focusID)
|
||||
}
|
||||
edited, editing := r.numericTempFloat(cell,
|
||||
numericInputKey{kind: numericEditDragFloat, widgetID: props.ID, component: int32(i)},
|
||||
focusID, props.Values, i, props.Format, props.Disabled)
|
||||
changed = changed || edited
|
||||
if editing {
|
||||
continue
|
||||
}
|
||||
if enabled {
|
||||
if next, keyboardChanged := r.dragFloatKeyboard(focusID, speed, props.Min, props.Max, props.Values[i]); keyboardChanged {
|
||||
props.Values[i] = next
|
||||
changed = true
|
||||
@@ -3212,6 +3237,15 @@ func (r *runtime) DragInt(props DragIntProps) bool {
|
||||
enabled := !props.Disabled && !r.contentDisabled()
|
||||
if enabled {
|
||||
r.registerField(focusID)
|
||||
}
|
||||
edited, editing := r.numericTempInt(cell,
|
||||
numericInputKey{kind: numericEditDragInt, widgetID: props.ID, component: int32(i)},
|
||||
focusID, props.Values, i, props.Format, props.Disabled)
|
||||
changed = changed || edited
|
||||
if editing {
|
||||
continue
|
||||
}
|
||||
if enabled {
|
||||
if next, keyboardChanged := r.dragIntKeyboard(focusID, speed, props.Min, props.Max, props.Values[i]); keyboardChanged {
|
||||
props.Values[i] = next
|
||||
changed = true
|
||||
@@ -3382,6 +3416,86 @@ func (r *runtime) drawDragLabel(bounds Rectangle, label string) {
|
||||
r.record(FrameOp{Kind: FrameOpText, Bounds: Rectangle{X: bounds.X + 6, Y: bounds.Y - 18, Width: bounds.Width - 12, Height: 16}, Text: label, Color: r.theme().text, FontSize: Text14})
|
||||
}
|
||||
|
||||
func (r *runtime) numericTempEdit(bounds Rectangle, key numericInputKey, focusID int32, formatted string, disabled bool) (*numericInputState, bool, bool) {
|
||||
enabled := !disabled && !r.contentDisabled()
|
||||
control := r.keyDown[KeyLeftControl] || r.keyDown[KeyRightControl]
|
||||
pressed := enabled && r.mousePressed[MouseButtonLeft] && r.hasTap(bounds)
|
||||
now := time.Now()
|
||||
dx := r.mousePos.X - r.lastNumericClick.x
|
||||
dy := r.mousePos.Y - r.lastNumericClick.y
|
||||
doubleClick := pressed && r.lastNumericClick.key == key &&
|
||||
now.Sub(r.lastNumericClick.when) <= 300*time.Millisecond &&
|
||||
dx >= -6 && dx <= 6 && dy >= -6 && dy <= 6
|
||||
activate := pressed && (control || doubleClick) && r.consumeTap(bounds)
|
||||
if pressed {
|
||||
r.lastNumericClick = numericClick{key: key, x: r.mousePos.X, y: r.mousePos.Y, when: now}
|
||||
if activate {
|
||||
r.lastNumericClick = numericClick{}
|
||||
}
|
||||
}
|
||||
state := r.numericInputs[key]
|
||||
if state == nil && !activate {
|
||||
return nil, false, false
|
||||
}
|
||||
if state == nil {
|
||||
state = r.numericInputState(key, formatted)
|
||||
}
|
||||
if !enabled && state.focused {
|
||||
state.focused = false
|
||||
if r.focusID == focusID {
|
||||
r.setFocus(0)
|
||||
}
|
||||
}
|
||||
if activate {
|
||||
r.setNumericInputText(key, formatted)
|
||||
state.focused = true
|
||||
r.setFocus(focusID)
|
||||
r.drag = scalarDrag{}
|
||||
r.slider = scalarDrag{}
|
||||
}
|
||||
if !state.focused {
|
||||
return state, false, false
|
||||
}
|
||||
commit := false
|
||||
textChanged := r.editText(bounds, state.text, &state.cursor, &state.focused, &commit, focusID, textEditOptions{maxCodepoints: 63})
|
||||
r.recordTextInput(FrameOpTextField, bounds, state.text, &state.cursor, &state.focused, focusID, Text14, false, false)
|
||||
if commit {
|
||||
state.focused = false
|
||||
r.setFocus(focusID)
|
||||
}
|
||||
return state, textChanged, state.focused
|
||||
}
|
||||
|
||||
func (r *runtime) numericTempFloat(bounds Rectangle, key numericInputKey, focusID int32, values []float32, index int, format string, disabled bool) (bool, bool) {
|
||||
if format == "" {
|
||||
format = "%.3f"
|
||||
}
|
||||
state, textChanged, editing := r.numericTempEdit(bounds, key, focusID, fmt.Sprintf(format, values[index]), disabled)
|
||||
if textChanged {
|
||||
text := string(state.text[:zeroIndex(state.text)])
|
||||
if parsed, err := strconv.ParseFloat(text, 32); err == nil && !math.IsInf(parsed, 0) && !math.IsNaN(parsed) && values[index] != float32(parsed) {
|
||||
values[index] = float32(parsed)
|
||||
return true, editing
|
||||
}
|
||||
}
|
||||
return false, editing
|
||||
}
|
||||
|
||||
func (r *runtime) numericTempInt(bounds Rectangle, key numericInputKey, focusID int32, values []int32, index int, format string, disabled bool) (bool, bool) {
|
||||
if format == "" {
|
||||
format = "%d"
|
||||
}
|
||||
state, textChanged, editing := r.numericTempEdit(bounds, key, focusID, fmt.Sprintf(format, values[index]), disabled)
|
||||
if textChanged {
|
||||
text := string(state.text[:zeroIndex(state.text)])
|
||||
if parsed, err := strconv.ParseInt(text, 0, 32); err == nil && values[index] != int32(parsed) {
|
||||
values[index] = int32(parsed)
|
||||
return true, editing
|
||||
}
|
||||
}
|
||||
return false, editing
|
||||
}
|
||||
|
||||
func (r *runtime) sliderRatio(token, focusID int32, bounds Rectangle, disabled, vertical bool) (float32, bool) {
|
||||
disabled = disabled || r.contentDisabled()
|
||||
if r.slider.active && r.popupInputOwnerCaptures(r.slider.owner) {
|
||||
@@ -3585,6 +3699,13 @@ func (r *runtime) sliderFloat(props SliderFloatProps, vertical bool) bool {
|
||||
if enabled {
|
||||
r.registerField(focusID)
|
||||
}
|
||||
edited, editing := r.numericTempFloat(cell,
|
||||
numericInputKey{kind: numericEditSliderFloat, widgetID: props.ID, component: int32(i)},
|
||||
focusID, props.Values, i, props.Format, props.Disabled)
|
||||
changed = changed || edited
|
||||
if editing {
|
||||
continue
|
||||
}
|
||||
ratio := float32(0)
|
||||
if rangeValue > 0 {
|
||||
ratio = (props.Values[i] - props.Min) / rangeValue
|
||||
@@ -3636,6 +3757,13 @@ func (r *runtime) sliderInt(props SliderIntProps, vertical bool) bool {
|
||||
if enabled {
|
||||
r.registerField(focusID)
|
||||
}
|
||||
edited, editing := r.numericTempInt(cell,
|
||||
numericInputKey{kind: numericEditSliderInt, widgetID: props.ID, component: int32(i)},
|
||||
focusID, props.Values, i, props.Format, props.Disabled)
|
||||
changed = changed || edited
|
||||
if editing {
|
||||
continue
|
||||
}
|
||||
ratio := float32(0)
|
||||
if rangeValue > 0 {
|
||||
ratio = float32(float64(int64(props.Values[i])-int64(props.Min)) / float64(rangeValue))
|
||||
@@ -3739,7 +3867,7 @@ func (r *runtime) numericInputCell(bounds Rectangle, key numericInputKey, format
|
||||
state.focused = false
|
||||
} else {
|
||||
var commit bool
|
||||
textChanged = r.editText(field, state.text, &state.cursor, &state.focused, &commit, token, 63, false, false)
|
||||
textChanged = r.editText(field, state.text, &state.cursor, &state.focused, &commit, token, textEditOptions{maxCodepoints: 63})
|
||||
}
|
||||
r.recordTextInput(FrameOpTextField, field, state.text, &state.cursor, &state.focused, token, Text14, false, false)
|
||||
if step == 0 {
|
||||
@@ -5170,10 +5298,37 @@ func (r *runtime) recordToast() {
|
||||
}
|
||||
func (r *runtime) TextArea(props TextAreaProps) bool {
|
||||
props.Bounds = r.layoutRect(props.Bounds)
|
||||
changed := r.editText(props.Bounds, props.Text, props.CursorPosition, props.Focused, nil, props.FocusID, props.MaxCodepoints, false, props.ReadOnly)
|
||||
changed := r.editText(props.Bounds, props.Text, props.CursorPosition, props.Focused, nil, props.FocusID, textEditOptions{
|
||||
maxCodepoints: props.MaxCodepoints,
|
||||
pageRows: textAreaPageRows(props),
|
||||
readOnly: props.ReadOnly,
|
||||
multiline: true,
|
||||
})
|
||||
r.recordTextInput(FrameOpTextArea, props.Bounds, props.Text, props.CursorPosition, props.Focused, props.FocusID, props.Font, false, props.ReadOnly)
|
||||
return changed
|
||||
}
|
||||
|
||||
func textAreaPageRows(props TextAreaProps) int {
|
||||
font := props.Font
|
||||
if font <= 0 {
|
||||
font = Text16
|
||||
}
|
||||
lineGap := props.LineGap
|
||||
if lineGap < 0 {
|
||||
lineGap = 6
|
||||
}
|
||||
paddingY := props.Style.PaddingY
|
||||
if paddingY <= 0 {
|
||||
paddingY = 8
|
||||
}
|
||||
lineHeight := font + lineGap
|
||||
visibleHeight := int32(props.Bounds.Height) - paddingY*2
|
||||
if lineHeight <= 0 || visibleHeight < lineHeight {
|
||||
return 1
|
||||
}
|
||||
return int(visibleHeight / lineHeight)
|
||||
}
|
||||
|
||||
func (r *runtime) Radio(props RadioButtonProps) int32 {
|
||||
props.Bounds = r.layoutRect(props.Bounds)
|
||||
pressed, focused := r.focusablePress(props.Bounds, props.ID, props.Disabled)
|
||||
@@ -5943,7 +6098,7 @@ func (r *runtime) PromptDialog(props PromptDialogProps) int32 {
|
||||
result, field := r.drawActionModal(props.Title, "", []string{props.CancelLabel, props.ConfirmLabel}, 38)
|
||||
commit := false
|
||||
if props.Text != nil && props.Cursor != nil && props.Focused != nil {
|
||||
r.editText(field, props.Text, props.Cursor, props.Focused, &commit, 7301, int32(len(props.Text)-1), false, false)
|
||||
r.editText(field, props.Text, props.Cursor, props.Focused, &commit, 7301, textEditOptions{maxCodepoints: int32(len(props.Text) - 1)})
|
||||
r.recordTextInput(FrameOpTextField, field, props.Text, props.Cursor, props.Focused, 7301, Text16, false, false)
|
||||
}
|
||||
if result == 0 && commit {
|
||||
@@ -6215,7 +6370,11 @@ func ThemeSettings(props ThemeSettingsProps, state *UIThemeSettingsState, result
|
||||
|
||||
func (r *runtime) TextField(props TextFieldProps) {
|
||||
props.Bounds = r.layoutRect(props.Bounds)
|
||||
r.editText(props.Bounds, props.Text, props.CursorPosition, props.Focused, props.CommitPressed, props.FocusID, props.MaxCodepoints, props.Secure, props.ReadOnly)
|
||||
r.editText(props.Bounds, props.Text, props.CursorPosition, props.Focused, props.CommitPressed, props.FocusID, textEditOptions{
|
||||
maxCodepoints: props.MaxCodepoints,
|
||||
secure: props.Secure,
|
||||
readOnly: props.ReadOnly,
|
||||
})
|
||||
r.recordTextInput(FrameOpTextField, props.Bounds, props.Text, props.CursorPosition, props.Focused, props.FocusID, props.Font, props.Secure, props.ReadOnly)
|
||||
}
|
||||
|
||||
@@ -6446,8 +6605,16 @@ func pageBoundsOrView(bounds Rectangle, viewWidth, viewHeight int32) Rectangle {
|
||||
return bounds
|
||||
}
|
||||
|
||||
func (r *runtime) editText(bounds Rectangle, buf []byte, cursor *int32, focused *bool, commit *bool, focusID int32, maxCodepoints int32, secure, readOnly bool) bool {
|
||||
if readOnly {
|
||||
type textEditOptions struct {
|
||||
maxCodepoints int32
|
||||
pageRows int
|
||||
secure bool
|
||||
readOnly bool
|
||||
multiline bool
|
||||
}
|
||||
|
||||
func (r *runtime) editText(bounds Rectangle, buf []byte, cursor *int32, focused *bool, commit *bool, focusID int32, options textEditOptions) bool {
|
||||
if options.readOnly {
|
||||
delete(r.preedit, focusID)
|
||||
}
|
||||
if len(buf) == 0 {
|
||||
@@ -6494,11 +6661,11 @@ func (r *runtime) editText(bounds Rectangle, buf []byte, cursor *int32, focused
|
||||
changed := false
|
||||
for _, event := range r.inputEvents {
|
||||
if event.text != "" {
|
||||
if readOnly {
|
||||
if options.readOnly {
|
||||
continue
|
||||
}
|
||||
var inserted bool
|
||||
text, pos, inserted = insertText(text, pos, sel, event.text, textLimit(buf, maxCodepoints))
|
||||
text, pos, inserted = insertText(text, pos, sel, event.text, textLimit(buf, options.maxCodepoints))
|
||||
if inserted {
|
||||
changed = true
|
||||
sel = selection{Anchor: pos, Cursor: pos}
|
||||
@@ -6510,15 +6677,15 @@ func (r *runtime) editText(bounds Rectangle, buf []byte, cursor *int32, focused
|
||||
case KeyA:
|
||||
sel = selection{Anchor: 0, Cursor: len(text)}
|
||||
case KeyC:
|
||||
if !secure && sel.Anchor != sel.Cursor {
|
||||
if !options.secure && sel.Anchor != sel.Cursor {
|
||||
start, end := selectionRange(sel)
|
||||
r.clipboard = text[start:end]
|
||||
}
|
||||
case KeyX:
|
||||
if readOnly {
|
||||
if options.readOnly {
|
||||
continue
|
||||
}
|
||||
if !secure && sel.Anchor != sel.Cursor {
|
||||
if !options.secure && sel.Anchor != sel.Cursor {
|
||||
start, end := selectionRange(sel)
|
||||
r.clipboard = text[start:end]
|
||||
text = text[:start] + text[end:]
|
||||
@@ -6527,11 +6694,11 @@ func (r *runtime) editText(bounds Rectangle, buf []byte, cursor *int32, focused
|
||||
changed = true
|
||||
}
|
||||
case KeyV:
|
||||
if readOnly {
|
||||
if options.readOnly {
|
||||
continue
|
||||
}
|
||||
var inserted bool
|
||||
text, pos, inserted = insertText(text, pos, sel, r.clipboard, textLimit(buf, maxCodepoints))
|
||||
text, pos, inserted = insertText(text, pos, sel, r.clipboard, textLimit(buf, options.maxCodepoints))
|
||||
if inserted {
|
||||
changed = true
|
||||
sel = selection{Anchor: pos, Cursor: pos}
|
||||
@@ -6555,8 +6722,20 @@ func (r *runtime) editText(bounds Rectangle, buf []byte, cursor *int32, focused
|
||||
case KeyEnd:
|
||||
pos = len(text)
|
||||
sel = selection{Anchor: pos, Cursor: pos}
|
||||
case KeyUp, KeyDown, KeyPageUp, KeyPageDown:
|
||||
if options.multiline {
|
||||
direction, rows := -1, 1
|
||||
if event.key == KeyDown || event.key == KeyPageDown {
|
||||
direction = 1
|
||||
}
|
||||
if event.key == KeyPageUp || event.key == KeyPageDown {
|
||||
rows = max(1, options.pageRows)
|
||||
}
|
||||
pos = textMoveVertical(text, pos, direction, rows)
|
||||
sel = selection{Anchor: pos, Cursor: pos}
|
||||
}
|
||||
case KeyBackspace:
|
||||
if readOnly {
|
||||
if options.readOnly {
|
||||
continue
|
||||
}
|
||||
if sel.Anchor != sel.Cursor {
|
||||
@@ -6573,7 +6752,7 @@ func (r *runtime) editText(bounds Rectangle, buf []byte, cursor *int32, focused
|
||||
}
|
||||
sel = selection{Anchor: pos, Cursor: pos}
|
||||
case KeyDelete:
|
||||
if readOnly {
|
||||
if options.readOnly {
|
||||
continue
|
||||
}
|
||||
if sel.Anchor != sel.Cursor {
|
||||
@@ -6589,7 +6768,12 @@ func (r *runtime) editText(bounds Rectangle, buf []byte, cursor *int32, focused
|
||||
}
|
||||
sel = selection{Anchor: pos, Cursor: pos}
|
||||
case KeyEnter:
|
||||
if commit != nil {
|
||||
if options.multiline && !options.readOnly {
|
||||
var inserted bool
|
||||
text, pos, inserted = insertText(text, pos, sel, "\n", textLimit(buf, options.maxCodepoints))
|
||||
changed = changed || inserted
|
||||
sel = selection{Anchor: pos, Cursor: pos}
|
||||
} else if commit != nil {
|
||||
*commit = true
|
||||
}
|
||||
}
|
||||
@@ -6598,13 +6782,13 @@ func (r *runtime) editText(bounds Rectangle, buf []byte, cursor *int32, focused
|
||||
r.inputEvents = nil
|
||||
}
|
||||
var composed bool
|
||||
if readOnly {
|
||||
if options.readOnly {
|
||||
r.ClearTextComposition()
|
||||
} else {
|
||||
text, pos, sel, composed = r.editComposition(focusID, text, pos, sel, textLimit(buf, maxCodepoints))
|
||||
text, pos, sel, composed = r.editComposition(focusID, text, pos, sel, textLimit(buf, options.maxCodepoints))
|
||||
}
|
||||
changed = changed || composed
|
||||
if !readOnly {
|
||||
if !options.readOnly {
|
||||
clear(buf)
|
||||
copy(buf, text)
|
||||
}
|
||||
@@ -6626,6 +6810,20 @@ func (r *runtime) pointerCanReach(bounds Rectangle) bool {
|
||||
pointInRect(r.mousePos.X, r.mousePos.Y, r.scrollClip(bounds))
|
||||
}
|
||||
|
||||
func (r *runtime) hasTap(bounds Rectangle) bool {
|
||||
bounds = r.scrollClip(bounds)
|
||||
if r.contentDisabled() {
|
||||
return false
|
||||
}
|
||||
for i := range r.taps {
|
||||
if !r.taps[i].consumed && !r.popupCaptures(r.taps[i].x, r.taps[i].y) &&
|
||||
pointInRect(r.taps[i].x, r.taps[i].y, bounds) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (r *runtime) consumeTapPoint(bounds Rectangle) (float32, bool) {
|
||||
bounds = r.scrollClip(bounds)
|
||||
if r.contentDisabled() {
|
||||
@@ -6979,6 +7177,49 @@ func nextRune(text string, pos int) int {
|
||||
return pos + size
|
||||
}
|
||||
|
||||
func textLineStart(text string, pos int) int {
|
||||
pos = clampCursor(text, pos)
|
||||
if start := strings.LastIndexByte(text[:pos], '\n'); start >= 0 {
|
||||
return start + 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func textLineEnd(text string, pos int) int {
|
||||
pos = clampCursor(text, pos)
|
||||
if end := strings.IndexByte(text[pos:], '\n'); end >= 0 {
|
||||
return pos + end
|
||||
}
|
||||
return len(text)
|
||||
}
|
||||
|
||||
func textMoveVertical(text string, pos, direction, rows int) int {
|
||||
start := textLineStart(text, pos)
|
||||
column := utf8.RuneCountInString(text[start:clampCursor(text, pos)])
|
||||
for step := 0; step < max(1, rows); step++ {
|
||||
if direction < 0 {
|
||||
if start == 0 {
|
||||
break
|
||||
}
|
||||
pos = start - 1
|
||||
start = textLineStart(text, pos)
|
||||
} else {
|
||||
end := textLineEnd(text, start)
|
||||
if end == len(text) {
|
||||
break
|
||||
}
|
||||
start = end + 1
|
||||
}
|
||||
}
|
||||
pos = start
|
||||
end := textLineEnd(text, start)
|
||||
for column > 0 && pos < end {
|
||||
pos = nextRune(text, pos)
|
||||
column--
|
||||
}
|
||||
return pos
|
||||
}
|
||||
|
||||
func cellW(grid Grid) float32 {
|
||||
return (grid.Bounds.Width - float32(grid.PadX*2) - float32(max32(0, grid.Cols-1)*grid.GapX)) / float32(grid.Cols)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package kryon
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestTextAreaMultilineNavigation(t *testing.T) {
|
||||
r := New(AppConfig{Width: 240, Height: 160}).(*runtime)
|
||||
text := make([]byte, 64)
|
||||
copy(text, "a0\nb1\nc2\nd3\ne4\nf5")
|
||||
cursor := int32(4)
|
||||
focused := true
|
||||
props := TextAreaProps{
|
||||
Bounds: NewRectangle(10, 10, 160, 60), Text: text,
|
||||
CursorPosition: &cursor, Focused: &focused, FocusID: 32100, Font: Text16, LineGap: 4,
|
||||
}
|
||||
draw := func(key int32) {
|
||||
if key != 0 {
|
||||
r.QueueKey(key)
|
||||
}
|
||||
r.BeginFrame()
|
||||
r.TextArea(props)
|
||||
r.EndFrame()
|
||||
}
|
||||
|
||||
r.SetFocus(props.FocusID)
|
||||
draw(KeyDown)
|
||||
if cursor != 7 {
|
||||
t.Fatalf("Down cursor = %d, want 7", cursor)
|
||||
}
|
||||
draw(KeyPageDown)
|
||||
if cursor != 13 {
|
||||
t.Fatalf("PageDown cursor = %d, want 13", cursor)
|
||||
}
|
||||
draw(KeyPageUp)
|
||||
if cursor != 7 {
|
||||
t.Fatalf("PageUp cursor = %d, want 7", cursor)
|
||||
}
|
||||
draw(KeyEnter)
|
||||
if got := CString(text); got != "a0\nb1\nc\n2\nd3\ne4\nf5" {
|
||||
t.Fatalf("multiline Enter text = %q", got)
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 142 KiB |
+1
-1
@@ -95,7 +95,7 @@
|
||||
* layout or a public function changes signature; KryonAbiVersion() is
|
||||
* compiled into libkryon.a, while the macro is read from the current
|
||||
* headers — a mismatch means the archive is stale and must be rebuilt. */
|
||||
#define KRYON_ABI_VERSION 9
|
||||
#define KRYON_ABI_VERSION 10
|
||||
int KryonAbiVersion(void);
|
||||
|
||||
#endif /* KRYON_H */
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#define KRYON_VERSION_MAJOR 0
|
||||
#define KRYON_VERSION_MINOR 1
|
||||
#define KRYON_VERSION_PATCH 71
|
||||
#define KRYON_VERSION_STRING "v0.1.71"
|
||||
#define KRYON_VERSION_PATCH 78
|
||||
#define KRYON_VERSION_STRING "v0.1.78"
|
||||
|
||||
#endif /* KRYON_VERSION_H */
|
||||
@@ -227,7 +227,7 @@ typedef void (*UIVerticalSliderMarkCallback)(void *user_data, int x, int y,
|
||||
typedef struct {
|
||||
const char *label;
|
||||
const char *font_name;
|
||||
} UIDropdownOption;
|
||||
} DropdownOption;
|
||||
|
||||
typedef struct {
|
||||
const char *label;
|
||||
@@ -286,6 +286,13 @@ int EditText(TextEdit edit);
|
||||
void QueueTextInputCodepoint(int codepoint);
|
||||
void QueueTextInputBackspace(void);
|
||||
void QueueTextInputEnter(void);
|
||||
int TextBufferLineAtCursor(const char *text, int cursor);
|
||||
int TextBufferColumnAtCursor(const char *text, int cursor);
|
||||
int TextBufferLineCount(const char *text);
|
||||
int TextBufferToggleLineComment(char *text, int text_size, int *cursor);
|
||||
int TextBufferIndentLine(char *text, int text_size, int *cursor, int outdent);
|
||||
int TextBufferBracketMatch(const char *text, int cursor);
|
||||
Rectangle TextAreaGutter(TextAreaProps area, int gutter_width);
|
||||
int GetTextAreaSelection(int focus_id, int *start, int *end);
|
||||
void SetTextAreaSelection(int focus_id, int anchor, int cursor);
|
||||
|
||||
@@ -300,7 +307,5 @@ SegmentedControlResult SegmentedControl(SegmentedControlProps control);
|
||||
int GetScoreControlHeight(ScoreControlProps control);
|
||||
ScoreControlResult ScoreControl(ScoreControlProps control);
|
||||
|
||||
void SetUIDropdownClipTop(int top);
|
||||
void SetUIDropdownClipBottom(int bottom);
|
||||
|
||||
#endif
|
||||
@@ -28,6 +28,7 @@ Texture2D LoadIconSheet(UIIconSheet sheet);
|
||||
void UnloadIconSheets(void);
|
||||
void DrawIcon(UIIconType type, Rectangle bounds, Color tint);
|
||||
void DrawIconByName(const char *name, Rectangle bounds, Color tint);
|
||||
void DrawProfilePictureIcon(UIIconType type, Rectangle bounds, int dark_mode);
|
||||
|
||||
/* Transitional texture API for controls that do not yet accept UIIconType. */
|
||||
Texture2D LoadUIIconTexture(UIIconType type);
|
||||
|
||||
+3
-3
@@ -349,9 +349,9 @@ void IconLink(int id, int x, int y, int icon_size, Texture2D icon,
|
||||
int Dropdown(int id, int x, int y, int w, int h,
|
||||
const char **options, int option_count,
|
||||
int *selected_index);
|
||||
int DropdownEx(int id, int x, int y, int w, int h,
|
||||
const UIDropdownOption *options, int option_count,
|
||||
int *selected_index);
|
||||
int DropdownOptions(int id, int x, int y, int w, int h,
|
||||
const DropdownOption *options, int option_count,
|
||||
int *selected_index);
|
||||
int Slider(int id, int x, int y, int w, const char *label,
|
||||
int min, int max, int *value, const char *suffix,
|
||||
const char *value_text_override);
|
||||
|
||||
@@ -18,7 +18,6 @@ SHEETS = (
|
||||
("logos", "UI_ICON_SHEET_LOGOS", "ui_logos_atlas_png"),
|
||||
)
|
||||
|
||||
|
||||
def enum_name(name: str) -> str:
|
||||
return re.sub(r"[^A-Za-z0-9]", "_", name).upper()
|
||||
|
||||
|
||||
+98
-111
@@ -1,4 +1,5 @@
|
||||
#include "ui_internal.h"
|
||||
#include "dropdown_store.h"
|
||||
#include "ui_widget.h"
|
||||
|
||||
/* zero constants: the native Plan 9 compiler rejects short
|
||||
@@ -11,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
|
||||
@@ -32,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;
|
||||
}
|
||||
@@ -56,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;
|
||||
@@ -104,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];
|
||||
@@ -122,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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -328,7 +317,7 @@ DrawUIBottomNavConfigModal(BottomNavConfigProps modal)
|
||||
: "";
|
||||
int remove_hover = 0;
|
||||
DrawUIText(slot_label, frame.content_x, y, GetFontSize(), c_text);
|
||||
if(DrawUIDropdown(modal.id + i, frame.content_x,
|
||||
if(draw_dropdown(modal.id + i, frame.content_x,
|
||||
y + Scale(22),
|
||||
frame.content_w - remove_w - Scale(8),
|
||||
dropdown_h, option_labels, option_count,
|
||||
@@ -353,11 +342,10 @@ DrawUIBottomNavConfigModal(BottomNavConfigProps modal)
|
||||
}
|
||||
EndUIScrollContainer(route_area, route_view);
|
||||
|
||||
SetUIDropdownClipTop(frame.content_y);
|
||||
SetUIDropdownClipBottom(add_y - Scale(8));
|
||||
dropdown_store_clip(frame.content_y, add_y - Scale(8));
|
||||
|
||||
y = add_y;
|
||||
dropdown_blocks_buttons = ui_dropdown_captures_click(ui_mouse_world());
|
||||
dropdown_blocks_buttons = dropdown_captures(ui_mouse_world());
|
||||
if(route_count < max_route_count && modal.routes != NULL) {
|
||||
int add_hover = 0;
|
||||
add_w = frame.content_w < Scale(180) ? frame.content_w : Scale(180);
|
||||
@@ -391,8 +379,7 @@ DrawUIBottomNavConfigModal(BottomNavConfigProps modal)
|
||||
result.action = 2;
|
||||
}
|
||||
|
||||
SetUIDropdownClipTop(0);
|
||||
SetUIDropdownClipBottom(0);
|
||||
dropdown_store_clip(0, 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
+6
-23
@@ -205,13 +205,6 @@ ui_render_button(ButtonSpec button, int handle_input, int paint,
|
||||
ui_draw_termi_button_outline(draw_bounds, draw_border, hovered,
|
||||
retained_pressed,
|
||||
button.disabled);
|
||||
if(cues && hovered && button.bounds.width > 4 && button.bounds.height > 4) {
|
||||
Color cue = LightenUIColor(draw_background, 42);
|
||||
cue.a = cue.a > 170 ? 170 : cue.a;
|
||||
DrawRectangle((int)draw_bounds.x + 2, (int)draw_bounds.y + 1,
|
||||
(int)button.bounds.width - 4, Scale(1), cue);
|
||||
}
|
||||
|
||||
if(focused) {
|
||||
SetUIFocusTextInputActive(0);
|
||||
DrawUIFocus(draw_bounds);
|
||||
@@ -353,12 +346,6 @@ DrawUIIconButton(IconButtonProps button)
|
||||
hovered &&
|
||||
IsMouseButtonDown(MOUSE_BUTTON_LEFT),
|
||||
button.disabled);
|
||||
if(cues && hovered && button.bounds.width > 4 && button.bounds.height > 4) {
|
||||
Color cue = LightenUIColor(draw_background, 42);
|
||||
cue.a = cue.a > 170 ? 170 : cue.a;
|
||||
DrawRectangle((int)button.bounds.x + 2, (int)button.bounds.y + 1,
|
||||
(int)button.bounds.width - 4, Scale(1), cue);
|
||||
}
|
||||
if(focused) {
|
||||
SetUIFocusTextInputActive(0);
|
||||
DrawUIFocus(button.bounds);
|
||||
@@ -448,10 +435,16 @@ RenderTextButton(int x, int y, const char *label, int *hover)
|
||||
const char *text = label != NULL ? label : "";
|
||||
int w = (int)TextWidth(text, font) + Scale(16);
|
||||
int h = TextLineHeight(font) + Scale(8);
|
||||
int min_w = Scale(34);
|
||||
int min_h = Scale(34);
|
||||
Rectangle bounds;
|
||||
int hovered;
|
||||
ButtonSpec spec;
|
||||
|
||||
if(w < min_w)
|
||||
w = min_w;
|
||||
if(h < min_h)
|
||||
h = min_h;
|
||||
x = x - w / 2;
|
||||
bounds.x = (float)x;
|
||||
bounds.y = (float)y;
|
||||
@@ -600,16 +593,6 @@ RenderStyledButton(int x, int y, int w, int h, const char *label,
|
||||
ui_material_scheme().outline);
|
||||
}
|
||||
|
||||
if(!ui_material_style() && UITransitionCuesEnabled() &&
|
||||
style == ButtonStyleTabSelected &&
|
||||
!disabled && w > Scale(18)) {
|
||||
int cue_h = Scale(2);
|
||||
if(cue_h < 1)
|
||||
cue_h = 1;
|
||||
DrawRectangle(x + Scale(9), y + h - cue_h, w - Scale(18),
|
||||
cue_h, LightenUIColor(c_button_hover, 18));
|
||||
}
|
||||
|
||||
return clicked;
|
||||
}
|
||||
|
||||
|
||||
+112
-105
@@ -1,20 +1,20 @@
|
||||
#include "ui_internal.h"
|
||||
#include "dropdown_store.h"
|
||||
#include "ui_popup_input_internal.h"
|
||||
|
||||
#include "locale.h"
|
||||
#include <limits.h>
|
||||
|
||||
|
||||
/* Per-dropdown state to track open/closed and click handling */
|
||||
|
||||
typedef struct UIDropdownState {
|
||||
struct UIDropdownState *next;
|
||||
typedef struct DropdownState {
|
||||
struct DropdownState *next;
|
||||
int id;
|
||||
int open;
|
||||
int just_opened;
|
||||
int scroll_offset;
|
||||
int x, y, w, h;
|
||||
UIDropdownOption *options;
|
||||
DropdownOption *options;
|
||||
int option_count;
|
||||
int selected_index;
|
||||
int highlight_index;
|
||||
@@ -29,18 +29,71 @@ typedef struct UIDropdownState {
|
||||
int clip_bottom;
|
||||
unsigned long frame_seen;
|
||||
unsigned long opened_frame;
|
||||
} UIDropdownState;
|
||||
} DropdownState;
|
||||
|
||||
static UIDropdownState *dropdown_states;
|
||||
static int dropdown_clip_top = 0;
|
||||
static int dropdown_clip_bottom = 0;
|
||||
struct DropdownStore {
|
||||
DropdownState *states;
|
||||
int clip_top;
|
||||
int clip_bottom;
|
||||
int previous_focused;
|
||||
};
|
||||
|
||||
static UIDropdownOption *
|
||||
static DropdownStore fallback_store = {.previous_focused = 1};
|
||||
static DropdownStore *dropdown_store = &fallback_store;
|
||||
static void dropdown_resize_options(DropdownState *state, int count);
|
||||
|
||||
static void
|
||||
free_dropdown_states(DropdownState *state)
|
||||
{
|
||||
while(state != NULL) {
|
||||
DropdownState *next = state->next;
|
||||
dropdown_resize_options(state, 0);
|
||||
free(state);
|
||||
state = next;
|
||||
}
|
||||
}
|
||||
|
||||
DropdownStore *
|
||||
dropdown_store_new(void)
|
||||
{
|
||||
DropdownStore *store = calloc(1, sizeof(*store));
|
||||
if(store == NULL)
|
||||
abort();
|
||||
store->previous_focused = 1;
|
||||
return store;
|
||||
}
|
||||
|
||||
void
|
||||
dropdown_store_free(DropdownStore *store)
|
||||
{
|
||||
if(store == NULL)
|
||||
return;
|
||||
if(store == dropdown_store || store == &fallback_store)
|
||||
abort();
|
||||
free_dropdown_states(store->states);
|
||||
free(store);
|
||||
}
|
||||
|
||||
DropdownStore *
|
||||
dropdown_store_swap(DropdownStore *store)
|
||||
{
|
||||
DropdownStore *previous = dropdown_store;
|
||||
dropdown_store = store != NULL ? store : &fallback_store;
|
||||
return previous;
|
||||
}
|
||||
|
||||
DropdownStore *
|
||||
dropdown_store_current(void)
|
||||
{
|
||||
return dropdown_store;
|
||||
}
|
||||
|
||||
static DropdownOption *
|
||||
dropdown_options_alloc(int count)
|
||||
{
|
||||
if(count <= 0) return NULL;
|
||||
if((size_t)count > SIZE_MAX / sizeof(UIDropdownOption)) abort();
|
||||
UIDropdownOption *options = calloc((size_t)count, sizeof(*options));
|
||||
if((size_t)count > SIZE_MAX / sizeof(DropdownOption)) abort();
|
||||
DropdownOption *options = calloc((size_t)count, sizeof(*options));
|
||||
if(options == NULL) abort();
|
||||
return options;
|
||||
}
|
||||
@@ -58,10 +111,10 @@ dropdown_copy_text(const char **target, const char *text)
|
||||
}
|
||||
|
||||
static void
|
||||
dropdown_resize_options(UIDropdownState *state, int count)
|
||||
dropdown_resize_options(DropdownState *state, int count)
|
||||
{
|
||||
if(state->option_count == count) return;
|
||||
UIDropdownOption *options = dropdown_options_alloc(count);
|
||||
DropdownOption *options = dropdown_options_alloc(count);
|
||||
int keep = count < state->option_count ? count : state->option_count;
|
||||
if(keep > 0) memcpy(options, state->options, (size_t)keep * sizeof(*options));
|
||||
for(int i = keep; i < state->option_count; i++) {
|
||||
@@ -80,29 +133,15 @@ dropdown_content_height(int count, int row_height, int padding)
|
||||
return height > INT_MAX ? INT_MAX : (int)height;
|
||||
}
|
||||
|
||||
static const char *
|
||||
locale_dropdown_font_name(const char *code)
|
||||
{
|
||||
if(code == NULL)
|
||||
return "ui-lang-latin";
|
||||
if(strcmp(code, "ja") == 0)
|
||||
return "ui-lang-ja";
|
||||
if(strcmp(code, "ko") == 0)
|
||||
return "ui-lang-ko";
|
||||
if(strcmp(code, "zh") == 0)
|
||||
return "ui-lang-zh";
|
||||
return "ui-lang-latin";
|
||||
}
|
||||
|
||||
static Color
|
||||
ui_dropdown_panel_color(int amount)
|
||||
dropdown_panel_color(int amount)
|
||||
{
|
||||
int luminance = ((int)c_bg.r + (int)c_bg.g + (int)c_bg.b) / 3;
|
||||
return luminance < 96 ? LightenUIColor(c_bg, amount) : DarkenUIColor(c_bg, amount);
|
||||
}
|
||||
|
||||
static Color
|
||||
ui_dropdown_text_on(Color bg)
|
||||
dropdown_text_color(Color bg)
|
||||
{
|
||||
int luma = (int)bg.r * 299 + (int)bg.g * 587 + (int)bg.b * 114;
|
||||
|
||||
@@ -130,19 +169,14 @@ dropdown_draw_indicator(int center_x, int center_y, int size, int open,
|
||||
}
|
||||
|
||||
void
|
||||
SetUIDropdownClipTop(int top)
|
||||
dropdown_store_clip(int top, int bottom)
|
||||
{
|
||||
dropdown_clip_top = top > 0 ? top : 0;
|
||||
}
|
||||
|
||||
void
|
||||
SetUIDropdownClipBottom(int bottom)
|
||||
{
|
||||
dropdown_clip_bottom = bottom > 0 ? bottom : 0;
|
||||
dropdown_store->clip_top = top > 0 ? top : 0;
|
||||
dropdown_store->clip_bottom = bottom > 0 ? bottom : 0;
|
||||
}
|
||||
|
||||
static void
|
||||
dropdown_menu_layout(const UIDropdownState *state, int *dropdown_y, int *dropdown_h,
|
||||
dropdown_menu_layout(const DropdownState *state, int *dropdown_y, int *dropdown_h,
|
||||
int *visible_options, int *open_up)
|
||||
{
|
||||
int option_h;
|
||||
@@ -211,7 +245,7 @@ dropdown_menu_layout(const UIDropdownState *state, int *dropdown_y, int *dropdow
|
||||
}
|
||||
|
||||
static Rectangle
|
||||
dropdown_menu_bounds(const UIDropdownState *state)
|
||||
dropdown_menu_bounds(const DropdownState *state)
|
||||
{
|
||||
int y = 0, height = 0;
|
||||
dropdown_menu_layout(state, &y, &height, NULL, NULL);
|
||||
@@ -221,9 +255,9 @@ dropdown_menu_bounds(const UIDropdownState *state)
|
||||
}
|
||||
|
||||
int
|
||||
ui_dropdown_captures_click(Vector2 point)
|
||||
dropdown_captures(Vector2 point)
|
||||
{
|
||||
for(UIDropdownState *state = dropdown_states; state != NULL; state = state->next) {
|
||||
for(DropdownState *state = dropdown_store->states; state != NULL; state = state->next) {
|
||||
if(!state->open || state->option_count <= 0)
|
||||
continue;
|
||||
Rectangle bounds = dropdown_menu_bounds(state);
|
||||
@@ -234,7 +268,7 @@ ui_dropdown_captures_click(Vector2 point)
|
||||
}
|
||||
|
||||
static void
|
||||
close_dropdown_state(UIDropdownState *state)
|
||||
close_dropdown_state(DropdownState *state)
|
||||
{
|
||||
if(state == NULL)
|
||||
return;
|
||||
@@ -247,9 +281,9 @@ close_dropdown_state(UIDropdownState *state)
|
||||
}
|
||||
|
||||
void
|
||||
ui_dropdown_close(int id)
|
||||
dropdown_close(int id)
|
||||
{
|
||||
for(UIDropdownState *state = dropdown_states; state != NULL; state = state->next) {
|
||||
for(DropdownState *state = dropdown_store->states; state != NULL; state = state->next) {
|
||||
if(state->id == id) {
|
||||
close_dropdown_state(state);
|
||||
return;
|
||||
@@ -260,54 +294,54 @@ ui_dropdown_close(int id)
|
||||
static void
|
||||
close_other_dropdowns(int id)
|
||||
{
|
||||
for(UIDropdownState *state = dropdown_states; state != NULL; state = state->next) {
|
||||
for(DropdownState *state = dropdown_store->states; state != NULL; state = state->next) {
|
||||
if(state->id != id)
|
||||
close_dropdown_state(state);
|
||||
}
|
||||
}
|
||||
|
||||
static UIDropdownState *
|
||||
static DropdownState *
|
||||
get_or_create_dropdown_state(int id)
|
||||
{
|
||||
for(UIDropdownState *state = dropdown_states; state != NULL; state = state->next) {
|
||||
for(DropdownState *state = dropdown_store->states; state != NULL; state = state->next) {
|
||||
if(state->id == id)
|
||||
return state;
|
||||
}
|
||||
/* State and owned option strings never alias another control's ID. */
|
||||
UIDropdownState *state = calloc(1, sizeof(*state));
|
||||
DropdownState *state = calloc(1, sizeof(*state));
|
||||
if(state == NULL) abort();
|
||||
state->id = id;
|
||||
state->next = dropdown_states;
|
||||
dropdown_states = state;
|
||||
state->next = dropdown_store->states;
|
||||
dropdown_store->states = state;
|
||||
return state;
|
||||
}
|
||||
|
||||
int
|
||||
DrawUIDropdown(int id, int x, int y, int w, int h,
|
||||
draw_dropdown(int id, int x, int y, int w, int h,
|
||||
const char **options, int option_count, int *selected_index)
|
||||
{
|
||||
if(option_count < 0)
|
||||
option_count = 0;
|
||||
UIDropdownOption *dropdown_options = dropdown_options_alloc(option_count);
|
||||
DropdownOption *dropdown_options = dropdown_options_alloc(option_count);
|
||||
|
||||
for(int i = 0; i < option_count; i++) {
|
||||
dropdown_options[i].label = options != NULL ? options[i] : NULL;
|
||||
dropdown_options[i].font_name = NULL;
|
||||
}
|
||||
|
||||
int changed = DrawUIDropdownEx(id, x, y, w, h, dropdown_options,
|
||||
option_count, selected_index);
|
||||
int changed = draw_dropdown_options(id, x, y, w, h, dropdown_options,
|
||||
option_count, selected_index);
|
||||
free(dropdown_options);
|
||||
return changed;
|
||||
}
|
||||
|
||||
int
|
||||
DrawUIDropdownEx(int id, int x, int y, int w, int h,
|
||||
const UIDropdownOption *options, int option_count,
|
||||
int *selected_index)
|
||||
draw_dropdown_options(int id, int x, int y, int w, int h,
|
||||
const DropdownOption *options, int option_count,
|
||||
int *selected_index)
|
||||
{
|
||||
char editor_id[96];
|
||||
UIDropdownState *state = get_or_create_dropdown_state(id);
|
||||
DropdownState *state = get_or_create_dropdown_state(id);
|
||||
UIWidget widget;
|
||||
int font = GetFontSize();
|
||||
int arrow_pad = Scale(24);
|
||||
@@ -372,8 +406,8 @@ DrawUIDropdownEx(int id, int x, int y, int w, int h,
|
||||
state->y = y;
|
||||
state->w = w;
|
||||
state->h = h;
|
||||
state->clip_top = dropdown_clip_top;
|
||||
state->clip_bottom = dropdown_clip_bottom;
|
||||
state->clip_top = dropdown_store->clip_top;
|
||||
state->clip_bottom = dropdown_store->clip_bottom;
|
||||
state->selected_index = selected_index != NULL ? *selected_index : state->selected_index;
|
||||
if(option_count < 0)
|
||||
option_count = 0;
|
||||
@@ -411,8 +445,8 @@ DrawUIDropdownEx(int id, int x, int y, int w, int h,
|
||||
}
|
||||
|
||||
/* Draw button background */
|
||||
button_bg = state->open ? ui_dropdown_panel_color(28)
|
||||
: (hover ? c_button_hover : ui_dropdown_panel_color(16));
|
||||
button_bg = state->open ? dropdown_panel_color(28)
|
||||
: (hover ? c_button_hover : dropdown_panel_color(16));
|
||||
if(can_draw) {
|
||||
if(ui_material_style()) {
|
||||
Color surface = ui_material_surface_container();
|
||||
@@ -434,7 +468,7 @@ DrawUIDropdownEx(int id, int x, int y, int w, int h,
|
||||
: DarkenUIColor(button_bg, 30));
|
||||
}
|
||||
}
|
||||
button_text = ui_dropdown_text_on(button_bg);
|
||||
button_text = dropdown_text_color(button_bg);
|
||||
|
||||
/* Draw current selection text, clipped before the chevron. */
|
||||
int current_index = state->selected_index;
|
||||
@@ -464,36 +498,10 @@ DrawUIDropdownEx(int id, int x, int y, int w, int h,
|
||||
return changed;
|
||||
}
|
||||
|
||||
int
|
||||
DrawUILocaleDropdown(int id, int x, int y, int w, int h,
|
||||
int *selected_index)
|
||||
{
|
||||
int count = GetLocaleCount();
|
||||
|
||||
if(selected_index == NULL)
|
||||
return 0;
|
||||
if(count < 0)
|
||||
count = 0;
|
||||
UIDropdownOption *options = dropdown_options_alloc(count);
|
||||
for(int i = 0; i < count; i++) {
|
||||
options[i].label = GetLocaleLabel(i);
|
||||
options[i].font_name = locale_dropdown_font_name(GetLocaleCode(i));
|
||||
}
|
||||
if(count <= 0) {
|
||||
const char *fallback[] = {"Language"};
|
||||
return DrawUIDropdown(id, x, y, w, h, fallback, 1, selected_index);
|
||||
}
|
||||
if(*selected_index < 0 || *selected_index >= count)
|
||||
*selected_index = 0;
|
||||
int changed = DrawUIDropdownEx(id, x, y, w, h, options, count, selected_index);
|
||||
free(options);
|
||||
return changed;
|
||||
}
|
||||
|
||||
static int
|
||||
draw_dropdown_menu(int id)
|
||||
{
|
||||
UIDropdownState *state = get_or_create_dropdown_state(id);
|
||||
DropdownState *state = get_or_create_dropdown_state(id);
|
||||
int changed = 0;
|
||||
|
||||
if(!state->open)
|
||||
@@ -510,9 +518,9 @@ draw_dropdown_menu(int id)
|
||||
int h = state->h;
|
||||
int option_h = h;
|
||||
int option_count = state->option_count;
|
||||
const UIDropdownOption *options = state->options;
|
||||
Color panel = ui_dropdown_panel_color(18);
|
||||
Color option_text = ui_dropdown_text_on(panel);
|
||||
const DropdownOption *options = state->options;
|
||||
Color panel = dropdown_panel_color(18);
|
||||
Color option_text = dropdown_text_color(panel);
|
||||
int can_draw = IsWindowReady();
|
||||
int clip_started = 0;
|
||||
|
||||
@@ -649,16 +657,16 @@ draw_dropdown_menu(int id)
|
||||
Color border = ui_material_outline();
|
||||
|
||||
panel = ui_material_surface_container();
|
||||
option_text = ui_dropdown_text_on(panel);
|
||||
option_text = dropdown_text_color(panel);
|
||||
/* Use subtle radius for dropdown panels to prevent distortion during resize */
|
||||
ui_draw_control_background((Rectangle){x, dropdown_y, w, dropdown_h},
|
||||
panel, border, 0.06f);
|
||||
} else if(ui_modern_style()) {
|
||||
UIStyleTokens tokens = GetUIStyleTokens();
|
||||
Color border = ui_dropdown_panel_color(36);
|
||||
Color border = dropdown_panel_color(36);
|
||||
if(tokens.panel_alpha < panel.a)
|
||||
panel.a = tokens.panel_alpha;
|
||||
option_text = ui_dropdown_text_on(panel);
|
||||
option_text = dropdown_text_color(panel);
|
||||
ui_draw_control_background(
|
||||
(Rectangle){x, dropdown_y, w, dropdown_h}, panel, border,
|
||||
ui_radius_px((Rectangle){x, dropdown_y, w, dropdown_h},
|
||||
@@ -666,8 +674,8 @@ draw_dropdown_menu(int id)
|
||||
} else {
|
||||
DrawRectangle(x, dropdown_y, w, dropdown_h, panel);
|
||||
DrawUIBevel(x, dropdown_y, w, dropdown_h,
|
||||
ui_dropdown_panel_color(32),
|
||||
ui_dropdown_panel_color(8));
|
||||
dropdown_panel_color(32),
|
||||
dropdown_panel_color(8));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -797,23 +805,22 @@ draw_arrow:
|
||||
}
|
||||
|
||||
void
|
||||
ui_draw_dropdown_overlays(void)
|
||||
draw_dropdown_overlays(void)
|
||||
{
|
||||
/* Escape and losing the window focus dismiss open popups, so a
|
||||
* dropdown can never trap the pointer state. */
|
||||
static int prev_focused = 1;
|
||||
int focused = IsWindowFocused();
|
||||
int lost_focus = prev_focused && !focused;
|
||||
int lost_focus = dropdown_store->previous_focused && !focused;
|
||||
int escape_pressed = IsKeyPressed(KEY_ESCAPE);
|
||||
|
||||
prev_focused = focused;
|
||||
dropdown_store->previous_focused = focused;
|
||||
if(lost_focus || escape_pressed) {
|
||||
for(UIDropdownState *state = dropdown_states; state != NULL; state = state->next)
|
||||
for(DropdownState *state = dropdown_store->states; state != NULL; state = state->next)
|
||||
close_dropdown_state(state);
|
||||
}
|
||||
UIDropdownState **link = &dropdown_states;
|
||||
DropdownState **link = &dropdown_store->states;
|
||||
while(*link != NULL) {
|
||||
UIDropdownState *state = *link;
|
||||
DropdownState *state = *link;
|
||||
if(state->frame_seen != g_ui_frame_serial) {
|
||||
*link = state->next;
|
||||
close_dropdown_state(state);
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef KRYON_DROPDOWN_STORE_H
|
||||
#define KRYON_DROPDOWN_STORE_H
|
||||
|
||||
/* Private retained state for the canonical Dropdown/Combobox implementation.
|
||||
* Each render host owns one store, so equal widget IDs in different windows
|
||||
* cannot collide. */
|
||||
typedef struct DropdownStore DropdownStore;
|
||||
|
||||
DropdownStore *dropdown_store_new(void);
|
||||
void dropdown_store_free(DropdownStore *store);
|
||||
DropdownStore *dropdown_store_swap(DropdownStore *store);
|
||||
DropdownStore *dropdown_store_current(void);
|
||||
void dropdown_store_clip(int top, int bottom);
|
||||
|
||||
#endif
|
||||
+45
-17
@@ -166,17 +166,27 @@ ui_draw_pfp_texture(Texture2D icon, int x, int y, int size)
|
||||
static void
|
||||
ui_draw_pfp_texture_in_circle(Texture2D icon, int cx, int cy, int radius)
|
||||
{
|
||||
int inner_size = radius * 14 / 10;
|
||||
int inner_size = radius * 2;
|
||||
int x;
|
||||
int y;
|
||||
|
||||
if(inner_size > radius * 2)
|
||||
inner_size = radius * 2;
|
||||
x = cx - inner_size / 2;
|
||||
y = cy - inner_size / 2;
|
||||
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)
|
||||
{
|
||||
return IsThemeColorDark(GetThemeBackground()) ? 1 : 0;
|
||||
}
|
||||
|
||||
static void
|
||||
ui_draw_pfp_fallback(int x, int y, int size, Color color)
|
||||
{
|
||||
@@ -258,12 +268,22 @@ 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));
|
||||
if(pfp_icon.id != 0)
|
||||
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 + 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)
|
||||
ui_draw_pfp_texture_in_circle(pfp_icon, avatar_x, avatar_y, avatar_r);
|
||||
else
|
||||
ui_draw_pfp_fallback(avatar_x - avatar_r, avatar_y - avatar_r,
|
||||
@@ -375,7 +395,7 @@ DrawUIProfilePicturePickerModal(ProfilePicturePickerProps modal)
|
||||
scroll_view = BeginUIScrollContainer(scroll_area);
|
||||
|
||||
mouse = ui_mouse_world();
|
||||
icon_inset = Scale(12);
|
||||
icon_inset = Scale(6);
|
||||
for(i = 0; i < count; i++) {
|
||||
int row = i / columns;
|
||||
int col = i % columns;
|
||||
@@ -389,18 +409,26 @@ 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 &&
|
||||
type < UI_ICON_TYPE_COUNT)
|
||||
icon = modal.icons[type];
|
||||
if(icon.id != 0)
|
||||
if(type > UI_ICON_TYPE_NONE && type < UI_ICON_TYPE_COUNT) {
|
||||
Rectangle icon_bounds;
|
||||
|
||||
icon_bounds.x = (float)(x + icon_inset);
|
||||
icon_bounds.y = (float)(y + icon_inset);
|
||||
icon_bounds.width = (float)(cell - icon_inset * 2);
|
||||
icon_bounds.height = (float)(cell - icon_inset * 2);
|
||||
DrawProfilePictureIcon(type, icon_bounds,
|
||||
ui_profile_pictures_dark_mode());
|
||||
} else if(icon.id != 0)
|
||||
ui_draw_pfp_texture(icon, x + icon_inset, y + icon_inset,
|
||||
cell - icon_inset * 2);
|
||||
else
|
||||
|
||||
@@ -184,7 +184,7 @@ DrawUIThemeSettings(ThemeSettingsProps settings, UIThemeSettingsState *state)
|
||||
if(show_mode) {
|
||||
DrawUIText(ui_theme_settings_text(settings.mode_label, "theme_mode_label", "Mode"),
|
||||
settings.x, y, font, c_text);
|
||||
if(DrawUIDropdown(settings.id_base + 1, settings.x, y + font + label_gap,
|
||||
if(draw_dropdown(settings.id_base + 1, settings.x, y + font + label_gap,
|
||||
settings.w, row_h, mode_options, mode_count,
|
||||
&mode_index)) {
|
||||
*settings.theme_mode = mode_values[ui_clampi(mode_index, 0, mode_count - 1)];
|
||||
@@ -195,7 +195,7 @@ DrawUIThemeSettings(ThemeSettingsProps settings, UIThemeSettingsState *state)
|
||||
}
|
||||
y += font + label_gap + row_h + row_gap;
|
||||
} else {
|
||||
ui_dropdown_close(settings.id_base + 1);
|
||||
dropdown_close(settings.id_base + 1);
|
||||
}
|
||||
|
||||
palette_count = ui_theme_palette_option_count(settings);
|
||||
@@ -215,7 +215,7 @@ DrawUIThemeSettings(ThemeSettingsProps settings, UIThemeSettingsState *state)
|
||||
}
|
||||
DrawUIText(ui_theme_settings_text(settings.palette_label, "theme_color_label", "Color"),
|
||||
settings.x, y, font, c_text);
|
||||
if(DrawUIDropdown(settings.id_base + 2, settings.x, y + font + label_gap,
|
||||
if(draw_dropdown(settings.id_base + 2, settings.x, y + font + label_gap,
|
||||
settings.w, row_h, theme_options, palette_count,
|
||||
state != NULL ? &state->palette_index : &palette_index)) {
|
||||
if(state != NULL)
|
||||
@@ -247,7 +247,7 @@ DrawUIThemeSettings(ThemeSettingsProps settings, UIThemeSettingsState *state)
|
||||
}
|
||||
DrawUIText(ui_theme_settings_text(settings.style_label, "theme_style_label", "Style"),
|
||||
settings.x, y, font, c_text);
|
||||
if(DrawUIDropdown(settings.id_base + 3,
|
||||
if(draw_dropdown(settings.id_base + 3,
|
||||
settings.x, y + font + label_gap,
|
||||
settings.w, row_h, style_options, 3,
|
||||
&style_index)) {
|
||||
@@ -259,7 +259,7 @@ DrawUIThemeSettings(ThemeSettingsProps settings, UIThemeSettingsState *state)
|
||||
}
|
||||
y += font + label_gap + row_h + row_gap;
|
||||
} else {
|
||||
ui_dropdown_close(settings.id_base + 3);
|
||||
dropdown_close(settings.id_base + 3);
|
||||
}
|
||||
|
||||
return y - row_gap;
|
||||
|
||||
+1
-1
@@ -72,7 +72,7 @@ DrawUIToolbar(ToolbarProps toolbar)
|
||||
dropdown_w = dropdown_available_w;
|
||||
if(dropdown_w < 0)
|
||||
dropdown_w = 0;
|
||||
if(DrawUIDropdown(toolbar.id, dropdown_x, dropdown_y,
|
||||
if(draw_dropdown(toolbar.id, dropdown_x, dropdown_y,
|
||||
dropdown_w, dropdown_h,
|
||||
toolbar.options, toolbar.option_count,
|
||||
toolbar.selected_index))
|
||||
|
||||
+3
-3
@@ -87,9 +87,9 @@ DrawUITopNav(TopNavProps nav)
|
||||
if(dropdown_w < 1)
|
||||
dropdown_w = 1;
|
||||
if(!nav.disabled)
|
||||
DrawUIDropdown(nav.id, dropdown_x, dropdown_y, dropdown_w,
|
||||
dropdown_h, nav.options, nav.option_count,
|
||||
nav.selected_index);
|
||||
draw_dropdown(nav.id, dropdown_x, dropdown_y, dropdown_w,
|
||||
dropdown_h, nav.options, nav.option_count,
|
||||
nav.selected_index);
|
||||
if(*nav.selected_index != previous)
|
||||
result.selected_menu_item = *nav.selected_index;
|
||||
} else {
|
||||
|
||||
+355
-13
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -719,7 +739,7 @@ ui_input_captures_click_internal(Vector2 point, int include_pointer_drag)
|
||||
{
|
||||
return ui_base_input_captures_click(point, include_pointer_drag) ||
|
||||
ui_popup_input_current_captures(point) ||
|
||||
ui_dropdown_captures_click(point);
|
||||
dropdown_captures(point);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -727,7 +747,7 @@ ui_input_captures_snapshot(Vector2 point, UIPopupInputToken snapshot)
|
||||
{
|
||||
return UIContentDisabled() || UIInspectInputCapturesClick(point) ||
|
||||
ui_base_input_captures_click(point,1) ||
|
||||
ui_dropdown_captures_click(point) ||
|
||||
dropdown_captures(point) ||
|
||||
ui_popup_input_snapshot_captures(snapshot,point);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -1511,7 +1561,7 @@ ui_register_focus_snapshot(int id, Rectangle bounds, UIPopupInputToken snapshot)
|
||||
ui_popup_input_register_focus(id,snapshot,
|
||||
!UIContentDisabled() && !UIInspectInputCapturesClick(focus_point) &&
|
||||
!ui_base_input_captures_click(focus_point,0) &&
|
||||
!ui_dropdown_captures_click(focus_point) &&
|
||||
!dropdown_captures(focus_point) &&
|
||||
!ui_popup_input_snapshot_captures(snapshot,focus_point));
|
||||
if(g_ui_focus_count < UI_FOCUS_MAX_ITEMS)
|
||||
g_ui_focus_ids[g_ui_focus_count++] = id;
|
||||
@@ -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;
|
||||
@@ -2885,6 +2963,259 @@ ui_paint_text_area(TextAreaProps area, int cursor, int focused,
|
||||
EndUIClip();
|
||||
}
|
||||
|
||||
int
|
||||
TextBufferLineAtCursor(const char *text, int cursor)
|
||||
{
|
||||
int line = 1;
|
||||
|
||||
if(text == NULL)
|
||||
return 1;
|
||||
for(int i = 0; text[i] != '\0' && i < cursor; i++) {
|
||||
if(text[i] == '\n')
|
||||
line++;
|
||||
}
|
||||
return line;
|
||||
}
|
||||
|
||||
int
|
||||
TextBufferColumnAtCursor(const char *text, int cursor)
|
||||
{
|
||||
int col = 1;
|
||||
|
||||
if(text == NULL)
|
||||
return 1;
|
||||
for(int i = 0; text[i] != '\0' && i < cursor; i++) {
|
||||
if(text[i] == '\n')
|
||||
col = 1;
|
||||
else
|
||||
col++;
|
||||
}
|
||||
return col;
|
||||
}
|
||||
|
||||
int
|
||||
TextBufferLineCount(const char *text)
|
||||
{
|
||||
int lines = 1;
|
||||
|
||||
if(text == NULL)
|
||||
return 1;
|
||||
for(int i = 0; text[i] != '\0'; i++) {
|
||||
if(text[i] == '\n')
|
||||
lines++;
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
static int
|
||||
text_buffer_line_start(const char *text, int cursor)
|
||||
{
|
||||
int start = cursor;
|
||||
|
||||
if(text == NULL)
|
||||
return 0;
|
||||
if(start < 0)
|
||||
start = 0;
|
||||
while(start > 0 && text[start - 1] != '\n')
|
||||
start--;
|
||||
return start;
|
||||
}
|
||||
|
||||
static int
|
||||
text_buffer_insert(char *text, int text_size, int at, const char *bytes,
|
||||
int len)
|
||||
{
|
||||
int used;
|
||||
|
||||
if(text == NULL || bytes == NULL || text_size <= 0 || len <= 0)
|
||||
return 0;
|
||||
used = (int)strlen(text);
|
||||
if(at < 0 || at > used || used + len >= text_size)
|
||||
return 0;
|
||||
memmove(text + at + len, text + at, (size_t)(used - at + 1));
|
||||
memcpy(text + at, bytes, (size_t)len);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
text_buffer_delete(char *text, int at, int len)
|
||||
{
|
||||
int used;
|
||||
|
||||
if(text == NULL || len <= 0)
|
||||
return 0;
|
||||
used = (int)strlen(text);
|
||||
if(at < 0 || at + len > used)
|
||||
return 0;
|
||||
memmove(text + at, text + at + len, (size_t)(used - at - len + 1));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
TextBufferToggleLineComment(char *text, int text_size, int *cursor)
|
||||
{
|
||||
int start;
|
||||
int p;
|
||||
|
||||
if(text == NULL || cursor == NULL)
|
||||
return 0;
|
||||
start = text_buffer_line_start(text, *cursor);
|
||||
p = start;
|
||||
while(text[p] == ' ' || text[p] == '\t')
|
||||
p++;
|
||||
if(text[p] == '/' && text[p + 1] == '/') {
|
||||
if(!text_buffer_delete(text, p, 2))
|
||||
return 0;
|
||||
if(*cursor >= p + 2)
|
||||
*cursor -= 2;
|
||||
else if(*cursor > p)
|
||||
*cursor = p;
|
||||
return 1;
|
||||
}
|
||||
if(!text_buffer_insert(text, text_size, p, "//", 2))
|
||||
return 0;
|
||||
if(*cursor >= p)
|
||||
*cursor += 2;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
TextBufferIndentLine(char *text, int text_size, int *cursor, int outdent)
|
||||
{
|
||||
int start;
|
||||
int remove = 0;
|
||||
|
||||
if(text == NULL || cursor == NULL)
|
||||
return 0;
|
||||
start = text_buffer_line_start(text, *cursor);
|
||||
if(outdent) {
|
||||
while(remove < 4 && text[start + remove] == ' ')
|
||||
remove++;
|
||||
if(remove == 0 && text[start] == '\t')
|
||||
remove = 1;
|
||||
if(remove == 0)
|
||||
return 0;
|
||||
if(!text_buffer_delete(text, start, remove))
|
||||
return 0;
|
||||
if(*cursor >= start + remove)
|
||||
*cursor -= remove;
|
||||
else if(*cursor > start)
|
||||
*cursor = start;
|
||||
return 1;
|
||||
}
|
||||
if(!text_buffer_insert(text, text_size, start, " ", 4))
|
||||
return 0;
|
||||
if(*cursor >= start)
|
||||
*cursor += 4;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
TextBufferBracketMatch(const char *text, int cursor)
|
||||
{
|
||||
const char *opens = "([{";
|
||||
const char *closes = ")]}";
|
||||
int len;
|
||||
int pos;
|
||||
const char *p;
|
||||
int dir;
|
||||
char open;
|
||||
char close;
|
||||
int depth = 0;
|
||||
|
||||
if(text == NULL)
|
||||
return -1;
|
||||
len = (int)strlen(text);
|
||||
if(len <= 0)
|
||||
return -1;
|
||||
if(cursor < 0)
|
||||
cursor = 0;
|
||||
if(cursor >= len)
|
||||
cursor = len - 1;
|
||||
pos = cursor;
|
||||
if(pos > 0 && strchr(opens, text[pos]) == NULL &&
|
||||
strchr(closes, text[pos]) == NULL)
|
||||
pos--;
|
||||
p = strchr(opens, text[pos]);
|
||||
if(p != NULL) {
|
||||
open = *p;
|
||||
close = closes[p - opens];
|
||||
dir = 1;
|
||||
} else {
|
||||
p = strchr(closes, text[pos]);
|
||||
if(p == NULL)
|
||||
return -1;
|
||||
close = *p;
|
||||
open = opens[p - closes];
|
||||
dir = -1;
|
||||
}
|
||||
for(int i = pos; i >= 0 && i < len; i += dir) {
|
||||
if(text[i] == open)
|
||||
depth += dir > 0 ? 1 : -1;
|
||||
else if(text[i] == close)
|
||||
depth += dir > 0 ? -1 : 1;
|
||||
if(depth == 0 && i != pos)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
Rectangle
|
||||
TextAreaGutter(TextAreaProps area, int gutter_width)
|
||||
{
|
||||
int font;
|
||||
int line_gap;
|
||||
int line_h;
|
||||
int scroll_y;
|
||||
int first;
|
||||
int rows;
|
||||
int active;
|
||||
int total;
|
||||
int y;
|
||||
Rectangle gutter;
|
||||
|
||||
if(gutter_width <= 0)
|
||||
return area.bounds;
|
||||
area.style = ui_resolve_text_input_style(area.style);
|
||||
font = area.font > 0 ? area.font : GetFontSize();
|
||||
line_gap = area.line_gap >= 0 ? area.line_gap : Scale(6);
|
||||
line_h = TextLineHeight(font) + line_gap;
|
||||
if(line_h <= 0)
|
||||
return area.bounds;
|
||||
scroll_y = area.scroll_y != NULL ? *area.scroll_y : 0;
|
||||
first = scroll_y / line_h;
|
||||
rows = ((int)area.bounds.height / line_h) + 3;
|
||||
active = TextBufferLineAtCursor(area.text, area.cursor_position != NULL
|
||||
? *area.cursor_position : 0);
|
||||
total = TextBufferLineCount(area.text);
|
||||
gutter = (Rectangle){area.bounds.x, area.bounds.y, (float)gutter_width,
|
||||
area.bounds.height};
|
||||
DrawRectangleRec(gutter, area.style.background);
|
||||
DrawLine((int)(gutter.x + gutter.width) - 1, (int)gutter.y,
|
||||
(int)(gutter.x + gutter.width) - 1,
|
||||
(int)(gutter.y + gutter.height), area.style.border);
|
||||
y = (int)gutter.y + Scale(10) - (scroll_y % line_h);
|
||||
for(int row = 0; row < rows; row++) {
|
||||
int line_no = first + row + 1;
|
||||
char label[24];
|
||||
|
||||
if(line_no > total)
|
||||
break;
|
||||
if(line_no == active)
|
||||
DrawRectangle((int)gutter.x, y - Scale(2), (int)gutter.width,
|
||||
line_h, area.style.border);
|
||||
snprintf(label, sizeof(label), "%d", line_no);
|
||||
DrawUIText(label, (int)gutter.x + Scale(6), y, Scale(10),
|
||||
line_no == active ? area.style.text : GetThemeIcon());
|
||||
y += line_h;
|
||||
if(y > (int)(gutter.y + gutter.height))
|
||||
break;
|
||||
}
|
||||
area.bounds.x += gutter_width;
|
||||
area.bounds.width -= gutter_width;
|
||||
return area.bounds;
|
||||
}
|
||||
|
||||
int
|
||||
RenderTextArea(TextAreaProps area)
|
||||
{
|
||||
@@ -3277,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,
|
||||
@@ -3311,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(
|
||||
@@ -4551,7 +4889,7 @@ DrawUIFrameOverlays(void)
|
||||
return;
|
||||
g_ui_overlays_drawn_frame = g_ui_frame_serial;
|
||||
ResetUIClip();
|
||||
ui_draw_dropdown_overlays();
|
||||
draw_dropdown_overlays();
|
||||
ui_draw_menu_overlays();
|
||||
ui_tab_bar_finish_frame();
|
||||
ui_text_draw_context_overlay();
|
||||
@@ -4650,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
-692
File diff suppressed because it is too large.
Load diff
+13
-2
@@ -84,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;
|
||||
}
|
||||
|
||||
@@ -161,6 +161,17 @@ DrawIconByName(const char *name, Rectangle bounds, Color tint)
|
||||
draw_icon_asset(GetUIIconAssetByName(name), bounds, tint);
|
||||
}
|
||||
|
||||
void
|
||||
DrawProfilePictureIcon(UIIconType type, Rectangle bounds, int dark_mode)
|
||||
{
|
||||
const UIIconAsset *asset = GetUIIconAsset(type);
|
||||
|
||||
(void)dark_mode;
|
||||
if(asset == NULL || bounds.width <= 0 || bounds.height <= 0)
|
||||
return;
|
||||
DrawIcon(type, bounds, WHITE);
|
||||
}
|
||||
|
||||
static Texture2D
|
||||
load_icon_asset_texture(const UIIconAsset *asset)
|
||||
{
|
||||
@@ -217,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;
|
||||
}
|
||||
|
||||
|
||||
+12
-11
@@ -57,13 +57,14 @@ 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);
|
||||
int ui_input_captures_click_internal(Vector2 point, int include_pointer_drag);
|
||||
int ui_dropdown_captures_click(Vector2 point);
|
||||
void ui_dropdown_close(int id);
|
||||
void ui_draw_dropdown_overlays(void);
|
||||
int dropdown_captures(Vector2 point);
|
||||
void dropdown_close(int id);
|
||||
void draw_dropdown_overlays(void);
|
||||
void ui_draw_menu_overlays(void);
|
||||
void ui_tab_bar_finish_frame(void);
|
||||
void ui_tab_scope_finish_frame(void);
|
||||
@@ -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);
|
||||
@@ -190,14 +193,12 @@ int DrawUIToggleSwitch(int x, int y, int w, int h, int *value,
|
||||
int DrawUICheckboxToggle(int x, int y, const char *label, int *value);
|
||||
int DrawDisabledUICheckboxToggle(int x, int y, const char *label,
|
||||
int *value, int disabled);
|
||||
int DrawUIDropdown(int id, int x, int y, int w, int h,
|
||||
const char **options, int option_count,
|
||||
int *selected_index);
|
||||
int DrawUIDropdownEx(int id, int x, int y, int w, int h,
|
||||
const UIDropdownOption *options, int option_count,
|
||||
int *selected_index);
|
||||
int DrawUILocaleDropdown(int id, int x, int y, int w, int h,
|
||||
int *selected_index);
|
||||
int draw_dropdown(int id, int x, int y, int w, int h,
|
||||
const char **options, int option_count,
|
||||
int *selected_index);
|
||||
int draw_dropdown_options(int id, int x, int y, int w, int h,
|
||||
const DropdownOption *options, int option_count,
|
||||
int *selected_index);
|
||||
void DrawUIInfoRows(InfoRowsProps rows);
|
||||
int DrawUILabelTextField(LabelTextFieldProps row, int x, int y, int w);
|
||||
int DrawUISectionLabel(SectionLabelProps label, int x, int y);
|
||||
|
||||
@@ -29,7 +29,7 @@ static const KryonNodeType kryon_node_types[] = {
|
||||
{"InfoButton", "Info Button", "UI/Input", "Control", "Help action", EDITABLE},
|
||||
{"IconLink", "Icon Link", "UI/Input", "Control", "Icon link", EDITABLE},
|
||||
{"Dropdown", "Dropdown", "UI/Input", "Control", "Selection", INSERT_EDITABLE},
|
||||
{"DropdownEx", "Dropdown Ex", "UI/Input", "Control", "Rich selection", EDITABLE},
|
||||
{"DropdownOptions", "Dropdown Options", "UI/Input", "Control", "Rich selection", EDITABLE},
|
||||
{"Slider", "Slider", "UI/Input", "Control", "Value", INSERT_EDITABLE},
|
||||
{"Toggle", "Toggle", "UI/Input", "Control", "On/off", INSERT_EDITABLE},
|
||||
{"Checkbox", "Checkbox", "UI/Input", "Control", "Boolean", INSERT_EDITABLE},
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "ui_paint_layers_internal.h"
|
||||
#include "ui_tree_layout_internal.h"
|
||||
#include "ui_disabled_internal.h"
|
||||
#include "dropdown_store.h"
|
||||
#include "ui_input_clip_internal.h"
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
@@ -58,6 +59,7 @@ struct UIPaintLayers {
|
||||
unsigned long frame;
|
||||
Matrix projection, modelview;
|
||||
UIPopupInput *input, *previous_input;
|
||||
DropdownStore *dropdowns, *previous_dropdowns;
|
||||
};
|
||||
|
||||
static UIPaintLayers *main_layers;
|
||||
@@ -66,6 +68,7 @@ static int main_frame_open;
|
||||
* generated parity, and other headless callers still need popup scopes even
|
||||
* when no texture-backed paint-layer host can exist. */
|
||||
static UIPopupInput *headless_input, *headless_previous_input;
|
||||
static DropdownStore *headless_dropdowns, *headless_previous_dropdowns;
|
||||
static int headless_input_open;
|
||||
/* Graphics scopes form one stack even when their textures belong to separate
|
||||
* host contexts. Validate it before restoring any backend or borrowed state. */
|
||||
@@ -75,11 +78,17 @@ static unsigned long scope_generation;
|
||||
void ui_frame_layers_begin(void)
|
||||
{
|
||||
if(ui_window_frame_active()) return;
|
||||
if(main_layers) ui_paint_layers_frame(main_layers,ui_view_width,ui_view_height);
|
||||
else if(!IsWindowReady() && ui_popup_input_bound() == NULL) {
|
||||
if(IsWindowReady()) {
|
||||
if(!main_layers) main_layers = ui_paint_layers_create();
|
||||
ui_paint_layers_frame(main_layers,ui_view_width,ui_view_height);
|
||||
} else if(ui_popup_input_bound() == NULL) {
|
||||
if(!headless_input) headless_input = ui_popup_input_create();
|
||||
if(!headless_dropdowns)
|
||||
headless_dropdowns = dropdown_store_new();
|
||||
ui_popup_input_frame(headless_input);
|
||||
headless_previous_input = ui_popup_input_bind(headless_input);
|
||||
headless_previous_dropdowns =
|
||||
dropdown_store_swap(headless_dropdowns);
|
||||
headless_input_open = 1;
|
||||
}
|
||||
main_frame_open = 1;
|
||||
@@ -99,12 +108,19 @@ UIPaintLayers *ui_frame_paint_layers(void)
|
||||
void ui_frame_layers_end(void)
|
||||
{
|
||||
if(ui_window_frame_active() || !main_frame_open) return;
|
||||
if(main_layers) ui_paint_layers_composite(main_layers);
|
||||
if(main_layers) {
|
||||
ui_paint_layers_composite(main_layers);
|
||||
/* Input routing happens before the next frame redeclares owners. */
|
||||
dropdown_store_swap(main_layers->dropdowns);
|
||||
}
|
||||
if(headless_input_open) {
|
||||
ui_popup_input_finish(headless_input);
|
||||
ui_popup_input_bind(headless_previous_input);
|
||||
dropdown_store_swap(headless_previous_dropdowns);
|
||||
headless_previous_input = NULL;
|
||||
headless_previous_dropdowns = NULL;
|
||||
headless_input_open = 0;
|
||||
dropdown_store_swap(headless_dropdowns);
|
||||
}
|
||||
main_frame_open = 0;
|
||||
}
|
||||
@@ -114,6 +130,8 @@ void ui_paint_layers_shutdown(void)
|
||||
if(main_layers) {
|
||||
if(!main_layers->finished && main_layers->active == -1)
|
||||
ui_paint_layers_composite(main_layers);
|
||||
if(dropdown_store_current() == main_layers->dropdowns)
|
||||
dropdown_store_swap(NULL);
|
||||
ui_paint_layers_destroy(main_layers);
|
||||
main_layers = NULL;
|
||||
}
|
||||
@@ -121,11 +139,19 @@ void ui_paint_layers_shutdown(void)
|
||||
if(headless_input_open) {
|
||||
ui_popup_input_finish(headless_input);
|
||||
ui_popup_input_bind(headless_previous_input);
|
||||
dropdown_store_swap(headless_previous_dropdowns);
|
||||
headless_input_open = 0;
|
||||
}
|
||||
ui_popup_input_destroy(headless_input);
|
||||
headless_input = NULL;
|
||||
headless_previous_input = NULL;
|
||||
headless_previous_dropdowns = NULL;
|
||||
}
|
||||
if(headless_dropdowns) {
|
||||
if(dropdown_store_current() == headless_dropdowns)
|
||||
dropdown_store_swap(NULL);
|
||||
dropdown_store_free(headless_dropdowns);
|
||||
headless_dropdowns = NULL;
|
||||
}
|
||||
main_frame_open = 0;
|
||||
}
|
||||
@@ -137,6 +163,7 @@ UIPaintLayers *ui_paint_layers_create(void)
|
||||
layers->active = -1;
|
||||
layers->finished = 1;
|
||||
layers->input = ui_popup_input_create();
|
||||
layers->dropdowns = dropdown_store_new();
|
||||
return layers;
|
||||
}
|
||||
|
||||
@@ -151,6 +178,7 @@ void ui_paint_layers_destroy(UIPaintLayers *layers)
|
||||
if(layers->active != -1 || !layers->finished) abort();
|
||||
for(int i = 0; i < layers->allocated; i++) layer_texture_replace(layers->items[i].texture,0,0);
|
||||
ui_popup_input_destroy(layers->input);
|
||||
dropdown_store_free(layers->dropdowns);
|
||||
free(layers->items);
|
||||
free(layers);
|
||||
}
|
||||
@@ -168,6 +196,7 @@ void ui_paint_layers_frame(UIPaintLayers *layers, int width, int height)
|
||||
layers->frame = ++scope_generation;
|
||||
ui_popup_input_frame(layers->input);
|
||||
layers->previous_input = ui_popup_input_bind(layers->input);
|
||||
layers->previous_dropdowns = dropdown_store_swap(layers->dropdowns);
|
||||
}
|
||||
|
||||
UIPaintLayerToken ui_paint_layer_begin(UIPaintLayers *layers, int owner)
|
||||
@@ -258,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];
|
||||
@@ -275,4 +307,5 @@ void ui_paint_layers_composite(UIPaintLayers *layers)
|
||||
layers->allocated = layers->count;
|
||||
layers->finished = 1;
|
||||
ui_popup_input_bind(layers->previous_input);
|
||||
dropdown_store_swap(layers->previous_dropdowns);
|
||||
}
|
||||
+10
-8
@@ -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;
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ DrawUIReturnDropdownTitleBar(Texture2D return_icon,
|
||||
DrawUITitleBarBackground(height);
|
||||
clicked = DrawUITitleBarReturnButton(return_icon, height);
|
||||
if(!dropdown.disabled)
|
||||
DrawUIDropdown(dropdown.id, dropdown_x, dropdown_y,
|
||||
draw_dropdown(dropdown.id, dropdown_x, dropdown_y,
|
||||
dropdown_w, dropdown_h,
|
||||
dropdown.options, dropdown.option_count,
|
||||
dropdown.selected_index);
|
||||
|
||||
+184
-7
@@ -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)
|
||||
@@ -2408,10 +2585,10 @@ DrawUICombobox(ComboboxProps combo)
|
||||
if(combo.disabled)
|
||||
MarkUIDisabled();
|
||||
BeginDisabled(combo.disabled);
|
||||
changed = DrawUIDropdown(combo.id, (int)combo.bounds.x, (int)combo.bounds.y,
|
||||
(int)combo.bounds.width, (int)combo.bounds.height,
|
||||
combo.options, combo.option_count,
|
||||
combo.selected_index);
|
||||
changed = draw_dropdown(combo.id, (int)combo.bounds.x,
|
||||
(int)combo.bounds.y, (int)combo.bounds.width,
|
||||
(int)combo.bounds.height, combo.options,
|
||||
combo.option_count, combo.selected_index);
|
||||
EndDisabled();
|
||||
return changed;
|
||||
}
|
||||
|
||||
+29
-7
@@ -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; }
|
||||
@@ -2572,19 +2594,19 @@ Dropdown(int id, int x, int y, int w, int h,
|
||||
{
|
||||
ui_tree_add(id, UI_WIDGET_DROPDOWN_NODE, (Rectangle){x, y, w, h},
|
||||
selected_index);
|
||||
return DrawUIDropdown(id, x, y, w, h, options, option_count,
|
||||
selected_index);
|
||||
return draw_dropdown(id, x, y, w, h, options, option_count,
|
||||
selected_index);
|
||||
}
|
||||
|
||||
int
|
||||
DropdownEx(int id, int x, int y, int w, int h,
|
||||
const UIDropdownOption *options, int option_count,
|
||||
int *selected_index)
|
||||
DropdownOptions(int id, int x, int y, int w, int h,
|
||||
const DropdownOption *options, int option_count,
|
||||
int *selected_index)
|
||||
{
|
||||
ui_tree_add(id, UI_WIDGET_DROPDOWN_NODE, (Rectangle){x, y, w, h},
|
||||
selected_index);
|
||||
return DrawUIDropdownEx(id, x, y, w, h, options, option_count,
|
||||
selected_index);
|
||||
return draw_dropdown_options(id, x, y, w, h, options, option_count,
|
||||
selected_index);
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
+3
-4
@@ -1588,9 +1588,8 @@ void ui_window_layers_begin(void)
|
||||
#if defined(UI_WINDOW_OWNS_PAINT_LAYERS)
|
||||
UIWindow *window = ui_window_active;
|
||||
if(window == NULL) return;
|
||||
if(window->paint_layers)
|
||||
ui_paint_layers_frame(window->paint_layers,window->width,window->height);
|
||||
else if(ui_popup_input_bound() != NULL)
|
||||
(void)ui_window_paint_layers();
|
||||
if(window->paint_layers == NULL)
|
||||
window->paint_layers = ui_paint_layers_create();
|
||||
ui_paint_layers_frame(window->paint_layers,window->width,window->height);
|
||||
#endif
|
||||
}
|
||||
@@ -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++) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "kryon.h"
|
||||
#include "kry_inject.h"
|
||||
#include "kryon_test.h"
|
||||
#include "../src/ui/dropdown_store.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -244,8 +245,7 @@ main(void)
|
||||
/* App-style clip constraints (titlebar above, bottom nav below):
|
||||
* the flip must respect the clips; 10 options fit, so the bottom
|
||||
* visible row is option 9. */
|
||||
SetUIDropdownClipTop(60);
|
||||
SetUIDropdownClipBottom(660);
|
||||
dropdown_store_clip(60,660);
|
||||
open_dropdown();
|
||||
check_int("clipped popup reports open", popup_open(), 1);
|
||||
tap(660);
|
||||
@@ -258,8 +258,7 @@ main(void)
|
||||
open_dropdown();
|
||||
tap(582);
|
||||
check_int("clipped: button toggles closed", popup_open(), 0);
|
||||
SetUIDropdownClipTop(0);
|
||||
SetUIDropdownClipBottom(0);
|
||||
dropdown_store_clip(0,0);
|
||||
|
||||
printf("dropdown layout test ok\n");
|
||||
return 0;
|
||||
|
||||
@@ -43,9 +43,10 @@ require_contains icons/ui.json '"style": "mingcute-core"'
|
||||
require_contains icons/ui.json '"license": "Apache-2.0"'
|
||||
require_contains icons/ui.json '"upstream_revision"'
|
||||
|
||||
icon_output_count=$(find icons -mindepth 1 -maxdepth 1 -type f | wc -l | tr -d ' ')
|
||||
if [ "$icon_output_count" -ne 14 ]; then
|
||||
echo "icons/ must contain exactly 7 spritesheets and 7 manifests" >&2
|
||||
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 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'
|
||||
|
||||
@@ -78,6 +78,7 @@ import (
|
||||
"fmt"
|
||||
"image/color"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
kryon "github.com/waozixyz/kryon/go/kryon"
|
||||
)
|
||||
@@ -772,6 +773,19 @@ func main() {
|
||||
}
|
||||
}
|
||||
CompositionStateValue.CompositionReadOnly = false
|
||||
driver.SetFocus(26102)
|
||||
driver.QueueKey(kryon.KeyDown); drawComposition()
|
||||
if CompositionStateValue.CompositionPageCursor <= 4 { panic("generated TextArea Down did not move") }
|
||||
beforePage := CompositionStateValue.CompositionPageCursor
|
||||
driver.QueueKey(kryon.KeyPageDown); drawComposition()
|
||||
if CompositionStateValue.CompositionPageCursor < beforePage+4 { panic("generated TextArea PageDown did not move a page") }
|
||||
beforePage = CompositionStateValue.CompositionPageCursor
|
||||
driver.QueueKey(kryon.KeyPageUp); drawComposition()
|
||||
if CompositionStateValue.CompositionPageCursor > beforePage-4 { panic("generated TextArea PageUp did not move a page") }
|
||||
pageTextBefore := text64(CompositionStateValue.CompositionPageArea)
|
||||
driver.QueueKey(kryon.KeyEnter); drawComposition()
|
||||
pageTextAfter := text64(CompositionStateValue.CompositionPageArea)
|
||||
if len(pageTextAfter) != len(pageTextBefore)+1 || strings.Count(pageTextAfter, "\n") != strings.Count(pageTextBefore, "\n")+1 { panic("generated TextArea Enter did not insert newline") }
|
||||
fields := FieldsStateValue
|
||||
focus := FocusStateValue
|
||||
buttons := ButtonsLayoutStateValue
|
||||
@@ -1082,6 +1096,38 @@ func main() {
|
||||
if value := PlotsStateValue.SliderInts[0]; value != 3 {
|
||||
panic(fmt.Sprintf("generated vertical int slider keyboard value=%d, want 3", value))
|
||||
}
|
||||
driver.QueueKey(kryon.KeyLeftControl)
|
||||
driver.QueueTap(30, 190)
|
||||
drawPlots()
|
||||
driver.QueueShortcut(kryon.KeyA)
|
||||
driver.QueueText("12.5")
|
||||
drawPlots()
|
||||
if value := PlotsStateValue.DragFloats[0]; value != 12.5 {
|
||||
panic(fmt.Sprintf("generated float drag temporary input=%v, want 12.5", value))
|
||||
}
|
||||
driver.QueueKey(kryon.KeyEnter)
|
||||
drawPlots()
|
||||
driver.QueueTap(145, 190)
|
||||
drawPlots()
|
||||
driver.QueueTap(145, 190)
|
||||
drawPlots()
|
||||
driver.QueueShortcut(kryon.KeyA)
|
||||
driver.QueueText("17")
|
||||
drawPlots()
|
||||
if value := PlotsStateValue.DragInts[0]; value != 17 {
|
||||
panic(fmt.Sprintf("generated int drag double-click input=%d, want 17", value))
|
||||
}
|
||||
driver.QueueKey(kryon.KeyEnter)
|
||||
drawPlots()
|
||||
driver.QueueKey(kryon.KeyLeftControl)
|
||||
driver.QueueTap(150, 246)
|
||||
drawPlots()
|
||||
driver.QueueShortcut(kryon.KeyA)
|
||||
driver.QueueText("19")
|
||||
drawPlots()
|
||||
if value := PlotsStateValue.SliderInts[0]; value != 19 {
|
||||
panic(fmt.Sprintf("generated int slider temporary input=%d, want 19", value))
|
||||
}
|
||||
driver.SetFocus(0x60000008)
|
||||
driver.QueueKey(kryon.KeySpace)
|
||||
drawPlots()
|
||||
@@ -1521,6 +1567,28 @@ int main(void)
|
||||
InjectReset();
|
||||
}
|
||||
composition_read_only = 0;
|
||||
SetUIFocus(26102);
|
||||
InjectKeyTap(KEY_DOWN); InjectPump(); draw_composition();
|
||||
if(composition_page_cursor <= 4) {
|
||||
fprintf(stderr,"generated TextArea Down did not move\n"); return 1;
|
||||
}
|
||||
int composition_before_page = composition_page_cursor;
|
||||
InjectKeyTap(KEY_PAGE_DOWN); InjectPump(); draw_composition();
|
||||
if(composition_page_cursor < composition_before_page + 4) {
|
||||
fprintf(stderr,"generated TextArea PageDown did not move a page\n"); return 1;
|
||||
}
|
||||
composition_before_page = composition_page_cursor;
|
||||
InjectKeyTap(KEY_PAGE_UP); InjectPump(); draw_composition();
|
||||
if(composition_page_cursor > composition_before_page - 4) {
|
||||
fprintf(stderr,"generated TextArea PageUp did not move a page\n"); return 1;
|
||||
}
|
||||
int composition_page_length = (int)strlen(composition_page_area);
|
||||
int composition_page_lines = TextBufferLineCount(composition_page_area);
|
||||
InjectKeyTap(KEY_ENTER); InjectPump(); draw_composition();
|
||||
if((int)strlen(composition_page_area) != composition_page_length + 1 ||
|
||||
TextBufferLineCount(composition_page_area) != composition_page_lines + 1) {
|
||||
fprintf(stderr,"generated TextArea Enter did not insert newline\n"); return 1;
|
||||
}
|
||||
InjectMousePosition(20,20);
|
||||
InjectMouseButton(MOUSE_BUTTON_LEFT,1);
|
||||
InjectPump(); draw_ui(drag_drop_frame);
|
||||
@@ -2070,6 +2138,49 @@ int main(void)
|
||||
slider_ints[0]);
|
||||
return 1;
|
||||
}
|
||||
InjectMousePosition(30,190); InjectKey(KEY_LEFT_CONTROL,1);
|
||||
InjectMouseButton(MOUSE_BUTTON_LEFT,1); InjectPump(); draw_plots();
|
||||
InjectMouseButton(MOUSE_BUTTON_LEFT,0); InjectKey(KEY_LEFT_CONTROL,0);
|
||||
InjectPump(); draw_plots();
|
||||
InjectKey(KEY_LEFT_CONTROL,1); InjectKeyTap(KEY_A);
|
||||
InjectPump(); draw_plots();
|
||||
InjectKey(KEY_LEFT_CONTROL,0); InjectText("12.5");
|
||||
InjectPump(); draw_plots();
|
||||
if(drag_floats[0] != 12.5f) {
|
||||
fprintf(stderr,"generated float drag temporary input=%f, want 12.5\n",
|
||||
drag_floats[0]);
|
||||
return 1;
|
||||
}
|
||||
InjectKeyTap(KEY_ENTER); InjectPump(); draw_plots();
|
||||
InjectMousePosition(145,190);
|
||||
InjectMouseButton(MOUSE_BUTTON_LEFT,1); InjectPump(); draw_plots();
|
||||
InjectMouseButton(MOUSE_BUTTON_LEFT,0); InjectPump(); draw_plots();
|
||||
InjectMousePosition(145,190);
|
||||
InjectMouseButton(MOUSE_BUTTON_LEFT,1); InjectPump(); draw_plots();
|
||||
InjectMouseButton(MOUSE_BUTTON_LEFT,0); InjectPump(); draw_plots();
|
||||
InjectKey(KEY_LEFT_CONTROL,1); InjectKeyTap(KEY_A);
|
||||
InjectPump(); draw_plots();
|
||||
InjectKey(KEY_LEFT_CONTROL,0); InjectText("17");
|
||||
InjectPump(); draw_plots();
|
||||
if(drag_ints[0] != 17) {
|
||||
fprintf(stderr,"generated int drag double-click input=%d, want 17\n",
|
||||
drag_ints[0]);
|
||||
return 1;
|
||||
}
|
||||
InjectKeyTap(KEY_ENTER); InjectPump(); draw_plots();
|
||||
InjectMousePosition(150,246); InjectKey(KEY_LEFT_CONTROL,1);
|
||||
InjectMouseButton(MOUSE_BUTTON_LEFT,1); InjectPump(); draw_plots();
|
||||
InjectMouseButton(MOUSE_BUTTON_LEFT,0); InjectKey(KEY_LEFT_CONTROL,0);
|
||||
InjectPump(); draw_plots();
|
||||
InjectKey(KEY_LEFT_CONTROL,1); InjectKeyTap(KEY_A);
|
||||
InjectPump(); draw_plots();
|
||||
InjectKey(KEY_LEFT_CONTROL,0); InjectText("19");
|
||||
InjectPump(); draw_plots();
|
||||
if(slider_ints[0] != 19) {
|
||||
fprintf(stderr,"generated int slider temporary input=%d, want 19\n",
|
||||
slider_ints[0]);
|
||||
return 1;
|
||||
}
|
||||
SetUIFocus(0x60000008); InjectKeyTap(KEY_SPACE); InjectPump(); draw_plots();
|
||||
if(input_ints[0] != 5) {
|
||||
fprintf(stderr,"generated input step keyboard value=%d, want 5\n",
|
||||
|
||||
@@ -10,6 +10,8 @@ state {
|
||||
composition_cursor: int = 4
|
||||
composition_area: [64] char = "area"
|
||||
composition_area_cursor: int = 4
|
||||
composition_page_area: [64] char = "a0\nb1\nc2\nd3\ne4\nf5"
|
||||
composition_page_cursor: int = 4
|
||||
composition_read_only: bool = false
|
||||
}
|
||||
|
||||
@@ -17,5 +19,6 @@ composition_frame :: () #ui {
|
||||
Screen root: {
|
||||
TextField((TextFieldProps){.bounds = {20,20,220,32}, .text = composition_text, .text_size = sizeof(composition_text), .cursor_position = &composition_cursor, .focus_id = 26100, .read_only = composition_read_only})
|
||||
TextArea((TextAreaProps){.bounds = {20,70,220,80}, .text = composition_area, .text_size = sizeof(composition_area), .cursor_position = &composition_area_cursor, .focus_id = 26101, .read_only = composition_read_only})
|
||||
TextArea((TextAreaProps){.bounds = {20,70,160,60}, .text = composition_page_area, .text_size = sizeof(composition_page_area), .cursor_position = &composition_page_cursor, .focus_id = 26102, .font = Text16, .line_gap = 4})
|
||||
}
|
||||
}
|
||||
@@ -30,8 +30,8 @@ if [ -n "$matches" ]; then
|
||||
fi
|
||||
|
||||
generated_matches="$(
|
||||
rg -n '\b(TextInputControl|GenericButton|TextButton|LocaleDropdown|VerticalSlider|VerticalSliderWithMarks|ReadonlyTextBox|DrawCenteredUIControlText|UIParagraphSpec|UIParagraphLayout|UIModalAction|UINodeId|UIKey|UISide|UI_SIDE_[A-Z_]+|UIFrame|UIGrid|BeginUIFrameBox|UIFramePack|UIGridCell|UIPlace|UICanvas|BeginUICanvas|EndUICanvas|UIMenuItemKind|UIMenuItem|UIMenuBarResult|UIMenu|UI_MENU_[A-Z_]+|UIContextMenu|UIAccelerator|UIAcceleratorPressed|DispatchUIAccelerators|UIIconRowItem|UIIconRowResult|UIBottomNavItem|UIBottomNavResult|UIBottomNavOption|UIBottomNavConfigResult|UIToolbarAction|UIToolbarResult|UIToolbarHeaderResult|UITopNavAction|UITopNavResult|UISubtab|UITab|UIPaneDropZone|UIPaneTabBar|UIPaneTabBarResult|GetUIPaneDropZone|GetUITabBarHeight|UI_PANE_DROP_[A-Z_]+|UISidebarAccountHeaderSpec|UISidebarAccountHeaderResult|UIProfilePicturePickerModal|UIProfilePicturePickerResult)\b' \
|
||||
go/kryon include/ui_tree.h include/ui_tk.h include/ui_nav.h include/ui_profile.h include/ui_draw.h include/ui_modal.h src/ui/ui_node_registry.c cmd/k2b examples tests/k2c_syntax_test.sh tests/k2go_syntax_test.sh docs/API.md docs/RUNTIME_PARITY.md docs/FEATURE_MATRIX.md docs/FEATURE_MATRIX.html \
|
||||
rg -n '\b(TextInputControl|GenericButton|TextButton|LocaleDropdown|VerticalSlider|VerticalSliderWithMarks|ReadonlyTextBox|DrawCenteredUIControlText|UIDropdownOption|DropdownEx|SetUIDropdownClipTop|SetUIDropdownClipBottom|DrawUIDropdown|DrawUIDropdownEx|UIParagraphSpec|UIParagraphLayout|UIModalAction|UINodeId|UIKey|UISide|UI_SIDE_[A-Z_]+|UIFrame|UIGrid|BeginUIFrameBox|UIFramePack|UIGridCell|UIPlace|UICanvas|BeginUICanvas|EndUICanvas|UIMenuItemKind|UIMenuItem|UIMenuBarResult|UIMenu|UI_MENU_[A-Z_]+|UIContextMenu|UIAccelerator|UIAcceleratorPressed|DispatchUIAccelerators|UIIconRowItem|UIIconRowResult|UIBottomNavItem|UIBottomNavResult|UIBottomNavOption|UIBottomNavConfigResult|UIToolbarAction|UIToolbarResult|UIToolbarHeaderResult|UITopNavAction|UITopNavResult|UISubtab|UITab|UIPaneDropZone|UIPaneTabBar|UIPaneTabBarResult|GetUIPaneDropZone|GetUITabBarHeight|UI_PANE_DROP_[A-Z_]+|UISidebarAccountHeaderSpec|UISidebarAccountHeaderResult|UIProfilePicturePickerModal|UIProfilePicturePickerResult)\b' \
|
||||
go/kryon include/ui_controls.h include/ui_tree.h include/ui_tk.h include/ui_nav.h include/ui_profile.h include/ui_draw.h include/ui_modal.h src/ui/dropdown.c src/ui/ui_node_registry.c cmd/k2b examples tests/k2c_syntax_test.sh tests/k2go_syntax_test.sh docs/API.md docs/RUNTIME_PARITY.md docs/FEATURE_MATRIX.md docs/FEATURE_MATRIX.html \
|
||||
--glob '!vendor/**' \
|
||||
--glob '!build/**' \
|
||||
--glob '!tests/public_api_names_test.sh' || true
|
||||
|
||||
@@ -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. */
|
||||
|
||||
+186
-6
@@ -7,6 +7,7 @@
|
||||
#include "../src/ui/ui_numeric_input_internal.h"
|
||||
#include "../src/ui/ui_tree_layout_internal.h"
|
||||
#include "../src/ui/ui_disabled_internal.h"
|
||||
#include "../src/ui/dropdown_store.h"
|
||||
#include "../src/ui/ui_input_clip_internal.h"
|
||||
#include "../src/ui/ui_popup_input_internal.h"
|
||||
|
||||
@@ -220,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)
|
||||
{
|
||||
@@ -1102,6 +1208,46 @@ test_combo_popup_lifecycle(void)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_dropdown_store_isolation(void)
|
||||
{
|
||||
const char *options[] = {"One", "Two"};
|
||||
DropdownStore *first = dropdown_store_new();
|
||||
DropdownStore *second = dropdown_store_new();
|
||||
DropdownStore *frame_store;
|
||||
int selected = 0;
|
||||
|
||||
InjectReset();
|
||||
InjectTap(20,20);
|
||||
for(int frame = 0; frame < 3; frame++) {
|
||||
InjectPump();
|
||||
BeginUIFrame(240,240,1.0f);
|
||||
frame_store = dropdown_store_swap(first);
|
||||
draw_dropdown(9961,10,10,160,28,options,2,&selected);
|
||||
draw_dropdown_overlays();
|
||||
dropdown_store_swap(frame_store);
|
||||
EndUIFrame();
|
||||
}
|
||||
frame_store = dropdown_store_swap(first);
|
||||
check_int("first dropdown store owns popup",
|
||||
dropdown_captures((Vector2){20,70}),1);
|
||||
|
||||
dropdown_store_swap(second);
|
||||
check_int("second dropdown store does not inherit popup",
|
||||
dropdown_captures((Vector2){20,70}),0);
|
||||
draw_dropdown(9961,10,10,160,28,options,2,&selected);
|
||||
check_int("same ID remains closed in second store",
|
||||
dropdown_captures((Vector2){20,70}),0);
|
||||
|
||||
dropdown_store_swap(first);
|
||||
check_int("first dropdown store restores popup",
|
||||
dropdown_captures((Vector2){20,70}),1);
|
||||
dropdown_store_swap(frame_store);
|
||||
|
||||
dropdown_store_free(second);
|
||||
dropdown_store_free(first);
|
||||
}
|
||||
|
||||
static void
|
||||
test_many_combo_identities(void)
|
||||
{
|
||||
@@ -1570,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)
|
||||
{
|
||||
@@ -2133,7 +2310,7 @@ test_popup_combo_keyboard_ownership(void)
|
||||
SetUIFocus(25400);
|
||||
Combobox((ComboboxProps){.bounds={10,10,100,28},.id=25400,
|
||||
.options=options,.option_count=2,.selected_index=&selected});
|
||||
check_int("only top popup may open a focused combo",ui_dropdown_captures_click((Vector2){20,60}),inside);
|
||||
check_int("only top popup may open a focused combo",dropdown_captures((Vector2){20,60}),inside);
|
||||
if(inside) ui_popup_input_end(child);
|
||||
ui_popup_input_close(context,1);
|
||||
check_int("child dismissal restores parent keyboard",ui_popup_input_keyboard_captures(),0);
|
||||
@@ -2144,7 +2321,7 @@ test_popup_combo_keyboard_ownership(void)
|
||||
ui_popup_input_finish(context);
|
||||
ui_popup_input_bind(previous);
|
||||
ui_popup_input_destroy(context);
|
||||
ui_dropdown_close(25400);
|
||||
dropdown_close(25400);
|
||||
EndUIFrame();
|
||||
}
|
||||
InjectReset();
|
||||
@@ -2452,9 +2629,9 @@ test_combo_horizontal_viewport(void)
|
||||
EndUIFrame();
|
||||
}
|
||||
int x = i == 1 ? 92 : 12;
|
||||
check_int("shifted popup captures row",ui_dropdown_captures_click((Vector2){x,80}),1);
|
||||
check_int("popup left edge bounded",ui_dropdown_captures_click((Vector2){-1,80}),0);
|
||||
check_int("popup right edge bounded",ui_dropdown_captures_click((Vector2){241,80}),0);
|
||||
check_int("shifted popup captures row",dropdown_captures((Vector2){x,80}),1);
|
||||
check_int("popup left edge bounded",dropdown_captures((Vector2){-1,80}),0);
|
||||
check_int("popup right edge bounded",dropdown_captures((Vector2){241,80}),0);
|
||||
InjectTap(x,80);
|
||||
for(int frame = 0; frame < 3; frame++) {
|
||||
InjectPump(); BeginUIFrame(240,240,1);
|
||||
@@ -2495,7 +2672,7 @@ test_combo_scrollbar_dismissal(void)
|
||||
.options=options,.option_count=131,.selected_index=&selected,.disabled=mode==1});
|
||||
EndUIFrame();
|
||||
check_int("dismissed combo scrollbar released drag",g_ui_pointer_owner,UI_POINTER_OWNER_NONE);
|
||||
check_int("dismissed combo scrollbar released capture",ui_dropdown_captures_click((Vector2){20,70}),0);
|
||||
check_int("dismissed combo scrollbar released capture",dropdown_captures((Vector2){20,70}),0);
|
||||
InjectReset(); BeginUIFrame(240,240,1); EndUIFrame();
|
||||
}
|
||||
}
|
||||
@@ -3238,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();
|
||||
@@ -3254,6 +3432,7 @@ main(void)
|
||||
test_closeable_collapsible();
|
||||
test_tree_header_keyboard_gates();
|
||||
test_combo_popup_lifecycle();
|
||||
test_dropdown_store_isolation();
|
||||
test_many_combo_identities();
|
||||
test_large_combo_options();
|
||||
test_combo_keyboard_navigation();
|
||||
@@ -3277,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();
|
||||
|
||||
@@ -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)),
|
||||
|
||||
@@ -263,10 +263,31 @@ def run_tab_limits():
|
||||
category(4)
|
||||
check("Close first tab","tabs",lambda:click(612,352),1)
|
||||
check("Close last tab","tabs",lambda:click(992,352),0)
|
||||
check("Reopen empty tab bar","tabs",lambda:click(730,410),1)
|
||||
|
||||
def add_tab(name, expected):
|
||||
before=state()["tabs"]
|
||||
after=before
|
||||
# Xvfb can occasionally drop an injected click while llvmpipe is busy.
|
||||
# Retry only while the button had no effect; never click again after the
|
||||
# count changes, so a real double-add or capacity error still fails.
|
||||
for _ in range(3):
|
||||
click(730,410)
|
||||
after=state()["tabs"]
|
||||
if after != before:
|
||||
break
|
||||
results.append(dict(widget=name, passed=after == expected, key="tabs",
|
||||
before=before, after=after))
|
||||
|
||||
add_tab("Reopen empty tab bar",1)
|
||||
for count in range(2,9):
|
||||
check(f"Add tab {count}","tabs",lambda:click(730,410),count)
|
||||
check("Tab capacity disables add","tabs",lambda:click(730,410),8)
|
||||
add_tab(f"Add tab {count}",count)
|
||||
before=state()["tabs"]
|
||||
for _ in range(3):
|
||||
click(730,410)
|
||||
after=state()["tabs"]
|
||||
results.append(dict(widget="Tab capacity disables add",
|
||||
passed=before == 8 and after == 8, key="tabs",
|
||||
before=before, after=after))
|
||||
capture("full-tab-bar")
|
||||
|
||||
def run_settings():
|
||||
|
||||
Reference in new issue
Block a user