guidefs

package
v0.0.0-...-3973335 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2024 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// IconNames is an array with the list of names of all the Icons
	IconNames []string

	// IconReverse Contains the key value pair where the key is the address of the icon and the value is the Name
	IconReverse map[string]string

	// 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`
	Icons map[string]fyne.Resource
)
View Source
var (
	// WidgetNames is an array with the list of names of all the Widgets
	WidgetNames []string

	Widgets map[string]WidgetInfo
)
View Source
var (
	Layouts = map[string]layoutInfo{
		"Border": {
			func(c *fyne.Container, props map[string]string) fyne.Layout {
				topNum := props["top"]
				topID, _ := strconv.Atoi(topNum)
				bottomNum := props["bottom"]
				bottomID, _ := strconv.Atoi(bottomNum)
				leftNum := props["left"]
				leftID, _ := strconv.Atoi(leftNum)
				rightNum := props["right"]
				rightID, _ := strconv.Atoi(rightNum)

				var t, b, l, r fyne.CanvasObject
				if topNum != "" && topID < len(c.Objects) {
					t = c.Objects[topID]
				}
				if bottomNum != "" && bottomID < len(c.Objects) {
					b = c.Objects[bottomID]
				}
				if leftNum != "" && leftID < len(c.Objects) {
					l = c.Objects[leftID]
				}
				if rightNum != "" && rightID < len(c.Objects) {
					r = c.Objects[rightID]
				}

				return layout.NewBorderLayout(t, b, l, r)
			},
			func(c *fyne.Container, props map[string]string) []*widget.FormItem {
				topNum := props["top"]
				topID, _ := strconv.Atoi(topNum)
				bottomNum := props["bottom"]
				bottomID, _ := strconv.Atoi(bottomNum)
				leftNum := props["left"]
				leftID, _ := strconv.Atoi(leftNum)
				rightNum := props["right"]
				rightID, _ := strconv.Atoi(rightNum)

				var t, b, l, r fyne.CanvasObject
				list := []string{"(Empty)"}
				for _, w := range c.Objects {
					label := ""
					if c, ok := w.(*fyne.Container); ok {
						name := props["name"]
						if name == "" {
							name = fmt.Sprintf("%p", c)
						}
						label = fmt.Sprintf("Container (%s)", name)
					} else {
						wid := w.(fyne.Widget)
						name := props["name"]
						if name == "" {
							name = fmt.Sprintf("%p", wid)
						}
						label = fmt.Sprintf("%s (%s)", reflect.TypeOf(wid).Elem().Name(), name)
					}
					list = append(list, label)
				}
				top := widget.NewSelect(list, nil)
				if topNum != "" && topID < len(c.Objects) {
					top.SetSelectedIndex(topID + 1)
					t = c.Objects[topID]
				}
				bottom := widget.NewSelect(list, nil)
				if bottomNum != "" && bottomID < len(c.Objects) {
					bottom.SetSelectedIndex(bottomID + 1)
					b = c.Objects[bottomID]
				}
				left := widget.NewSelect(list, nil)
				if leftNum != "" && leftID < len(c.Objects) {
					left.SetSelectedIndex(leftID + 1)
					l = c.Objects[leftID]
				}
				right := widget.NewSelect(list, nil)
				if rightNum != "" && rightID < len(c.Objects) {
					right.SetSelectedIndex(rightID + 1)
					r = c.Objects[rightID]
				}
				change := func(string) {
					t, b, l, r = nil, nil, nil, nil
					props["top"] = ""
					props["bottom"] = ""
					props["left"] = ""
					props["right"] = ""
					if top.SelectedIndex() > 0 {
						props["top"] = strconv.Itoa(top.SelectedIndex() - 1)
						t = c.Objects[top.SelectedIndex()-1]
					}
					if bottom.SelectedIndex() > 0 {
						props["bottom"] = strconv.Itoa(bottom.SelectedIndex() - 1)
						b = c.Objects[bottom.SelectedIndex()-1]
					}
					if left.SelectedIndex() > 0 {
						props["left"] = strconv.Itoa(left.SelectedIndex() - 1)
						l = c.Objects[left.SelectedIndex()-1]
					}
					if right.SelectedIndex() > 0 {
						props["right"] = strconv.Itoa(right.SelectedIndex() - 1)
						r = c.Objects[right.SelectedIndex()-1]
					}

					c.Layout = layout.NewBorderLayout(t, b, l, r)
					c.Refresh()
				}
				top.OnChanged = change
				bottom.OnChanged = change
				left.OnChanged = change
				right.OnChanged = change
				c.Layout = layout.NewBorderLayout(t, b, l, r)

				return []*widget.FormItem{
					widget.NewFormItem("Top", top),
					widget.NewFormItem("Bottom", bottom),
					widget.NewFormItem("Left", left),
					widget.NewFormItem("Right", right),
				}
			},
			func(c *fyne.Container, props map[fyne.CanvasObject]map[string]string, defs map[string]string) string {
				topNum := props[c]["top"]
				topID, _ := strconv.Atoi(topNum)
				bottomNum := props[c]["bottom"]
				bottomID, _ := strconv.Atoi(bottomNum)
				leftNum := props[c]["left"]
				leftID, _ := strconv.Atoi(leftNum)
				rightNum := props[c]["right"]
				rightID, _ := strconv.Atoi(rightNum)

				ignored := 0
				var t, b, l, r fyne.CanvasObject
				if topNum != "" && topID < len(c.Objects) {
					t = c.Objects[topID]
					ignored++
				}
				if bottomNum != "" && bottomID < len(c.Objects) {
					b = c.Objects[bottomID]
					ignored++
				}
				if leftNum != "" && leftID < len(c.Objects) {
					l = c.Objects[leftID]
					ignored++
				}
				if rightNum != "" && rightID < len(c.Objects) {
					r = c.Objects[rightID]
					ignored++
				}

				str := &strings.Builder{}
				str.WriteString("container.NewBorder(\n\t\t")
				writeGoStringOrNil(str, props, defs, t)
				str.WriteString(", \n\t\t")
				writeGoStringOrNil(str, props, defs, b)
				str.WriteString(", \n\t\t")
				writeGoStringOrNil(str, props, defs, l)
				str.WriteString(", \n\t\t")
				writeGoStringOrNil(str, props, defs, r)
				if len(c.Objects) > ignored {
					str.WriteString(", ")
					writeGoStringExcluding(str, func(o fyne.CanvasObject) bool {
						return o == t || o == b || o == l || o == r
					}, props, defs, c.Objects...)
				}
				str.WriteString(")")
				return str.String()
			},
		},
		"Center": {
			func(*fyne.Container, map[string]string) fyne.Layout {
				return layout.NewCenterLayout()
			},
			nil,
			nil,
		},
		"Form": {
			func(*fyne.Container, map[string]string) fyne.Layout {
				return layout.NewFormLayout()
			},
			nil,
			nil,
		},
		"Grid": {
			func(c *fyne.Container, props map[string]string) fyne.Layout {
				rowCol := props["grid_type"]
				if rowCol == "" {
					rowCol = "Columns"
				}
				count := props["count"]
				if count == "" {
					count = "2"
				}

				num, err := strconv.ParseInt(count, 0, 0)
				if err != nil {
					num = 2
				}

				if rowCol == "Rows" {
					return layout.NewGridLayoutWithRows(int(num))
				}
				return layout.NewGridLayoutWithColumns(int(num))
			},
			func(c *fyne.Container, props map[string]string) []*widget.FormItem {
				rowCol := props["grid_type"]
				if rowCol == "" {
					rowCol = "Columns"
				}
				count := props["count"]
				if count == "" {
					count = "2"
				}

				cols := widget.NewEntry()
				cols.SetText(count)
				vert := widget.NewSelect([]string{"Columns", "Rows"}, nil)
				vert.SetSelected(rowCol)
				change := func(string) {
					if cols.Text == "" {
						return
					}
					num, err := strconv.ParseInt(cols.Text, 0, 0)
					if err != nil {
						return
					}

					props["grid_type"] = vert.Selected
					props["count"] = cols.Text
					if vert.Selected == "Rows" {
						c.Layout = layout.NewGridLayoutWithRows(int(num))
					} else {
						c.Layout = layout.NewGridLayoutWithColumns(int(num))
					}
					c.Refresh()
				}
				cols.OnChanged = change
				vert.OnChanged = change
				return []*widget.FormItem{
					widget.NewFormItem("Count", cols),
					widget.NewFormItem("Arrange in", vert),
				}
			},
			func(c *fyne.Container, props map[fyne.CanvasObject]map[string]string, defs map[string]string) string {
				rowCol := props[c]["grid_type"]
				if rowCol == "" {
					rowCol = "Columns"
				}
				count := props[c]["count"]
				if count == "" {
					count = "2"
				}

				num, err := strconv.ParseInt(count, 0, 0)
				if err != nil {
					num = 2
				}

				str := &strings.Builder{}
				if rowCol == "Rows" {
					str.WriteString(fmt.Sprintf("container.NewGridWithRows(%d, ", num))
				} else {
					str.WriteString(fmt.Sprintf("container.NewGridWithColumns(%d, ", num))
				}
				writeGoStringExcluding(str, nil, props, defs, c.Objects...)
				str.WriteString(")")
				return str.String()
			},
		},
		"GridWrap": {
			func(c *fyne.Container, props map[string]string) fyne.Layout {
				width := props["width"]
				if width == "" {
					width = "100"
				}
				height := props["height"]
				if height == "" {
					height = "100"
				}
				w, err := strconv.ParseInt(width, 0, 0)
				if err != nil {
					w = 100
				}
				h, err := strconv.ParseInt(height, 0, 0)
				if err != nil {
					h = 100
				}

				return layout.NewGridWrapLayout(fyne.NewSize(float32(w), float32(h)))
			},
			func(c *fyne.Container, props map[string]string) []*widget.FormItem {
				width := props["width"]
				if width == "" {
					width = "100"
				}
				height := props["height"]
				if height == "" {
					height = "100"
				}

				widthEnt := widget.NewEntry()
				widthEnt.SetText(width)
				heightEnt := widget.NewEntry()
				heightEnt.SetText(height)
				change := func(string) {
					if widthEnt.Text == "" {
						return
					}
					w, err := strconv.ParseInt(widthEnt.Text, 0, 0)
					if err != nil {
						return
					}
					if widthEnt.Text == "" {
						return
					}
					h, err := strconv.ParseInt(heightEnt.Text, 0, 0)
					if err != nil {
						return
					}

					props["width"] = widthEnt.Text
					props["height"] = heightEnt.Text
					c.Layout = layout.NewGridWrapLayout(fyne.NewSize(float32(w), float32(h)))
					c.Refresh()
				}
				widthEnt.OnChanged = change
				heightEnt.OnChanged = change
				return []*widget.FormItem{
					widget.NewFormItem("Item Width", widthEnt),
					widget.NewFormItem("Item Height", heightEnt),
				}
			},
			nil,
		},
		"HBox": {
			func(c *fyne.Container, props map[string]string) fyne.Layout {
				props["dir"] = "horizontal"
				return layout.NewHBoxLayout()
			},
			nil,
			nil,
		},
		"Max": {
			func(c *fyne.Container, props map[string]string) fyne.Layout {
				return layout.NewStackLayout()
			},
			nil,
			nil,
		},
		"Padded": {
			func(c *fyne.Container, props map[string]string) fyne.Layout {
				return layout.NewPaddedLayout()
			},
			nil,
			nil,
		},
		"Stack": {
			func(c *fyne.Container, props map[string]string) fyne.Layout {
				return layout.NewStackLayout()
			},
			nil,
			nil,
		},
		"VBox": {
			func(c *fyne.Container, props map[string]string) fyne.Layout {
				props["dir"] = "vertical"
				return layout.NewVBoxLayout()
			},
			nil,
			nil,
		},
	}
)

Functions

func IconName

func IconName(res fyne.Resource) string

func InitOnce

func InitOnce()

func WrapResource

func WrapResource(r fyne.Resource) fyne.Resource

Types

type WidgetInfo

type WidgetInfo struct {
	Name     string
	Create   func() fyne.CanvasObject
	Edit     func(fyne.CanvasObject, map[string]string) []*widget.FormItem
	Gostring func(fyne.CanvasObject, map[fyne.CanvasObject]map[string]string, map[string]string) string
	Packages func(object fyne.CanvasObject) []string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL