WIP components (as built)
This commit is contained in:
110 files changed
+3975
-273
No files matched your search
+37
-18
@@ -10,10 +10,10 @@ import (
|
||||
"mujicaui/theme"
|
||||
)
|
||||
|
||||
// SymbolSearchState is the query and the market filter, empty for all markets.
|
||||
type SymbolSearchState struct {
|
||||
Query, Market string
|
||||
focusFirst bool
|
||||
cursor int
|
||||
}
|
||||
|
||||
// SymbolSearchOptions configure a SymbolSearch.
|
||||
@@ -31,7 +31,6 @@ type SymbolSearchOptions struct {
|
||||
// SymbolSearchView is a built SymbolSearch and this frame's events.
|
||||
type SymbolSearchView struct {
|
||||
Element *ui.Element
|
||||
// Changed asks the caller to search again for State.Query and State.Market.
|
||||
Changed bool
|
||||
// Chosen is the symbol picked when Picked is set.
|
||||
Chosen MarketSymbol
|
||||
@@ -39,7 +38,6 @@ type SymbolSearchView struct {
|
||||
Retry bool
|
||||
}
|
||||
|
||||
// SymbolSearch finds symbols by code or name, filtered by market, with recent picks; the caller supplies results.
|
||||
func SymbolSearch(c *ui.Context, s *SymbolSearchState, results []MarketSymbol, opts SymbolSearchOptions) SymbolSearchView {
|
||||
if s == nil {
|
||||
panic("mujica: SymbolSearch needs a state")
|
||||
@@ -48,6 +46,11 @@ func SymbolSearch(c *ui.Context, s *SymbolSearchState, results []MarketSymbol, o
|
||||
u := Density(c).Unit()
|
||||
var v SymbolSearchView
|
||||
v.Element = ui.Column(c).Gap(u * 2).Disabled(opts.Disabled)
|
||||
opts.Disabled = v.Element.IsDisabled()
|
||||
if opts.Disabled {
|
||||
copy := *s
|
||||
s = ©
|
||||
}
|
||||
v.Element.Children(func() {
|
||||
ui.Row(c).Gap(u * 2).AlignItems(ui.Center).Children(func() {
|
||||
in := SearchInput(c, &s.Query, SearchInputOptions{Placeholder: msg(c, "symbol_search.placeholder"), Disabled: opts.Disabled})
|
||||
@@ -75,11 +78,11 @@ func SymbolSearch(c *ui.Context, s *SymbolSearchState, results []MarketSymbol, o
|
||||
v.Retry = Button(c, msg(c, "symbol_search.retry"), ButtonOptions{Variant: Secondary}).Clicked()
|
||||
})
|
||||
return
|
||||
case s.Query == "":
|
||||
list, title = opts.Recent, msg(c, "symbol_search.recent")
|
||||
case opts.Loading && len(results) == 0:
|
||||
Spinner(c, SpinnerOptions{Label: msg(c, "symbol_search.searching"), ShowLabel: true})
|
||||
return
|
||||
case s.Query == "":
|
||||
list, title = opts.Recent, msg(c, "symbol_search.recent")
|
||||
case len(results) == 0:
|
||||
ui.Text(c, msg(c, "symbol_search.no_results")).TextColor(k.TextMuted).Role(ui.RoleStatus)
|
||||
return
|
||||
@@ -87,15 +90,30 @@ func SymbolSearch(c *ui.Context, s *SymbolSearchState, results []MarketSymbol, o
|
||||
if title != "" && len(list) > 0 {
|
||||
ui.Text(c, title).Font(theme.SerifFont).FontSize(FontSize(c, theme.CaptionSize)).TextColor(k.TextMuted)
|
||||
}
|
||||
ui.Scroll(c).MaxHeight(320).Children(func() {
|
||||
ui.Column(c).Gap(2).FocusGroup(ui.Vertical).Role(ui.RoleList).Children(func() {
|
||||
for i, sym := range list {
|
||||
if symbolSearchRow(c, sym, i == 0 && s.focusFirst) {
|
||||
v.Chosen, v.Picked = sym, true
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
rows := ui.Local(v.Element, "mujica.symbol.rows", func() ui.ListState { return ui.ListState{} })
|
||||
rows.Key = func(i int) any { return list[i].Market + ":" + list[i].Code }
|
||||
rows.Label = func(i int) string { return symbolBadgeName(list[i]) }
|
||||
rows.Selected = &s.cursor
|
||||
if s.focusFirst {
|
||||
s.cursor = 0
|
||||
rows.ScrollTo(0, ui.Start)
|
||||
}
|
||||
restore := dataSelectTheme(c, 0)
|
||||
resultList := ui.List(c, rows, len(list), func(i int) {
|
||||
if symbolSearchRow(c, list[i], i == s.cursor) {
|
||||
s.cursor = i
|
||||
v.Chosen, v.Picked = list[i], true
|
||||
}
|
||||
}).Height(320).MaxHeight(320)
|
||||
restore()
|
||||
internal.Ring(resultList, k.Focus, theme.ControlRadius)
|
||||
if s.focusFirst || v.Picked {
|
||||
resultList.Focus()
|
||||
}
|
||||
if !resultList.IsDisabled() && resultList.Submitted() && s.cursor >= 0 && s.cursor < len(list) {
|
||||
v.Chosen, v.Picked = list[s.cursor], true
|
||||
}
|
||||
|
||||
s.focusFirst = false
|
||||
})
|
||||
if v.Element.IsDisabled() {
|
||||
@@ -107,21 +125,22 @@ func SymbolSearch(c *ui.Context, s *SymbolSearchState, results []MarketSymbol, o
|
||||
return v
|
||||
}
|
||||
|
||||
func symbolSearchRow(c *ui.Context, sym MarketSymbol, focus bool) bool {
|
||||
func symbolSearchRow(c *ui.Context, sym MarketSymbol, selected bool) bool {
|
||||
k := Tokens(c)
|
||||
d := Density(c)
|
||||
b := ui.ButtonBase(c).Key(sym.Market+":"+sym.Code).MinHeight(d.ControlHeight()).Padding(0, d.Unit()*2).Gap(d.Unit() * 3).
|
||||
Justify(ui.Start).Radius(theme.ControlRadius).Label(symbolBadgeName(sym)).Role(ui.RoleListItem)
|
||||
internal.Ring(b, k.Focus, theme.ControlRadius)
|
||||
if focus {
|
||||
b.Focus()
|
||||
}
|
||||
|
||||
if b.Hovered() {
|
||||
b.Background(k.SurfaceHover)
|
||||
}
|
||||
b.Children(func() {
|
||||
ui.Text(c, sym.Code).Font(theme.MonoFont).FontWeight(700).Width(80).SingleLine()
|
||||
ui.Text(c, sym.Name).SingleLine().Grow(1).MinWidth(0).TextColor(k.Text)
|
||||
if selected {
|
||||
ui.Icon(c, icons.Must("check")).Size(14, 14).TextColor(k.AccentText)
|
||||
}
|
||||
if sym.Market != "" {
|
||||
ui.Text(c, sym.Market).FontSize(FontSize(c, theme.CaptionSize)).TextColor(k.TextMuted)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user