github.com/wtfutil/wtf@v0.43.0/cfg/position_settings.go (about)

     1  package cfg
     2  
     3  import (
     4  	"github.com/olebedev/config"
     5  )
     6  
     7  const (
     8  	positionPath = "position"
     9  )
    10  
    11  // PositionSettings represents the onscreen location of a widget
    12  type PositionSettings struct {
    13  	Validations *Validations
    14  
    15  	Height int
    16  	Left   int
    17  	Top    int
    18  	Width  int
    19  }
    20  
    21  // NewPositionSettingsFromYAML creates and returns a new instance of cfg.Position
    22  func NewPositionSettingsFromYAML(moduleConfig *config.Config) PositionSettings {
    23  	var currVal int
    24  	var err error
    25  
    26  	validations := NewValidations()
    27  
    28  	// Parse the positional data from the config data
    29  	currVal, err = moduleConfig.Int(positionPath + ".top")
    30  	validations.append("top", newPositionValidation("top", currVal, err))
    31  
    32  	currVal, err = moduleConfig.Int(positionPath + ".left")
    33  	validations.append("left", newPositionValidation("left", currVal, err))
    34  
    35  	currVal, err = moduleConfig.Int(positionPath + ".width")
    36  	validations.append("width", newPositionValidation("width", currVal, err))
    37  
    38  	currVal, err = moduleConfig.Int(positionPath + ".height")
    39  	validations.append("height", newPositionValidation("height", currVal, err))
    40  
    41  	pos := PositionSettings{
    42  		Validations: validations,
    43  
    44  		Top:    validations.intValueFor("top"),
    45  		Left:   validations.intValueFor("left"),
    46  		Width:  validations.intValueFor("width"),
    47  		Height: validations.intValueFor("height"),
    48  	}
    49  
    50  	return pos
    51  }