Open kafpost opened 4 years ago
For this you can use any expression evaluating to a boolean value.
Walk currently uses https://gopkg.in/Knetic/govaluate.v3 to support evaluating expressions specified with the declarative.Bind
function.
For examples of supported expressions have a look at this tests.
Also check the widget structs in the declarative
sub package of walk to find fields of type declarative.Property
, which you can use in your expressions.
AFAIK there are currently only two examples in Walk, that make use of this feature.
The databinding
example uses a named DataBinder
to be able to refer to its DataSource
in an expression:
...
Dialog{
AssignTo: &dlg,
Title: Bind("'Animal Details' + (animal.Name == '' ? '' : ' - ' + animal.Name)"),
DefaultButton: &acceptPB,
CancelButton: &cancelPB,
DataBinder: DataBinder{
AssignTo: &db,
Name: "animal",
DataSource: animal,
ErrorPresenter: ToolTipErrorPresenter{},
},
...
The webview
example uses a function to choose an icon depending on the current URL:
...
MainWindow{
Icon: Bind("'../img/' + icon(wv.URL) + '.ico'"),
Title: "Walk WebView Example'",
MinSize: Size{800, 600},
Layout: VBox{MarginsZero: true},
Children: []Widget{
LineEdit{
AssignTo: &le,
Text: Bind("wv.URL"),
OnKeyDown: func(key walk.Key) {
if key == walk.KeyReturn {
wv.SetURL(le.Text())
}
},
},
WebView{
AssignTo: &wv,
Name: "wv",
URL: "https://github.com/lxn/walk",
},
},
Functions: map[string]func(args ...interface{}) (interface{}, error){
"icon": func(args ...interface{}) (interface{}, error) {
if strings.HasPrefix(args[0].(string), "https") {
return "check", nil
}
return "stop", nil
},
},
}.Run()
...
Additionally to the Functions
map, there is an Expressions
map in declarative.Composite
, declarative.Dialog
and declarative.MainWindow
, which you can add your own custom expressions to. Have a look at https://github.com/lxn/walk/blob/master/condition.go.
Hi,the lineEdit can be enabled by the RadioButton checked. Is there any other expressions or statements to enable the lineEdit not just the RadioButton checked. Thanks !