whispervis/widgets/graphics.go

54 lines
1.4 KiB
Go
Raw Normal View History

2018-10-24 20:43:31 +02:00
package widgets
import (
"github.com/gopherjs/vecty"
"github.com/gopherjs/vecty/elem"
2018-10-24 22:48:53 +02:00
"github.com/status-im/whispervis/storage"
2018-10-24 20:43:31 +02:00
)
// Graphics represents graphics configuration widget.
type Graphics struct {
vecty.Core
rtSwitch *Switch
2018-10-24 22:05:23 +02:00
fpsRadio *RadioGroup
2018-10-26 16:38:49 +02:00
blinkRange *Range
2018-10-24 20:43:31 +02:00
collapsable *Collapsable
conf SceneConfigurator
2018-10-24 20:43:31 +02:00
}
// NewGraphics creates a new Graphics widget. It needs to have
// access to scene configuration, as it configures mostly things from it.
2018-10-24 22:48:53 +02:00
func NewGraphics(conf SceneConfigurator) *Graphics {
g := &Graphics{
conf: conf,
}
2018-10-24 22:48:53 +02:00
g.rtSwitch = NewSwitch("Render throttler", storage.RT(), conf.ToggleRenderThrottler)
g.fpsRadio = NewRadioGroup("FPS", storage.FPS(), conf.ChangeFPS, []int{60, 30, 20, 15})
2018-10-27 09:45:12 +02:00
g.blinkRange = NewRange("Blink:", BlinkDescription, storage.BlinkTime(), 10, 1500, conf.ChangeBlinkTime)
2018-10-24 20:43:31 +02:00
g.collapsable = NewCollapsable("Graphics:", false,
g.applyButton,
2018-10-24 22:05:23 +02:00
g.fpsRadio,
2018-10-24 20:43:31 +02:00
g.rtSwitch,
2018-10-26 16:38:49 +02:00
g.blinkRange,
2018-10-24 20:43:31 +02:00
)
return g
}
// Render implements vecty's Component interface for Graphics.
func (g *Graphics) Render() vecty.ComponentOrHTML {
return Widget(
g.collapsable,
)
}
2018-10-24 22:05:23 +02:00
// FIXME: it exists due to limitations of collapsible.
2018-10-24 20:43:31 +02:00
func (g *Graphics) applyButton() vecty.ComponentOrHTML {
2018-10-24 22:05:23 +02:00
return elem.Span()
2018-10-24 20:43:31 +02:00
}
2018-10-26 16:38:49 +02:00
const (
BlinkDescription = "How many milliseconds should blink last. You may want to change this value to make animations more interesting depending on the length of the total simulation"
)