1 Star 0 Fork 1

wmdng/walk

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
slider.go 2.24 KB
一键复制 编辑 原始数据 按行查看 历史
wmdng 提交于 2022-11-20 15:46 . clone from github.com//lxn//walk
// Copyright 2016 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"log"
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
)
func main() {
var slv, slh *walk.Slider
var maxEdit, minEdit, valueEdit *walk.NumberEdit
data := struct{ Min, Max, Value int }{0, 100, 30}
MainWindow{
Title: "Walk Slider Example",
MinSize: Size{320, 240},
Layout: HBox{},
Children: []Widget{
Slider{
AssignTo: &slv,
MinValue: data.Min,
MaxValue: data.Max,
Value: data.Value,
Orientation: Vertical,
OnValueChanged: func() {
data.Value = slv.Value()
valueEdit.SetValue(float64(data.Value))
},
},
Composite{
Layout: Grid{Columns: 3},
StretchFactor: 4,
Children: []Widget{
Label{Text: "Min value"},
Label{Text: "Value"},
Label{Text: "Max value"},
NumberEdit{
AssignTo: &minEdit,
Value: float64(data.Min),
OnValueChanged: func() {
data.Min = int(minEdit.Value())
slh.SetRange(data.Min, data.Max)
slv.SetRange(data.Min, data.Max)
},
},
NumberEdit{
AssignTo: &valueEdit,
Value: float64(data.Value),
OnValueChanged: func() {
data.Value = int(valueEdit.Value())
slh.SetValue(data.Value)
slv.SetValue(data.Value)
},
},
NumberEdit{
AssignTo: &maxEdit,
Value: float64(data.Max),
OnValueChanged: func() {
data.Max = int(maxEdit.Value())
slh.SetRange(data.Min, data.Max)
slv.SetRange(data.Min, data.Max)
},
},
Slider{
ColumnSpan: 3,
AssignTo: &slh,
MinValue: data.Min,
MaxValue: data.Max,
Value: data.Value,
OnValueChanged: func() {
data.Value = slh.Value()
valueEdit.SetValue(float64(data.Value))
},
},
VSpacer{},
PushButton{
ColumnSpan: 3,
Text: "Print state",
OnClicked: func() {
log.Printf("H: < %d | %d | %d >\n", slh.MinValue(), slh.Value(), slh.MaxValue())
log.Printf("V: < %d | %d | %d >\n", slv.MinValue(), slv.Value(), slv.MaxValue())
},
},
},
},
},
}.Run()
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/wmdng/walk.git
git@gitee.com:wmdng/walk.git
wmdng
walk
walk
9fd96a6317b5

搜索帮助