diff --git a/ui/cryptomaterial/dropdown.go b/ui/cryptomaterial/dropdown.go index f07dc1778..9a2de5fd9 100644 --- a/ui/cryptomaterial/dropdown.go +++ b/ui/cryptomaterial/dropdown.go @@ -211,8 +211,6 @@ func (d *DropDown) Changed(gtx C) bool { // If no dropdown item was clicked, check if there's a click on the // backdrop and close all dropdowns. - //TODO07 - // if len(d.theme.DropdownBackdrop.Clicks()) > 0 { if d.theme.DropdownBackdrop.Clicked(gtx) { d.theme.closeAllDropdowns() } diff --git a/ui/cryptomaterial/editor.go b/ui/cryptomaterial/editor.go index b29335be8..2f46e18d5 100644 --- a/ui/cryptomaterial/editor.go +++ b/ui/cryptomaterial/editor.go @@ -3,14 +3,18 @@ package cryptomaterial import ( + "image" "image/color" "io" "strings" + "gioui.org/gesture" "gioui.org/io/clipboard" "gioui.org/io/key" + "gioui.org/io/pointer" "gioui.org/layout" "gioui.org/op" + "gioui.org/op/clip" "gioui.org/unit" "gioui.org/widget" "gioui.org/widget/material" @@ -68,10 +72,10 @@ type Editor struct { m2 unit.Dp m5 unit.Dp - clickable *widget.Clickable + // clickable *widget.Clickable + click gesture.Click copy, paste Button - eventKey int isShowMenu bool isDisableMenu bool @@ -165,9 +169,9 @@ func (t *Theme) Editor(editor *widget.Editor, hint string) Editor { t.Styles.IconButtonColorStyle, }, CustomButton: t.Button(""), - clickable: new(widget.Clickable), - copy: t.Button(values.String(values.StrCopy)), - paste: t.Button(values.String(values.StrPaste)), + // clickable: new(widget.Clickable), + copy: t.Button(values.String(values.StrCopy)), + paste: t.Button(values.String(values.StrPaste)), } newEditor.copy.TextSize = values.TextSize10 newEditor.copy.Background = color.NRGBA{} @@ -186,34 +190,47 @@ func (t *Theme) Editor(editor *widget.Editor, hint string) Editor { } func (e *Editor) Pressed(gtx C) bool { - return e.clickable.Pressed() || e.copy.Clicked(gtx) || e.paste.Clicked(gtx) + // return e.clickable.Pressed() || e.copy.Clicked(gtx) || e.paste.Clicked(gtx) + return e.copy.Clicked(gtx) || e.paste.Clicked(gtx) } func (e *Editor) FirstPressed(gtx C) bool { // TODO07 // return !e.Editor.Focused() && e.clickable.Pressed() - return !gtx.Source.Focused(&e.Editor) && e.clickable.Pressed() + // return !gtx.Source.Focused(&e.Editor) && e.clickable.Pressed() + return !gtx.Source.Focused(e.Editor) } func (e *Editor) Layout(gtx C) D { e.handleEvents(gtx) - clicks1, _ := e.clickable.Update(gtx) - // clicks := e.clickable.Clicks() - // if len(clicks) > 0 { - if clicks1.NumClicks == 2 { - e.isShowMenu = true - } - if clicks1.NumClicks == 1 { - gtx.Execute(key.FocusCmd{Tag: &e.Editor}) - // e.Editor.Focus() - } - if clicks1.NumClicks != 2 && clicks1.NumClicks > 0 { - e.isShowMenu = false - } + e.update(gtx) return e.layout(gtx) } +func (e *Editor) update(gtx C) { + for { + ev, ok := e.click.Update(gtx.Source) + if !ok { + break + } + + switch ev.Kind { + case gesture.KindPress: + gtx.Execute(key.FocusCmd{Tag: e.Editor}) + } + + switch ev.NumClicks { + case 1: + gtx.Execute(key.FocusCmd{Tag: e.Editor}) + case 2: + e.isShowMenu = true + default: + e.isShowMenu = false + } + } +} + func (e *Editor) layout(gtx C) D { e.LineColor, e.TitleLabel.Color = e.t.Color.Gray2, e.t.Color.GrayText3 if e.Editor.Len() > 0 && len(e.Hint) > 0 { @@ -223,10 +240,8 @@ func (e *Editor) layout(gtx C) D { e.TitleLabel.Text = "" } - // TODO07 - focused := gtx.Source.Focused(&e.Editor) + focused := gtx.Source.Focused(e.Editor) if focused { - // if e.Editor.Focused() { e.TitleLabel.Text = e.Hint e.TitleLabel.Color, e.LineColor = e.t.Color.Primary, e.t.Color.Primary e.Hint = "" @@ -257,24 +272,22 @@ func (e *Editor) layout(gtx C) D { layout.Rigid(func(gtx C) D { return layout.Stack{}.Layout(gtx, layout.Stacked(func(gtx C) D { - return e.clickable.Layout(gtx, func(gtx C) D { - return layout.Flex{Axis: layout.Vertical}.Layout(gtx, - layout.Rigid(e.editorLayout), - layout.Rigid(func(gtx C) D { - if e.errorLabel.Text != "" { - inset := layout.Inset{ - Top: e.m2, - Left: e.m5, - } - return inset.Layout(gtx, e.errorLabel.Layout) - } - if e.isSpaceError { - return layout.Spacer{Height: values.MarginPadding18}.Layout(gtx) + return layout.Flex{Axis: layout.Vertical}.Layout(gtx, + layout.Rigid(e.editorLayout), + layout.Rigid(func(gtx C) D { + if e.errorLabel.Text != "" { + inset := layout.Inset{ + Top: e.m2, + Left: e.m5, } - return D{} - }), - ) - }) + return inset.Layout(gtx, e.errorLabel.Layout) + } + if e.isSpaceError { + return layout.Spacer{Height: values.MarginPadding18}.Layout(gtx) + } + return D{} + }), + ) }), layout.Stacked(func(gtx C) D { if e.IsTitleLabel { @@ -287,6 +300,14 @@ func (e *Editor) layout(gtx C) D { } return D{} }), + layout.Expanded(func(gtx C) D { + defer pointer.PassOp{}.Push(gtx.Ops).Pop() + defer clip.Rect(image.Rectangle{ + Max: gtx.Constraints.Min, + }).Push(gtx.Ops).Pop() + e.click.Add(gtx.Ops) + return D{} + }), layout.Stacked(overLay), ) }), @@ -323,8 +344,7 @@ func (e *Editor) editorLayout(gtx C) D { } func (e *Editor) editorMenusLayout(gtx C, editorHeight int) { - // TODO07 - e.isShowMenu = e.isShowMenu && (gtx.Source.Focused(&e.Editor) || e.copy.Hovered() || e.paste.Hovered()) + e.isShowMenu = e.isShowMenu && (gtx.Source.Focused(e.Editor) || e.copy.Hovered() || e.paste.Hovered()) if e.isShowMenu { flexChilds := make([]layout.FlexChild, 0) if len(e.Editor.Text()) > 0 { @@ -374,15 +394,7 @@ func (e *Editor) editor(gtx C) D { return D{} }), layout.Flexed(1, func(gtx C) D { - return layout.Flex{Axis: layout.Vertical}.Layout(gtx, - layout.Rigid(func(gtx C) D { - inset := layout.Inset{ - Top: e.m5, - Bottom: e.m5, - } - return inset.Layout(gtx, e.EditorStyle.Layout) - }), - ) + return layout.Inset{Top: e.m5, Bottom: e.m5}.Layout(gtx, e.EditorStyle.Layout) }), layout.Rigid(func(gtx C) D { if e.ExtraText == "" { @@ -440,28 +452,17 @@ func (e *Editor) handleEvents(gtx C) { e.EditorIconButtonEvent() } - // TODO07 if e.copy.Clicked(gtx) { gtx.Execute(clipboard.WriteCmd{Data: io.NopCloser(strings.NewReader(e.Editor.Text()))}) e.isShowMenu = false } if e.paste.Clicked(gtx) { - gtx.Execute(clipboard.ReadCmd{Tag: &e.eventKey}) + gtx.Execute(clipboard.ReadCmd{Tag: e.Editor}) e.isShowMenu = false } } -// TODO07 -// func (e *Editor) processEvent(gtx C) { -// for _, event := range gtx.Events(&e.eventKey) { -// switch eventType := event.(type) { -// case clipboard.Event: -// e.Editor.Insert(eventType.Text) -// } -// } -// } - func (re RestoreEditor) Layout(gtx C) D { width := int(gtx.Metric.PxPerDp * 2.0) height := int(gtx.Metric.PxPerDp * float32(re.height)) diff --git a/ui/cryptomaterial/slider.go b/ui/cryptomaterial/slider.go index c5972e681..5b3a138e8 100644 --- a/ui/cryptomaterial/slider.go +++ b/ui/cryptomaterial/slider.go @@ -35,9 +35,9 @@ type Slider struct { SelectedIndicatorColor color.NRGBA // this is a full color no opacity slideAction *SlideAction clicker gesture.Click - clicked bool - disableButtonDirection bool - ControlInset layout.Inset + // clicked bool + disableButtonDirection bool + ControlInset layout.Inset } var m4 = values.MarginPadding4 @@ -208,12 +208,6 @@ func (s *Slider) RefreshItems() { s.isSliderItemsSet = false } -func (s *Slider) Clicked() bool { - clicked := s.clicked - s.clicked = false - return clicked -} - func (s *Slider) handleClickEvent(gtx C) { if s.nextButton.Clicked(gtx) { s.handleActionEvent(true) @@ -238,29 +232,6 @@ func (s *Slider) handleClickEvent(gtx C) { break } } - - // TODO07 - for { - e, ok := s.clicker.Update(gtx.Source) - if !ok { - break - } - switch e.Kind { - case gesture.KindClick: - if !s.clicked { - s.clicked = true - } - } - } - - // for _, events := range s.clicker.Events(gtx) { - // switch events.Type { - // case gesture.TypeClick: - // if !s.clicked { - // s.clicked = true - // } - // } - // } } func (s *Slider) handleActionEvent(isNext bool) { diff --git a/ui/cryptomaterial/switch.go b/ui/cryptomaterial/switch.go index 5b2029d4a..8dd83a365 100644 --- a/ui/cryptomaterial/switch.go +++ b/ui/cryptomaterial/switch.go @@ -144,7 +144,6 @@ func (s *Switch) Layout(gtx layout.Context) layout.Dimensions { return layout.Dimensions{Size: dims} } -// TODO07 func (s *Switch) Changed(gtx C) bool { return s.clk.Update(gtx) } diff --git a/ui/cryptomaterial/theme.go b/ui/cryptomaterial/theme.go index 67975811a..419d7f39d 100644 --- a/ui/cryptomaterial/theme.go +++ b/ui/cryptomaterial/theme.go @@ -275,18 +275,18 @@ func approxLuminance(c color.NRGBA) byte { func HandleEditorEvents(gtx C, editors ...*widget.Editor) (bool, bool) { var submit, changed bool - for _, editor := range editors { - evt, ok := editor.Update(gtx) - if !ok { - continue - } - switch evt.(type) { - case widget.ChangeEvent: - changed = true - case widget.SubmitEvent: - submit = true - } - } + // for _, editor := range editors { + // evt, ok := editor.Update(gtx) + // if !ok { + // continue + // } + // switch evt.(type) { + // case widget.ChangeEvent: + // changed = true + // case widget.SubmitEvent: + // submit = true + // } + // } return submit, changed } diff --git a/ui/page/components/restore_page.go b/ui/page/components/restore_page.go index a29442526..d6e4d6eda 100644 --- a/ui/page/components/restore_page.go +++ b/ui/page/components/restore_page.go @@ -254,7 +254,7 @@ func (pg *Restore) HandleUserInteractions(gtx C) { if pg.confirmSeedButton.Clicked(gtx) { if !pg.restoreInProgress { - go pg.restoreFromSeedEditor(gtx) + go pg.restoreFromSeedEditor() } } @@ -283,7 +283,7 @@ func (pg *Restore) HandleKeyPress(gtx C, evt *key.Event) { } } -func (pg *Restore) restoreFromSeedEditor(gtx C) { +func (pg *Restore) restoreFromSeedEditor() { pg.restoreInProgress = true clearEditor := func() { pg.restoreInProgress = false diff --git a/ui/page/components/seed_restore_page.go b/ui/page/components/seed_restore_page.go index 0ea4d730a..89f041834 100644 --- a/ui/page/components/seed_restore_page.go +++ b/ui/page/components/seed_restore_page.go @@ -459,7 +459,7 @@ func (pg *SeedRestore) validateSeeds() (bool, string) { return true, seedPhrase } -func (pg *SeedRestore) verifySeeds(gtx C) bool { +func (pg *SeedRestore) verifySeeds() bool { isValid, seedphrase := pg.validateSeeds() if isValid { pg.seedPhrase = seedphrase @@ -536,7 +536,7 @@ func (pg *SeedRestore) HandleUserInteractions(gtx C) { } if pg.validateSeed.Clicked(gtx) { - if !pg.verifySeeds(gtx) { + if !pg.verifySeeds() { return } diff --git a/ui/page/components/wallet_setup_page.go b/ui/page/components/wallet_setup_page.go index 3a03db50c..714e0c81e 100644 --- a/ui/page/components/wallet_setup_page.go +++ b/ui/page/components/wallet_setup_page.go @@ -443,7 +443,7 @@ func (pg *CreateWallet) HandleUserInteractions(gtx C) { } // editor event listener - isSubmit, isChanged := cryptomaterial.HandleEditorEvents(gtx, pg.walletName.Editor, pg.watchOnlyWalletHex.Editor, pg.passwordEditor.Editor, pg.confirmPasswordEditor.Editor) + isSubmit, isChanged := cryptomaterial.HandleEditorEvents(gtx, pg.watchOnlyWalletHex.Editor, pg.passwordEditor.Editor, pg.confirmPasswordEditor.Editor) if isChanged { // reset error when any editor is modified pg.walletName.SetError("") diff --git a/ui/window.go b/ui/window.go index f59352e04..b2f5f9c44 100644 --- a/ui/window.go +++ b/ui/window.go @@ -324,7 +324,7 @@ func (win *Window) prepareToDisplayUI(gtx layout.Context) { // list via a graphical context that is linked to the ops. // ops := &op.Ops{} // gtx := giouiApp.NewContext(ops, evt) - // win.addEvents(gtx) + win.addEvents(gtx) layout.Stack{Alignment: layout.N}.Layout( gtx, backgroundWidget, @@ -476,14 +476,15 @@ func (win *Window) listenSoftKey(gtx C) { // } } -// func (win *Window) addEvents(gtx C) { -// // clicker use for show and hide soft keyboard and menu button on editor -// win.clicker.Add(gtx.Ops) +func (win *Window) addEvents(gtx C) { + // clicker use for show and hide soft keyboard and menu button on editor + win.clicker.Add(gtx.Ops) -// if runtime.GOOS == "android" { -// key.InputOp{ -// Tag: win, -// Keys: key.NameBack, -// }.Add(gtx.Ops) -// } -// } + //TODO07 Need handle + // if runtime.GOOS == "android" { + // key.InputOp{ + // Tag: win, + // Keys: key.NameBack, + // }.Add(gtx.Ops) + // } +}