-
Notifications
You must be signed in to change notification settings - Fork 46
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
Adds editor icons #677
Changes from 5 commits
72c046e
2a308d3
92abe7a
e2bcd97
5c0c346
8c38fc7
3c302a3
6c7e1e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 | ||||||
//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 | ||||||
} | ||||||
|
@@ -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 | ||||||
} | ||||||
|
||||||
|
@@ -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 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
func (t *Theme) IconEditor(editor *widget.Editor, hint string, editorIcon []byte, showEditorIcon bool, editorIconEvent func()) Editor { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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 | ||||||
|
@@ -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)), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
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)), | ||||||
|
@@ -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, | ||||||
|
@@ -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 { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.