-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathprogressBar.go
113 lines (93 loc) · 3.16 KB
/
progressBar.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package rui
import (
"strconv"
"strings"
)
// Constants for [ProgressBar] specific properties and events
const (
// ProgressBarMax is the constant for "progress-max" property tag.
//
// Used by ProgressBar.
// Maximum value, default is 1.
//
// Supported types: float, int, string.
//
// Internal type is float, other types converted to it during assignment.
ProgressBarMax PropertyName = "progress-max"
// ProgressBarValue is the constant for "progress-value" property tag.
//
// Used by ProgressBar.
// Current value, default is 0.
//
// Supported types: float, int, string.
//
// Internal type is float, other types converted to it during assignment.
ProgressBarValue PropertyName = "progress-value"
)
// ProgressBar represents a ProgressBar view
type ProgressBar interface {
View
}
type progressBarData struct {
viewData
}
// NewProgressBar create new ProgressBar object and return it
func NewProgressBar(session Session, params Params) ProgressBar {
view := new(progressBarData)
view.init(session)
setInitParams(view, params)
return view
}
func newProgressBar(session Session) View {
return new(progressBarData)
}
func (progress *progressBarData) init(session Session) {
progress.viewData.init(session)
progress.tag = "ProgressBar"
progress.normalize = normalizeProgressBarTag
progress.changed = progress.propertyChanged
}
func normalizeProgressBarTag(tag PropertyName) PropertyName {
tag = defaultNormalize(tag)
switch tag {
case Max, "progress-bar-max", "progressbar-max":
return ProgressBarMax
case Value, "progress-bar-value", "progressbar-value":
return ProgressBarValue
}
return tag
}
func (progress *progressBarData) propertyChanged(tag PropertyName) {
switch tag {
case ProgressBarMax:
progress.Session().updateProperty(progress.htmlID(), "max",
strconv.FormatFloat(GetProgressBarMax(progress), 'f', -1, 32))
case ProgressBarValue:
progress.Session().updateProperty(progress.htmlID(), "value",
strconv.FormatFloat(GetProgressBarValue(progress), 'f', -1, 32))
default:
progress.viewData.propertyChanged(tag)
}
}
func (progress *progressBarData) htmlTag() string {
return "progress"
}
func (progress *progressBarData) htmlProperties(self View, buffer *strings.Builder) {
progress.viewData.htmlProperties(self, buffer)
buffer.WriteString(` max="`)
buffer.WriteString(strconv.FormatFloat(GetProgressBarMax(progress), 'f', -1, 64))
buffer.WriteByte('"')
buffer.WriteString(` value="`)
buffer.WriteString(strconv.FormatFloat(GetProgressBarValue(progress), 'f', -1, 64))
buffer.WriteByte('"')
}
// GetProgressBarMax returns the max value of ProgressBar subview.
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetProgressBarMax(view View, subviewID ...string) float64 {
return floatStyledProperty(view, subviewID, ProgressBarMax, 1)
}
// GetProgressBarValue returns the value of ProgressBar subview.
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetProgressBarValue(view View, subviewID ...string) float64 {
return floatStyledProperty(view, subviewID, ProgressBarValue, 0)
}