forked from wtfutil/wtf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathposition_settings.go
51 lines (38 loc) · 1.31 KB
/
position_settings.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
package cfg
import (
"github.com/olebedev/config"
)
const (
positionPath = "position"
)
// PositionSettings represents the onscreen location of a widget
type PositionSettings struct {
Validations *Validations
Height int
Left int
Top int
Width int
}
// NewPositionSettingsFromYAML creates and returns a new instance of cfg.Position
func NewPositionSettingsFromYAML(moduleName string, moduleConfig *config.Config) PositionSettings {
var currVal int
var err error
validations := NewValidations()
// Parse the positional data from the config data
currVal, err = moduleConfig.Int(positionPath + ".top")
validations.append("top", newPositionValidation("top", currVal, err))
currVal, err = moduleConfig.Int(positionPath + ".left")
validations.append("left", newPositionValidation("left", currVal, err))
currVal, err = moduleConfig.Int(positionPath + ".width")
validations.append("width", newPositionValidation("width", currVal, err))
currVal, err = moduleConfig.Int(positionPath + ".height")
validations.append("height", newPositionValidation("height", currVal, err))
pos := PositionSettings{
Validations: validations,
Top: validations.intValueFor("top"),
Left: validations.intValueFor("left"),
Width: validations.intValueFor("width"),
Height: validations.intValueFor("height"),
}
return pos
}