本文整理匯總了Golang中github.com/sqp/godock/widgets/cfbuild/cftype.Key.NbElements方法的典型用法代碼示例。如果您正苦於以下問題:Golang Key.NbElements方法的具體用法?Golang Key.NbElements怎麽用?Golang Key.NbElements使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/sqp/godock/widgets/cfbuild/cftype.Key
的用法示例。
在下文中一共展示了Key.NbElements方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ColorSelector
// ColorSelector adds a color selector widget.
//
func ColorSelector(key *cftype.Key) {
values := key.Value().ListFloat()
if len(values) == 3 {
values = append(values, 1) // no transparency.
}
gdkColor := gdk.NewRGBA(values...)
widget := newgtk.ColorButtonWithRGBA(gdkColor)
var getValue func() interface{}
switch key.Type {
case cftype.KeyColorSelectorRGB:
key.NbElements = 3
getValue = func() interface{} { return widget.GetRGBA().Floats()[:3] } // Need to trunk ?
case cftype.KeyColorSelectorRGBA:
key.NbElements = 4
getValue = func() interface{} { return widget.GetRGBA().Floats() }
}
widget.Set("use-alpha", key.IsType(cftype.KeyColorSelectorRGBA))
key.PackKeyWidget(key,
getValue,
func(uncast interface{}) { widget.SetRGBA(gdk.NewRGBA(uncast.([]float64)...)) },
widget,
)
oldval, e := key.Storage().Default(key.Group, key.Name)
if e == nil {
PackReset(key, oldval.ListFloat())
}
}
示例2: IntegerSize
// IntegerSize adds an integer selector widget.
//
func IntegerSize(key *cftype.Key) {
if key.NbElements > 1 { // TODO: remove temp test
key.Log().Info("IntegerSize multi", key.NbElements, key.Type.String())
}
toggle := newgtk.ToggleButton()
img := newgtk.ImageFromIconName("media-playback-pause", gtk.ICON_SIZE_MENU) // get better image.
toggle.SetImage(img)
values := key.Value().ListInt()
minValue, maxValue := minMaxValues(key)
var valuers []WidgetValuer
key.NbElements *= 2 // Two widgets to add.
// Value pair data.
var firstValue int
var firstWidget *gtk.SpinButton
var cbBlock func() func()
for k := 0; k < key.NbElements; k++ {
var value int
if k < len(values) {
value = values[k]
}
w := newgtk.SpinButtonWithRange(minValue, maxValue, 1)
w.SetValue(float64(value))
key.PackSubWidget(w)
valuers = append(valuers, w)
if k&1 == 0 { // first value, separator
label := newgtk.Label("x")
key.PackSubWidget(label)
firstWidget = w
firstValue = value
} else { // second value. connect both spin values.
if firstValue == value {
toggle.SetActive(true)
}
cb0, e := firstWidget.Connect("value-changed", onValuePairChanged, &valuePair{
linked: w,
toggle: toggle})
key.Log().Err(e, "IntegerSize connect value-changed 1")
cb1, e := w.Connect("value-changed", onValuePairChanged, &valuePair{
linked: firstWidget,
toggle: toggle})
key.Log().Err(e, "IntegerSize connect value-changed 2")
cbBlock = func() func() {
firstWidget.HandlerBlock(cb0)
w.HandlerBlock(cb1)
return func() {
firstWidget.HandlerUnblock(cb0)
w.HandlerUnblock(cb1)
}
}
}
}
setValue := func(uncast interface{}) {
if cbBlock == nil {
key.Log().NewErr("no valuePair callbacks", "IntegerSize", key.Name)
} else {
defer cbBlock()() // This disables now and reenables during defer.
}
values := uncast.([]int)
if len(values) < 2 {
key.Log().NewErr("not enough values provided", "IntegerSize set value", key.Name, values)
values = []int{0, 0}
}
listValuerSet(valuers, cast.IntsToFloats(values))
toggle.SetActive(values[0] == values[1])
}
key.PackKeyWidget(key,
func() interface{} { return cast.FloatsToInts(listValuerGet(valuers)) },
setValue,
toggle,
)
oldval, e := key.Storage().Default(key.Group, key.Name)
key.Log().Err(e, "IntegerSize original value")
if e == nil {
PackReset(key, oldval.ListInt())
}
}