Skip to content

Commit

Permalink
Adding basic card widget and support for Icon Selectors (#1)
Browse files Browse the repository at this point in the history
* Added Card to the list of widgets
* Added edit fields on select for the card widget
* Added Support for dynamic icons
  • Loading branch information
aayush420 authored Nov 23, 2020
1 parent ada89ec commit d584dc3
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea

fynebuilder
tmp
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7 h1:SCYMcCJ89LjRGwEa0tRluN
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7/go.mod h1:482civXOzJJCPzJ4ZOX/pwvXBWSnzD4OKMdH4ClKGbk=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200625191551-73d3c3675aa3 h1:q521PfSp5/z6/sD9FZZOWj4d1MLmfQW8PkRnI9M6PCE=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200625191551-73d3c3675aa3/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/godbus/dbus/v5 v5.0.3 h1:ZqHaoEF7TBzh4jzPmqVhE/5A1z9of6orkAe5uHoAeME=
github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/goki/freetype v0.0.0-20181231101311-fa8a33aabaff h1:W71vTCKoxtdXgnm1ECDFkfQnpdqAO00zzGXLA5yaEX8=
github.com/goki/freetype v0.0.0-20181231101311-fa8a33aabaff/go.mod h1:wfqRWLHRBsRgkp5dmbG56SA0DmVtwrF5N3oPdI8t+Aw=
Expand Down
18 changes: 16 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var (
)

func buildLibrary() fyne.CanvasObject {
widgets := []string{"Button", "Icon", "Label", "Entry"}
widgets := []string{"Card", "Button", "Icon", "Label", "Entry"}

var selected fyne.CanvasObject
list := widget.NewList(func() int {
Expand All @@ -31,6 +31,8 @@ func buildLibrary() fyne.CanvasObject {
})
list.OnSelected = func(i widget.ListItemID) {
switch widgets[i] {
case "Card":
selected = widget.NewCard("Title", "Subtitle", widget.NewLabel("Content here"))
case "Button":
selected = widget.NewButton("Button", func() {})
case "Icon":
Expand Down Expand Up @@ -116,14 +118,26 @@ func choose(o fyne.CanvasObject) {
obj.SetText(text)
}
items = []fyne.CanvasObject{widget.NewForm(widget.NewFormItem("Text", entry))}
case *widget.Card:
title := widget.NewEntry()
title.SetText(obj.Title)
title.OnChanged = func(text string) {
obj.SetTitle(text)
}
subtitle := widget.NewEntry()
subtitle.SetText(obj.Subtitle)
subtitle.OnChanged = func(text string) {
obj.SetSubTitle(text)
}
items = []fyne.CanvasObject{widget.NewForm(widget.NewFormItem("Title", title), widget.NewFormItem("Title", subtitle))}
case *widget.Button:
entry := widget.NewEntry()
entry.SetText(obj.Text)
entry.OnChanged = func(text string) {
obj.SetText(text)
}
items = []fyne.CanvasObject{widget.NewForm(widget.NewFormItem("Text", entry),
widget.NewFormItem("Icon", widget.NewSelect([]string{}, func(selected string) {})))}
widget.NewFormItem("Icon", widget.NewSelect(iconNames, func(selected string) { obj.SetIcon(icons[selected]) })))}
}
paletteList.Objects = items
paletteList.Refresh()
Expand Down
117 changes: 117 additions & 0 deletions repo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package main

import (
"fyne.io/fyne"
"fyne.io/fyne/theme"
)

// icons Has the hashmap of icons from the standard theme.
// ToDo: Will have to look for a way to sync the list from `fyne_demo`
var icons = map[string]fyne.Resource{
"CancelIcon": theme.CancelIcon(),
"ConfirmIcon": theme.ConfirmIcon(),
"DeleteIcon": theme.DeleteIcon(),
"SearchIcon": theme.SearchIcon(),
"SearchReplaceIcon": theme.SearchReplaceIcon(),

"CheckButtonIcon": theme.CheckButtonIcon(),
"CheckButtonCheckedIcon": theme.CheckButtonCheckedIcon(),
"RadioButtonIcon": theme.RadioButtonIcon(),
"RadioButtonCheckedIcon": theme.RadioButtonCheckedIcon(),

"ColorAchromaticIcon": theme.ColorAchromaticIcon(),
"ColorChromaticIcon": theme.ColorChromaticIcon(),
"ColorPaletteIcon": theme.ColorPaletteIcon(),

"ContentAddIcon": theme.ContentAddIcon(),
"ContentRemoveIcon": theme.ContentRemoveIcon(),
"ContentClearIcon": theme.ContentClearIcon(),
"ContentCutIcon": theme.ContentCutIcon(),
"ContentCopyIcon": theme.ContentCopyIcon(),
"ContentPasteIcon": theme.ContentPasteIcon(),
"ContentRedoIcon": theme.ContentRedoIcon(),
"ContentUndoIcon": theme.ContentUndoIcon(),

"InfoIcon": theme.InfoIcon(),
"ErrorIcon": theme.ErrorIcon(),
"QuestionIcon": theme.QuestionIcon(),
"WarningIcon": theme.WarningIcon(),

"DocumentIcon": theme.DocumentIcon(),
"DocumentCreateIcon": theme.DocumentCreateIcon(),
"DocumentPrintIcon": theme.DocumentPrintIcon(),
"DocumentSaveIcon": theme.DocumentSaveIcon(),

"FileIcon": theme.FileIcon(),
"FileApplicationIcon": theme.FileApplicationIcon(),
"FileAudioIcon": theme.FileAudioIcon(),
"FileImageIcon": theme.FileImageIcon(),
"FileTextIcon": theme.FileTextIcon(),
"FileVideoIcon": theme.FileVideoIcon(),
"FolderIcon": theme.FolderIcon(),
"FolderNewIcon": theme.FolderNewIcon(),
"FolderOpenIcon": theme.FolderOpenIcon(),
"ComputerIcon": theme.ComputerIcon(),
"HomeIcon": theme.HomeIcon(),
"HelpIcon": theme.HelpIcon(),
"HistoryIcon": theme.HistoryIcon(),
"SettingsIcon": theme.SettingsIcon(),
"StorageIcon": theme.StorageIcon(),
"DownloadIcon": theme.DownloadIcon(),
// "UploadIcon": theme.UploadIcon(),

"ViewFullScreenIcon": theme.ViewFullScreenIcon(),
"ViewRestoreIcon": theme.ViewRestoreIcon(),
"ViewRefreshIcon": theme.ViewRefreshIcon(),
"VisibilityIcon": theme.VisibilityIcon(),
"VisibilityOffIcon": theme.VisibilityOffIcon(),
"ZoomFitIcon": theme.ZoomFitIcon(),
"ZoomInIcon": theme.ZoomInIcon(),
"ZoomOutIcon": theme.ZoomOutIcon(),

"MoveDownIcon": theme.MoveDownIcon(),
"MoveUpIcon": theme.MoveUpIcon(),

"NavigateBackIcon": theme.NavigateBackIcon(),
"NavigateNextIcon": theme.NavigateNextIcon(),

"Menu": theme.MenuIcon(),
"MenuExpand": theme.MenuExpandIcon(),
"MenuDropDown": theme.MenuDropDownIcon(),
"MenuDropUp": theme.MenuDropUpIcon(),

"MailAttachmentIcon": theme.MailAttachmentIcon(),
"MailComposeIcon": theme.MailComposeIcon(),
"MailForwardIcon": theme.MailForwardIcon(),
"MailReplyIcon": theme.MailReplyIcon(),
"MailReplyAllIcon": theme.MailReplyAllIcon(),
"MailSendIcon": theme.MailSendIcon(),

"MediaFastForward": theme.MediaFastForwardIcon(),
"MediaFastRewind": theme.MediaFastRewindIcon(),
"MediaPause": theme.MediaPauseIcon(),
"MediaPlay": theme.MediaPlayIcon(),
// "MediaStop": theme.MediaStopIcon(),
"MediaRecord": theme.MediaRecordIcon(),
"MediaReplay": theme.MediaReplayIcon(),
"MediaSkipNext": theme.MediaSkipNextIcon(),
"MediaSkipPrevious": theme.MediaSkipPreviousIcon(),

"VolumeDown": theme.VolumeDownIcon(),
"VolumeMute": theme.VolumeMuteIcon(),
"VolumeUp": theme.VolumeUpIcon(),
}

// iconNames is an array with the list of names of all the icons
var iconNames = extractIconNames()

// extractIconNames returns all the list of names of all the icons from the hashmap `icons`
func extractIconNames() []string {
var iconNamesFromData = make([]string, len(icons))
i := 0
for k := range icons {
iconNamesFromData[i] = k
i++
}
return iconNamesFromData
}

0 comments on commit d584dc3

Please sign in to comment.