Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds editor icons #677

Merged
merged 8 commits into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 42 additions & 5 deletions ui/decredmaterial/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,27 @@ type Editor struct {
LineColor color.NRGBA
TitleLabelColor color.NRGBA

//IsRequired if true, displays a required field text at the buttom of the editor.
// IsRequired if true, displays a required field text at the buttom of the editor.
IsRequired bool
//IsTitleLabel if true makes the title label visible.
// IsTitleLabel if true makes the title label visible.
IsTitleLabel bool
//Bordered if true makes the adds a border around the editor.
// Bordered if true makes the adds a border around the editor.
HasCustomButton bool
CustomButton Button

Bordered bool
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Bordered if true makes the adds a border around the editor.
HasCustomButton bool
CustomButton Button
Bordered bool
HasCustomButton bool
CustomButton Button
// Bordered if true makes the adds a border around the editor.
Bordered bool

//IsPassword if true, displays the show and hide button.
// 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

editorIconButton IconButton
showHidePassword IconButton

editorIconButtonEvent func()

m2 unit.Value
m5 unit.Value
}
Expand All @@ -56,6 +61,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 @@ -73,6 +79,15 @@ func (t *Theme) RestoreEditor(editor *widget.Editor, hint string, title string)
}
}

// IconEditor func creates an editor widget with icon of choice
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// IconEditor func creates an editor widget with icon of choice
// IconEditor creates an editor widget with icon of choice

func (t *Theme) IconEditor(editor *widget.Editor, hint string, editorIcon []byte, showEditorIcon bool, editorIconEvent func()) Editor {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for icons that shouldn't be clickable, trying to pass an empty event , e.g emptyEvent := func(), crashes the app when the icon is clicked.

we can try passing a boolean argument to allow buttons to either be clickable or not

e := t.Editor(editor, hint)
e.showEditorIcon = showEditorIcon
e.editorIconButton.IconButtonStyle.Icon = MustIcon(widget.NewIcon(editorIcon))
e.editorIconButtonEvent = editorIconEvent
return e
}

func (t *Theme) Editor(editor *widget.Editor, hint string) Editor {
errorLabel := t.Caption("")
errorLabel.Color = t.Color.Danger
Expand Down Expand Up @@ -100,6 +115,16 @@ func (t *Theme) Editor(editor *widget.Editor, hint string) Editor {
m2: unit.Dp(2),
m5: unit.Dp(5),

editorIconButton: IconButton{
material.IconButtonStyle{
Icon: MustIcon(widget.NewIcon(icons.ActionVisibilityOff)),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Icon: MustIcon(widget.NewIcon(icons.ActionVisibilityOff)),

This doesn't need to be initialized here

Size: values.MarginPadding24,
Background: color.NRGBA{},
Color: t.Color.Gray,
Inset: layout.UniformInset(m0),
Button: new(widget.Clickable),
},
},
showHidePassword: IconButton{
material.IconButtonStyle{
Icon: MustIcon(widget.NewIcon(icons.ActionVisibilityOff)),
Expand Down Expand Up @@ -213,7 +238,15 @@ 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 {
return e.editorIconButton.Layout(gtx)
})
} else if e.isPassword {
inset := layout.Inset{
Top: e.m2,
Left: e.m5,
Expand Down Expand Up @@ -255,6 +288,10 @@ func (e Editor) handleEvents() {
}
}

if e.editorIconButton.Button.Clicked() {
e.editorIconButtonEvent()
}

if e.errorLabel.Text != "" {
e.LineColor = e.t.Color.Danger
} else {
Expand Down
15 changes: 15 additions & 0 deletions ui/modal/create_password_modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ func NewCreatePasswordModal(l *load.Load) *CreatePasswordModal {
cm.walletName = l.Theme.Editor(new(widget.Editor), "Wallet name")
cm.walletName.Editor.SingleLine, cm.walletName.Editor.Submit = true, true

//PLEASE UNCOMMENT TO SEE AN EXAMPLE OF THE ICONEDITOR FUNCTION USED ON THE WALLET NAME EDITOR
// showEditorIcon := true
// editorIcon := icons.AVArtTrack
// cm.walletName = l.Theme.IconEditor(new(widget.Editor), "Wallet Name", editorIcon, showEditorIcon, cm.walletNameEvent)
// cm.walletName.Editor.SingleLine, cm.walletName.Editor.Submit = true, true

cm.passwordEditor = l.Theme.EditorPassword(new(widget.Editor), "Spending password")
cm.passwordEditor.Editor.SingleLine, cm.passwordEditor.Editor.Submit = true, true

Expand All @@ -78,6 +84,15 @@ func NewCreatePasswordModal(l *load.Load) *CreatePasswordModal {
return cm
}

//PLEASE UNCOMMENT TO SEE AN EXAMPLE OF THE ICONEDITOR FUNCTION USED ON THE WALLET NAME EDITOR
// func (cm *CreatePasswordModal) walletNameEvent() {
// info:= NewInfoModal(cm.Load).
// Title("Set up startup password").
// Body("Startup password helps protect your wallet from unauthorized access.").
// PositiveButton("Got it", func() {})
// cm.ShowModal(info)
// }

func (cm *CreatePasswordModal) ModalID() string {
return cm.randomID
}
Expand Down