Skip to content

Commit

Permalink
Adds dynamic Icons to Editor Widget
Browse files Browse the repository at this point in the history
  • Loading branch information
AdimekweEbuka committed Oct 26, 2021
1 parent cdbd6a1 commit 58edce0
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 3 deletions.
64 changes: 62 additions & 2 deletions ui/decredmaterial/editor.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Unlicense OR MIT

package decredmaterial

//
import (
"image/color"

Expand Down Expand Up @@ -43,6 +43,8 @@ type Editor struct {
Bordered bool
//IsPassword if true, displays the show and hide button.
isPassword bool
//If ShowEditorIcon is true, displays the editor widget Icon of choice
showEditorIcon bool

requiredErrorText string

Expand All @@ -56,6 +58,7 @@ func (t *Theme) EditorPassword(editor *widget.Editor, hint string) Editor {
editor.Mask = '*'
e := t.Editor(editor, hint)
e.isPassword = true
e.showEditorIcon = false
return e
}

Expand All @@ -71,6 +74,49 @@ func (t *Theme) RestoreEditor(editor *widget.Editor, hint string, title string)
height: 31,
}
}
//CREATES AN EDITOR WIDGET WITH DYNAMIC ICONS.
func (t *Theme) NewEditor(editor *widget.Editor, hint string, editorIcon []byte, showEditorIcon bool) Editor {
errorLabel := t.Caption("")
errorLabel.Color = t.Color.Danger

m := material.Editor(t.Base, editor, hint)
m.TextSize = t.TextSize
m.Color = t.Color.Text
m.Hint = hint
m.HintColor = t.Color.Hint

var m0 = unit.Dp(0)

return Editor{
t: t,
EditorStyle: m,
TitleLabel: t.Body2(""),
IsTitleLabel: true,
Bordered: true,
LineColor: t.Color.Gray1,
TitleLabelColor: t.Color.Gray3,
showEditorIcon: showEditorIcon,


errorLabel: errorLabel,
requiredErrorText: "Field is required",

m2: unit.Dp(2),
m5: unit.Dp(5),

showHidePassword: IconButton{
material.IconButtonStyle{
Icon: MustIcon(widget.NewIcon(editorIcon)),
Size: values.MarginPadding24,
Background: color.NRGBA{},
Color: t.Color.Gray,
Inset: layout.UniformInset(m0),
Button: new(widget.Clickable),
},
},
CustomButton: t.Button(""),
}
}

func (t *Theme) Editor(editor *widget.Editor, hint string) Editor {
errorLabel := t.Caption("")
Expand All @@ -92,6 +138,7 @@ func (t *Theme) Editor(editor *widget.Editor, hint string) Editor {
Bordered: true,
LineColor: t.Color.Gray1,
TitleLabelColor: t.Color.Gray3,


errorLabel: errorLabel,
requiredErrorText: "Field is required",
Expand Down Expand Up @@ -212,7 +259,20 @@ func (e Editor) editor(gtx layout.Context) layout.Dimensions {
)
}),
layout.Rigid(func(gtx C) D {
if e.isPassword {
if e.showEditorIcon{
inset := layout.Inset{
Top: e.m2,
Left: e.m5,
}
return inset.Layout(gtx, func(gtx C) D {
// icon := MustIcon(widget.NewIcon(icons.ActionVisibilityOff))
// if e.Editor.Mask == '*' {
// icon = MustIcon(widget.NewIcon(icons.ActionVisibility))
// }
//e.showHidePassword.Icon = MustIcon(widget.NewIcon(icons.AVAVTimer))
return e.showHidePassword.Layout(gtx)
})
} else if e.isPassword {
inset := layout.Inset{
Top: e.m2,
Left: e.m5,
Expand Down
9 changes: 8 additions & 1 deletion ui/modal/create_password_modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"gioui.org/text"
"gioui.org/widget"
"gioui.org/widget/material"
"golang.org/x/exp/shiny/materialdesign/icons"

"github.com/planetdecred/godcr/ui/decredmaterial"
"github.com/planetdecred/godcr/ui/load"
Expand Down Expand Up @@ -63,7 +64,13 @@ func NewCreatePasswordModal(l *load.Load) *CreatePasswordModal {
cm.btnNegative.Font.Weight = text.Medium
cm.btnNegative.Margin = layout.Inset{Right: values.MarginPadding8}

cm.walletName = l.Theme.Editor(new(widget.Editor), "Wallet name")
//cm.walletName = l.Theme.Editor(new(widget.Editor), "Wallet name")
//cm.walletName.Editor.SingleLine, cm.walletName.Editor.Submit = true, true

//TEST RUN OF NEW EDITOR
showEditorIcon := true
editorIcon:= icons.AVArtTrack
cm.walletName = l.Theme.NewEditor(new(widget.Editor), "Wallet Name", editorIcon, showEditorIcon)
cm.walletName.Editor.SingleLine, cm.walletName.Editor.Submit = true, true

cm.passwordEditor = l.Theme.EditorPassword(new(widget.Editor), "Spending password")
Expand Down

0 comments on commit 58edce0

Please sign in to comment.