Esempio n. 1
0
// IntegerScale adds an integer scale widget.
//
func IntegerScale(key *cftype.Key) {
	if key.NbElements > 1 { // TODO: remove temp test
		key.Log().Info("IntegerScale multi", key.NbElements, key.Type.String())
	}

	value := key.Value().Int()
	minValue, maxValue := minMaxValues(key)

	step := (maxValue - minValue) / 20
	if step < 1 {
		step = 1
	}
	adjustment := newgtk.Adjustment(float64(value), minValue, maxValue, 1, step, 0)
	w := newgtk.Scale(gtk.ORIENTATION_HORIZONTAL, adjustment)
	w.Set("digits", 0)

	PackValuerAsInt(key, WrapKeyScale(key, w), w, value)
}
Esempio n. 2
0
// Float adds a float selector widget. SpinButton or Horizontal Scale
//
func Float(key *cftype.Key) {
	if key.NbElements > 1 { // TODO: remove temp test
		key.Log().Info("Float multi", key.NbElements, key.Type.String())
	}

	values := key.Value().ListFloat()
	minValue, maxValue := minMaxValues(key)

	var valuers []WidgetValuer

	for k := 0; k < key.NbElements; k++ {
		var value float64
		if k < len(values) {
			value = values[k]
		}

		switch key.Type {
		case cftype.KeyFloatScale:
			adjustment := newgtk.Adjustment(
				value,
				minValue,
				maxValue,
				(maxValue-minValue)/20,
				(maxValue-minValue)/10, 0,
			)
			w := newgtk.Scale(gtk.ORIENTATION_HORIZONTAL, adjustment)
			w.Set("digits", 3)

			key.PackSubWidget(WrapKeyScale(key, w))
			valuers = append(valuers, w)

		case cftype.KeyFloatSpin:
			w := newgtk.SpinButtonWithRange(minValue, maxValue, 1)
			w.Set("digits", 3)
			w.SetValue(value)

			key.PackSubWidget(w)
			valuers = append(valuers, w)
		}
	}

	switch {
	case key.NbElements == 1:
		key.PackKeyWidget(key,
			func() interface{} { return valuers[0].GetValue() },
			func(uncast interface{}) { valuers[0].SetValue(uncast.(float64)) },
		)
		oldval, e := key.Storage().Default(key.Group, key.Name)
		if e == nil {
			PackReset(key, oldval.Float())
		}

	default:
		key.PackKeyWidget(key,
			func() interface{} { return listValuerGet(valuers) },
			func(uncast interface{}) { listValuerSet(valuers, uncast.([]float64)) },
		)
		oldval, e := key.Storage().Default(key.Group, key.Name)
		if e == nil {
			PackReset(key, oldval.ListFloat())
		}
	}
}