Progress
Example sourceGo · Copyable
This is the complete source for the gallery example above.examples/components/progress.go
Reuse the component construction and Render methods in a scaffolded project. The example’s registerSection and shared helpers are provided by the component gallery.
package main
import (
"github.com/dyike/keel/ui/core"
"github.com/dyike/keel/ui/el"
"github.com/dyike/keel/ui/kit"
"github.com/dyike/keel/ui/theme"
)
func init() {
registerSection("progress", "feedback", func() core.Widget {
done := kit.Progress(demoText("Import orders", "导入订单"))
done.SetValue(0.42)
busy := kit.Progress(demoText("Syncing · Thin bar", "同步中 · 细条")).Height(4).Rounded(0)
busy.SetIndeterminate(true)
custom := kit.Progress(demoText("Custom colors and border", "自定义颜色与边框")).Height(16).Rounded(2)
custom.SetValue(.65)
return el.Embed(el.ViewFunc(func(cx *el.Context) el.Element {
return el.Div().P(24).Gap(16).W(el.Dp(360)).MaxW(el.Full).Child(done.Render(cx), busy.Render(cx), custom.Color(theme.Success).TrackStyle(func(e *el.DivEl) { e.Border(1, theme.Border).Bg(theme.Surface) }).Render(cx),
el.Div().Row().Gap(8).Child(
kit.Button("+10%", func() { done.SetValue(done.Value() + 0.1) }).Variant(kit.ButtonSecondary).Render(cx),
kit.Button(demoText("Reset", "重置"), func() { done.SetValue(0) }).Variant(kit.ButtonGhost).Render(cx)))
}))
})
}
Labeled progress bar.
p := kit.Progress("Import orders")
p.SetValue(0.42) // Show 42%
p.SetIndeterminate(true) // When the total amount is unknown, a progress block sliding back and forth is displayed.
SetValuewill clamp the value to 0–1 (NaN returns to zero) and exit indeterminate mode. When the reduced motion is turned on, the indeterminate progress is displayed statically.
Agent: role progressbar, value is percentage or indeterminate.
Verify: go run ./examples/components -section progress, add -theme dark to check the dark theme.
See ProgressCircle for circle progress and center content.
Height(dp) sets the bar height, range 1–128dp, default 8; Color(c) overrides the fill color and turns off the theme gradient of this instance; Rounded(dp) sets the track and progress block rounded corners, 0 is right angle. Illegal values are ignored. TrackStyle(func(*el.DivEl)) sets the track background, border, etc. after the default style of each frame; nil restores the default and does not retain element references. Labels and percentages are not affected by track styles; the progress block fills the inner height of the track. Configuration is available in both deterministic and indeterminate modes.
Determine the progress update using a 200ms smooth transition (kit.ProgressDuration), and continuous updates from the current display position. Displays the target value immediately upon first display, return from indeterminate mode, and reduced motion. Value(), Percent and Agent semantics always return the target value, only graphical interpolation. Animation uses the frame clock and does not create timers or goroutines.