From b0abb36e649d12a3288ac79d1152db4d1ec34eda Mon Sep 17 00:00:00 2001 From: Greg Date: Thu, 3 Oct 2019 17:34:04 -0400 Subject: [PATCH] Improve handling of SelButtons. Reset password insertion page as appropriate. --- cmd/passgo-gui/main.go | 8 ++++++++ cmd/passgo-gui/ui.go | 27 +++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/cmd/passgo-gui/main.go b/cmd/passgo-gui/main.go index 6e8574a..635e71d 100644 --- a/cmd/passgo-gui/main.go +++ b/cmd/passgo-gui/main.go @@ -504,6 +504,12 @@ func eventLoop() { passvalEd.SetText(string(pw)) } + resetInsertPage := func() { + passnameEd.SetText("") + passvalEd.SetText("") + genBtn.Deselect() + } + insertPage = func() { c2 := flex.End(insertLabel.Layout(ops, flex.Rigid())) @@ -560,6 +566,7 @@ func eventLoop() { } if backBtn.Clicked() { w.Invalidate() + resetInsertPage() page = listPage } if saveBtn.Clicked() { @@ -597,6 +604,7 @@ func eventLoop() { if yesBtn.Clicked() { w.Invalidate() page = listPage + resetInsertPage() store.Insert(insName, insValue) } } diff --git a/cmd/passgo-gui/ui.go b/cmd/passgo-gui/ui.go index a50ca08..3fdc74f 100644 --- a/cmd/passgo-gui/ui.go +++ b/cmd/passgo-gui/ui.go @@ -134,10 +134,33 @@ func (b *Button) Clicked() bool { return b.clicked } +func (b *SelButton) Select() { + if b.Selected { + return + } + b.Selected = true + b.SelColor, b.Background = b.Background, b.SelColor +} + +func (b *SelButton) Deselect() { + if !b.Selected { + return + } + b.Selected = false + b.SelColor, b.Background = b.Background, b.SelColor +} + +func (b *SelButton) Toggle() { + if b.Selected { + b.Deselect() + } else { + b.Select() + } +} + func (b *SelButton) Clicked() bool { if b.clicked { - b.Selected = !b.Selected - b.SelColor, b.Background = b.Background, b.SelColor + b.Toggle() return true } else { return false