Files
MujicaUI/chart_type_switcher.go
T

38 lines
1.1 KiB
Go

package mujica
import (
"fmt"
"log/slog"
"github.com/egoist/mygo/ui"
)
// ChartTypeSwitcherOptions configure a ChartTypeSwitcher.
type ChartTypeSwitcherOptions struct {
Disabled bool
}
// ChartTypeSwitcher chooses candles, OHLC, line, area, or Heikin-Ashi.
func ChartTypeSwitcher(c *ui.Context, value *ChartType, opts ChartTypeSwitcherOptions) ChoiceResult {
if value == nil {
panic("mujica: ChartTypeSwitcher needs a value")
}
if *value < ChartCandles || *value > ChartHeikinAshi {
panic(fmt.Sprintf("mujica: unknown ChartType %d", *value))
}
var items []ToggleItem[ChartType]
for t := ChartCandles; t <= ChartHeikinAshi; t++ {
items = append(items, ToggleItem[ChartType]{Value: t, Label: msg(c, fmt.Sprintf("chart_type_switcher.type%d", t))})
}
sel := []ChartType{*value}
var r ChoiceResult
ui.Row(c).Disabled(opts.Disabled).Children(func() {
r = ToggleGroup(c, &sel, items, ToggleGroupOptions{Label: msg(c, "chart_type_switcher.label")})
})
if r.Changed() {
*value = sel[0]
slog.Debug("mujica: chart_type_switcher changed", "type", *value)
}
return r
}