Added password entry fields; they are the alternate mode of LineEdit.

This commit is contained in:
Pietro Gagliardi 2014-02-25 15:06:51 -05:00
parent 04ae299ef0
commit 06fa3a5174
7 changed files with 30 additions and 9 deletions

View File

@ -154,6 +154,12 @@ func gtk_entry_new() *gtkWidget {
return fromgtkwidget(C.gtk_entry_new())
}
func gtkPasswordEntryNew() *gtkWidget {
e := gtk_entry_new()
C.gtk_entry_set_visibility(togtkentry(e), C.FALSE)
return e
}
func gtk_entry_set_text(widget *gtkWidget, text string) {
ctext := C.CString(text)
defer C.free(unsafe.Pointer(ctext))

View File

@ -9,10 +9,11 @@ import (
type LineEdit struct {
// TODO Typing event
lock sync.Mutex
created bool
sysData *sysData
initText string
lock sync.Mutex
created bool
sysData *sysData
initText string
password bool
}
// NewLineEdit makes a new LineEdit with the specified text.
@ -23,6 +24,14 @@ func NewLineEdit(text string) *LineEdit {
}
}
// NewPasswordEdit makes a new LineEdit which allows the user to enter a password.
func NewPasswordEdit() *LineEdit {
return &LineEdit{
sysData: mksysdata(c_lineedit),
password: true,
}
}
// SetText sets the LineEdit's text.
func (l *LineEdit) SetText(text string) (err error) {
l.lock.Lock()
@ -50,6 +59,7 @@ func (l *LineEdit) make(window *sysData) error {
l.lock.Lock()
defer l.lock.Unlock()
l.sysData.alternate = l.password
err := l.sysData.make(l.initText, window)
if err != nil {
return err

View File

@ -26,7 +26,8 @@ func TestMain(t *testing.T) {
incButton := NewButton("Inc")
decButton := NewButton("Dec")
sincdec := NewStack(Horizontal, incButton, decButton)
s0 := NewStack(Vertical, s2, c, cb1, cb2, e, s3, pbar, sincdec)
password := NewPasswordEdit()
s0 := NewStack(Vertical, s2, c, cb1, cb2, e, s3, pbar, sincdec, password)
lb1 := NewListbox(true, "Select One", "Or More", "To Continue")
lb2 := NewListbox(false, "Select", "Only", "One", "Please")
i := 0
@ -55,11 +56,12 @@ mainloop:
case <-w.Closing:
break mainloop
case <-b.Clicked:
err = w.SetTitle(fmt.Sprintf("%v | %s | %s | %s",
err = w.SetTitle(fmt.Sprintf("%v | %s | %s | %s | %s",
c.Checked(),
cb1.Selection(),
cb2.Selection(),
e.Text()))
e.Text(),
password.Text()))
if err != nil {
panic(err)
}

View File

@ -17,7 +17,7 @@ type cSysData struct {
ctype int
event chan struct{}
resize func(x int, y int, width int, height int) error
alternate bool // editable for Combobox, multi-select for listbox
alternate bool // editable for Combobox, multi-select for listbox, password for lineedit
}
func (c *cSysData) make(initText string, window *sysData) error {
panic(runtime.GOOS + " sysData does not define make()")

View File

@ -86,6 +86,7 @@ var classTypes = [nctypes]*classData{
},
c_lineedit: &classData{
make: gtk_entry_new,
makeAlt: gtkPasswordEntryNew,
setText: gtk_entry_set_text,
text: gtk_entry_get_text,
},

View File

@ -70,6 +70,7 @@ var classTypes = [nctypes]*classData{
name: "EDIT",
style: _ES_AUTOHSCROLL | _WS_BORDER | controlstyle,
xstyle: 0 | controlxstyle,
altStyle: _ES_PASSWORD | _ES_AUTOHSCROLL | _WS_BORDER | controlstyle,
font: &controlFont,
},
c_label: &classData{

View File

@ -5,8 +5,9 @@ so I don't forget:
- determine if a selection in a non-editable combobox has been made
- see if we really need to track errors on Combobox.Selection()
- in fact, see if we really need to track errors on a lot of things...
- password entry fields, character-limited entry fields, numeric entry fields, multiline entry fields
- character-limited entry fields, numeric entry fields, multiline entry fields
- possible rename of LineEdit?
- especially for password fields - NewPasswordEntry()?
- more flexible size appropriation: allow a small button to be at the top of everything in the main() example here
- [Windows] should ListBox have a border style?
- a different border on LineEdits?