Switch from Asuka to MyGo, keeping the API client and the feature set: - servers: saved servers, passwordless and password login, proxy, self-signed certificates, per-server device tokens (Keystore), connect form, instance list sheet with switch/disconnect - sessions: virtualized list, search, new session, rename/archive/delete, running indicator, event stream keeps it live - chat: pushed window with system back bar, streaming Markdown via ui/markdown, reasoning and tool rows with image previews, footer menu (read aloud via a Kotlin TTS plugin, copy, fork), user message menu (copy, revert, fork), context usage ring and detail sheet, attachments (photos/files via the document picker), permissions - release builds allow plain http:// LAN servers (Go's net/http dials directly, no cleartext manifest needed) - a local fork of MyGo (third_party/mygo) lowers the Android host's minSdk to 24 (Android 7.0); Go 1.27.4 via mise Version 0.3.0.
78 lines
2.2 KiB
Go
78 lines
2.2 KiB
Go
package ui
|
||
|
||
import (
|
||
"math"
|
||
"strconv"
|
||
"strings"
|
||
)
|
||
|
||
// NumberInput creates a text input editing *value as a number between lo
|
||
// and hi, which the arrows Up and Down, and the buttons beside it, step
|
||
// by step. What is typed applies as soon as it is a number in range, and
|
||
// shows rounded to the decimals of step once the input loses the focus.
|
||
// Changed reports a new value.
|
||
//
|
||
// ui.NumberInput(c, &app.copies, 1, 99, 1)
|
||
func coreNumberInput(c *context, value *float64, lo, hi, step float64) *node {
|
||
t := c.theme
|
||
row := coreRow(c).Gap(t.Space(1)).Shrink(0).AlignItems(Center)
|
||
row.widget = "NumberInput"
|
||
decimals := 0
|
||
if s := strconv.FormatFloat(step, 'f', -1, 64); strings.Contains(s, ".") {
|
||
decimals = len(s) - strings.IndexByte(s, '.') - 1
|
||
}
|
||
format := func(v float64) string { return strconv.FormatFloat(v, 'f', decimals, 64) }
|
||
text := coreLocal(row, "text", func() string { return format(*value) })
|
||
set := func(v float64) {
|
||
v = math.Max(lo, math.Min(hi, v))
|
||
if decimals >= 0 {
|
||
p := math.Pow(10, float64(decimals))
|
||
v = math.Round(v*p) / p
|
||
}
|
||
if v != *value {
|
||
*value = v
|
||
row.st.markChanged()
|
||
c.rt.consumed = true
|
||
}
|
||
}
|
||
row.Children(func() {
|
||
in := coreTextInput(c, text).Width(t.Space(20)).Shrink(1).MinWidth(0)
|
||
in.widget = "NumberInput"
|
||
in.afterInput(func() {
|
||
if in.Changed() {
|
||
if v, err := strconv.ParseFloat(strings.TrimSpace(*text), 64); err == nil && v >= lo && v <= hi {
|
||
set(v)
|
||
}
|
||
}
|
||
if in.Shortcut(0, KeyUp) {
|
||
set(*value + step)
|
||
*text = format(*value)
|
||
}
|
||
if in.Shortcut(0, KeyDown) {
|
||
set(*value - step)
|
||
*text = format(*value)
|
||
}
|
||
if !in.Focused() {
|
||
// What the app set, or what was typed, shown in full.
|
||
*text = format(*value)
|
||
}
|
||
})
|
||
in.hasRange, in.accRange, in.accStep = true, [3]float64{lo, hi, *value}, step
|
||
for _, b := range []struct {
|
||
label string
|
||
delta float64
|
||
}{{"−", -step}, {"+", step}} {
|
||
btn := coreButton(c, b.label).Padding(t.Space(1), t.Space(2)).Label(map[bool]string{true: "Increase", false: "Decrease"}[b.delta > 0])
|
||
btn.Disabled(b.delta < 0 && *value <= lo || b.delta > 0 && *value >= hi)
|
||
btn.afterInput(func() {
|
||
if btn.Clicked() {
|
||
set(*value + b.delta)
|
||
*text = format(*value)
|
||
}
|
||
})
|
||
btn.TextColor(t.Text)
|
||
}
|
||
})
|
||
return row
|
||
}
|