Upgrade MyGo to v0.5.5
MyGo v0.5.5 returns ui.Element as a checked value handle instead of a
pointer. Migrated with `mygo migrate-ui`, then fixed what the codemod
leaves to review:
- Element nil checks become .Valid(); absent elements are ui.Element{}.
- Input handlers and paint callbacks run outside the build pass, where
elements expire and Context methods are inert: read IsDisabled into a
local during the build, keep a ui.Handle for Focus, use c.Services()
for clipboard access, create ui.Local state during the build.
- Add core.AutoFocus: v0.5.5 records an overlay's opener after its
content builds, so same-frame autofocus lost focus restore on close.
It focuses one frame later; cascader rows defer their focus likewise.
- core.OverlayLayer identifies build passes by the root element, not
c.Now(), which repeats across passes and under the Tester clock.
- Context menus survive the opening press counted as PressedOutside;
split button tooltip no longer reorders its open menu; disabled
menubar rows pass presses to the panel; Form defers blur-started
async checks so the growing message no longer moves Submit away
from the release; Combobox drops its disabled copy now that MyGo
blocks typing under a disabled wrapper (canary flipped to a guard).
- The Tester clock is virtual: tests use Advance/Now instead of
time.Sleep/time.Now and read element state inside the view. The web
mirror advances the clock to wall time before each frame and input.
- AGENTS.md and docs describe the value Element API and the new pin.
Snapshot goldens are darwin-only and were not re-verified here.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
bc716d27be
commit
bcce34cda1
603 files changed
+1366
-1277
No files matched your search
@@ -9,11 +9,11 @@ Planned: once 001–500 land, the root package splits into category sub-packages
|
|||||||
| Item | Value |
|
| Item | Value |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| Go | 1.27.1 (MyGo's minimum) |
|
| Go | 1.27.1 (MyGo's minimum) |
|
||||||
| MyGo | `github.com/egoist/mygo v0.2.10` (commit 459b512), pinned in go.mod |
|
| MyGo | `github.com/egoist/mygo v0.5.5` (commit 4d8673c), pinned in go.mod |
|
||||||
| Icons | Lucide 1.52.0, ISC, copied into `icons/svg` |
|
| Icons | Lucide 1.52.0, ISC, copied into `icons/svg` |
|
||||||
| Web mirror | `examples/gallery -web :8080`: Go stdlib server drives the Gallery through `ui.NewTester` and streams frames to a canvas. The browser shows pixels; Go runs the components. |
|
| Web mirror | `examples/gallery -web :8080`: Go stdlib server drives the Gallery through `ui.NewTester` and streams frames to a canvas. The browser shows pixels; Go runs the components. |
|
||||||
|
|
||||||
Read MyGo source before using an API: `go env GOMODCACHE`/github.com/egoist/mygo@v0.2.10 (`ui/*.go`, `docs/ui/*.md`). Never guess.
|
Read MyGo source before using an API: `go env GOMODCACHE`/github.com/egoist/mygo@v0.5.5 (`ui/*.go`, `docs/ui/*.md`, migration guide `docs/ui/migration.md`). Never guess.
|
||||||
|
|
||||||
## Layout
|
## Layout
|
||||||
|
|
||||||
@@ -36,8 +36,8 @@ Gallery categories map to packages: Inputs, Choices, Forms, Essentials -> input;
|
|||||||
|
|
||||||
## Component rules
|
## Component rules
|
||||||
|
|
||||||
- Signature: `func Name(c *ui.Context, value *T, opts NameOptions) *ui.Element`. Composites may return a named struct.
|
- Signature: `func Name(c *ui.Context, value *T, opts NameOptions) ui.Element`. Composites may return a named struct.
|
||||||
- Result structs expose the element as a named field `Element *ui.Element`, never embedded; element plus changed is `ChoiceResult`.
|
- Result structs expose the element as a named field `Element ui.Element`, never embedded; element plus changed is `ChoiceResult`.
|
||||||
- Shared helpers: `iconAction` (borderless icon button), `overlayStyle(c, panel, overlayEnter(c, panel))` (popup surface and entry fade), `internal.RuleDiamond` / `internal.Frame` (ornaments), `colorFade` (state color transition).
|
- Shared helpers: `iconAction` (borderless icon button), `overlayStyle(c, panel, overlayEnter(c, panel))` (popup surface and entry fade), `internal.RuleDiamond` / `internal.Frame` (ornaments), `colorFade` (state color transition).
|
||||||
- Zero `Options` gives the default look. No `map[string]any` config.
|
- Zero `Options` gives the default look. No `map[string]any` config.
|
||||||
- Explicit font sizes: `FontSize(c, theme.CaptionSize)`; it applies the desktop text scale.
|
- Explicit font sizes: `FontSize(c, theme.CaptionSize)`; it applies the desktop text scale.
|
||||||
@@ -50,7 +50,9 @@ Gallery categories map to packages: Inputs, Choices, Forms, Essentials -> input;
|
|||||||
- Durations: `core.Motion(c, theme.StateDuration)`; popups use `theme.PopupDuration`.
|
- Durations: `core.Motion(c, theme.StateDuration)`; popups use `theme.PopupDuration`.
|
||||||
- Disabled blocks input before handling it (`Disabled(true)`); MyGo dims disabled elements, do not add opacity.
|
- Disabled blocks input before handling it (`Disabled(true)`); MyGo dims disabled elements, do not add opacity.
|
||||||
- Copy shown by a component comes from `core.Msg(c, key)`; business copy comes from the caller.
|
- Copy shown by a component comes from `core.Msg(c, key)`; business copy comes from the caller.
|
||||||
- No cross-frame `*ui.Element` caching, no goroutines touching elements.
|
- `ui.Element` is a handle valid only during its build pass: no cross-frame caching, no goroutines touching elements, no element methods inside `HandleInput` or other callbacks (read state such as `IsDisabled` into a local during the build). Keep a `ui.Handle` for persistent identity and `c.Services()` for clipboard or URLs from callbacks. The absent element is `ui.Element{}`; test it with `.Valid()`.
|
||||||
|
- Overlay content takes initial focus with `core.AutoFocus(c, e)`, not `e.AutoFocus()`: MyGo v0.5.5 records an overlay's opener after its content builds, so same-frame autofocus loses focus restore on close.
|
||||||
|
- Tests run on the Tester's virtual clock: `tt.Advance(d)` and `tt.Now()`, never `time.Sleep` or `time.Now()`; read element state inside the view.
|
||||||
- Fail fast: panic on programmer errors (bad options); never swallow errors.
|
- Fail fast: panic on programmer errors (bad options); never swallow errors.
|
||||||
- Log state transitions in composites with `slog.Debug("mujica: <component> <event>", ...)`. Never log passwords.
|
- Log state transitions in composites with `slog.Debug("mujica: <component> <event>", ...)`. Never log passwords.
|
||||||
- Files under 500 lines. Comments: one line, only when needed.
|
- Files under 500 lines. Comments: one line, only when needed.
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ type AccountSwitcherOptions struct {
|
|||||||
|
|
||||||
// AccountSwitcherResult reports account changes and addition requests.
|
// AccountSwitcherResult reports account changes and addition requests.
|
||||||
type AccountSwitcherResult struct {
|
type AccountSwitcherResult struct {
|
||||||
Element *ui.Element
|
Element ui.Element
|
||||||
changed bool
|
changed bool
|
||||||
add bool
|
add bool
|
||||||
}
|
}
|
||||||
@@ -75,7 +75,7 @@ func AccountSwitcher(c *ui.Context, current *string, accounts []Account, opts Ac
|
|||||||
if a.Email != "" {
|
if a.Email != "" {
|
||||||
label += " · " + a.Email
|
label += " · " + a.Email
|
||||||
}
|
}
|
||||||
ui.Column(c).Key(a.ID).Shrink(0).Children(func() {
|
ui.Column(c.Key(a.ID)).Shrink(0).Children(func() {
|
||||||
if m.Check(label, &on, overlay.PopupMenuItemOptions{}) && a.ID != *current && !b.IsDisabled() {
|
if m.Check(label, &on, overlay.PopupMenuItemOptions{}) && a.ID != *current && !b.IsDisabled() {
|
||||||
*current, r.changed = a.ID, true
|
*current, r.changed = a.ID, true
|
||||||
slog.Debug("mujica: account_switcher switched")
|
slog.Debug("mujica: account_switcher switched")
|
||||||
@@ -92,7 +92,7 @@ func AccountSwitcher(c *ui.Context, current *string, accounts []Account, opts Ac
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func accountSwitcherLarge(c *ui.Context, b *ui.Element, open *bool, current *string, accounts []Account, r *AccountSwitcherResult) {
|
func accountSwitcherLarge(c *ui.Context, b ui.Element, open *bool, current *string, accounts []Account, r *AccountSwitcherResult) {
|
||||||
overlay.Popover(c, b, open, overlay.PopoverOptions{Label: core.Msg(c, "account_switcher.accounts"), Width: 320}, func() {
|
overlay.Popover(c, b, open, overlay.PopoverOptions{Label: core.Msg(c, "account_switcher.accounts"), Width: 320}, func() {
|
||||||
cursor := ui.Local(b, "cursor", func() int { return -1 })
|
cursor := ui.Local(b, "cursor", func() int { return -1 })
|
||||||
rows := ui.Local(b, "list", func() ui.ListState { return ui.ListState{} })
|
rows := ui.Local(b, "list", func() ui.ListState { return ui.ListState{} })
|
||||||
@@ -100,7 +100,7 @@ func accountSwitcherLarge(c *ui.Context, b *ui.Element, open *bool, current *str
|
|||||||
rows.Label = func(i int) string { return accounts[i].Name }
|
rows.Label = func(i int) string { return accounts[i].Name }
|
||||||
rows.Selected = cursor
|
rows.Selected = cursor
|
||||||
restore := data.DataSelectTheme(c, 0)
|
restore := data.DataSelectTheme(c, 0)
|
||||||
list := ui.List(c, rows, len(accounts), func(i int) {
|
list := core.AutoFocus(c, ui.List(c, rows, len(accounts), func(i int) {
|
||||||
a := accounts[i]
|
a := accounts[i]
|
||||||
row := workspaceRow(c, Workspace{ID: a.ID, Name: a.Name, Detail: a.Email}, a.ID == *current, i == *cursor)
|
row := workspaceRow(c, Workspace{ID: a.ID, Name: a.Name, Detail: a.Email}, a.ID == *current, i == *cursor)
|
||||||
if row.Focused() && !b.IsDisabled() {
|
if row.Focused() && !b.IsDisabled() {
|
||||||
@@ -109,7 +109,8 @@ func accountSwitcherLarge(c *ui.Context, b *ui.Element, open *bool, current *str
|
|||||||
if row.Clicked() && !row.IsDisabled() && !b.IsDisabled() {
|
if row.Clicked() && !row.IsDisabled() && !b.IsDisabled() {
|
||||||
r.changed, *current, *open = a.ID != *current, a.ID, false
|
r.changed, *current, *open = a.ID != *current, a.ID, false
|
||||||
}
|
}
|
||||||
}).Height(280).MinHeight(0).AutoFocus()
|
}).Height(280).MinHeight(0))
|
||||||
|
|
||||||
restore()
|
restore()
|
||||||
internal.Ring(list, core.Tokens(c).Focus, theme.ControlRadius)
|
internal.Ring(list, core.Tokens(c).Focus, theme.ControlRadius)
|
||||||
if list.Changed() && !b.IsDisabled() {
|
if list.Changed() && !b.IsDisabled() {
|
||||||
@@ -129,7 +130,7 @@ func accountSwitcherLarge(c *ui.Context, b *ui.Element, open *bool, current *str
|
|||||||
}
|
}
|
||||||
|
|
||||||
// accountTrigger displays an avatar, name and detail.
|
// accountTrigger displays an avatar, name and detail.
|
||||||
func accountTrigger(c *ui.Context, name, detail string, avatar *ui.Bitmap, disabled bool) *ui.Element {
|
func accountTrigger(c *ui.Context, name, detail string, avatar *ui.Bitmap, disabled bool) ui.Element {
|
||||||
k := core.Tokens(c)
|
k := core.Tokens(c)
|
||||||
d := core.Density(c)
|
d := core.Density(c)
|
||||||
b := ui.ButtonBase(c).Role(ui.RoleMenuButton).MinHeight(d.ControlHeight()+d.Unit()*2).Padding(d.Unit(), d.Unit()*3, d.Unit(), d.Unit()*2).
|
b := ui.ButtonBase(c).Role(ui.RoleMenuButton).MinHeight(d.ControlHeight()+d.Unit()*2).Padding(d.Unit(), d.Unit()*3, d.Unit(), d.Unit()*2).
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ type ApiKeyManagerOptions struct {
|
|||||||
|
|
||||||
// ApiKeyManagerResult reports creation and revocation requests.
|
// ApiKeyManagerResult reports creation and revocation requests.
|
||||||
type ApiKeyManagerResult struct {
|
type ApiKeyManagerResult struct {
|
||||||
Element *ui.Element
|
Element ui.Element
|
||||||
create, revoke string
|
create, revoke string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +102,7 @@ func ApiKeyManager(c *ui.Context, s *ApiKeyManagerState, keys []APIKey, opts Api
|
|||||||
}
|
}
|
||||||
accountRows(c, len(keys), func(i int) any { return keys[i].ID }, func(i int) {
|
accountRows(c, len(keys), func(i int) any { return keys[i].ID }, func(i int) {
|
||||||
key := keys[i]
|
key := keys[i]
|
||||||
ui.Row(c).Key(key.ID).MinHeight(d.ControlHeight()+d.Unit()*4).Gap(d.Unit()*3).AlignItems(ui.Center).
|
ui.Row(c.Key(key.ID)).MinHeight(d.ControlHeight()+d.Unit()*4).Gap(d.Unit()*3).AlignItems(ui.Center).
|
||||||
BorderWidth(0, 0, theme.BorderWidth, 0).BorderColor(k.Border).Children(func() {
|
BorderWidth(0, 0, theme.BorderWidth, 0).BorderColor(k.Border).Children(func() {
|
||||||
ui.Column(c).Grow(1).MinWidth(0).Gap(2).Children(func() {
|
ui.Column(c).Grow(1).MinWidth(0).Gap(2).Children(func() {
|
||||||
ui.Text(c, key.Name).FontWeight(600).SingleLine()
|
ui.Text(c, key.Name).FontWeight(600).SingleLine()
|
||||||
@@ -191,7 +191,7 @@ func apiKeyCreateDialog(c *ui.Context, s *ApiKeyManagerState, disabled bool) (st
|
|||||||
}
|
}
|
||||||
res := input.TextInput(c, &s.name, input.TextInputOptions{Label: core.Msg(c, "api_key_manager.name"), Placeholder: core.Msg(c, "api_key_manager.name"),
|
res := input.TextInput(c, &s.name, input.TextInputOptions{Label: core.Msg(c, "api_key_manager.name"), Placeholder: core.Msg(c, "api_key_manager.name"),
|
||||||
Disabled: s.pending, Error: s.err})
|
Disabled: s.pending, Error: s.err})
|
||||||
res.Input.AutoFocus()
|
core.AutoFocus(c, res.Input)
|
||||||
if res.Submitted() && strings.TrimSpace(s.name) != "" && !s.pending {
|
if res.Submitted() && strings.TrimSpace(s.name) != "" && !s.pending {
|
||||||
asked = true
|
asked = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,13 +14,13 @@ import (
|
|||||||
|
|
||||||
// CoachmarkStep uses an anchor built in the current frame.
|
// CoachmarkStep uses an anchor built in the current frame.
|
||||||
type CoachmarkStep struct {
|
type CoachmarkStep struct {
|
||||||
Anchor *ui.Element
|
Anchor ui.Element
|
||||||
Title, Body string
|
Title, Body string
|
||||||
}
|
}
|
||||||
|
|
||||||
// CoachmarkResult reports tour completion or dismissal.
|
// CoachmarkResult reports tour completion or dismissal.
|
||||||
type CoachmarkResult struct {
|
type CoachmarkResult struct {
|
||||||
Element *ui.Element
|
Element ui.Element
|
||||||
finished, dismissed bool
|
finished, dismissed bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ func Coachmark(c *ui.Context, open *bool, step *int, steps []CoachmarkStep) Coac
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
cur := steps[*step]
|
cur := steps[*step]
|
||||||
if cur.Anchor == nil || cur.Title == "" {
|
if !cur.Anchor.Valid() || cur.Title == "" {
|
||||||
panic("mujica: CoachmarkStep needs an Anchor and a Title")
|
panic("mujica: CoachmarkStep needs an Anchor and a Title")
|
||||||
}
|
}
|
||||||
if cur.Anchor.IsDisabled() {
|
if cur.Anchor.IsDisabled() {
|
||||||
@@ -76,7 +76,7 @@ func Coachmark(c *ui.Context, open *bool, step *int, steps []CoachmarkStep) Coac
|
|||||||
if last {
|
if last {
|
||||||
next = core.Msg(c, "coachmark.done")
|
next = core.Msg(c, "coachmark.done")
|
||||||
}
|
}
|
||||||
if input.Button(c, next, input.ButtonOptions{}).AutoFocus().Clicked() {
|
if core.AutoFocus(c, input.Button(c, next, input.ButtonOptions{})).Clicked() {
|
||||||
if last {
|
if last {
|
||||||
*open, r.finished = false, true
|
*open, r.finished = false, true
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func coachmarkView(c *ui.Context, open *bool, step *int, r *CoachmarkResult) {
|
func coachmarkView(c *ui.Context, open *bool, step *int, r *CoachmarkResult) {
|
||||||
var a, b *ui.Element
|
var a, b ui.Element
|
||||||
ui.Row(c).Gap(40).Padding(20).Children(func() {
|
ui.Row(c).Gap(40).Padding(20).Children(func() {
|
||||||
a = input.Button(c, "Compose", input.ButtonOptions{})
|
a = input.Button(c, "Compose", input.ButtonOptions{})
|
||||||
b = input.Button(c, "Archive", input.ButtonOptions{Variant: input.Secondary})
|
b = input.Button(c, "Archive", input.ButtonOptions{Variant: input.Secondary})
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ func ExampleSettingsLayout() {
|
|||||||
core.Use(c, core.Settings{})
|
core.Use(c, core.Settings{})
|
||||||
account.SettingsLayout(c, &page, pages, account.SettingsLayoutOptions{}, func(id string) {
|
account.SettingsLayout(c, &page, pages, account.SettingsLayoutOptions{}, func(id string) {
|
||||||
account.SettingsSection(c, "Notifications", func() {
|
account.SettingsSection(c, "Notifications", func() {
|
||||||
account.SettingsRow(c, "Sound", account.SettingsRowOptions{ID: "sound"}, func() *ui.Element {
|
account.SettingsRow(c, "Sound", account.SettingsRowOptions{ID: "sound"}, func() ui.Element {
|
||||||
return input.Switch(c, &sound, "", input.SwitchOptions{})
|
return input.Switch(c, &sound, "", input.SwitchOptions{})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ type FeedbackWidgetOptions struct {
|
|||||||
|
|
||||||
// FeedbackWidgetResult carries the submitted feedback.
|
// FeedbackWidgetResult carries the submitted feedback.
|
||||||
type FeedbackWidgetResult struct {
|
type FeedbackWidgetResult struct {
|
||||||
Element *ui.Element
|
Element ui.Element
|
||||||
feedback Feedback
|
feedback Feedback
|
||||||
submitted bool
|
submitted bool
|
||||||
}
|
}
|
||||||
@@ -106,7 +106,7 @@ func FeedbackWidget(c *ui.Context, s *FeedbackWidgetState, opts FeedbackWidgetOp
|
|||||||
return fmt.Sprintf(core.Msg(c, "feedback_widget.short"), minLen)
|
return fmt.Sprintf(core.Msg(c, "feedback_widget.short"), minLen)
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}}, func() *ui.Element {
|
}}, func() ui.Element {
|
||||||
return input.TextArea(c, &s.Draft.Text, input.TextAreaOptions{MinHeight: 96, MaxLength: 2000, Disabled: locked}).Input
|
return input.TextArea(c, &s.Draft.Text, input.TextAreaOptions{MinHeight: 96, MaxLength: 2000, Disabled: locked}).Input
|
||||||
})
|
})
|
||||||
if opts.Attachments != nil {
|
if opts.Attachments != nil {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ type shortcutsListState struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// KeyboardShortcutsList displays searchable, grouped shortcuts using visible rows.
|
// KeyboardShortcutsList displays searchable, grouped shortcuts using visible rows.
|
||||||
func KeyboardShortcutsList(c *ui.Context, query *string, groups []ShortcutGroup, opts KeyboardShortcutsListOptions) *ui.Element {
|
func KeyboardShortcutsList(c *ui.Context, query *string, groups []ShortcutGroup, opts KeyboardShortcutsListOptions) ui.Element {
|
||||||
k := core.Tokens(c)
|
k := core.Tokens(c)
|
||||||
d := core.Density(c)
|
d := core.Density(c)
|
||||||
label := opts.Label
|
label := opts.Label
|
||||||
@@ -96,11 +96,11 @@ func shortcutsListPlan(st *shortcutsListState, groups []ShortcutGroup, q string)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func accountRows(c *ui.Context, n int, key func(int) any, row func(int)) *ui.Element {
|
func accountRows(c *ui.Context, n int, key func(int) any, row func(int)) ui.Element {
|
||||||
if n <= 8 {
|
if n <= 8 {
|
||||||
return ui.Column(c).Children(func() {
|
return ui.Column(c).Children(func() {
|
||||||
for i := range n {
|
for i := range n {
|
||||||
ui.Column(c).Key(key(i)).Children(func() { row(i) })
|
ui.Column(c.Key(key(i))).Children(func() { row(i) })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ type LoginFormOptions struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// LoginForm collects credentials; it never checks or stores them.
|
// LoginForm collects credentials; it never checks or stores them.
|
||||||
func LoginForm(c *ui.Context, s *LoginFormState, opts LoginFormOptions) *ui.Element {
|
func LoginForm(c *ui.Context, s *LoginFormState, opts LoginFormOptions) ui.Element {
|
||||||
if opts.OnSubmit == nil {
|
if opts.OnSubmit == nil {
|
||||||
panic("mujica: LoginForm needs OnSubmit")
|
panic("mujica: LoginForm needs OnSubmit")
|
||||||
}
|
}
|
||||||
@@ -61,11 +61,11 @@ func LoginForm(c *ui.Context, s *LoginFormState, opts LoginFormOptions) *ui.Elem
|
|||||||
submit := false
|
submit := false
|
||||||
var acc, pw input.InputResult
|
var acc, pw input.InputResult
|
||||||
e.Children(func() {
|
e.Children(func() {
|
||||||
input.FormField(c, accountLabel, input.FormFieldOptions{Required: true}, func() *ui.Element {
|
input.FormField(c, accountLabel, input.FormFieldOptions{Required: true}, func() ui.Element {
|
||||||
acc = input.TextInput(c, &s.Account, input.TextInputOptions{Disabled: disabled || s.submitting, Error: missing(s.Account)})
|
acc = input.TextInput(c, &s.Account, input.TextInputOptions{Disabled: disabled || s.submitting, Error: missing(s.Account)})
|
||||||
return acc.Input
|
return acc.Input
|
||||||
})
|
})
|
||||||
input.FormField(c, core.Msg(c, "login_form.password"), input.FormFieldOptions{Required: true}, func() *ui.Element {
|
input.FormField(c, core.Msg(c, "login_form.password"), input.FormFieldOptions{Required: true}, func() ui.Element {
|
||||||
pw = input.PasswordInput(c, &s.password, input.PasswordInputOptions{Disabled: disabled || s.submitting, Error: missing(s.password)})
|
pw = input.PasswordInput(c, &s.password, input.PasswordInputOptions{Disabled: disabled || s.submitting, Error: missing(s.password)})
|
||||||
return pw.Input
|
return pw.Input
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ type OAuthButtonsOptions struct {
|
|||||||
|
|
||||||
// OAuthButtonsResult carries the selected provider.
|
// OAuthButtonsResult carries the selected provider.
|
||||||
type OAuthButtonsResult struct {
|
type OAuthButtonsResult struct {
|
||||||
Element *ui.Element
|
Element ui.Element
|
||||||
chosen string
|
chosen string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ func OAuthButtons(c *ui.Context, providers []OAuthProvider, opts OAuthButtonsOpt
|
|||||||
panic("mujica: OAuthProvider needs an ID and a Name")
|
panic("mujica: OAuthProvider needs an ID and a Name")
|
||||||
}
|
}
|
||||||
label := fmt.Sprintf(core.Msg(c, "oauth_buttons.continue"), p.Name)
|
label := fmt.Sprintf(core.Msg(c, "oauth_buttons.continue"), p.Name)
|
||||||
ui.Column(c).Key(p.ID).AlignItems(ui.Stretch).Children(func() {
|
ui.Column(c.Key(p.ID)).AlignItems(ui.Stretch).Children(func() {
|
||||||
b := input.Button(c, label, input.ButtonOptions{Variant: input.Secondary, Icon: p.Icon, Loading: opts.Pending == p.ID,
|
b := input.Button(c, label, input.ButtonOptions{Variant: input.Secondary, Icon: p.Icon, Loading: opts.Pending == p.ID,
|
||||||
Disabled: opts.Pending != "" && opts.Pending != p.ID})
|
Disabled: opts.Pending != "" && opts.Pending != p.ID})
|
||||||
if b.Clicked() && !disabled && opts.Pending == "" {
|
if b.Clicked() && !disabled && opts.Pending == "" {
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ type OnboardingWizardOptions struct {
|
|||||||
|
|
||||||
// OnboardingWizardResult reports completion or skipping.
|
// OnboardingWizardResult reports completion or skipping.
|
||||||
type OnboardingWizardResult struct {
|
type OnboardingWizardResult struct {
|
||||||
Element *ui.Element
|
Element ui.Element
|
||||||
finished, skipped bool
|
finished, skipped bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ func OnboardingWizard(c *ui.Context, step *int, steps []WizardStep, opts Onboard
|
|||||||
at := *step
|
at := *step
|
||||||
navigation.Steps(c, &at, head, navigation.StepsOptions{Label: core.Msg(c, "onboarding_wizard.progress")})
|
navigation.Steps(c, &at, head, navigation.StepsOptions{Label: core.Msg(c, "onboarding_wizard.progress")})
|
||||||
cur := steps[*step]
|
cur := steps[*step]
|
||||||
ui.Column(c).Key(*step).Gap(d.Unit() * 3).Children(func() {
|
ui.Column(c.Key(*step)).Gap(d.Unit() * 3).Children(func() {
|
||||||
ui.Text(c, fmt.Sprintf(core.Msg(c, "onboarding_wizard.count"), *step+1, len(steps))).TextColor(k.TextMuted).FontSize(core.FontSize(c, theme.CaptionSize))
|
ui.Text(c, fmt.Sprintf(core.Msg(c, "onboarding_wizard.count"), *step+1, len(steps))).TextColor(k.TextMuted).FontSize(core.FontSize(c, theme.CaptionSize))
|
||||||
ui.Text(c, cur.Title).Font(theme.SerifFont).FontSize(core.FontSize(c, theme.H2Size)).FontWeight(600)
|
ui.Text(c, cur.Title).Font(theme.SerifFont).FontSize(core.FontSize(c, theme.H2Size)).FontWeight(600)
|
||||||
if cur.Description != "" {
|
if cur.Description != "" {
|
||||||
@@ -84,7 +84,7 @@ func OnboardingWizard(c *ui.Context, step *int, steps []WizardStep, opts Onboard
|
|||||||
if last {
|
if last {
|
||||||
next = core.Msg(c, "onboarding_wizard.finish")
|
next = core.Msg(c, "onboarding_wizard.finish")
|
||||||
}
|
}
|
||||||
if input.Button(c, next, input.ButtonOptions{Disabled: !ready}).AutoFocus().Clicked() && ready {
|
if core.AutoFocus(c, input.Button(c, next, input.ButtonOptions{Disabled: !ready})).Clicked() && ready {
|
||||||
if last {
|
if last {
|
||||||
r.finished = true
|
r.finished = true
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ type ProfileEditorOptions struct {
|
|||||||
|
|
||||||
// ProfileEditorResult reports save, avatar and discard requests.
|
// ProfileEditorResult reports save, avatar and discard requests.
|
||||||
type ProfileEditorResult struct {
|
type ProfileEditorResult struct {
|
||||||
Element *ui.Element
|
Element ui.Element
|
||||||
save, avatar, reset bool
|
save, avatar, reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,10 +73,10 @@ func ProfileEditor(c *ui.Context, p *Profile, opts ProfileEditorOptions) Profile
|
|||||||
r.avatar = true
|
r.avatar = true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
input.FormField(c, core.Msg(c, "profile_editor.name"), input.FormFieldOptions{Required: true}, func() *ui.Element {
|
input.FormField(c, core.Msg(c, "profile_editor.name"), input.FormFieldOptions{Required: true}, func() ui.Element {
|
||||||
return input.TextInput(c, &p.Name, input.TextInputOptions{Disabled: locked, Error: nameErr}).Input
|
return input.TextInput(c, &p.Name, input.TextInputOptions{Disabled: locked, Error: nameErr}).Input
|
||||||
})
|
})
|
||||||
input.FormField(c, core.Msg(c, "profile_editor.bio"), input.FormFieldOptions{}, func() *ui.Element {
|
input.FormField(c, core.Msg(c, "profile_editor.bio"), input.FormFieldOptions{}, func() ui.Element {
|
||||||
return input.TextArea(c, &p.Bio, input.TextAreaOptions{MaxLength: limit, Disabled: locked}).Input
|
return input.TextArea(c, &p.Bio, input.TextAreaOptions{MaxLength: limit, Disabled: locked}).Input
|
||||||
})
|
})
|
||||||
ui.Row(c).Gap(d.Unit() * 3).AlignItems(ui.Center).Children(func() {
|
ui.Row(c).Gap(d.Unit() * 3).AlignItems(ui.Center).Children(func() {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ type SessionListOptions struct {
|
|||||||
|
|
||||||
// SessionListResult reports individual and bulk sign-out requests.
|
// SessionListResult reports individual and bulk sign-out requests.
|
||||||
type SessionListResult struct {
|
type SessionListResult struct {
|
||||||
Element *ui.Element
|
Element ui.Element
|
||||||
revoke string
|
revoke string
|
||||||
others bool
|
others bool
|
||||||
}
|
}
|
||||||
@@ -74,7 +74,7 @@ func SessionList(c *ui.Context, sessions []Session, opts SessionListOptions) Ses
|
|||||||
ui.Column(c).Role(ui.RoleList).Label(core.Msg(c, "session_list.label")).Children(func() {
|
ui.Column(c).Role(ui.RoleList).Label(core.Msg(c, "session_list.label")).Children(func() {
|
||||||
accountRows(c, len(sessions), func(i int) any { return sessions[i].ID }, func(i int) {
|
accountRows(c, len(sessions), func(i int) any { return sessions[i].ID }, func(i int) {
|
||||||
s := sessions[i]
|
s := sessions[i]
|
||||||
ui.Row(c).Key(s.ID).MinHeight(d.ControlHeight()+d.Unit()*4).Gap(d.Unit()*3).AlignItems(ui.Center).
|
ui.Row(c.Key(s.ID)).MinHeight(d.ControlHeight()+d.Unit()*4).Gap(d.Unit()*3).AlignItems(ui.Center).
|
||||||
BorderWidth(0, 0, theme.BorderWidth, 0).BorderColor(k.Border).Role(ui.RoleListItem).Children(func() {
|
BorderWidth(0, 0, theme.BorderWidth, 0).BorderColor(k.Border).Role(ui.RoleListItem).Children(func() {
|
||||||
ui.Column(c).Grow(1).MinWidth(0).Gap(2).Children(func() {
|
ui.Column(c).Grow(1).MinWidth(0).Gap(2).Children(func() {
|
||||||
ui.Row(c).Gap(d.Unit() * 2).AlignItems(ui.Center).Children(func() {
|
ui.Row(c).Gap(d.Unit() * 2).AlignItems(ui.Center).Children(func() {
|
||||||
|
|||||||
@@ -58,14 +58,14 @@ func SettingsLayout(c *ui.Context, page *string, pages []SettingsPage, opts Sett
|
|||||||
slog.Debug("mujica: settings_layout page", "page", *page)
|
slog.Debug("mujica: settings_layout page", "page", *page)
|
||||||
}
|
}
|
||||||
ui.Scroll(c).Grow(1).MinWidth(0).Padding(d.Unit()*6, d.Unit()*8).Children(func() {
|
ui.Scroll(c).Grow(1).MinWidth(0).Padding(d.Unit()*6, d.Unit()*8).Children(func() {
|
||||||
ui.Column(c).Key(*page).MaxWidth(720).Gap(d.Unit() * 8).Children(func() { content(*page) })
|
ui.Column(c.Key(*page)).MaxWidth(720).Gap(d.Unit() * 8).Children(func() { content(*page) })
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
// SettingsSection groups rows under a serif heading.
|
// SettingsSection groups rows under a serif heading.
|
||||||
func SettingsSection(c *ui.Context, title string, rows func()) *ui.Element {
|
func SettingsSection(c *ui.Context, title string, rows func()) ui.Element {
|
||||||
k := core.Tokens(c)
|
k := core.Tokens(c)
|
||||||
d := core.Density(c)
|
d := core.Density(c)
|
||||||
e := ui.Column(c).Gap(d.Unit() * 2).Role(ui.RoleGroup).Label(title)
|
e := ui.Column(c).Gap(d.Unit() * 2).Role(ui.RoleGroup).Label(title)
|
||||||
@@ -94,7 +94,7 @@ func settingsReveal(c *ui.Context, id string) {
|
|||||||
type settingsRowState struct{ at time.Time }
|
type settingsRowState struct{ at time.Time }
|
||||||
|
|
||||||
// SettingsRow associates a label and description with its control.
|
// SettingsRow associates a label and description with its control.
|
||||||
func SettingsRow(c *ui.Context, label string, opts SettingsRowOptions, control func() *ui.Element) *ui.Element {
|
func SettingsRow(c *ui.Context, label string, opts SettingsRowOptions, control func() ui.Element) ui.Element {
|
||||||
if label == "" || control == nil {
|
if label == "" || control == nil {
|
||||||
panic("mujica: SettingsRow needs a label and a control")
|
panic("mujica: SettingsRow needs a label and a control")
|
||||||
}
|
}
|
||||||
@@ -106,7 +106,7 @@ func SettingsRow(c *ui.Context, label string, opts SettingsRowOptions, control f
|
|||||||
}
|
}
|
||||||
st := ui.Local(row, "reveal", func() settingsRowState { return settingsRowState{} })
|
st := ui.Local(row, "reveal", func() settingsRowState { return settingsRowState{} })
|
||||||
reveal := ui.Local(c.Root(), settingsRevealKey{}, func() string { return "" })
|
reveal := ui.Local(c.Root(), settingsRevealKey{}, func() string { return "" })
|
||||||
var ctrl, text *ui.Element
|
var ctrl, text ui.Element
|
||||||
row.Children(func() {
|
row.Children(func() {
|
||||||
text = ui.Column(c).Grow(1).MinWidth(0).Gap(d.Unit())
|
text = ui.Column(c).Grow(1).MinWidth(0).Gap(d.Unit())
|
||||||
text.Children(func() {
|
text.Children(func() {
|
||||||
@@ -117,7 +117,7 @@ func SettingsRow(c *ui.Context, label string, opts SettingsRowOptions, control f
|
|||||||
})
|
})
|
||||||
ui.Row(c).Shrink(0).Children(func() { ctrl = control() })
|
ui.Row(c).Shrink(0).Children(func() { ctrl = control() })
|
||||||
})
|
})
|
||||||
if ctrl == nil {
|
if !ctrl.Valid() {
|
||||||
panic("mujica: SettingsRow " + label + ": control returned nil")
|
panic("mujica: SettingsRow " + label + ": control returned nil")
|
||||||
}
|
}
|
||||||
ctrl.Label(label).Description(opts.Description)
|
ctrl.Label(label).Description(opts.Description)
|
||||||
|
|||||||
@@ -24,13 +24,13 @@ func settingsView(c *ui.Context, page *string, sound, track *bool, changes *int)
|
|||||||
switch id {
|
switch id {
|
||||||
case "general":
|
case "general":
|
||||||
SettingsSection(c, "Notifications", func() {
|
SettingsSection(c, "Notifications", func() {
|
||||||
SettingsRow(c, "Sound", SettingsRowOptions{ID: "sound", Description: "Chime on new messages."}, func() *ui.Element {
|
SettingsRow(c, "Sound", SettingsRowOptions{ID: "sound", Description: "Chime on new messages."}, func() ui.Element {
|
||||||
return input.Switch(c, sound, "", input.SwitchOptions{})
|
return input.Switch(c, sound, "", input.SwitchOptions{})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
case "privacy":
|
case "privacy":
|
||||||
SettingsSection(c, "Data", func() {
|
SettingsSection(c, "Data", func() {
|
||||||
SettingsRow(c, "Usage reports", SettingsRowOptions{ID: "track"}, func() *ui.Element {
|
SettingsRow(c, "Usage reports", SettingsRowOptions{ID: "track"}, func() ui.Element {
|
||||||
return input.Switch(c, track, "", input.SwitchOptions{})
|
return input.Switch(c, track, "", input.SwitchOptions{})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ type SettingsSearchOptions struct {
|
|||||||
|
|
||||||
// SettingsSearchResult carries the selected destination.
|
// SettingsSearchResult carries the selected destination.
|
||||||
type SettingsSearchResult struct {
|
type SettingsSearchResult struct {
|
||||||
Element *ui.Element
|
Element ui.Element
|
||||||
chosen *SettingEntry
|
chosen *SettingEntry
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +135,7 @@ func settingsSearchPlan(st *settingsSearchState, entries []SettingEntry, q strin
|
|||||||
func settingsSearchHit(c *ui.Context, e SettingEntry, q string, current bool) bool {
|
func settingsSearchHit(c *ui.Context, e SettingEntry, q string, current bool) bool {
|
||||||
k := core.Tokens(c)
|
k := core.Tokens(c)
|
||||||
d := core.Density(c)
|
d := core.Density(c)
|
||||||
b := ui.ButtonBase(c).Key(e.ID).MinHeight(d.ControlHeight()).Padding(d.Unit(), d.Unit()*3).Justify(ui.Start).
|
b := ui.ButtonBase(c.Key(e.ID)).MinHeight(d.ControlHeight()).Padding(d.Unit(), d.Unit()*3).Justify(ui.Start).
|
||||||
Radius(theme.ControlRadius).Role(ui.RoleListItem).Label(e.Label).Description(e.Description).Selected(current).Gap(d.Unit() * 2)
|
Radius(theme.ControlRadius).Role(ui.RoleListItem).Label(e.Label).Description(e.Description).Selected(current).Gap(d.Unit() * 2)
|
||||||
internal.Ring(b, k.Focus, theme.ControlRadius)
|
internal.Ring(b, k.Focus, theme.ControlRadius)
|
||||||
switch {
|
switch {
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ func ShortcutRecorder(c *ui.Context, value *Shortcut, opts ShortcutRecorderOptio
|
|||||||
}
|
}
|
||||||
if st.recording {
|
if st.recording {
|
||||||
b.HandleInput(func(ev ui.InputEvent) bool {
|
b.HandleInput(func(ev ui.InputEvent) bool {
|
||||||
if b.IsDisabled() {
|
if disabled {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return shortcutRecorderKey(st, ev)
|
return shortcutRecorderKey(st, ev)
|
||||||
@@ -178,7 +178,7 @@ func shortcutRecorderKey(st *shortcutRecorderState, ev ui.InputEvent) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// shortcutRecorderLook displays the shortcut or recording prompt.
|
// shortcutRecorderLook displays the shortcut or recording prompt.
|
||||||
func shortcutRecorderLook(c *ui.Context, b *ui.Element, st *shortcutRecorderState, value Shortcut, name string) {
|
func shortcutRecorderLook(c *ui.Context, b ui.Element, st *shortcutRecorderState, value Shortcut, name string) {
|
||||||
k := core.Tokens(c)
|
k := core.Tokens(c)
|
||||||
internal.Ring(b, k.Focus, theme.ControlRadius)
|
internal.Ring(b, k.Focus, theme.ControlRadius)
|
||||||
label := name + ": " + value.String()
|
label := name + ": " + value.String()
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ type TwoFactorInputOptions struct {
|
|||||||
|
|
||||||
// TwoFactorResult reports completion and resend events.
|
// TwoFactorResult reports completion and resend events.
|
||||||
type TwoFactorResult struct {
|
type TwoFactorResult struct {
|
||||||
Element *ui.Element
|
Element ui.Element
|
||||||
completed, resend bool
|
completed, resend bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ func TestTwoFactorInputPasteCompleteAndResend(t *testing.T) {
|
|||||||
if resent != 1 {
|
if resent != 1 {
|
||||||
t.Fatal("resend not reported")
|
t.Fatal("resend not reported")
|
||||||
}
|
}
|
||||||
opts.ResendAt = time.Now().Add(65 * time.Second)
|
opts.ResendAt = tt.Now().Add(65 * time.Second)
|
||||||
opts.Error = "That code has expired."
|
opts.Error = "That code has expired."
|
||||||
tt.Frame()
|
tt.Frame()
|
||||||
if !tt.HasText("Resend in 1:05") && !tt.HasText("Resend in 1:04") || !tt.HasText("That code has expired.") {
|
if !tt.HasText("Resend in 1:05") && !tt.HasText("Resend in 1:04") || !tt.HasText("That code has expired.") {
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ type UsageQuotaOptions struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UsageQuota displays usage bars and reset time.
|
// UsageQuota displays usage bars and reset time.
|
||||||
func UsageQuota(c *ui.Context, items []QuotaItem, opts UsageQuotaOptions) *ui.Element {
|
func UsageQuota(c *ui.Context, items []QuotaItem, opts UsageQuotaOptions) ui.Element {
|
||||||
warn := opts.Warn
|
warn := opts.Warn
|
||||||
if warn == 0 {
|
if warn == 0 {
|
||||||
warn = 0.8
|
warn = 0.8
|
||||||
@@ -54,7 +54,7 @@ func UsageQuota(c *ui.Context, items []QuotaItem, opts UsageQuotaOptions) *ui.El
|
|||||||
col, icon, note = k.Warning, "triangle-alert", core.Msg(c, "usage_quota.near")
|
col, icon, note = k.Warning, "triangle-alert", core.Msg(c, "usage_quota.near")
|
||||||
}
|
}
|
||||||
amount := fmt.Sprintf(core.Msg(c, "usage_quota.amount"), data.StatisticFormat(it.Used, 0), data.StatisticFormat(it.Limit, 0), it.Unit)
|
amount := fmt.Sprintf(core.Msg(c, "usage_quota.amount"), data.StatisticFormat(it.Used, 0), data.StatisticFormat(it.Limit, 0), it.Unit)
|
||||||
ui.Column(c).Key(i).Gap(d.Unit()).Role(ui.RoleMeter).Label(it.Label).
|
ui.Column(c.Key(i)).Gap(d.Unit()).Role(ui.RoleMeter).Label(it.Label).
|
||||||
Description(fmt.Sprintf("%s, %s%% %s", amount, data.StatisticFormat(share*100, 0), note)).Children(func() {
|
Description(fmt.Sprintf("%s, %s%% %s", amount, data.StatisticFormat(share*100, 0), note)).Children(func() {
|
||||||
ui.Row(c).Gap(d.Unit() * 2).AlignItems(ui.Center).Children(func() {
|
ui.Row(c).Gap(d.Unit() * 2).AlignItems(ui.Center).Children(func() {
|
||||||
ui.Text(c, it.Label).FontWeight(500).Grow(1)
|
ui.Text(c, it.Label).FontWeight(500).Grow(1)
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ type UserMenuOptions struct {
|
|||||||
|
|
||||||
// UserMenuResult reports presence, settings and sign-out events.
|
// UserMenuResult reports presence, settings and sign-out events.
|
||||||
type UserMenuResult struct {
|
type UserMenuResult struct {
|
||||||
Element *ui.Element
|
Element ui.Element
|
||||||
changed, settings, leave bool
|
changed, settings, leave bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ func TestUserMenuSnapshot(t *testing.T) {
|
|||||||
ui.Row(c).Padding(20).Gap(16).Children(func() {
|
ui.Row(c).Padding(20).Gap(16).Children(func() {
|
||||||
for s := UserStatusOnline; s <= UserStatusInvisible; s++ {
|
for s := UserStatusOnline; s <= UserStatusInvisible; s++ {
|
||||||
st := s
|
st := s
|
||||||
ui.Box(c).Key(int(s)).Children(func() { UserMenu(c, &st, UserMenuOptions{Name: "Sakiko Togawa"}) })
|
ui.Box(c.Key(int(s))).Children(func() { UserMenu(c, &st, UserMenuOptions{Name: "Sakiko Togawa"}) })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ func WhatsNewDialog(c *ui.Context, open *bool, hide *bool, releases []Release, o
|
|||||||
r.Element = overlay.Dialog(c, open, overlay.DialogOptions{Title: title, Width: 480, Decorated: true, Actions: func() {
|
r.Element = overlay.Dialog(c, open, overlay.DialogOptions{Title: title, Width: 480, Decorated: true, Actions: func() {
|
||||||
input.Checkbox(c, hide, core.Msg(c, "whats_new_dialog.hide"), input.CheckboxOptions{})
|
input.Checkbox(c, hide, core.Msg(c, "whats_new_dialog.hide"), input.CheckboxOptions{})
|
||||||
ui.Box(c).Grow(1)
|
ui.Box(c).Grow(1)
|
||||||
if input.Button(c, core.Msg(c, "whats_new_dialog.close"), input.ButtonOptions{}).AutoFocus().Clicked() {
|
if core.AutoFocus(c, input.Button(c, core.Msg(c, "whats_new_dialog.close"), input.ButtonOptions{})).Clicked() {
|
||||||
*open = false
|
*open = false
|
||||||
}
|
}
|
||||||
}}, func() {
|
}}, func() {
|
||||||
@@ -78,7 +78,7 @@ func WhatsNewDialog(c *ui.Context, open *bool, hide *bool, releases []Release, o
|
|||||||
if rel.Version == "" {
|
if rel.Version == "" {
|
||||||
panic("mujica: Release needs a Version")
|
panic("mujica: Release needs a Version")
|
||||||
}
|
}
|
||||||
ui.Column(c).Key(i).Gap(d.Unit() * 2).Role(ui.RoleGroup).Label(rel.Version).Children(func() {
|
ui.Column(c.Key(i)).Gap(d.Unit() * 2).Role(ui.RoleGroup).Label(rel.Version).Children(func() {
|
||||||
ui.Row(c).Gap(d.Unit() * 2).AlignItems(ui.End).Children(func() {
|
ui.Row(c).Gap(d.Unit() * 2).AlignItems(ui.End).Children(func() {
|
||||||
ui.Text(c, rel.Version).Font(theme.SerifFont).FontSize(core.FontSize(c, theme.H3Size)).FontWeight(600)
|
ui.Text(c, rel.Version).Font(theme.SerifFont).FontSize(core.FontSize(c, theme.H3Size)).FontWeight(600)
|
||||||
if rel.Date != "" {
|
if rel.Date != "" {
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ func WorkspaceSwitcher(c *ui.Context, current *string, spaces []Workspace, opts
|
|||||||
overlay.Popover(c, b, &st.open, overlay.PopoverOptions{Width: 300, Label: core.Msg(c, "workspace_switcher.label")}, func() {
|
overlay.Popover(c, b, &st.open, overlay.PopoverOptions{Width: 300, Label: core.Msg(c, "workspace_switcher.label")}, func() {
|
||||||
res := input.SearchInput(c, &st.query, input.SearchInputOptions{Placeholder: core.Msg(c, "workspace_switcher.search"), Label: core.Msg(c, "workspace_switcher.search")})
|
res := input.SearchInput(c, &st.query, input.SearchInputOptions{Placeholder: core.Msg(c, "workspace_switcher.search"), Label: core.Msg(c, "workspace_switcher.search")})
|
||||||
in := res.Input
|
in := res.Input
|
||||||
in.AutoFocus()
|
core.AutoFocus(c, in)
|
||||||
q := strings.ToLower(strings.TrimSpace(st.query))
|
q := strings.ToLower(strings.TrimSpace(st.query))
|
||||||
if !st.ready || st.filtered != q || !slices.Equal(st.source, spaces) {
|
if !st.ready || st.filtered != q || !slices.Equal(st.source, spaces) {
|
||||||
st.source, st.filtered, st.ready = slices.Clone(spaces), q, true
|
st.source, st.filtered, st.ready = slices.Clone(spaces), q, true
|
||||||
@@ -115,10 +115,10 @@ func WorkspaceSwitcher(c *ui.Context, current *string, spaces []Workspace, opts
|
|||||||
}
|
}
|
||||||
|
|
||||||
// workspaceRow displays a clickable workspace with a selection mark.
|
// workspaceRow displays a clickable workspace with a selection mark.
|
||||||
func workspaceRow(c *ui.Context, w Workspace, current, cursor bool) *ui.Element {
|
func workspaceRow(c *ui.Context, w Workspace, current, cursor bool) ui.Element {
|
||||||
k := core.Tokens(c)
|
k := core.Tokens(c)
|
||||||
d := core.Density(c)
|
d := core.Density(c)
|
||||||
b := ui.ButtonBase(c).Key(w.ID).MinHeight(d.ControlHeight()).Padding(d.Unit(), d.Unit()*2).Gap(d.Unit() * 2).
|
b := ui.ButtonBase(c.Key(w.ID)).MinHeight(d.ControlHeight()).Padding(d.Unit(), d.Unit()*2).Gap(d.Unit() * 2).
|
||||||
Justify(ui.Start).Radius(theme.ControlRadius).Role(ui.RoleListItem).Label(w.Name).Selected(current)
|
Justify(ui.Start).Radius(theme.ControlRadius).Role(ui.RoleListItem).Label(w.Name).Selected(current)
|
||||||
internal.Ring(b, k.Focus, theme.ControlRadius)
|
internal.Ring(b, k.Focus, theme.ControlRadius)
|
||||||
switch {
|
switch {
|
||||||
|
|||||||
+2
-2
@@ -52,7 +52,7 @@ func (dc *agentDiffCache) update(ch FileChange) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// agentDiffOf returns the cached diff of ch kept on holder.
|
// agentDiffOf returns the cached diff of ch kept on holder.
|
||||||
func agentDiffOf(holder *ui.Element, ch FileChange) *agentDiffCache {
|
func agentDiffOf(holder ui.Element, ch FileChange) *agentDiffCache {
|
||||||
dc := ui.Local(holder, "mujica.agent.diff", func() *agentDiffCache { return &agentDiffCache{} })
|
dc := ui.Local(holder, "mujica.agent.diff", func() *agentDiffCache { return &agentDiffCache{} })
|
||||||
(*dc).update(ch)
|
(*dc).update(ch)
|
||||||
return *dc
|
return *dc
|
||||||
@@ -98,7 +98,7 @@ func agentDiffRow(c *ui.Context, l internal.DiffLine) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// agentDiffView shows lines[from:to] in a capped well, virtualized when long.
|
// agentDiffView shows lines[from:to] in a capped well, virtualized when long.
|
||||||
func agentDiffView(c *ui.Context, lines []internal.DiffLine, maxHeight float32) *ui.Element {
|
func agentDiffView(c *ui.Context, lines []internal.DiffLine, maxHeight float32) ui.Element {
|
||||||
w := AgentWellRows(c, len(lines), func(i int) { agentDiffRow(c, lines[i]) }, maxHeight)
|
w := AgentWellRows(c, len(lines), func(i int) { agentDiffRow(c, lines[i]) }, maxHeight)
|
||||||
return w.Padding(core.Density(c).Unit(), 0)
|
return w.Padding(core.Density(c).Unit(), 0)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ func agentTone(k theme.Tokens, s AgentState) (ui.Color, *ui.SVG) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// agentMark draws s; running spins unless still.
|
// agentMark draws s; running spins unless still.
|
||||||
func agentMark(c *ui.Context, s AgentState, size float32, still bool) *ui.Element {
|
func agentMark(c *ui.Context, s AgentState, size float32, still bool) ui.Element {
|
||||||
tone, icon := agentTone(core.Tokens(c), s)
|
tone, icon := agentTone(core.Tokens(c), s)
|
||||||
if s == AgentRunning && !still {
|
if s == AgentRunning && !still {
|
||||||
return core.Spinner(c, core.SpinnerOptions{Size: size, Color: tone, Label: core.Msg(c, "agent_status.running")})
|
return core.Spinner(c, core.SpinnerOptions{Size: size, Color: tone, Label: core.Msg(c, "agent_status.running")})
|
||||||
@@ -95,7 +95,7 @@ func AgentDuration(d time.Duration) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AgentCard is the bordered surface every agent card sits on.
|
// AgentCard is the bordered surface every agent card sits on.
|
||||||
func AgentCard(c *ui.Context) *ui.Element {
|
func AgentCard(c *ui.Context) ui.Element {
|
||||||
k := core.Tokens(c)
|
k := core.Tokens(c)
|
||||||
u := core.Density(c).Unit()
|
u := core.Density(c).Unit()
|
||||||
return ui.Column(c).Shrink(0).Padding(u*3).Gap(u*2).Radius(theme.CardRadius).
|
return ui.Column(c).Shrink(0).Padding(u*3).Gap(u*2).Radius(theme.CardRadius).
|
||||||
@@ -103,12 +103,12 @@ func AgentCard(c *ui.Context) *ui.Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AgentCaption is small muted text.
|
// AgentCaption is small muted text.
|
||||||
func AgentCaption(c *ui.Context, s string) *ui.Element {
|
func AgentCaption(c *ui.Context, s string) ui.Element {
|
||||||
return ui.Text(c, s).FontSize(core.FontSize(c, theme.CaptionSize)).TextColor(core.Tokens(c).TextMuted)
|
return ui.Text(c, s).FontSize(core.FontSize(c, theme.CaptionSize)).TextColor(core.Tokens(c).TextMuted)
|
||||||
}
|
}
|
||||||
|
|
||||||
// agentWell styles a sunken monospace well.
|
// agentWell styles a sunken monospace well.
|
||||||
func agentWell(c *ui.Context, l *ui.Element, maxHeight float32) *ui.Element {
|
func agentWell(c *ui.Context, l ui.Element, maxHeight float32) ui.Element {
|
||||||
k := core.Tokens(c)
|
k := core.Tokens(c)
|
||||||
u := core.Density(c).Unit()
|
u := core.Density(c).Unit()
|
||||||
return l.Shrink(1).MaxHeight(maxHeight).Padding(u*2, u*3).Radius(theme.ControlRadius).
|
return l.Shrink(1).MaxHeight(maxHeight).Padding(u*2, u*3).Radius(theme.ControlRadius).
|
||||||
@@ -117,12 +117,12 @@ func agentWell(c *ui.Context, l *ui.Element, maxHeight float32) *ui.Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AgentWellRows builds n rows in a well.
|
// AgentWellRows builds n rows in a well.
|
||||||
func AgentWellRows(c *ui.Context, n int, row func(i int), maxHeight float32) *ui.Element {
|
func AgentWellRows(c *ui.Context, n int, row func(i int), maxHeight float32) ui.Element {
|
||||||
return agentWell(c, AgentRows(c, n, row), maxHeight)
|
return agentWell(c, AgentRows(c, n, row), maxHeight)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AgentRows builds n scrolling rows, virtualized when many.
|
// AgentRows builds n scrolling rows, virtualized when many.
|
||||||
func AgentRows(c *ui.Context, n int, row func(i int)) *ui.Element {
|
func AgentRows(c *ui.Context, n int, row func(i int)) ui.Element {
|
||||||
if n > agentVirtualRows {
|
if n > agentVirtualRows {
|
||||||
return ui.List(c, nil, n, row)
|
return ui.List(c, nil, n, row)
|
||||||
}
|
}
|
||||||
@@ -196,7 +196,7 @@ func agentCodeLine(c *ui.Context, language, line string, inBlock bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AgentCode shows highlighted text in a capped well.
|
// AgentCode shows highlighted text in a capped well.
|
||||||
func AgentCode(c *ui.Context, language, text string, maxHeight float32) *ui.Element {
|
func AgentCode(c *ui.Context, language, text string, maxHeight float32) ui.Element {
|
||||||
holder := ui.Column(c).Shrink(1)
|
holder := ui.Column(c).Shrink(1)
|
||||||
cc := ui.Local(holder, "mujica.agent.code", func() *agentCodeCache { return &agentCodeCache{} })
|
cc := ui.Local(holder, "mujica.agent.code", func() *agentCodeCache { return &agentCodeCache{} })
|
||||||
(*cc).update(language, text)
|
(*cc).update(language, text)
|
||||||
@@ -260,7 +260,7 @@ func agentAnsiSpans(k theme.Tokens, in []internal.AnsiSpan) []ui.Span {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// agentBar is a thin progress bar named label.
|
// agentBar is a thin progress bar named label.
|
||||||
func agentBar(c *ui.Context, frac float64, label string) *ui.Element {
|
func agentBar(c *ui.Context, frac float64, label string) ui.Element {
|
||||||
if frac < 0 || frac > 1 || frac != frac {
|
if frac < 0 || frac > 1 || frac != frac {
|
||||||
panic(fmt.Sprintf("mujica: progress %v outside 0..1", frac))
|
panic(fmt.Sprintf("mujica: progress %v outside 0..1", frac))
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -72,7 +72,7 @@ func AgentPlan(c *ui.Context, items *[]PlanItem, opts AgentPlanOptions) core.Cho
|
|||||||
agentBar(c, frac, fmt.Sprintf(core.Msg(c, "agent_plan.progress"), done, counted))
|
agentBar(c, frac, fmt.Sprintf(core.Msg(c, "agent_plan.progress"), done, counted))
|
||||||
list := *items
|
list := *items
|
||||||
for i := range list {
|
for i := range list {
|
||||||
ui.Row(c).Key(list[i].ID).Gap(u * 2).AlignItems(ui.Center).MinHeight(core.Density(c).ControlHeight()).Children(func() {
|
ui.Row(c.Key(list[i].ID)).Gap(u * 2).AlignItems(ui.Center).MinHeight(core.Density(c).ControlHeight()).Children(func() {
|
||||||
if agentPlanRow(c, &list[i], locked, opts.Still) {
|
if agentPlanRow(c, &list[i], locked, opts.Still) {
|
||||||
r = core.NewChoiceResult(r.Element, true)
|
r = core.NewChoiceResult(r.Element, true)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ type AgentProgressOptions struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AgentProgress shows progress 0 to 1 and the current action.
|
// AgentProgress shows progress 0 to 1 and the current action.
|
||||||
func AgentProgress(c *ui.Context, value float64, opts AgentProgressOptions) *ui.Element {
|
func AgentProgress(c *ui.Context, value float64, opts AgentProgressOptions) ui.Element {
|
||||||
label := opts.Label
|
label := opts.Label
|
||||||
if label == "" {
|
if label == "" {
|
||||||
label = core.Msg(c, "agent_progress.label")
|
label = core.Msg(c, "agent_progress.label")
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ type AgentStatusOptions struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AgentStatus shows a state by icon shape and word.
|
// AgentStatus shows a state by icon shape and word.
|
||||||
func AgentStatus(c *ui.Context, state AgentState, opts AgentStatusOptions) *ui.Element {
|
func AgentStatus(c *ui.Context, state AgentState, opts AgentStatusOptions) ui.Element {
|
||||||
label := opts.Label
|
label := opts.Label
|
||||||
if label == "" {
|
if label == "" {
|
||||||
label = agentWord(c, state) // panics on an unknown state
|
label = agentWord(c, state) // panics on an unknown state
|
||||||
|
|||||||
@@ -33,16 +33,14 @@ func TestAgentStatusAnimationStopsWhenStill(t *testing.T) {
|
|||||||
}, 300, 100)
|
}, 300, 100)
|
||||||
tt.Frame()
|
tt.Frame()
|
||||||
moving := string(tt.Image().Pix)
|
moving := string(tt.Image().Pix)
|
||||||
time.Sleep(80 * time.Millisecond)
|
tt.Advance(80 * time.Millisecond)
|
||||||
tt.Frame()
|
|
||||||
if moving == string(tt.Image().Pix) {
|
if moving == string(tt.Image().Pix) {
|
||||||
t.Fatal("running status did not animate")
|
t.Fatal("running status did not animate")
|
||||||
}
|
}
|
||||||
still = true
|
still = true
|
||||||
tt.Frame()
|
tt.Frame()
|
||||||
a := string(tt.Image().Pix)
|
a := string(tt.Image().Pix)
|
||||||
time.Sleep(80 * time.Millisecond)
|
tt.Advance(80 * time.Millisecond)
|
||||||
tt.Frame()
|
|
||||||
if a != string(tt.Image().Pix) {
|
if a != string(tt.Image().Pix) {
|
||||||
t.Fatal("still status kept moving")
|
t.Fatal("still status kept moving")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ type AgentStepListOptions struct {
|
|||||||
|
|
||||||
// AgentStepListResult reports this frame's events.
|
// AgentStepListResult reports this frame's events.
|
||||||
type AgentStepListResult struct {
|
type AgentStepListResult struct {
|
||||||
Element *ui.Element
|
Element ui.Element
|
||||||
// Retry is the failed step to retry, else "".
|
// Retry is the failed step to retry, else "".
|
||||||
Retry string
|
Retry string
|
||||||
// Toggled is the step whose detail toggled, else "".
|
// Toggled is the step whose detail toggled, else "".
|
||||||
@@ -55,7 +55,7 @@ func AgentStepList(c *ui.Context, steps []AgentStep, opts AgentStepListOptions)
|
|||||||
open := ui.Local(r.Element, "mujica.steps.open", func() map[string]bool { return map[string]bool{} })
|
open := ui.Local(r.Element, "mujica.steps.open", func() map[string]bool { return map[string]bool{} })
|
||||||
r.Element.Children(func() {
|
r.Element.Children(func() {
|
||||||
for i, s := range steps {
|
for i, s := range steps {
|
||||||
ui.Column(c).Key(s.ID).Children(func() {
|
ui.Column(c.Key(s.ID)).Children(func() {
|
||||||
if agentStepRow(c, s, i, len(steps), i == current, (*open)[s.ID], opts.Still, &r) {
|
if agentStepRow(c, s, i, len(steps), i == current, (*open)[s.ID], opts.Still, &r) {
|
||||||
(*open)[s.ID] = !(*open)[s.ID]
|
(*open)[s.ID] = !(*open)[s.ID]
|
||||||
r.Toggled = s.ID
|
r.Toggled = s.ID
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ type ArtifactPanelOptions struct {
|
|||||||
|
|
||||||
// ArtifactPanelResult reports this frame's events.
|
// ArtifactPanelResult reports this frame's events.
|
||||||
type ArtifactPanelResult struct {
|
type ArtifactPanelResult struct {
|
||||||
Element *ui.Element
|
Element ui.Element
|
||||||
// Copied reports the content went to the clipboard.
|
// Copied reports the content went to the clipboard.
|
||||||
Copied bool
|
Copied bool
|
||||||
// Exported asks the caller to export the artifact.
|
// Exported asks the caller to export the artifact.
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ type ArtifactVersionSwitcherOptions struct {
|
|||||||
|
|
||||||
// ArtifactVersionResult reports this frame's events.
|
// ArtifactVersionResult reports this frame's events.
|
||||||
type ArtifactVersionResult struct {
|
type ArtifactVersionResult struct {
|
||||||
Element *ui.Element
|
Element ui.Element
|
||||||
// Changed reports *current moved.
|
// Changed reports *current moved.
|
||||||
Changed bool
|
Changed bool
|
||||||
// Compare asks to diff current against the previous version.
|
// Compare asks to diff current against the previous version.
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ func checkpointRow(c *ui.Context, p Checkpoint, current, locked bool) bool {
|
|||||||
d := core.Density(c)
|
d := core.Density(c)
|
||||||
u := d.Unit()
|
u := d.Unit()
|
||||||
asked := false
|
asked := false
|
||||||
row := ui.Row(c).Key(p.ID).Gap(u*3).AlignItems(ui.Center).MinHeight(d.ControlHeight()+u*2).Padding(u*2, u*3)
|
row := ui.Row(c.Key(p.ID)).Gap(u*3).AlignItems(ui.Center).MinHeight(d.ControlHeight()+u*2).Padding(u*2, u*3)
|
||||||
if current {
|
if current {
|
||||||
row.Background(k.Selection)
|
row.Background(k.Selection)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ type FileChangeCardOptions struct {
|
|||||||
|
|
||||||
// FileChangeResult reports this frame's events.
|
// FileChangeResult reports this frame's events.
|
||||||
type FileChangeResult struct {
|
type FileChangeResult struct {
|
||||||
Element *ui.Element
|
Element ui.Element
|
||||||
// Decided reports that *decision changed.
|
// Decided reports that *decision changed.
|
||||||
Decided bool
|
Decided bool
|
||||||
// OpenDiff asks the caller to show the full diff.
|
// OpenDiff asks the caller to show the full diff.
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ type HumanInputRequestOptions struct {
|
|||||||
|
|
||||||
// HumanInputResult reports this frame's events.
|
// HumanInputResult reports this frame's events.
|
||||||
type HumanInputResult struct {
|
type HumanInputResult struct {
|
||||||
Element *ui.Element
|
Element ui.Element
|
||||||
Submitted bool
|
Submitted bool
|
||||||
// TimedOut reports the frame the deadline passed.
|
// TimedOut reports the frame the deadline passed.
|
||||||
TimedOut bool
|
TimedOut bool
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ type MCPServerListOptions struct {
|
|||||||
|
|
||||||
// MCPServerListResult reports this frame's request.
|
// MCPServerListResult reports this frame's request.
|
||||||
type MCPServerListResult struct {
|
type MCPServerListResult struct {
|
||||||
Element *ui.Element
|
Element ui.Element
|
||||||
Action MCPAction
|
Action MCPAction
|
||||||
// Server is the ID the action is for.
|
// Server is the ID the action is for.
|
||||||
Server string
|
Server string
|
||||||
@@ -105,7 +105,7 @@ func mcpServerRow(c *ui.Context, s MCPServer, locked, still bool) MCPAction {
|
|||||||
words := [...]string{"stopped", "connecting", "connected", "error"}
|
words := [...]string{"stopped", "connecting", "connected", "error"}
|
||||||
word := core.Msg(c, "mcp_server_list."+words[s.State])
|
word := core.Msg(c, "mcp_server_list."+words[s.State])
|
||||||
act := MCPNone
|
act := MCPNone
|
||||||
ui.Row(c).Key(s.ID).Gap(u*3).AlignItems(ui.Center).MinHeight(d.ControlHeight()+u*2).Padding(u*2, u*3).
|
ui.Row(c.Key(s.ID)).Gap(u*3).AlignItems(ui.Center).MinHeight(d.ControlHeight()+u*2).Padding(u*2, u*3).
|
||||||
Label(s.Name + ", " + word).Children(func() {
|
Label(s.Name + ", " + word).Children(func() {
|
||||||
switch s.State {
|
switch s.State {
|
||||||
case MCPConnecting:
|
case MCPConnecting:
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ type MemoryPanelOptions struct {
|
|||||||
|
|
||||||
// MemoryPanelResult reports this frame's in-place edits.
|
// MemoryPanelResult reports this frame's in-place edits.
|
||||||
type MemoryPanelResult struct {
|
type MemoryPanelResult struct {
|
||||||
Element *ui.Element
|
Element ui.Element
|
||||||
// Edited and Deleted are changed IDs, else "".
|
// Edited and Deleted are changed IDs, else "".
|
||||||
Edited string
|
Edited string
|
||||||
Deleted string
|
Deleted string
|
||||||
@@ -74,7 +74,7 @@ func MemoryPanel(c *ui.Context, entries *[]MemoryEntry, opts MemoryPanelOptions)
|
|||||||
}
|
}
|
||||||
AgentRows(c, len(st.shown), func(i int) {
|
AgentRows(c, len(st.shown), func(i int) {
|
||||||
idx := st.shown[i]
|
idx := st.shown[i]
|
||||||
ui.Column(c).Key((*entries)[idx].ID).Children(func() { memoryRow(c, entries, idx, st, locked, &r) })
|
ui.Column(c.Key((*entries)[idx].ID)).Children(func() { memoryRow(c, entries, idx, st, locked, &r) })
|
||||||
}).Shrink(1).MaxHeight(maxH).Dividers(theme.BorderWidth, core.Tokens(c).Border)
|
}).Shrink(1).MaxHeight(maxH).Dividers(theme.BorderWidth, core.Tokens(c).Border)
|
||||||
})
|
})
|
||||||
if r.Deleted != "" {
|
if r.Deleted != "" {
|
||||||
@@ -123,7 +123,7 @@ func memoryRow(c *ui.Context, entries *[]MemoryEntry, idx int, st *memoryPanelSt
|
|||||||
u := core.Density(c).Unit()
|
u := core.Density(c).Unit()
|
||||||
ui.Column(c).Gap(u).Padding(u*2, 0).Children(func() {
|
ui.Column(c).Gap(u).Padding(u*2, 0).Children(func() {
|
||||||
if st.editing == e.ID && !locked {
|
if st.editing == e.ID && !locked {
|
||||||
input.TextArea(c, &st.draft, input.TextAreaOptions{Label: core.Msg(c, "memory_panel.edit"), MinHeight: 60}).Input.AutoFocus()
|
core.AutoFocus(c, input.TextArea(c, &st.draft, input.TextAreaOptions{Label: core.Msg(c, "memory_panel.edit"), MinHeight: 60}).Input)
|
||||||
ui.Row(c).Gap(u * 2).Justify(ui.End).Children(func() {
|
ui.Row(c).Gap(u * 2).Justify(ui.End).Children(func() {
|
||||||
if input.Button(c, core.Msg(c, "memory_panel.cancel"), input.ButtonOptions{Variant: input.Secondary}).Clicked() {
|
if input.Button(c, core.Msg(c, "memory_panel.cancel"), input.ButtonOptions{Variant: input.Secondary}).Clicked() {
|
||||||
st.editing = ""
|
st.editing = ""
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ func MultiFileDiffReview(c *ui.Context, decisions *[]FileDecision, files []FileC
|
|||||||
slog.Debug("mujica: multi_file_diff_review select", "path", files[i].Path)
|
slog.Debug("mujica: multi_file_diff_review select", "path", files[i].Path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var list *ui.Element
|
var list ui.Element
|
||||||
if len(files) > agentVirtualRows {
|
if len(files) > agentVirtualRows {
|
||||||
list = ui.List(c, nil, len(files), row)
|
list = ui.List(c, nil, len(files), row)
|
||||||
} else {
|
} else {
|
||||||
@@ -109,7 +109,7 @@ func MultiFileDiffReview(c *ui.Context, decisions *[]FileDecision, files []FileC
|
|||||||
func multiFileRow(c *ui.Context, f FileChange, d FileDecision, selected bool) bool {
|
func multiFileRow(c *ui.Context, f FileChange, d FileDecision, selected bool) bool {
|
||||||
k := core.Tokens(c)
|
k := core.Tokens(c)
|
||||||
u := core.Density(c).Unit()
|
u := core.Density(c).Unit()
|
||||||
row := ui.ButtonBase(c).Key(f.Path).Justify(ui.Start).Gap(u*2).MinHeight(core.Density(c).ControlHeight()).
|
row := ui.ButtonBase(c.Key(f.Path)).Justify(ui.Start).Gap(u*2).MinHeight(core.Density(c).ControlHeight()).
|
||||||
Padding(0, u*2).Radius(theme.ControlRadius).Label(f.Path)
|
Padding(0, u*2).Radius(theme.ControlRadius).Label(f.Path)
|
||||||
internal.Ring(row, k.Focus, theme.ControlRadius)
|
internal.Ring(row, k.Focus, theme.ControlRadius)
|
||||||
dc := agentDiffOf(row, f)
|
dc := agentDiffOf(row, f)
|
||||||
@@ -133,7 +133,7 @@ func multiFileRow(c *ui.Context, f FileChange, d FileDecision, selected bool) bo
|
|||||||
func fileChangeDecide(c *ui.Context, d *FileDecision, f FileChange, locked bool) bool {
|
func fileChangeDecide(c *ui.Context, d *FileDecision, f FileChange, locked bool) bool {
|
||||||
u := core.Density(c).Unit()
|
u := core.Density(c).Unit()
|
||||||
changed := false
|
changed := false
|
||||||
holder := ui.Column(c).Key(f.Path).Grow(1).Shrink(1).Gap(u * 2)
|
holder := ui.Column(c.Key(f.Path)).Grow(1).Shrink(1).Gap(u * 2)
|
||||||
dc := agentDiffOf(holder, f)
|
dc := agentDiffOf(holder, f)
|
||||||
holder.Children(func() {
|
holder.Children(func() {
|
||||||
ui.Row(c).Gap(u * 2).AlignItems(ui.Center).Children(func() {
|
ui.Row(c).Gap(u * 2).AlignItems(ui.Center).Children(func() {
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ type PermissionPromptOptions struct {
|
|||||||
|
|
||||||
// PermissionResult reports the choice made in this frame.
|
// PermissionResult reports the choice made in this frame.
|
||||||
type PermissionResult struct {
|
type PermissionResult struct {
|
||||||
Element *ui.Element
|
Element ui.Element
|
||||||
Choice PermissionChoice
|
Choice PermissionChoice
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ func PermissionPrompt(c *ui.Context, open *bool, opts PermissionPromptOptions) P
|
|||||||
r.Element = overlay.Dialog(c, open, overlay.DialogOptions{
|
r.Element = overlay.Dialog(c, open, overlay.DialogOptions{
|
||||||
Title: opts.Title, Description: opts.Description, KeepOnBackdrop: true, HideClose: true,
|
Title: opts.Title, Description: opts.Description, KeepOnBackdrop: true, HideClose: true,
|
||||||
Actions: func() {
|
Actions: func() {
|
||||||
if input.Button(c, core.Msg(c, "permission_prompt.deny"), input.ButtonOptions{Variant: input.Secondary}).AutoFocus().Clicked() {
|
if core.AutoFocus(c, input.Button(c, core.Msg(c, "permission_prompt.deny"), input.ButtonOptions{Variant: input.Secondary})).Clicked() {
|
||||||
r.Choice = PermissionDeny
|
r.Choice = PermissionDeny
|
||||||
}
|
}
|
||||||
if input.Button(c, core.Msg(c, "permission_prompt.always"), input.ButtonOptions{Variant: input.Outline}).Clicked() {
|
if input.Button(c, core.Msg(c, "permission_prompt.always"), input.ButtonOptions{Variant: input.Outline}).Clicked() {
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ type SandboxStatusOptions struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SandboxStatus shows sandbox state, resources and time left.
|
// SandboxStatus shows sandbox state, resources and time left.
|
||||||
func SandboxStatus(c *ui.Context, info SandboxInfo, opts SandboxStatusOptions) *ui.Element {
|
func SandboxStatus(c *ui.Context, info SandboxInfo, opts SandboxStatusOptions) ui.Element {
|
||||||
agent := map[SandboxState]AgentState{SandboxStarting: AgentPlanning, SandboxRunning: AgentRunning, SandboxStopped: AgentSkipped, SandboxFailed: AgentFailed}
|
agent := map[SandboxState]AgentState{SandboxStarting: AgentPlanning, SandboxRunning: AgentRunning, SandboxStopped: AgentSkipped, SandboxFailed: AgentFailed}
|
||||||
state, ok := agent[info.State]
|
state, ok := agent[info.State]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ func subAgentRow(c *ui.Context, a SubAgent, depth int, open, still bool) bool {
|
|||||||
d := core.Density(c)
|
d := core.Density(c)
|
||||||
u := d.Unit()
|
u := d.Unit()
|
||||||
parent := len(a.Children) > 0
|
parent := len(a.Children) > 0
|
||||||
row := ui.ButtonBase(c).Key(a.ID).Justify(ui.Start).Gap(u*2).MinHeight(d.ControlHeight()).
|
row := ui.ButtonBase(c.Key(a.ID)).Justify(ui.Start).Gap(u*2).MinHeight(d.ControlHeight()).
|
||||||
Padding(0, u*2, 0, u*2+float32(depth)*u*5).Radius(theme.ControlRadius).
|
Padding(0, u*2, 0, u*2+float32(depth)*u*5).Radius(theme.ControlRadius).
|
||||||
Label(a.Name + ", " + agentWord(c, a.State))
|
Label(a.Name + ", " + agentWord(c, a.State))
|
||||||
internal.Ring(row, k.Focus, theme.ControlRadius)
|
internal.Ring(row, k.Focus, theme.ControlRadius)
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ type ToolApprovalOptions struct {
|
|||||||
|
|
||||||
// ToolApprovalResult reports the choice made in this frame.
|
// ToolApprovalResult reports the choice made in this frame.
|
||||||
type ToolApprovalResult struct {
|
type ToolApprovalResult struct {
|
||||||
Element *ui.Element
|
Element ui.Element
|
||||||
Allowed bool
|
Allowed bool
|
||||||
Denied bool
|
Denied bool
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ func ToolApprovalDialog(c *ui.Context, open *bool, opts ToolApprovalOptions) Too
|
|||||||
Title: core.Msg(c, "tool_approval_dialog.title"), Description: opts.Reason, KeepOnBackdrop: true, HideClose: true,
|
Title: core.Msg(c, "tool_approval_dialog.title"), Description: opts.Reason, KeepOnBackdrop: true, HideClose: true,
|
||||||
Actions: func() {
|
Actions: func() {
|
||||||
// Deny first: a reflexive Enter never runs the tool.
|
// Deny first: a reflexive Enter never runs the tool.
|
||||||
if input.Button(c, core.Msg(c, "tool_approval_dialog.deny"), input.ButtonOptions{Variant: input.Secondary}).AutoFocus().Clicked() {
|
if core.AutoFocus(c, input.Button(c, core.Msg(c, "tool_approval_dialog.deny"), input.ButtonOptions{Variant: input.Secondary})).Clicked() {
|
||||||
r.Denied = true
|
r.Denied = true
|
||||||
}
|
}
|
||||||
if input.Button(c, core.Msg(c, "tool_approval_dialog.allow"), input.ButtonOptions{}).Clicked() {
|
if input.Button(c, core.Msg(c, "tool_approval_dialog.allow"), input.ButtonOptions{}).Clicked() {
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ func ToolCallGroup(c *ui.Context, open *bool, calls []ToolCall, opts ToolCallGro
|
|||||||
})
|
})
|
||||||
}}, func() {
|
}}, func() {
|
||||||
for _, call := range calls {
|
for _, call := range calls {
|
||||||
ui.Column(c).Key(call.ID).Children(func() { ToolCallCard(c, call, ToolCallCardOptions{Still: opts.Still}) })
|
ui.Column(c.Key(call.ID)).Children(func() { ToolCallCard(c, call, ToolCallCardOptions{Still: opts.Still}) })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ func TestAreaChartStackedReadout(t *testing.T) {
|
|||||||
if got := chartReadout(tt); got != "0 · Pews 3 · Candles 5" {
|
if got := chartReadout(tt); got != "0 · Pews 3 · Candles 5" {
|
||||||
t.Fatalf("readout shows the series values, not the stack: %q", got)
|
t.Fatalf("readout shows the series values, not the stack: %q", got)
|
||||||
}
|
}
|
||||||
b := h.res.Element.Bounds()
|
b := h.box(tt)
|
||||||
tt.Move(b.X+52+(b.W-64)*0.5, b.Y+b.H/2)
|
tt.Move(b.X+52+(b.W-64)*0.5, b.Y+b.H/2)
|
||||||
if got := chartReadout(tt); got != "2 · Pews no value · Candles 6" || h.res.Point != 2 {
|
if got := chartReadout(tt); got != "2 · Pews no value · Candles 6" || h.res.Point != 2 {
|
||||||
t.Fatalf("hover %q", got)
|
t.Fatalf("hover %q", got)
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ func TestBarChartHoverStackedHorizontal(t *testing.T) {
|
|||||||
tt := ui.NewTester(h.view, 520, 420)
|
tt := ui.NewTester(h.view, 520, 420)
|
||||||
tabTo(t, tt, "Tithes")
|
tabTo(t, tt, "Tithes")
|
||||||
found := map[string]bool{}
|
found := map[string]bool{}
|
||||||
b := h.res.Element.Bounds()
|
b := h.box(tt)
|
||||||
for y := b.Y + 30; y < b.Y+b.H-40; y += 4 {
|
for y := b.Y + 30; y < b.Y+b.H-40; y += 4 {
|
||||||
for x := b.X + 60; x < b.X+b.W-16; x += 8 {
|
for x := b.X + 60; x < b.X+b.W-16; x += 8 {
|
||||||
tt.Move(x, y)
|
tt.Move(x, y)
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ func TestBoxPlotReadout(t *testing.T) {
|
|||||||
if got := chartReadout(tt); got != "Choir · median 5.5 · quartiles 3.25–7.75 · whiskers 1–9 · 1 outliers" {
|
if got := chartReadout(tt); got != "Choir · median 5.5 · quartiles 3.25–7.75 · whiskers 1–9 · 1 outliers" {
|
||||||
t.Fatalf("readout %q", got)
|
t.Fatalf("readout %q", got)
|
||||||
}
|
}
|
||||||
b := h.res.Element.Bounds()
|
b := h.box(tt)
|
||||||
tt.Key(0, ui.KeyEscape)
|
tt.Key(0, ui.KeyEscape)
|
||||||
tt.Move(b.X+52+(b.W-64)*0.75, b.Y+100)
|
tt.Move(b.X+52+(b.W-64)*0.75, b.Y+100)
|
||||||
if got := chartReadout(tt); got != "Nave · median 5 · quartiles 5–6 · whiskers 4–7 · 0 outliers" {
|
if got := chartReadout(tt); got != "Nave · median 5 · quartiles 5–6 · whiskers 4–7 · 0 outliers" {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ func TestBulletChartReadout(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
tt.Key(0, ui.KeyEscape)
|
tt.Key(0, ui.KeyEscape)
|
||||||
b := h.res.Element.Bounds()
|
b := h.box(tt)
|
||||||
plotW := b.W - 24
|
plotW := b.W - 24
|
||||||
tt.Move(b.X+8+plotW*0.1, b.Y+6+21) // band 1, inside the value bar
|
tt.Move(b.X+8+plotW*0.1, b.Y+6+21) // band 1, inside the value bar
|
||||||
if got := chartReadout(tt); got != "Actual 270" {
|
if got := chartReadout(tt); got != "Actual 270" {
|
||||||
@@ -40,7 +40,7 @@ func TestBulletChartVerticalAndBad(t *testing.T) {
|
|||||||
return BulletChart(c, 40, BulletChartOptions{Frame: ChartFrame{Label: "Alms", Height: 200}, Vertical: true, Max: 100})
|
return BulletChart(c, 40, BulletChartOptions{Frame: ChartFrame{Label: "Alms", Height: 200}, Vertical: true, Max: 100})
|
||||||
}}
|
}}
|
||||||
tt := ui.NewTester(h.view, 520, 420)
|
tt := ui.NewTester(h.view, 520, 420)
|
||||||
b := h.res.Element.Bounds()
|
b := h.box(tt)
|
||||||
tt.Move(b.X+b.W/2, b.Y+8+184*0.8) // low on the scale: inside the bar
|
tt.Move(b.X+b.W/2, b.Y+8+184*0.8) // low on the scale: inside the bar
|
||||||
if got := chartReadout(tt); got != "Actual 40" {
|
if got := chartReadout(tt); got != "Actual 40" {
|
||||||
t.Fatalf("vertical hover %q", got)
|
t.Fatalf("vertical hover %q", got)
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ func TestCalendarHeatmapWeekStartHover(t *testing.T) {
|
|||||||
return CalendarHeatmap(c, &year, calendarValues(), CalendarHeatmapOptions{Frame: ChartFrame{Label: "Prayers"}, WeekStart: tc.start})
|
return CalendarHeatmap(c, &year, calendarValues(), CalendarHeatmapOptions{Frame: ChartFrame{Label: "Prayers"}, WeekStart: tc.start})
|
||||||
}}
|
}}
|
||||||
tt := ui.NewTester(h.view, 560, 420)
|
tt := ui.NewTester(h.view, 560, 420)
|
||||||
b := h.res.Element.Bounds()
|
b := h.box(tt)
|
||||||
plotY := b.Y + b.H - 20 - 8 - 240 // above the readout line and gap
|
plotY := b.Y + b.H - 20 - 8 - 240 // above the readout line and gap
|
||||||
step := min((b.W-36)/53, float32(240-48)/7)
|
step := min((b.W-36)/53, float32(240-48)/7)
|
||||||
tt.Move(b.X+32+step/2, plotY+18+float32(tc.row)*step+step/2)
|
tt.Move(b.X+32+step/2, plotY+18+float32(tc.row)*step+step/2)
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ type CandleCountdownOptions struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CandleCountdown displays closing time and schedules visible updates.
|
// CandleCountdown displays closing time and schedules visible updates.
|
||||||
func CandleCountdown(c *ui.Context, interval Interval, opts CandleCountdownOptions) *ui.Element {
|
func CandleCountdown(c *ui.Context, interval Interval, opts CandleCountdownOptions) ui.Element {
|
||||||
loc := opts.Location
|
loc := opts.Location
|
||||||
if loc == nil {
|
if loc == nil {
|
||||||
loc = time.UTC
|
loc = time.UTC
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ func CandlestickChart(c *ui.Context, candles []Candle, view *MarketView, opts Ca
|
|||||||
m.yDomain()
|
m.yDomain()
|
||||||
m.alertsCheck()
|
m.alertsCheck()
|
||||||
res, plot := ch.Build(m.spec())
|
res, plot := ch.Build(m.spec())
|
||||||
if plot != nil {
|
if plot.Valid() {
|
||||||
m.input(plot)
|
m.input(plot)
|
||||||
}
|
}
|
||||||
if s := opts.Sync; s != nil {
|
if s := opts.Sync; s != nil {
|
||||||
|
|||||||
@@ -33,13 +33,12 @@ func mktState0(r ChartResult) *mktState {
|
|||||||
func TestCandlestickChartDrawsOnlyVisible(t *testing.T) {
|
func TestCandlestickChartDrawsOnlyVisible(t *testing.T) {
|
||||||
candles := sampleCandles(100000)
|
candles := sampleCandles(100000)
|
||||||
var view MarketView
|
var view MarketView
|
||||||
var res ChartResult
|
var st *mktState
|
||||||
tt := ui.NewTester(func(c *ui.Context) {
|
tt := ui.NewTester(func(c *ui.Context) {
|
||||||
core.Use(c, core.Settings{})
|
core.Use(c, core.Settings{})
|
||||||
res = CandlestickChart(c, candles, &view, CandlestickOptions{Frame: ChartFrame{Label: "BTC"}})
|
st = mktState0(CandlestickChart(c, candles, &view, CandlestickOptions{Frame: ChartFrame{Label: "BTC"}}))
|
||||||
}, 900, 400)
|
}, 900, 400)
|
||||||
tt.Frame()
|
tt.Frame()
|
||||||
st := mktState0(res)
|
|
||||||
if st.drawn != 120 {
|
if st.drawn != 120 {
|
||||||
t.Fatalf("drew %d candles of 100000", st.drawn)
|
t.Fatalf("drew %d candles of 100000", st.drawn)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ type noteDrag struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Drag handles movement; plot uses element coordinates.
|
// Drag handles movement; plot uses element coordinates.
|
||||||
func (a ChartAnnotationPart) Drag(plotElement *ui.Element, plot ui.Rect) bool {
|
func (a ChartAnnotationPart) Drag(plotElement ui.Element, plot ui.Rect) bool {
|
||||||
if plotElement.IsDisabled() {
|
if plotElement.IsDisabled() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -185,7 +185,7 @@ func (a ChartAnnotationPart) Drag(plotElement *ui.Element, plot ui.Rect) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a ChartAnnotationPart) keyboard(e *ui.Element) bool {
|
func (a ChartAnnotationPart) keyboard(e ui.Element) bool {
|
||||||
index := ui.Local(e, "mujica.notes.key", func() int { return 0 })
|
index := ui.Local(e, "mujica.notes.key", func() int { return 0 })
|
||||||
dir := 0
|
dir := 0
|
||||||
if e.Shortcut(ui.Alt, ui.KeyPageDown) {
|
if e.Shortcut(ui.Alt, ui.KeyPageDown) {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ func TestChartAnnotationDrag(t *testing.T) {
|
|||||||
}
|
}
|
||||||
h := &chartHarness{build: func(c *ui.Context) ChartResult { return partsChart(c, notes, false) }}
|
h := &chartHarness{build: func(c *ui.Context) ChartResult { return partsChart(c, notes, false) }}
|
||||||
tt := ui.NewTester(h.view, 520, 420)
|
tt := ui.NewTester(h.view, 520, 420)
|
||||||
b := h.res.Element.Bounds()
|
b := h.box(tt)
|
||||||
plot := ChartInset(ui.Rect{X: b.X, Y: b.Y, W: b.W, H: 240}, 52, 26)
|
plot := ChartInset(ui.Rect{X: b.X, Y: b.Y, W: b.W, H: 240}, 52, 26)
|
||||||
yAt := func(v float32) float32 { return plot.Y + plot.H*(1-v/100) }
|
yAt := func(v float32) float32 { return plot.Y + plot.H*(1-v/100) }
|
||||||
xAt := func(v float32) float32 { return plot.X + plot.W*v/10 }
|
xAt := func(v float32) float32 { return plot.X + plot.W*v/10 }
|
||||||
@@ -51,7 +51,7 @@ func TestChartAnnotationDisabledAndBad(t *testing.T) {
|
|||||||
notes := []ChartNote{{Kind: NoteHLine, Value: 50, Draggable: true}}
|
notes := []ChartNote{{Kind: NoteHLine, Value: 50, Draggable: true}}
|
||||||
h := &chartHarness{disabled: true, build: func(c *ui.Context) ChartResult { return partsChart(c, notes, false) }}
|
h := &chartHarness{disabled: true, build: func(c *ui.Context) ChartResult { return partsChart(c, notes, false) }}
|
||||||
tt := ui.NewTester(h.view, 520, 420)
|
tt := ui.NewTester(h.view, 520, 420)
|
||||||
b := h.res.Element.Bounds()
|
b := h.box(tt)
|
||||||
plot := ChartInset(ui.Rect{X: b.X, Y: b.Y, W: b.W, H: 240}, 52, 26)
|
plot := ChartInset(ui.Rect{X: b.X, Y: b.Y, W: b.W, H: 240}, 52, 26)
|
||||||
tt.Press(plot.X+100, plot.Y+plot.H/2)
|
tt.Press(plot.X+100, plot.Y+plot.H/2)
|
||||||
tt.Move(plot.X+100, plot.Y+20)
|
tt.Move(plot.X+100, plot.Y+20)
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ func partsChart(c *ui.Context, notes []ChartNote, crosshair bool) ChartResult {
|
|||||||
return hair.Snap(len(pts), func(i int) (float32, float32) { return at(r, i) }, px, py)
|
return hair.Snap(len(pts), func(i int) (float32, float32) { return at(r, i) }, px, py)
|
||||||
},
|
},
|
||||||
Anchor: at,
|
Anchor: at,
|
||||||
Input: func(plot *ui.Element, r ui.Rect) { notesPart.Drag(plot, plotOf(r)) },
|
Input: func(plot ui.Element, r ui.Rect) { notesPart.Drag(plot, plotOf(r)) },
|
||||||
Draw: func(p *ui.Painter, r ui.Rect, active int) {
|
Draw: func(p *ui.Painter, r ui.Rect, active int) {
|
||||||
plot := plotOf(r)
|
plot := plotOf(r)
|
||||||
grid.Draw(p, plot)
|
grid.Draw(p, plot)
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ func ChartBrush(c *ui.Context, value *[2]float64, opts ChartBrushOptions) core.C
|
|||||||
track.Draw(func(p *ui.Painter, r ui.Rect) { brushPaint(p, r, *value, opts, k, preview) })
|
track.Draw(func(p *ui.Painter, r ui.Rect) { brushPaint(p, r, *value, opts, k, preview) })
|
||||||
track.Children(func() {
|
track.Children(func() {
|
||||||
x0, x1 := at(value[0]), at(value[1])
|
x0, x1 := at(value[0]), at(value[1])
|
||||||
end := func(i int, x float32) *ui.Element {
|
end := func(i int, x float32) ui.Element {
|
||||||
e := ui.Box(c).Absolute().Left(x-theme.MinHitSize/2).Top(0).Size(theme.MinHitSize, h).Focusable().
|
e := ui.Box(c).Absolute().Left(x-theme.MinHitSize/2).Top(0).Size(theme.MinHitSize, h).Focusable().
|
||||||
Role(ui.RoleSlider).Label(fmt.Sprintf(core.Msg(c, []string{"chart_brush.start", "chart_brush.end"}[i]), val(value[i])))
|
Role(ui.RoleSlider).Label(fmt.Sprintf(core.Msg(c, []string{"chart_brush.start", "chart_brush.end"}[i]), val(value[i])))
|
||||||
internal.Ring(e, k.Focus, theme.ControlRadius)
|
internal.Ring(e, k.Focus, theme.ControlRadius)
|
||||||
@@ -104,7 +104,7 @@ func ChartBrush(c *ui.Context, value *[2]float64, opts ChartBrushOptions) core.C
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
// Tab order runs start, window, end.
|
// Tab order runs start, window, end.
|
||||||
ends := [2]*ui.Element{end(0, x0)}
|
ends := [2]ui.Element{end(0, x0)}
|
||||||
window := ui.Box(c).Absolute().Left(x0 + theme.MinHitSize/2).Top(0).Width(max(x1-x0-theme.MinHitSize, theme.MinHitSize)).Height(h).Focusable().
|
window := ui.Box(c).Absolute().Left(x0 + theme.MinHitSize/2).Top(0).Width(max(x1-x0-theme.MinHitSize, theme.MinHitSize)).Height(h).Focusable().
|
||||||
Role(ui.RoleGroup).Label(fmt.Sprintf(core.Msg(c, "chart_brush.window"), opts.Label, val(value[0]), val(value[1])))
|
Role(ui.RoleGroup).Label(fmt.Sprintf(core.Msg(c, "chart_brush.window"), opts.Label, val(value[0]), val(value[1])))
|
||||||
internal.Ring(window, k.Focus, theme.ControlRadius)
|
internal.Ring(window, k.Focus, theme.ControlRadius)
|
||||||
@@ -149,7 +149,7 @@ func ChartBrush(c *ui.Context, value *[2]float64, opts ChartBrushOptions) core.C
|
|||||||
}
|
}
|
||||||
|
|
||||||
// brushKey handles arrow, Page, Home and End keys.
|
// brushKey handles arrow, Page, Home and End keys.
|
||||||
func brushKey(e *ui.Element, v float64, spec input.NumberInputSpec) (float64, bool) {
|
func brushKey(e ui.Element, v float64, spec input.NumberInputSpec) (float64, bool) {
|
||||||
if e.IsDisabled() {
|
if e.IsDisabled() {
|
||||||
return v, false
|
return v, false
|
||||||
}
|
}
|
||||||
@@ -171,10 +171,10 @@ func brushKey(e *ui.Element, v float64, spec input.NumberInputSpec) (float64, bo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// brushPointer drags handles, the window, or a new range.
|
// brushPointer drags handles, the window, or a new range.
|
||||||
func brushPointer(track, window *ui.Element, ends [2]*ui.Element, drag *brushDrag, value *[2]float64, from func(float32) float64, set, move func(lo, hi float64)) {
|
func brushPointer(track, window ui.Element, ends [2]ui.Element, drag *brushDrag, value *[2]float64, from func(float32) float64, set, move func(lo, hi float64)) {
|
||||||
px, _, _ := track.PointerPosition()
|
px, _, _ := track.PointerPosition()
|
||||||
at := from(px)
|
at := from(px)
|
||||||
parts := []*ui.Element{ends[0], ends[1], window, track}
|
parts := []ui.Element{ends[0], ends[1], window, track}
|
||||||
held := -1
|
held := -1
|
||||||
for i, e := range parts {
|
for i, e := range parts {
|
||||||
if _, _, ok := e.Dragged(); ok && held < 0 {
|
if _, _, ok := e.Dragged(); ok && held < 0 {
|
||||||
|
|||||||
@@ -14,14 +14,14 @@ type brushHarness struct {
|
|||||||
value [2]float64
|
value [2]float64
|
||||||
changes int
|
changes int
|
||||||
disabled bool
|
disabled bool
|
||||||
el *ui.Element
|
bounds ui.Rect
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *brushHarness) view(c *ui.Context) {
|
func (h *brushHarness) view(c *ui.Context) {
|
||||||
core.Use(c, core.Settings{Mode: core.Light})
|
core.Use(c, core.Settings{Mode: core.Light})
|
||||||
ui.Column(c).Padding(10).Width(420).Children(func() {
|
ui.Column(c).Padding(10).Width(420).Children(func() {
|
||||||
r := ChartBrush(c, &h.value, ChartBrushOptions{Label: "Months", Min: 0, Max: 100, Step: 1, Disabled: h.disabled})
|
r := ChartBrush(c, &h.value, ChartBrushOptions{Label: "Months", Min: 0, Max: 100, Step: 1, Disabled: h.disabled})
|
||||||
h.el = r.Element
|
h.bounds = r.Element.Bounds()
|
||||||
if r.Changed() {
|
if r.Changed() {
|
||||||
h.changes++
|
h.changes++
|
||||||
}
|
}
|
||||||
@@ -57,7 +57,8 @@ func TestChartBrushKeyboard(t *testing.T) {
|
|||||||
func TestChartBrushDrag(t *testing.T) {
|
func TestChartBrushDrag(t *testing.T) {
|
||||||
h := &brushHarness{value: [2]float64{20, 40}}
|
h := &brushHarness{value: [2]float64{20, 40}}
|
||||||
tt := ui.NewTester(h.view, 460, 200)
|
tt := ui.NewTester(h.view, 460, 200)
|
||||||
b := h.el.Bounds()
|
tt.Frame() // Bounds reads the previous frame
|
||||||
|
b := h.bounds
|
||||||
x := func(v float32) float32 { return b.X + 400*v/100 }
|
x := func(v float32) float32 { return b.X + 400*v/100 }
|
||||||
y := b.Y + 24
|
y := b.Y + 24
|
||||||
tt.Press(x(30), y) // inside the window
|
tt.Press(x(30), y) // inside the window
|
||||||
@@ -86,7 +87,8 @@ func TestChartBrushDrag(t *testing.T) {
|
|||||||
func TestChartBrushDisabledAndBad(t *testing.T) {
|
func TestChartBrushDisabledAndBad(t *testing.T) {
|
||||||
h := &brushHarness{value: [2]float64{20, 40}, disabled: true}
|
h := &brushHarness{value: [2]float64{20, 40}, disabled: true}
|
||||||
tt := ui.NewTester(h.view, 460, 200)
|
tt := ui.NewTester(h.view, 460, 200)
|
||||||
b := h.el.Bounds()
|
tt.Frame() // Bounds reads the previous frame
|
||||||
|
b := h.bounds
|
||||||
tt.Press(b.X+120, b.Y+24)
|
tt.Press(b.X+120, b.Y+24)
|
||||||
tt.Move(b.X+200, b.Y+24)
|
tt.Move(b.X+200, b.Y+24)
|
||||||
tt.Release(b.X+200, b.Y+24)
|
tt.Release(b.X+200, b.Y+24)
|
||||||
@@ -128,7 +130,8 @@ func TestChartBrushSnapshot(t *testing.T) {
|
|||||||
func TestChartBrushWindowDragPreservesSpanAtEdges(t *testing.T) {
|
func TestChartBrushWindowDragPreservesSpanAtEdges(t *testing.T) {
|
||||||
h := &brushHarness{value: [2]float64{20, 60}}
|
h := &brushHarness{value: [2]float64{20, 60}}
|
||||||
tt := ui.NewTester(h.view, 460, 200)
|
tt := ui.NewTester(h.view, 460, 200)
|
||||||
b := h.el.Bounds()
|
tt.Frame() // Bounds reads the previous frame
|
||||||
|
b := h.bounds
|
||||||
tt.Press(b.X+160, b.Y+24)
|
tt.Press(b.X+160, b.Y+24)
|
||||||
tt.Move(b.X+380, b.Y+24)
|
tt.Move(b.X+380, b.Y+24)
|
||||||
tt.Release(b.X+380, b.Y+24)
|
tt.Release(b.X+380, b.Y+24)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import (
|
|||||||
func TestChartCrosshairSnapsAndFollowsKeys(t *testing.T) {
|
func TestChartCrosshairSnapsAndFollowsKeys(t *testing.T) {
|
||||||
h := &chartHarness{build: func(c *ui.Context) ChartResult { return partsChart(c, nil, true) }}
|
h := &chartHarness{build: func(c *ui.Context) ChartResult { return partsChart(c, nil, true) }}
|
||||||
tt := ui.NewTester(h.view, 520, 420)
|
tt := ui.NewTester(h.view, 520, 420)
|
||||||
b := h.res.Element.Bounds()
|
b := h.box(tt)
|
||||||
plot := ChartInset(ui.Rect{X: b.X, Y: b.Y, W: b.W, H: 240}, 52, 26)
|
plot := ChartInset(ui.Rect{X: b.X, Y: b.Y, W: b.W, H: 240}, 52, 26)
|
||||||
// Point 1 is ten DIPs from the pointer.
|
// Point 1 is ten DIPs from the pointer.
|
||||||
px, py := plot.X+plot.W/2, plot.Y+plot.H*0.2
|
px, py := plot.X+plot.W/2, plot.Y+plot.H*0.2
|
||||||
|
|||||||
@@ -13,30 +13,33 @@ func TestChartEmptyStateKeepsSizeAndRetries(t *testing.T) {
|
|||||||
status := data.DataReady
|
status := data.DataReady
|
||||||
retries, disabled := 0, false
|
retries, disabled := 0, false
|
||||||
var heights []float32
|
var heights []float32
|
||||||
var el *ui.Element
|
var box ui.Rect
|
||||||
tt := ui.NewTester(func(c *ui.Context) {
|
tt := ui.NewTester(func(c *ui.Context) {
|
||||||
core.Use(c, core.Settings{})
|
core.Use(c, core.Settings{})
|
||||||
ui.Column(c).Width(400).Disabled(disabled).Children(func() {
|
ui.Column(c).Width(400).Disabled(disabled).Children(func() {
|
||||||
r := ChartEmptyState(c, status, ChartEmptyStateOptions{Height: 180, Empty: "No hymns this week", Error: "The choir did not answer"})
|
r := ChartEmptyState(c, status, ChartEmptyStateOptions{Height: 180, Empty: "No hymns this week", Error: "The choir did not answer"})
|
||||||
el = r.Element
|
box = r.Element.Bounds()
|
||||||
if r.Changed() {
|
if r.Changed() {
|
||||||
retries++
|
retries++
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}, 440, 300)
|
}, 440, 300)
|
||||||
heights = append(heights, el.Bounds().H)
|
tt.Frame() // Bounds reads the previous frame
|
||||||
|
heights = append(heights, box.H)
|
||||||
if !tt.HasText("No hymns this week") {
|
if !tt.HasText("No hymns this week") {
|
||||||
t.Fatalf("empty: %q", tt.Texts())
|
t.Fatalf("empty: %q", tt.Texts())
|
||||||
}
|
}
|
||||||
status = data.DataLoading
|
status = data.DataLoading
|
||||||
tt.Frame()
|
tt.Frame()
|
||||||
heights = append(heights, el.Bounds().H)
|
tt.Frame() // Bounds reads the previous frame
|
||||||
|
heights = append(heights, box.H)
|
||||||
if !tt.HasText("Loading") {
|
if !tt.HasText("Loading") {
|
||||||
t.Fatalf("loading: %q", tt.Texts())
|
t.Fatalf("loading: %q", tt.Texts())
|
||||||
}
|
}
|
||||||
status = data.DataFailed
|
status = data.DataFailed
|
||||||
tt.Frame()
|
tt.Frame()
|
||||||
heights = append(heights, el.Bounds().H)
|
tt.Frame() // Bounds reads the previous frame
|
||||||
|
heights = append(heights, box.H)
|
||||||
if err := tt.Click("Retry"); err != nil || retries != 1 || !tt.HasText("The choir did not answer") {
|
if err := tt.Click("Retry"); err != nil || retries != 1 || !tt.HasText("The choir did not answer") {
|
||||||
t.Fatalf("retry: %v %d", err, retries)
|
t.Fatalf("retry: %v %d", err, retries)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ type ChartFrame struct {
|
|||||||
|
|
||||||
// ChartResult is a built chart and this frame's events.
|
// ChartResult is a built chart and this frame's events.
|
||||||
type ChartResult struct {
|
type ChartResult struct {
|
||||||
Element *ui.Element
|
Element ui.Element
|
||||||
// Point is the hovered or focused mark, -1 for none.
|
// Point is the hovered or focused mark, -1 for none.
|
||||||
Point int
|
Point int
|
||||||
changed, retry bool
|
changed, retry bool
|
||||||
@@ -69,7 +69,7 @@ type ChartSpec struct {
|
|||||||
// Tooltip writes mark i's tooltip; nil splits Readout at " · ".
|
// Tooltip writes mark i's tooltip; nil splits Readout at " · ".
|
||||||
Tooltip func(i int) []ChartTooltipLine
|
Tooltip func(i int) []ChartTooltipLine
|
||||||
// Input takes the plot's other input, as a ChartAnnotation's drags.
|
// Input takes the plot's other input, as a ChartAnnotation's drags.
|
||||||
Input func(plot *ui.Element, r ui.Rect)
|
Input func(plot ui.Element, r ui.Rect)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Chart frames a custom chart: legend, focus, keys, readout, tooltip and empty states.
|
// Chart frames a custom chart: legend, focus, keys, readout, tooltip and empty states.
|
||||||
@@ -120,10 +120,10 @@ func (ch *chart) Toggles(on bool) *map[string]bool {
|
|||||||
func (ch *chart) Hidden(name string) bool { return ch.st.hidden[name] }
|
func (ch *chart) Hidden(name string) bool { return ch.st.hidden[name] }
|
||||||
|
|
||||||
// Build lays out legend, plot and readout; returns the plot.
|
// Build lays out legend, plot and readout; returns the plot.
|
||||||
func (ch *chart) Build(spec ChartSpec) (ChartResult, *ui.Element) {
|
func (ch *chart) Build(spec ChartSpec) (ChartResult, ui.Element) {
|
||||||
c, k, st := ch.c, core.Tokens(ch.c), ch.st
|
c, k, st := ch.c, core.Tokens(ch.c), ch.st
|
||||||
u := core.Density(c).Unit()
|
u := core.Density(c).Unit()
|
||||||
var plot *ui.Element
|
var plot ui.Element
|
||||||
ch.Res.Element.Children(func() {
|
ch.Res.Element.Children(func() {
|
||||||
if len(spec.Legend) > 0 {
|
if len(spec.Legend) > 0 {
|
||||||
if name, ok := ChartLegend(c, spec.Hidden, spec.Legend, ChartLegendOptions{}).Toggled(); ok {
|
if name, ok := ChartLegend(c, spec.Hidden, spec.Legend, ChartLegendOptions{}).Toggled(); ok {
|
||||||
@@ -181,7 +181,7 @@ func (ch *chart) Build(spec ChartSpec) (ChartResult, *ui.Element) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// input moves the keyboard mark, and takes clicks on marks.
|
// input moves the keyboard mark, and takes clicks on marks.
|
||||||
func (ch *chart) input(plot *ui.Element, spec ChartSpec) {
|
func (ch *chart) input(plot ui.Element, spec ChartSpec) {
|
||||||
st := ch.st
|
st := ch.st
|
||||||
if plot.IsDisabled() {
|
if plot.IsDisabled() {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ func TestChartsIgnoreInputWhenDisabled(t *testing.T) {
|
|||||||
tt.Key(0, ui.KeyEnter)
|
tt.Key(0, ui.KeyEnter)
|
||||||
tt.Key(0, ui.KeySpace)
|
tt.Key(0, ui.KeySpace)
|
||||||
}
|
}
|
||||||
b := h.res.Element.Bounds()
|
b := h.box(tt)
|
||||||
tt.Click("Under test")
|
tt.Click("Under test")
|
||||||
tt.ClickAt(b.X+b.W/2, b.Y+b.H/2)
|
tt.ClickAt(b.X+b.W/2, b.Y+b.H/2)
|
||||||
if h.res.Point != -1 || values != 0 {
|
if h.res.Point != -1 || values != 0 {
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ type ChartLegendOptions struct {
|
|||||||
|
|
||||||
// ChartLegendResult exposes the element and legend events.
|
// ChartLegendResult exposes the element and legend events.
|
||||||
type ChartLegendResult struct {
|
type ChartLegendResult struct {
|
||||||
Element *ui.Element
|
Element ui.Element
|
||||||
toggled string
|
toggled string
|
||||||
expanded, folded bool
|
expanded, folded bool
|
||||||
}
|
}
|
||||||
@@ -68,7 +68,7 @@ func ChartLegend(c *ui.Context, hidden *map[string]bool, items []ChartLegendItem
|
|||||||
shown = items[:opts.MaxItems]
|
shown = items[:opts.MaxItems]
|
||||||
}
|
}
|
||||||
for _, it := range shown {
|
for _, it := range shown {
|
||||||
ui.Row(c).Key(it.Name).Children(func() {
|
ui.Row(c.Key(it.Name)).Children(func() {
|
||||||
if name, ok := chartLegendEntry(c, hidden, it, res.Element.IsDisabled()); ok {
|
if name, ok := chartLegendEntry(c, hidden, it, res.Element.IsDisabled()); ok {
|
||||||
res.toggled = name
|
res.toggled = name
|
||||||
}
|
}
|
||||||
@@ -100,7 +100,7 @@ func chartLegendEntry(c *ui.Context, hidden *map[string]bool, it ChartLegendItem
|
|||||||
k := core.Tokens(c)
|
k := core.Tokens(c)
|
||||||
u := core.Density(c).Unit()
|
u := core.Density(c).Unit()
|
||||||
on := hidden == nil || !(*hidden)[it.Name]
|
on := hidden == nil || !(*hidden)[it.Name]
|
||||||
var e *ui.Element
|
var e ui.Element
|
||||||
switched := false
|
switched := false
|
||||||
if hidden != nil {
|
if hidden != nil {
|
||||||
e = ui.CheckboxBase(c, &on).Disabled(disabled).Label(it.Name)
|
e = ui.CheckboxBase(c, &on).Disabled(disabled).Label(it.Name)
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ type ChartTooltipLine struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ChartTooltip shows readouts beside a window point, avoiding edges.
|
// ChartTooltip shows readouts beside a window point, avoiding edges.
|
||||||
func ChartTooltip(c *ui.Context, x, y float32, lines []ChartTooltipLine) *ui.Element {
|
func ChartTooltip(c *ui.Context, x, y float32, lines []ChartTooltipLine) ui.Element {
|
||||||
if len(lines) == 0 {
|
if len(lines) == 0 {
|
||||||
panic("mujica: ChartTooltip needs a line")
|
panic("mujica: ChartTooltip needs a line")
|
||||||
}
|
}
|
||||||
@@ -45,7 +45,7 @@ func ChartTooltip(c *ui.Context, x, y float32, lines []ChartTooltipLine) *ui.Ele
|
|||||||
} else {
|
} else {
|
||||||
left = max(4, min(x-gap-w, ww-4-w))
|
left = max(4, min(x-gap-w, ww-4-w))
|
||||||
}
|
}
|
||||||
var tip *ui.Element
|
var tip ui.Element
|
||||||
ui.Overlay(c, func() {
|
ui.Overlay(c, func() {
|
||||||
tip = ui.Column(c).Absolute().Left(left).Top(top).Size(w, h).Role(ui.RoleNone).PassThrough()
|
tip = ui.Column(c).Absolute().Left(left).Top(top).Size(w, h).Role(ui.RoleNone).PassThrough()
|
||||||
core.OverlayStyle(c, tip, core.OverlayEnter(c, tip))
|
core.OverlayStyle(c, tip, core.OverlayEnter(c, tip))
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ func TestChartTooltipFollowsFocusAndPointer(t *testing.T) {
|
|||||||
if tooltipShown(tt) {
|
if tooltipShown(tt) {
|
||||||
t.Fatal("tooltip stayed after Escape")
|
t.Fatal("tooltip stayed after Escape")
|
||||||
}
|
}
|
||||||
b := h.res.Element.Bounds()
|
b := h.box(tt)
|
||||||
tt.Move(b.X+b.W/2, b.Y+b.H/2)
|
tt.Move(b.X+b.W/2, b.Y+b.H/2)
|
||||||
if !tooltipShown(tt) {
|
if !tooltipShown(tt) {
|
||||||
t.Fatal("no tooltip under the pointer")
|
t.Fatal("no tooltip under the pointer")
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ func TestChordDiagramReadout(t *testing.T) {
|
|||||||
t.Fatalf("chord %q", got)
|
t.Fatalf("chord %q", got)
|
||||||
}
|
}
|
||||||
tt.Key(0, ui.KeyEscape)
|
tt.Key(0, ui.KeyEscape)
|
||||||
b := h.res.Element.Bounds()
|
b := h.box(tt)
|
||||||
cx, cy, rad := b.X+b.W/2, b.Y+120, float32(240)/2-30
|
cx, cy, rad := b.X+b.W/2, b.Y+120, float32(240)/2-30
|
||||||
tt.Move(cx+(rad+6)*0.5, cy-(rad+6)*0.866) // 30°: inside the first arc
|
tt.Move(cx+(rad+6)*0.5, cy-(rad+6)*0.866) // 30°: inside the first arc
|
||||||
if h.res.Point != 0 {
|
if h.res.Point != 0 {
|
||||||
@@ -95,8 +95,9 @@ func TestChordDiagramDenseDataBoundedAndDisabled(t *testing.T) {
|
|||||||
h := &chartHarness{build: func(c *ui.Context) ChartResult {
|
h := &chartHarness{build: func(c *ui.Context) ChartResult {
|
||||||
return ChordDiagram(c, names, matrix, ChordDiagramOptions{Frame: ChartFrame{Label: "Dense chords"}})
|
return ChordDiagram(c, names, matrix, ChordDiagramOptions{Frame: ChartFrame{Label: "Dense chords"}})
|
||||||
}}
|
}}
|
||||||
|
var shown *[]int
|
||||||
|
h.built = func(r ChartResult) { shown = ui.Local(r.Element, "mujica.chord.visible", func() []int { return nil }) }
|
||||||
tt := ui.NewTester(h.view, 520, 420)
|
tt := ui.NewTester(h.view, 520, 420)
|
||||||
shown := ui.Local(h.res.Element, "mujica.chord.visible", func() []int { return nil })
|
|
||||||
if len(*shown) == 0 || len(*shown) > 360 {
|
if len(*shown) == 0 || len(*shown) > 360 {
|
||||||
t.Fatalf("built %d chords", len(*shown))
|
t.Fatalf("built %d chords", len(*shown))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ func DrawingToolbar(c *ui.Context, d *DrawingTools, opts DrawingToolbarOptions)
|
|||||||
for t := ToolSelect; t <= ToolText; t++ {
|
for t := ToolSelect; t <= ToolText; t++ {
|
||||||
name := fmt.Sprintf("%s (Alt+%d)", core.Msg(c, fmt.Sprintf("drawing_toolbar.tool%d", t)), t+1)
|
name := fmt.Sprintf("%s (Alt+%d)", core.Msg(c, fmt.Sprintf("drawing_toolbar.tool%d", t)), t+1)
|
||||||
on := d.Tool == t
|
on := d.Tool == t
|
||||||
b := ui.ButtonBase(c).Key(t).Size(theme.MinHitSize+4, theme.MinHitSize+4).Radius(theme.ControlRadius).Label(name).Tooltip(name).Disabled(d.Locked)
|
b := ui.ButtonBase(c.Key(t)).Size(theme.MinHitSize+4, theme.MinHitSize+4).Radius(theme.ControlRadius).Label(name).Tooltip(name).Disabled(d.Locked)
|
||||||
internal.Ring(b, k.Focus, theme.ControlRadius)
|
internal.Ring(b, k.Focus, theme.ControlRadius)
|
||||||
fg := k.Text
|
fg := k.Text
|
||||||
switch {
|
switch {
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ func (d *DrawingTools) xy(m *mktCore, g mktGeom, pt DrawingPoint) (float32, floa
|
|||||||
}
|
}
|
||||||
|
|
||||||
// input places, selects, moves, and deletes chart annotations.
|
// input places, selects, moves, and deletes chart annotations.
|
||||||
func (d *DrawingTools) input(m *mktCore, plot *ui.Element, g mktGeom, x, y float32, over, held bool, dx, dy float32) bool {
|
func (d *DrawingTools) input(m *mktCore, plot ui.Element, g mktGeom, x, y float32, over, held bool, dx, dy float32) bool {
|
||||||
if d.Tool < ToolSelect || d.Tool > ToolText {
|
if d.Tool < ToolSelect || d.Tool > ToolText {
|
||||||
panic(fmt.Sprintf("mujica: unknown DrawingTool %d", d.Tool))
|
panic(fmt.Sprintf("mujica: unknown DrawingTool %d", d.Tool))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ func TestFunnelChartReadout(t *testing.T) {
|
|||||||
t.Fatalf("readout %q", got)
|
t.Fatalf("readout %q", got)
|
||||||
}
|
}
|
||||||
tt.Key(0, ui.KeyEscape)
|
tt.Key(0, ui.KeyEscape)
|
||||||
b := h.res.Element.Bounds()
|
b := h.box(tt)
|
||||||
tt.Move(b.X+b.W/3, b.Y+4+232*0.6) // third stage band
|
tt.Move(b.X+b.W/3, b.Y+4+232*0.6) // third stage band
|
||||||
if got := chartReadout(tt); got != "Vows · 100 · 25.0% of the stage before · 10.0% of the first" {
|
if got := chartReadout(tt); got != "Vows · 100 · 25.0% of the stage before · 10.0% of the first" {
|
||||||
t.Fatalf("hover %q", got)
|
t.Fatalf("hover %q", got)
|
||||||
|
|||||||
+1
-1
@@ -28,7 +28,7 @@ func TestGaugeReadoutNamesSegment(t *testing.T) {
|
|||||||
tt.Key(0, ui.KeyEscape)
|
tt.Key(0, ui.KeyEscape)
|
||||||
for _, full = range []bool{false, true} {
|
for _, full = range []bool{false, true} {
|
||||||
tt.Frame()
|
tt.Frame()
|
||||||
b := h.res.Element.Bounds()
|
b := h.box(tt)
|
||||||
cx := b.X + b.W/2
|
cx := b.X + b.W/2
|
||||||
var cy, rad float32
|
var cy, rad float32
|
||||||
if full {
|
if full {
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ func TestHeatmapChartHover(t *testing.T) {
|
|||||||
return HeatmapChart(c, heatRows, heatCols, heatValues(), HeatmapChartOptions{Frame: ChartFrame{Label: "Hours"}})
|
return HeatmapChart(c, heatRows, heatCols, heatValues(), HeatmapChartOptions{Frame: ChartFrame{Label: "Hours"}})
|
||||||
}}
|
}}
|
||||||
tt := ui.NewTester(h.view, 520, 420)
|
tt := ui.NewTester(h.view, 520, 420)
|
||||||
b := h.res.Element.Bounds()
|
b := h.box(tt)
|
||||||
plotW := b.W - 72 - 64
|
plotW := b.W - 72 - 64
|
||||||
tt.Move(b.X+72+plotW*0.6, b.Y+4+212*0.2) // third column, first row
|
tt.Move(b.X+72+plotW*0.6, b.Y+4+212*0.2) // third column, first row
|
||||||
if got := chartReadout(tt); got != "Mon · Vespers · 9" {
|
if got := chartReadout(tt); got != "Mon · Vespers · 9" {
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ type IndicatorPaneOptions struct {
|
|||||||
|
|
||||||
// IndicatorPaneResult reports the stack's events.
|
// IndicatorPaneResult reports the stack's events.
|
||||||
type IndicatorPaneResult struct {
|
type IndicatorPaneResult struct {
|
||||||
Element *ui.Element
|
Element ui.Element
|
||||||
// Removed reports the closed pane; -1 means none.
|
// Removed reports the closed pane; -1 means none.
|
||||||
Removed int
|
Removed int
|
||||||
// Resized reports finished height changes, for saving.
|
// Resized reports finished height changes, for saving.
|
||||||
@@ -218,7 +218,7 @@ func indicatorPaneOne(c *ui.Context, candles []Candle, view *MarketView, spec In
|
|||||||
m.view = ©
|
m.view = ©
|
||||||
}
|
}
|
||||||
result, plot := ch.Build(spec2)
|
result, plot := ch.Build(spec2)
|
||||||
if plot != nil {
|
if plot.Valid() {
|
||||||
m.input(plot)
|
m.input(plot)
|
||||||
}
|
}
|
||||||
return closed && !ch.Res.Element.IsDisabled(), result
|
return closed && !ch.Res.Element.IsDisabled(), result
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ func IndicatorSelector(c *ui.Context, overlays *[]IndicatorOverlay, panes *Indic
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
found++
|
found++
|
||||||
ui.Row(c).Key(name).AlignItems(ui.Center).Gap(u * 2).MinHeight(core.Density(c).ControlHeight()).Children(func() {
|
ui.Row(c.Key(name)).AlignItems(ui.Center).Gap(u * 2).MinHeight(core.Density(c).ControlHeight()).Children(func() {
|
||||||
ui.Text(c, name).FontWeight(600).Width(56)
|
ui.Text(c, name).FontWeight(600).Width(56)
|
||||||
where := "indicator_selector.pane"
|
where := "indicator_selector.pane"
|
||||||
if indicatorInfo[kind].overlay {
|
if indicatorInfo[kind].overlay {
|
||||||
@@ -103,7 +103,7 @@ func IndicatorSelector(c *ui.Context, overlays *[]IndicatorOverlay, panes *Indic
|
|||||||
// indicatorSelectorActive edits parameters and reports removal of an indicator.
|
// indicatorSelectorActive edits parameters and reports removal of an indicator.
|
||||||
func indicatorSelectorActive(c *ui.Context, u float32, key string, kind IndicatorKind, params *[]float64, changed *bool) bool {
|
func indicatorSelectorActive(c *ui.Context, u float32, key string, kind IndicatorKind, params *[]float64, changed *bool) bool {
|
||||||
removed := false
|
removed := false
|
||||||
ui.Row(c).Key(key).AlignItems(ui.Center).Gap(u * 2).Wrap().Children(func() {
|
ui.Row(c.Key(key)).AlignItems(ui.Center).Gap(u * 2).Wrap().Children(func() {
|
||||||
ui.Text(c, kind.String()).FontWeight(600).Width(56)
|
ui.Text(c, kind.String()).FontWeight(600).Width(56)
|
||||||
if len(kind.DefaultParams()) > 0 && IndicatorParamsField(c, kind, params).Changed() {
|
if len(kind.DefaultParams()) > 0 && IndicatorParamsField(c, kind, params).Changed() {
|
||||||
*changed = true
|
*changed = true
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ func IntervalSelector(c *ui.Context, value *Interval, favorites *[]Interval, opt
|
|||||||
// intervalSelectorRow shows a selectable period and its favorite toggle.
|
// intervalSelectorRow shows a selectable period and its favorite toggle.
|
||||||
func intervalSelectorRow(c *ui.Context, k theme.Tokens, u float32, iv Interval, on, fav bool, favorites *[]Interval) bool {
|
func intervalSelectorRow(c *ui.Context, k theme.Tokens, u float32, iv Interval, on, fav bool, favorites *[]Interval) bool {
|
||||||
chosen := false
|
chosen := false
|
||||||
ui.Row(c).Key(string(iv)).AlignItems(ui.Center).Gap(u).Children(func() {
|
ui.Row(c.Key(string(iv))).AlignItems(ui.Center).Gap(u).Children(func() {
|
||||||
b := ui.ButtonBase(c).Grow(1).MinHeight(core.Density(c).ControlHeight()).Padding(0, u*2).Justify(ui.Start).Radius(theme.ControlRadius).Gap(u * 2)
|
b := ui.ButtonBase(c).Grow(1).MinHeight(core.Density(c).ControlHeight()).Padding(0, u*2).Justify(ui.Start).Radius(theme.ControlRadius).Gap(u * 2)
|
||||||
internal.Ring(b, k.Focus, theme.ControlRadius)
|
internal.Ring(b, k.Focus, theme.ControlRadius)
|
||||||
if on {
|
if on {
|
||||||
|
|||||||
@@ -14,15 +14,27 @@ import (
|
|||||||
|
|
||||||
type chartHarness struct {
|
type chartHarness struct {
|
||||||
res ChartResult
|
res ChartResult
|
||||||
|
bounds ui.Rect
|
||||||
changes int
|
changes int
|
||||||
disabled bool
|
disabled bool
|
||||||
build func(c *ui.Context) ChartResult
|
build func(c *ui.Context) ChartResult
|
||||||
|
built func(r ChartResult) // reads the live element during the build
|
||||||
|
}
|
||||||
|
|
||||||
|
// box is the plot's committed bounds: Bounds reads the previous frame, so one more frame settles it.
|
||||||
|
func (h *chartHarness) box(tt *ui.Tester) ui.Rect {
|
||||||
|
tt.Frame()
|
||||||
|
return h.bounds
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *chartHarness) view(c *ui.Context) {
|
func (h *chartHarness) view(c *ui.Context) {
|
||||||
core.Use(c, core.Settings{Mode: core.Light})
|
core.Use(c, core.Settings{Mode: core.Light})
|
||||||
ui.Column(c).Padding(16).Width(480).Disabled(h.disabled).Children(func() {
|
ui.Column(c).Padding(16).Width(480).Disabled(h.disabled).Children(func() {
|
||||||
h.res = h.build(c)
|
h.res = h.build(c)
|
||||||
|
h.bounds = h.res.Element.Bounds()
|
||||||
|
if h.built != nil {
|
||||||
|
h.built(h.res)
|
||||||
|
}
|
||||||
if h.res.Changed() {
|
if h.res.Changed() {
|
||||||
h.changes++
|
h.changes++
|
||||||
}
|
}
|
||||||
@@ -84,7 +96,7 @@ func TestLineChartHoverAndToggle(t *testing.T) {
|
|||||||
return r
|
return r
|
||||||
}}
|
}}
|
||||||
tt := ui.NewTester(h.view, 520, 420)
|
tt := ui.NewTester(h.view, 520, 420)
|
||||||
b := h.res.Element.Bounds()
|
b := h.box(tt)
|
||||||
// The plot spans 52..W-12; x 30 is three quarters across.
|
// The plot spans 52..W-12; x 30 is three quarters across.
|
||||||
px := b.X + 52 + (b.W-64)*0.75
|
px := b.X + 52 + (b.W-64)*0.75
|
||||||
tt.Move(px, b.Y+b.H/2)
|
tt.Move(px, b.Y+b.H/2)
|
||||||
@@ -118,11 +130,11 @@ func TestLineChartTimeAxisAndStates(t *testing.T) {
|
|||||||
if got := chartReadout(tt); !strings.HasPrefix(got, "2026-10-05 10:00:00 · ") {
|
if got := chartReadout(tt); !strings.HasPrefix(got, "2026-10-05 10:00:00 · ") {
|
||||||
t.Fatalf("time readout %q", got)
|
t.Fatalf("time readout %q", got)
|
||||||
}
|
}
|
||||||
heights = append(heights, h.res.Element.Bounds().H)
|
heights = append(heights, h.box(tt).H)
|
||||||
for _, st := range []data.DataStatus{data.DataLoading, data.DataFailed} {
|
for _, st := range []data.DataStatus{data.DataLoading, data.DataFailed} {
|
||||||
status = st
|
status = st
|
||||||
tt.Frame()
|
tt.Frame()
|
||||||
heights = append(heights, h.res.Element.Bounds().H)
|
heights = append(heights, h.box(tt).H)
|
||||||
}
|
}
|
||||||
if !tt.HasText("Retry") || heights[0] != heights[1] || heights[1] != heights[2] {
|
if !tt.HasText("Retry") || heights[0] != heights[1] || heights[1] != heights[2] {
|
||||||
t.Fatalf("states changed size: %v", heights)
|
t.Fatalf("states changed size: %v", heights)
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ func MarketHeatmap(c *ui.Context, path *[]string, root HeatNode, opts MarketHeat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
r, plot := ch.Build(spec)
|
r, plot := ch.Build(spec)
|
||||||
if plot != nil && !plot.IsDisabled() && plot.Shortcut(0, ui.KeyBackspace) && len(*path) > 0 {
|
if plot.Valid() && !plot.IsDisabled() && plot.Shortcut(0, ui.KeyBackspace) && len(*path) > 0 {
|
||||||
*path, res.value = (*path)[:len(*path)-1], true
|
*path, res.value = (*path)[:len(*path)-1], true
|
||||||
}
|
}
|
||||||
res.Element, res.Point, res.changed, res.retry = r.Element, r.Point, r.changed, r.retry
|
res.Element, res.Point, res.changed, res.retry = r.Element, r.Point, r.changed, r.retry
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ import (
|
|||||||
func TestMarketHeatmapAreaDrillAndKeys(t *testing.T) {
|
func TestMarketHeatmapAreaDrillAndKeys(t *testing.T) {
|
||||||
root := mktHeat()
|
root := mktHeat()
|
||||||
var path []string
|
var path []string
|
||||||
var got ChartResult
|
built := false
|
||||||
tt := chatTester(640, 400, func(c *ui.Context) {
|
tt := chatTester(640, 400, func(c *ui.Context) {
|
||||||
got = MarketHeatmap(c, &path, root, MarketHeatmapOptions{Frame: ChartFrame{Label: "Market"}})
|
built = MarketHeatmap(c, &path, root, MarketHeatmapOptions{Frame: ChartFrame{Label: "Market"}}).Element.Valid()
|
||||||
})
|
})
|
||||||
tt.Key(0, ui.KeyTab)
|
tt.Key(0, ui.KeyTab)
|
||||||
tt.Key(0, ui.KeyHome)
|
tt.Key(0, ui.KeyHome)
|
||||||
@@ -26,7 +26,7 @@ func TestMarketHeatmapAreaDrillAndKeys(t *testing.T) {
|
|||||||
if len(path) != 0 {
|
if len(path) != 0 {
|
||||||
t.Fatalf("back %v", path)
|
t.Fatalf("back %v", path)
|
||||||
}
|
}
|
||||||
if got.Element == nil {
|
if !built {
|
||||||
t.Fatal("element missing")
|
t.Fatal("element missing")
|
||||||
}
|
}
|
||||||
if root.total() != 9830 {
|
if root.total() != 9830 {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// input handles pan, zoom, alerts, drawings, and keyboard following.
|
// input handles pan, zoom, alerts, drawings, and keyboard following.
|
||||||
func (m *mktCore) input(plot *ui.Element) {
|
func (m *mktCore) input(plot ui.Element) {
|
||||||
if plot.IsDisabled() {
|
if plot.IsDisabled() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -20,7 +20,7 @@ func (m *mktCore) input(plot *ui.Element) {
|
|||||||
room := m.room()
|
room := m.room()
|
||||||
changed := false
|
changed := false
|
||||||
plot.HandleInput(func(ev ui.InputEvent) bool {
|
plot.HandleInput(func(ev ui.InputEvent) bool {
|
||||||
if ev.Kind != ui.InputScroll || plot.IsDisabled() || ev.DY == 0 {
|
if ev.Kind != ui.InputScroll || ev.DY == 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
f := 0.9
|
f := 0.9
|
||||||
@@ -90,7 +90,7 @@ func (m *mktCore) input(plot *ui.Element) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mktCore) alertsKeyboard(plot *ui.Element) {
|
func (m *mktCore) alertsKeyboard(plot ui.Element) {
|
||||||
if m.opts.Alerts == nil || len(*m.opts.Alerts) == 0 || m.base != 0 {
|
if m.opts.Alerts == nil || len(*m.opts.Alerts) == 0 || m.base != 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,12 +14,14 @@ func TestDepthChartLargeDataBounded(t *testing.T) {
|
|||||||
bids[i] = DepthLevel{100 - float64(i)*0.0001, 1}
|
bids[i] = DepthLevel{100 - float64(i)*0.0001, 1}
|
||||||
asks[i] = DepthLevel{101 + float64(i)*0.0001, 2}
|
asks[i] = DepthLevel{101 + float64(i)*0.0001, 2}
|
||||||
}
|
}
|
||||||
|
var drawnAt *int
|
||||||
var res ChartResult
|
var res ChartResult
|
||||||
tt := ui.NewTester(func(c *ui.Context) {
|
tt := ui.NewTester(func(c *ui.Context) {
|
||||||
core.Use(c, core.Settings{})
|
core.Use(c, core.Settings{})
|
||||||
res = DepthChart(c, bids, asks, DepthChartOptions{Frame: ChartFrame{Label: "Depth"}})
|
res = DepthChart(c, bids, asks, DepthChartOptions{Frame: ChartFrame{Label: "Depth"}})
|
||||||
|
drawnAt = ui.Local(res.Element, "mujica.depth.drawn", func() int { return 0 })
|
||||||
}, 640, 340)
|
}, 640, 340)
|
||||||
drawn := *ui.Local(res.Element, "mujica.depth.drawn", func() int { return 0 })
|
drawn := *drawnAt
|
||||||
if drawn <= 0 || drawn > 4*640+8 {
|
if drawn <= 0 || drawn > 4*640+8 {
|
||||||
t.Fatalf("painted %d depth vertices", drawn)
|
t.Fatalf("painted %d depth vertices", drawn)
|
||||||
}
|
}
|
||||||
@@ -35,12 +37,14 @@ func TestVolumeProfileLargeDataBounded(t *testing.T) {
|
|||||||
for i := range bins {
|
for i := range bins {
|
||||||
bins[i] = ProfileBin{float64(i), float64(i + 1), float64(i%19 + 1)}
|
bins[i] = ProfileBin{float64(i), float64(i + 1), float64(i%19 + 1)}
|
||||||
}
|
}
|
||||||
|
var drawnAt *int
|
||||||
var res ChartResult
|
var res ChartResult
|
||||||
tt := ui.NewTester(func(c *ui.Context) {
|
tt := ui.NewTester(func(c *ui.Context) {
|
||||||
core.Use(c, core.Settings{})
|
core.Use(c, core.Settings{})
|
||||||
res = VolumeProfile(c, bins, VolumeProfileOptions{Frame: ChartFrame{Label: "Profile"}})
|
res = VolumeProfile(c, bins, VolumeProfileOptions{Frame: ChartFrame{Label: "Profile"}})
|
||||||
|
drawnAt = ui.Local(res.Element, "mujica.profile.drawn", func() int { return 0 })
|
||||||
}, 640, 340)
|
}, 640, 340)
|
||||||
drawn := *ui.Local(res.Element, "mujica.profile.drawn", func() int { return 0 })
|
drawn := *drawnAt
|
||||||
if drawn <= 0 || drawn > 4*340+4 {
|
if drawn <= 0 || drawn > 4*340+4 {
|
||||||
t.Fatalf("painted %d profile bins", drawn)
|
t.Fatalf("painted %d profile bins", drawn)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ func CompareLegend(c *ui.Context, symbols *[]CompareSymbol) core.ChoiceResult {
|
|||||||
row := ui.Row(c).Wrap().Gap(u * 2).Role(ui.RoleList).Label(core.Msg(c, "compare_symbol.label"))
|
row := ui.Row(c).Wrap().Gap(u * 2).Role(ui.RoleList).Label(core.Msg(c, "compare_symbol.label"))
|
||||||
row.Children(func() {
|
row.Children(func() {
|
||||||
for i, s := range *symbols {
|
for i, s := range *symbols {
|
||||||
ui.Row(c).Key(s.Name).AlignItems(ui.Center).Gap(u).Padding(0, 0, 0, u*2).Radius(6).Border(1, k.Border).Role(ui.RoleListItem).Label(s.Name).Children(func() {
|
ui.Row(c.Key(s.Name)).AlignItems(ui.Center).Gap(u).Padding(0, 0, 0, u*2).Radius(6).Border(1, k.Border).Role(ui.RoleListItem).Label(s.Name).Children(func() {
|
||||||
col := pal[(i+1)%len(pal)]
|
col := pal[(i+1)%len(pal)]
|
||||||
ui.Box(c).Size(10, 10).Draw(func(p *ui.Painter, r ui.Rect) { internal.Marker(p, i+1, r.X+5, r.Y+5, 9, col) })
|
ui.Box(c).Size(10, 10).Draw(func(p *ui.Painter, r ui.Rect) { internal.Marker(p, i+1, r.X+5, r.Y+5, 9, col) })
|
||||||
ui.Text(c, s.Name).SingleLine()
|
ui.Text(c, s.Name).SingleLine()
|
||||||
|
|||||||
@@ -133,15 +133,14 @@ func TestMarketMissingComparisonCache(t *testing.T) {
|
|||||||
for i := range s[0].Closes {
|
for i := range s[0].Closes {
|
||||||
s[0].Closes[i] = math.NaN()
|
s[0].Closes[i] = math.NaN()
|
||||||
}
|
}
|
||||||
var r ChartResult
|
var memo *ChartMemoEntry
|
||||||
tt := ui.NewTester(func(c *ui.Context) {
|
tt := ui.NewTester(func(c *ui.Context) {
|
||||||
core.Use(c, core.Settings{})
|
core.Use(c, core.Settings{})
|
||||||
r = CandlestickChart(c, cs, &v, CandlestickOptions{Frame: ChartFrame{Label: "A"}, Compare: &s})
|
r := CandlestickChart(c, cs, &v, CandlestickOptions{Frame: ChartFrame{Label: "A"}, Compare: &s})
|
||||||
|
memo = ui.Local(r.Element, "mujica.memo.compare.missing", func() ChartMemoEntry { return ChartMemoEntry{} })
|
||||||
}, 640, 320)
|
}, 640, 320)
|
||||||
memo := ui.Local(r.Element, "mujica.memo.compare.missing", func() ChartMemoEntry { return ChartMemoEntry{} })
|
|
||||||
before := ChartID(memo.Val.([]float64))
|
before := ChartID(memo.Val.([]float64))
|
||||||
tt.Frame()
|
tt.Frame()
|
||||||
memo = ui.Local(r.Element, "mujica.memo.compare.missing", func() ChartMemoEntry { return ChartMemoEntry{} })
|
|
||||||
after := ChartID(memo.Val.([]float64))
|
after := ChartID(memo.Val.([]float64))
|
||||||
t.Logf("before=%s after=%s", before, after)
|
t.Logf("before=%s after=%s", before, after)
|
||||||
if before != after {
|
if before != after {
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ func TestMarketChartsStatesDisabledAndBoundaries(t *testing.T) {
|
|||||||
status := data.DataReady
|
status := data.DataReady
|
||||||
disabled, empty := false, false
|
disabled, empty := false, false
|
||||||
var r ChartResult
|
var r ChartResult
|
||||||
|
var box ui.Rect
|
||||||
tt := ui.NewTester(func(c *ui.Context) {
|
tt := ui.NewTester(func(c *ui.Context) {
|
||||||
core.Use(c, core.Settings{Density: theme.Compact})
|
core.Use(c, core.Settings{Density: theme.Compact})
|
||||||
ui.Column(c).Disabled(disabled).Width(600).Children(func() {
|
ui.Column(c).Disabled(disabled).Width(600).Children(func() {
|
||||||
@@ -75,6 +76,7 @@ func TestMarketChartsStatesDisabledAndBoundaries(t *testing.T) {
|
|||||||
}
|
}
|
||||||
r = CandlestickChart(c, candles, &v, opts)
|
r = CandlestickChart(c, candles, &v, opts)
|
||||||
}
|
}
|
||||||
|
box = r.Element.Bounds()
|
||||||
})
|
})
|
||||||
}, 620, 350)
|
}, 620, 350)
|
||||||
for range 10 {
|
for range 10 {
|
||||||
@@ -105,13 +107,15 @@ func TestMarketChartsStatesDisabledAndBoundaries(t *testing.T) {
|
|||||||
}
|
}
|
||||||
disabled = false
|
disabled = false
|
||||||
tt.Frame()
|
tt.Frame()
|
||||||
height := r.Element.Bounds().H
|
tt.Frame() // Bounds reads the previous frame
|
||||||
|
height := box.H
|
||||||
for _, st := range []data.DataStatus{data.DataLoading, data.DataFailed, data.DataReady} {
|
for _, st := range []data.DataStatus{data.DataLoading, data.DataFailed, data.DataReady} {
|
||||||
status = st
|
status = st
|
||||||
empty = st == data.DataReady
|
empty = st == data.DataReady
|
||||||
tt.Frame()
|
tt.Frame()
|
||||||
if r.Point != -1 || r.Element.Bounds().H != height {
|
tt.Frame()
|
||||||
t.Fatalf("state %v: point %d height %v want %v", st, r.Point, r.Element.Bounds().H, height)
|
if r.Point != -1 || box.H != height {
|
||||||
|
t.Fatalf("state %v: point %d height %v want %v", st, r.Point, box.H, height)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ func MultiChartLayout(c *ui.Context, state *MultiChartState, opts MultiChartLayo
|
|||||||
grid := ui.Box(c).Grid().Columns(cols).Gap(u * 2).Height(h).FillWidth()
|
grid := ui.Box(c).Grid().Columns(cols).Gap(u * 2).Height(h).FillWidth()
|
||||||
grid.Children(func() {
|
grid.Children(func() {
|
||||||
for i := range state.Count {
|
for i := range state.Count {
|
||||||
box := ui.Column(c).Key(i).MinWidth(0).MinHeight(0).Height((h - u*2*float32(rows-1)) / float32(rows)).Padding(u * 2).
|
box := ui.Column(c.Key(i)).MinWidth(0).MinHeight(0).Height((h - u*2*float32(rows-1)) / float32(rows)).Padding(u * 2).
|
||||||
Background(k.Surface).Radius(theme.CardRadius).Clip().Role(ui.RoleGroup).
|
Background(k.Surface).Radius(theme.CardRadius).Clip().Role(ui.RoleGroup).
|
||||||
Label(fmt.Sprintf(core.Msg(c, "multi_chart_layout.cell"), i+1, state.Cells[i].Symbol))
|
Label(fmt.Sprintf(core.Msg(c, "multi_chart_layout.cell"), i+1, state.Cells[i].Symbol))
|
||||||
if i == state.Active && state.Count > 1 {
|
if i == state.Active && state.Count > 1 {
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ func NetworkGraph(c *ui.Context, s *NetworkGraphState, nodes []GraphNode, edges
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
res, plot := ch.Build(spec)
|
res, plot := ch.Build(spec)
|
||||||
if plot == nil || plot.IsDisabled() {
|
if !plot.Valid() || plot.IsDisabled() {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
hit := func(x, y float32) string {
|
hit := func(x, y float32) string {
|
||||||
@@ -165,7 +165,7 @@ func NetworkGraph(c *ui.Context, s *NetworkGraphState, nodes []GraphNode, edges
|
|||||||
}
|
}
|
||||||
|
|
||||||
// networkInput drags, pans, zooms and moves the focused node.
|
// networkInput drags, pans, zooms and moves the focused node.
|
||||||
func networkInput(plot *ui.Element, s *NetworkGraphState, focus int, nodes []GraphNode, unit func(ui.Rect) float64, hit func(x, y float32) string) {
|
func networkInput(plot ui.Element, s *NetworkGraphState, focus int, nodes []GraphNode, unit func(ui.Rect) float64, hit func(x, y float32) string) {
|
||||||
b := plot.Bounds()
|
b := plot.Bounds()
|
||||||
r := ui.Rect{W: b.W, H: b.H}
|
r := ui.Rect{W: b.W, H: b.H}
|
||||||
move := func(id string, dx, dy float32) {
|
move := func(id string, dx, dy float32) {
|
||||||
@@ -187,8 +187,9 @@ func networkInput(plot *ui.Element, s *NetworkGraphState, focus int, nodes []Gra
|
|||||||
s.dragging = false
|
s.dragging = false
|
||||||
slog.Debug("mujica: network_graph drag", "node", s.drag)
|
slog.Debug("mujica: network_graph drag", "node", s.drag)
|
||||||
}
|
}
|
||||||
|
disabled := plot.IsDisabled()
|
||||||
plot.HandleInput(func(ev ui.InputEvent) bool {
|
plot.HandleInput(func(ev ui.InputEvent) bool {
|
||||||
if ev.Kind != ui.InputScroll || ev.DY == 0 || plot.IsDisabled() {
|
if ev.Kind != ui.InputScroll || ev.DY == 0 || disabled {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if ev.DY < 0 {
|
if ev.DY < 0 {
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ func TestNetworkGraphDragNodeAndPan(t *testing.T) {
|
|||||||
return NetworkGraph(c, &s, graphNodes, graphEdges, NetworkGraphOptions{Frame: ChartFrame{Label: "House"}})
|
return NetworkGraph(c, &s, graphNodes, graphEdges, NetworkGraphOptions{Frame: ChartFrame{Label: "House"}})
|
||||||
}}
|
}}
|
||||||
tt := ui.NewTester(h.view, 520, 420)
|
tt := ui.NewTester(h.view, 520, 420)
|
||||||
b := h.res.Element.Bounds()
|
b := h.box(tt)
|
||||||
// The 10×10 layout fits 240-48 DIPs, centered in the plot.
|
// The 10×10 layout fits 240-48 DIPs, centered in the plot.
|
||||||
cx, cy := b.X+b.W/2, b.Y+120
|
cx, cy := b.X+b.W/2, b.Y+120
|
||||||
ax, ay := cx-96, cy-96
|
ax, ay := cx-96, cy-96
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ func TestOHLCChartSharesDataAndDiffersInLook(t *testing.T) {
|
|||||||
view := MarketView{Count: 40}
|
view := MarketView{Count: 40}
|
||||||
ohlc := true
|
ohlc := true
|
||||||
var res ChartResult
|
var res ChartResult
|
||||||
|
var st *mktState
|
||||||
tt := ui.NewTester(func(c *ui.Context) {
|
tt := ui.NewTester(func(c *ui.Context) {
|
||||||
core.Use(c, core.Settings{})
|
core.Use(c, core.Settings{})
|
||||||
if ohlc {
|
if ohlc {
|
||||||
@@ -21,11 +22,12 @@ func TestOHLCChartSharesDataAndDiffersInLook(t *testing.T) {
|
|||||||
} else {
|
} else {
|
||||||
res = CandlestickChart(c, candles, &view, CandlestickOptions{Frame: ChartFrame{Label: "Bars"}})
|
res = CandlestickChart(c, candles, &view, CandlestickOptions{Frame: ChartFrame{Label: "Bars"}})
|
||||||
}
|
}
|
||||||
|
st = mktState0(res)
|
||||||
}, 600, 320)
|
}, 600, 320)
|
||||||
tt.Key(0, ui.KeyTab)
|
tt.Key(0, ui.KeyTab)
|
||||||
tt.Key(0, ui.KeyEnd)
|
tt.Key(0, ui.KeyEnd)
|
||||||
if res.Point != 59 || mktState0(res).drawn != 40 {
|
if res.Point != 59 || st.drawn != 40 {
|
||||||
t.Fatalf("point %d drawn %d", res.Point, mktState0(res).drawn)
|
t.Fatalf("point %d drawn %d", res.Point, st.drawn)
|
||||||
}
|
}
|
||||||
a := encode(t, tt.Image())
|
a := encode(t, tt.Image())
|
||||||
ohlc = false
|
ohlc = false
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ func ParallelCoordinates(c *ui.Context, filters *map[string][2]float64, axes []s
|
|||||||
}
|
}
|
||||||
drag := ui.Local(ch.Res.Element, "mujica.pc.drag", func() pcDrag { return pcDrag{axis: -1} })
|
drag := ui.Local(ch.Res.Element, "mujica.pc.drag", func() pcDrag { return pcDrag{axis: -1} })
|
||||||
keyAxis := ui.Local(ch.Res.Element, "mujica.pc.axis", func() int { return 0 })
|
keyAxis := ui.Local(ch.Res.Element, "mujica.pc.axis", func() int { return 0 })
|
||||||
spec.Input = func(plot *ui.Element, r ui.Rect) {
|
spec.Input = func(plot ui.Element, r ui.Rect) {
|
||||||
if plot.IsDisabled() {
|
if plot.IsDisabled() {
|
||||||
*drag = pcDrag{axis: -1}
|
*drag = pcDrag{axis: -1}
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ func TestParallelCoordinatesReadoutAndBrush(t *testing.T) {
|
|||||||
if got := chartReadout(tt); got != "Bede · Age 65 · Hymns 1 · Vigils no value" {
|
if got := chartReadout(tt); got != "Bede · Age 65 · Hymns 1 · Vigils no value" {
|
||||||
t.Fatalf("readout %q", got)
|
t.Fatalf("readout %q", got)
|
||||||
}
|
}
|
||||||
b := h.res.Element.Bounds()
|
b := h.box(tt)
|
||||||
plot := ui.Rect{X: b.X + 36, Y: b.Y + 24, W: b.W - 72, H: 240 - 32}
|
plot := ui.Rect{X: b.X + 36, Y: b.Y + 24, W: b.W - 72, H: 240 - 32}
|
||||||
// Age runs 20..80 on the first axis: brush 30..55.
|
// Age runs 20..80 on the first axis: brush 30..55.
|
||||||
y := func(v float32) float32 { return plot.Y + plot.H*(1-(v-20)/60) }
|
y := func(v float32) float32 { return plot.Y + plot.H*(1-(v-20)/60) }
|
||||||
@@ -58,7 +58,7 @@ func TestParallelCoordinatesHoverAndBad(t *testing.T) {
|
|||||||
return ParallelCoordinates(c, &filters, pcAxes, pcRows, ParallelCoordinatesOptions{Frame: ChartFrame{Label: "Monks"}})
|
return ParallelCoordinates(c, &filters, pcAxes, pcRows, ParallelCoordinatesOptions{Frame: ChartFrame{Label: "Monks"}})
|
||||||
}}
|
}}
|
||||||
tt := ui.NewTester(h.view, 520, 420)
|
tt := ui.NewTester(h.view, 520, 420)
|
||||||
b := h.res.Element.Bounds()
|
b := h.box(tt)
|
||||||
plot := ui.Rect{X: b.X + 36, Y: b.Y + 24, W: b.W - 72, H: 240 - 32}
|
plot := ui.Rect{X: b.X + 36, Y: b.Y + 24, W: b.W - 72, H: 240 - 32}
|
||||||
// Row 2 crosses this point between the first axes.
|
// Row 2 crosses this point between the first axes.
|
||||||
tt.Move(plot.X+plot.W/8, plot.Y+plot.H*(1-0.53125))
|
tt.Move(plot.X+plot.W/8, plot.Y+plot.H*(1-0.53125))
|
||||||
@@ -121,8 +121,9 @@ func TestParallelCoordinatesLargeDataBounded(t *testing.T) {
|
|||||||
h := &chartHarness{build: func(c *ui.Context) ChartResult {
|
h := &chartHarness{build: func(c *ui.Context) ChartResult {
|
||||||
return ParallelCoordinates(c, &filters, pcAxes, rows, ParallelCoordinatesOptions{Frame: ChartFrame{Label: "Large parallel"}})
|
return ParallelCoordinates(c, &filters, pcAxes, rows, ParallelCoordinatesOptions{Frame: ChartFrame{Label: "Large parallel"}})
|
||||||
}}
|
}}
|
||||||
|
var shown *[]int
|
||||||
|
h.built = func(r ChartResult) { shown = ui.Local(r.Element, "mujica.pc.visible", func() []int { return nil }) }
|
||||||
tt := ui.NewTester(h.view, 520, 420)
|
tt := ui.NewTester(h.view, 520, 420)
|
||||||
shown := ui.Local(h.res.Element, "mujica.pc.visible", func() []int { return nil })
|
|
||||||
if len(*shown) == 0 || len(*shown) > 480 {
|
if len(*shown) == 0 || len(*shown) > 480 {
|
||||||
t.Fatalf("built %d rows", len(*shown))
|
t.Fatalf("built %d rows", len(*shown))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ func TestPieChartReadoutAndHover(t *testing.T) {
|
|||||||
if got := chartReadout(tt); got != "Other · 8 · 8.0%" {
|
if got := chartReadout(tt); got != "Other · 8 · 8.0%" {
|
||||||
t.Fatalf("readout %q", got)
|
t.Fatalf("readout %q", got)
|
||||||
}
|
}
|
||||||
b := h.res.Element.Bounds()
|
b := h.box(tt)
|
||||||
plotTop := b.Y + 38 // below the one-line legend
|
plotTop := b.Y + 38 // below the one-line legend
|
||||||
cy := plotTop + 120
|
cy := plotTop + 120
|
||||||
tt.Move(b.X+b.W/2+60, cy-40) // upper right: the first slice
|
tt.Move(b.X+b.W/2+60, cy-40) // upper right: the first slice
|
||||||
|
|||||||
@@ -13,18 +13,16 @@ func TestPriceAlertLineDragAndTrigger(t *testing.T) {
|
|||||||
view := MarketView{Count: 60}
|
view := MarketView{Count: 60}
|
||||||
alerts := []PriceAlertLine{{ID: "a", Price: 100, Label: "Buy"}}
|
alerts := []PriceAlertLine{{ID: "a", Price: 100, Label: "Buy"}}
|
||||||
var fired []string
|
var fired []string
|
||||||
var res ChartResult
|
var st *mktState
|
||||||
_ = res
|
|
||||||
tt := ui.NewTester(func(c *ui.Context) {
|
tt := ui.NewTester(func(c *ui.Context) {
|
||||||
core.Use(c, core.Settings{})
|
core.Use(c, core.Settings{})
|
||||||
res = CandlestickChart(c, candles, &view, CandlestickOptions{Frame: ChartFrame{Label: "BTC"}, Alerts: &alerts,
|
st = mktState0(CandlestickChart(c, candles, &view, CandlestickOptions{Frame: ChartFrame{Label: "BTC"}, Alerts: &alerts,
|
||||||
OnAlert: func(a PriceAlertLine, last Candle) { fired = append(fired, a.ID) }})
|
OnAlert: func(a PriceAlertLine, last Candle) { fired = append(fired, a.ID) }}))
|
||||||
}, 800, 400)
|
}, 800, 400)
|
||||||
if !tt.HasText("BTC") {
|
if !tt.HasText("BTC") {
|
||||||
t.Fatal("not built")
|
t.Fatal("not built")
|
||||||
}
|
}
|
||||||
// Drag the line from its own y, as painted.
|
// Drag the line from its own y, as painted.
|
||||||
st := mktState0(res)
|
|
||||||
plot := st.plot
|
plot := st.plot
|
||||||
y := st.ys.Map(100)
|
y := st.ys.Map(100)
|
||||||
tt.Press(plot.X+100, y)
|
tt.Press(plot.X+100, y)
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ func TestRadarChartReadout(t *testing.T) {
|
|||||||
if got := chartReadout(tt); got != "Latin · Agnès 6 · Clare 9" {
|
if got := chartReadout(tt); got != "Latin · Agnès 6 · Clare 9" {
|
||||||
t.Fatalf("readout %q", got)
|
t.Fatalf("readout %q", got)
|
||||||
}
|
}
|
||||||
b := h.res.Element.Bounds()
|
b := h.box(tt)
|
||||||
cx, cy := b.X+b.W/2, b.Y+38+120+4
|
cx, cy := b.X+b.W/2, b.Y+38+120+4
|
||||||
tt.Key(0, ui.KeyEscape)
|
tt.Key(0, ui.KeyEscape)
|
||||||
tt.Move(cx, cy-60) // straight up: the first axis
|
tt.Move(cx, cy-60) // straight up: the first axis
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ func TestSankeyChartReadout(t *testing.T) {
|
|||||||
t.Fatalf("link %q", got)
|
t.Fatalf("link %q", got)
|
||||||
}
|
}
|
||||||
tt.Key(0, ui.KeyEscape)
|
tt.Key(0, ui.KeyEscape)
|
||||||
b := h.res.Element.Bounds()
|
b := h.box(tt)
|
||||||
tt.Move(b.X+8+4, b.Y+10) // the first node, at the top left
|
tt.Move(b.X+8+4, b.Y+10) // the first node, at the top left
|
||||||
if got := chartReadout(tt); got != "Tithes · in 0 · out 60" {
|
if got := chartReadout(tt); got != "Tithes · in 0 · out 60" {
|
||||||
t.Fatalf("hover %q", got)
|
t.Fatalf("hover %q", got)
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ func ScatterChart(c *ui.Context, selected *[]ScatterKey, groups []ScatterGroup,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
res, plot := ch.Build(spec)
|
res, plot := ch.Build(spec)
|
||||||
if plot != nil && !plot.IsDisabled() {
|
if plot.Valid() && !plot.IsDisabled() {
|
||||||
x, y, _ := plot.PointerPosition()
|
x, y, _ := plot.PointerPosition()
|
||||||
if _, _, held := plot.Dragged(); held {
|
if _, _, held := plot.Dragged(); held {
|
||||||
if !drag.on {
|
if !drag.on {
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ func TestScatterChartBoxSelect(t *testing.T) {
|
|||||||
return ScatterChart(c, &sel, scatterGroups, ScatterChartOptions{Frame: ChartFrame{Label: "Choir"}})
|
return ScatterChart(c, &sel, scatterGroups, ScatterChartOptions{Frame: ChartFrame{Label: "Choir"}})
|
||||||
}}
|
}}
|
||||||
tt := ui.NewTester(h.view, 520, 420)
|
tt := ui.NewTester(h.view, 520, 420)
|
||||||
b := h.res.Element.Bounds()
|
b := h.box(tt)
|
||||||
top := b.Y + 38
|
top := b.Y + 38
|
||||||
// Nice domains: x 0..10 over 52..W-12; y 0..10 over top+8..top+214.
|
// Nice domains: x 0..10 over 52..W-12; y 0..10 over top+8..top+214.
|
||||||
x := func(v float32) float32 { return b.X + 52 + (b.W-64)*v/10 }
|
x := func(v float32) float32 { return b.X + 52 + (b.W-64)*v/10 }
|
||||||
|
|||||||
@@ -150,14 +150,14 @@ func TestSparkBarFiniteWidthAndStates(t *testing.T) {
|
|||||||
|
|
||||||
func TestSparkBarMinimumHitWidth(t *testing.T) {
|
func TestSparkBarMinimumHitWidth(t *testing.T) {
|
||||||
for _, values := range [][]float64{nil, {1}} {
|
for _, values := range [][]float64{nil, {1}} {
|
||||||
var result ChartResult
|
var box ui.Rect
|
||||||
tt := ui.NewTester(func(c *ui.Context) {
|
tt := ui.NewTester(func(c *ui.Context) {
|
||||||
core.Use(c, core.Settings{})
|
core.Use(c, core.Settings{})
|
||||||
result = SparkBar(c, values, SparkBarOptions{Frame: ChartFrame{Label: "Bars"}})
|
box = SparkBar(c, values, SparkBarOptions{Frame: ChartFrame{Label: "Bars"}}).Element.Bounds()
|
||||||
}, 200, 100)
|
}, 200, 100)
|
||||||
tt.Frame()
|
tt.Frame()
|
||||||
if result.Element.Bounds().W < 28 {
|
if box.W < 28 {
|
||||||
t.Fatalf("hit width %v", result.Element.Bounds().W)
|
t.Fatalf("hit width %v", box.W)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -146,7 +146,7 @@ func Sunburst(c *ui.Context, path *[]string, root ChartNode, opts SunburstOption
|
|||||||
ChartText(p, ChartValue(c, sum, opts.Format), cx, cy+2, core.FontSize(c, theme.BodySize), k.Text, 0.5, 0)
|
ChartText(p, ChartValue(c, sum, opts.Format), cx, cy+2, core.FontSize(c, theme.BodySize), k.Text, 0.5, 0)
|
||||||
}
|
}
|
||||||
r, plot := ch.Build(spec)
|
r, plot := ch.Build(spec)
|
||||||
if plot != nil && !plot.IsDisabled() && plot.Shortcut(0, ui.KeyBackspace) && len(*path) > 0 {
|
if plot.Valid() && !plot.IsDisabled() && plot.Shortcut(0, ui.KeyBackspace) && len(*path) > 0 {
|
||||||
*path, res.value = (*path)[:len(*path)-1], true
|
*path, res.value = (*path)[:len(*path)-1], true
|
||||||
}
|
}
|
||||||
res.Point, res.changed, res.retry = r.Point, r.changed, r.retry
|
res.Point, res.changed, res.retry = r.Point, r.changed, r.retry
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ func TestSunburstReadoutAndDrill(t *testing.T) {
|
|||||||
if err := tt.Click("Abbey"); err != nil || len(path) != 0 {
|
if err := tt.Click("Abbey"); err != nil || len(path) != 0 {
|
||||||
t.Fatalf("breadcrumb back: %v %v", err, path)
|
t.Fatalf("breadcrumb back: %v %v", err, path)
|
||||||
}
|
}
|
||||||
b := h.res.Element.Bounds()
|
b := h.box(tt)
|
||||||
plotTop := b.Y + b.H - 20 - 8 - 240
|
plotTop := b.Y + b.H - 20 - 8 - 240
|
||||||
cx, cy := b.X+b.W/2, plotTop+120
|
cx, cy := b.X+b.W/2, plotTop+120
|
||||||
tt.Key(0, ui.KeyEscape)
|
tt.Key(0, ui.KeyEscape)
|
||||||
|
|||||||
+1
-1
@@ -89,7 +89,7 @@ func Treemap(c *ui.Context, path *[]string, root ChartNode, opts TreemapOptions)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
r, plot := ch.Build(spec)
|
r, plot := ch.Build(spec)
|
||||||
if plot != nil && !plot.IsDisabled() && plot.Shortcut(0, ui.KeyBackspace) && len(*path) > 0 {
|
if plot.Valid() && !plot.IsDisabled() && plot.Shortcut(0, ui.KeyBackspace) && len(*path) > 0 {
|
||||||
*path, res.value = (*path)[:len(*path)-1], true
|
*path, res.value = (*path)[:len(*path)-1], true
|
||||||
}
|
}
|
||||||
res.Element, res.Point, res.changed, res.retry = r.Element, r.Point, r.changed, r.retry
|
res.Element, res.Point, res.changed, res.retry = r.Element, r.Point, r.changed, r.retry
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ type TrendIndicatorOptions struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TrendIndicator shows signed change, direction, and semantic color.
|
// TrendIndicator shows signed change, direction, and semantic color.
|
||||||
func TrendIndicator(c *ui.Context, change float64, opts TrendIndicatorOptions) *ui.Element {
|
func TrendIndicator(c *ui.Context, change float64, opts TrendIndicatorOptions) ui.Element {
|
||||||
if opts.Precision < 0 || math.IsNaN(change) || math.IsInf(change, 0) {
|
if opts.Precision < 0 || math.IsNaN(change) || math.IsInf(change, 0) {
|
||||||
panic("mujica: TrendIndicator needs a number and Precision ≥ 0")
|
panic("mujica: TrendIndicator needs a number and Precision ≥ 0")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ func TestViolinPlotReadout(t *testing.T) {
|
|||||||
t.Fatalf("readout %q", got)
|
t.Fatalf("readout %q", got)
|
||||||
}
|
}
|
||||||
tt.Key(0, ui.KeyEscape)
|
tt.Key(0, ui.KeyEscape)
|
||||||
b := h.res.Element.Bounds()
|
b := h.box(tt)
|
||||||
tt.Move(b.X+52+(b.W-64)/6, b.Y+120)
|
tt.Move(b.X+52+(b.W-64)/6, b.Y+120)
|
||||||
if h.res.Point != 0 {
|
if h.res.Point != 0 {
|
||||||
t.Fatalf("hover %d", h.res.Point)
|
t.Fatalf("hover %d", h.res.Point)
|
||||||
@@ -62,13 +62,14 @@ func TestViolinPlotLargeDataAndDisabled(t *testing.T) {
|
|||||||
h := &chartHarness{build: func(c *ui.Context) ChartResult {
|
h := &chartHarness{build: func(c *ui.Context) ChartResult {
|
||||||
return ViolinPlot(c, groups, ViolinPlotOptions{Frame: ChartFrame{Label: "Large violin"}})
|
return ViolinPlot(c, groups, ViolinPlotOptions{Frame: ChartFrame{Label: "Large violin"}})
|
||||||
}}
|
}}
|
||||||
|
var shown *[]int
|
||||||
|
h.built = func(r ChartResult) { shown = ui.Local(r.Element, "mujica.violin.visible", func() []int { return nil }) }
|
||||||
tt := ui.NewTester(h.view, 520, 420)
|
tt := ui.NewTester(h.view, 520, 420)
|
||||||
tabTo(t, tt, "Large violin")
|
tabTo(t, tt, "Large violin")
|
||||||
tt.Key(0, ui.KeyRight)
|
tt.Key(0, ui.KeyRight)
|
||||||
if chartReadout(tt) != "Sample · median 49.5 · quartiles 24.75–74.25 · 100000 values" {
|
if chartReadout(tt) != "Sample · median 49.5 · quartiles 24.75–74.25 · 100000 values" {
|
||||||
t.Fatalf("large readout %q", chartReadout(tt))
|
t.Fatalf("large readout %q", chartReadout(tt))
|
||||||
}
|
}
|
||||||
shown := ui.Local(h.res.Element, "mujica.violin.visible", func() []int { return nil })
|
|
||||||
if len(*shown) != 1 {
|
if len(*shown) != 1 {
|
||||||
t.Fatalf("built %d violins", len(*shown))
|
t.Fatalf("built %d violins", len(*shown))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ func VolumeChart(c *ui.Context, candles []Candle, view *MarketView, opts VolumeC
|
|||||||
return strings.Join([]string{cd.Time.Format("2006-01-02 15:04"), core.Msg(c, "candlestick_chart.volume") + " " + data.StatisticFormat(cd.Volume, 0),
|
return strings.Join([]string{cd.Time.Format("2006-01-02 15:04"), core.Msg(c, "candlestick_chart.volume") + " " + data.StatisticFormat(cd.Volume, 0),
|
||||||
core.TrendWord(c, core.TrendSign(cd.Close-cd.Open))}, " · ")
|
core.TrendWord(c, core.TrendSign(cd.Close-cd.Open))}, " · ")
|
||||||
}
|
}
|
||||||
|
st := m.st0() // painting runs after the build, when Local is gone
|
||||||
spec.Draw = func(p *ui.Painter, r ui.Rect, active int) {
|
spec.Draw = func(p *ui.Painter, r ui.Rect, active int) {
|
||||||
plot, band, ys, ticks, step := geom(r)
|
plot, band, ys, ticks, step := geom(r)
|
||||||
internal.AxisY(p, plot, ys, ticks, func(v float64) string { return volumeShort(v, step) }, size, k)
|
internal.AxisY(p, plot, ys, ticks, func(v float64) string { return volumeShort(v, step) }, size, k)
|
||||||
@@ -99,14 +100,14 @@ func VolumeChart(c *ui.Context, candles []Candle, view *MarketView, opts VolumeC
|
|||||||
p.Fill(bar, col, 0)
|
p.Fill(bar, col, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.st0().drawn = m.to - m.from
|
st.drawn = m.to - m.from
|
||||||
if at >= m.from && at < m.to {
|
if at >= m.from && at < m.to {
|
||||||
x := internal.Snap(p, band.Center(at-m.from))
|
x := internal.Snap(p, band.Center(at-m.from))
|
||||||
p.Line(x, plot.Y, x, plot.Y+plot.H, 1, k.TextMuted)
|
p.Line(x, plot.Y, x, plot.Y+plot.H, 1, k.TextMuted)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res, plot := ch.Build(spec)
|
res, plot := ch.Build(spec)
|
||||||
if plot != nil && !plot.IsDisabled() {
|
if plot.Valid() && !plot.IsDisabled() {
|
||||||
room := m.room()
|
room := m.room()
|
||||||
switch {
|
switch {
|
||||||
case plot.Shortcut(ui.Shift, ui.KeyLeft):
|
case plot.Shortcut(ui.Shift, ui.KeyLeft):
|
||||||
|
|||||||
Loaded 100 of 603 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user