2023-02-01 23:48:16 -07:00
|
|
|
package basicElements
|
2023-01-17 18:16:03 -07:00
|
|
|
|
|
|
|
import "image"
|
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/theme"
|
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
|
|
|
|
|
|
|
|
// ProgressBar displays a visual indication of how far along a task is.
|
|
|
|
type ProgressBar struct {
|
|
|
|
*core.Core
|
|
|
|
core core.CoreControl
|
|
|
|
progress float64
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewProgressBar creates a new progress bar displaying the given progress
|
|
|
|
// level.
|
|
|
|
func NewProgressBar (progress float64) (element *ProgressBar) {
|
|
|
|
element = &ProgressBar { progress: progress }
|
2023-01-31 12:54:43 -07:00
|
|
|
element.Core, element.core = core.NewCore(element.draw)
|
2023-01-17 18:16:03 -07:00
|
|
|
element.core.SetMinimumSize(theme.Padding() * 2, theme.Padding() * 2)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetProgress sets the progress level of the bar.
|
|
|
|
func (element *ProgressBar) SetProgress (progress float64) {
|
|
|
|
if progress == element.progress { return }
|
|
|
|
element.progress = progress
|
|
|
|
if element.core.HasImage() {
|
|
|
|
element.draw()
|
2023-01-19 14:49:34 -07:00
|
|
|
element.core.DamageAll()
|
2023-01-17 18:16:03 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (element *ProgressBar) draw () {
|
2023-01-31 14:18:10 -07:00
|
|
|
bounds := element.Bounds()
|
2023-01-17 18:16:03 -07:00
|
|
|
|
2023-01-28 23:49:01 -07:00
|
|
|
pattern, inset := theme.SunkenPattern(theme.PatternState { })
|
2023-01-31 14:18:10 -07:00
|
|
|
artist.FillRectangle(element, pattern, bounds)
|
2023-01-28 23:49:01 -07:00
|
|
|
bounds = inset.Apply(bounds)
|
2023-01-17 18:16:03 -07:00
|
|
|
meterBounds := image.Rect (
|
2023-01-28 23:49:01 -07:00
|
|
|
bounds.Min.X, bounds.Min.Y,
|
|
|
|
bounds.Min.X + int(float64(bounds.Dx()) * element.progress),
|
|
|
|
bounds.Max.Y)
|
|
|
|
accent, _ := theme.AccentPattern(theme.PatternState { })
|
2023-01-31 14:18:10 -07:00
|
|
|
artist.FillRectangle(element, accent, meterBounds)
|
2023-01-17 18:16:03 -07:00
|
|
|
}
|