Added a test for TextField.Invalid() and implemented it on the GTK+ backend.
This commit is contained in:
parent
5f830deec8
commit
ac1b8e3cca
|
@ -10,6 +10,11 @@ import (
|
||||||
|
|
||||||
// #include "gtk_unix.h"
|
// #include "gtk_unix.h"
|
||||||
// extern void textfieldChanged(GtkEditable *, gpointer);
|
// extern void textfieldChanged(GtkEditable *, gpointer);
|
||||||
|
// /* because cgo doesn't like GTK_STOCK_DIALOG_ERROR */
|
||||||
|
// static inline void setErrorIcon(GtkEntry *entry)
|
||||||
|
// {
|
||||||
|
// gtk_entry_set_icon_from_stock(entry, GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_DIALOG_ERROR);
|
||||||
|
// }
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
type textfield struct {
|
type textfield struct {
|
||||||
|
@ -58,7 +63,14 @@ func (t *textfield) OnChanged(f func()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *textfield) Invalid(reason string) {
|
func (t *textfield) Invalid(reason string) {
|
||||||
// TODO
|
if reason == "" {
|
||||||
|
C.gtk_entry_set_icon_from_stock(t.entry, C.GTK_ENTRY_ICON_SECONDARY, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
C.setErrorIcon(t.entry)
|
||||||
|
creason := togstr(reason)
|
||||||
|
defer freegstr(creason)
|
||||||
|
C.gtk_entry_set_icon_tooltip_text(t.entry, C.GTK_ENTRY_ICON_SECONDARY, creason)
|
||||||
}
|
}
|
||||||
|
|
||||||
//export textfieldChanged
|
//export textfieldChanged
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"image/color"
|
"image/color"
|
||||||
"image/draw"
|
"image/draw"
|
||||||
"time"
|
"time"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var closeOnClick = flag.Bool("close", false, "close on click")
|
var closeOnClick = flag.Bool("close", false, "close on click")
|
||||||
|
@ -38,6 +39,7 @@ type testwin struct {
|
||||||
festart Button
|
festart Button
|
||||||
felabel Label
|
felabel Label
|
||||||
festop Button
|
festop Button
|
||||||
|
vedit TextField
|
||||||
openbtn Button
|
openbtn Button
|
||||||
fnlabel Label
|
fnlabel Label
|
||||||
icons []icon
|
icons []icon
|
||||||
|
@ -91,6 +93,14 @@ func (tw *testwin) addfe() {
|
||||||
tw.fe = nil
|
tw.fe = nil
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
tw.vedit = NewTextField()
|
||||||
|
tw.vedit.OnChanged(func() {
|
||||||
|
if strings.Contains(tw.vedit.Text(), "bad") {
|
||||||
|
tw.vedit.Invalid("bad entered")
|
||||||
|
} else {
|
||||||
|
tw.vedit.Invalid("")
|
||||||
|
}
|
||||||
|
})
|
||||||
tw.openbtn = NewButton("Open")
|
tw.openbtn = NewButton("Open")
|
||||||
tw.openbtn.OnClicked(func() {
|
tw.openbtn.OnClicked(func() {
|
||||||
fn := OpenFile()
|
fn := OpenFile()
|
||||||
|
@ -101,9 +111,12 @@ func (tw *testwin) addfe() {
|
||||||
})
|
})
|
||||||
tw.fnlabel = NewStandaloneLabel("<no file selected>")
|
tw.fnlabel = NewStandaloneLabel("<no file selected>")
|
||||||
tw.festack = NewVerticalStack(tw.festart, tw.felabel, tw.festop,
|
tw.festack = NewVerticalStack(tw.festart, tw.felabel, tw.festop,
|
||||||
|
Space(),
|
||||||
|
tw.vedit,
|
||||||
Space(),
|
Space(),
|
||||||
tw.openbtn, tw.fnlabel)
|
tw.openbtn, tw.fnlabel)
|
||||||
tw.festack.SetStretchy(3)
|
tw.festack.SetStretchy(3)
|
||||||
|
tw.festack.SetStretchy(5)
|
||||||
tw.t.Append("Foreign Events", tw.festack)
|
tw.t.Append("Foreign Events", tw.festack)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue