screen

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssetToImage

func AssetToImage(
	s ScreenHandler,
	asset string,
) (
	img *canvas.Image,
	err error,
)

func AssetToResource

func AssetToResource(
	s ScreenHandler,
	asset string,
) (
	res fyne.Resource,
	err error,
)

func NewTemplate

func NewTemplate(
	filesystem embed.FS,
	name string,
	localizer *i18n.Localizer,
) (
	scr *Screen,
	handler *TemplateScreenHandler,
	err error,
)

Types

type Canvas

type Canvas string
const (
	Image     Canvas = "Image"
	Rectangle Canvas = "Rectangle"
	Text      Canvas = "Text"
)

func (Canvas) Build

func (c Canvas) Build(
	e *Element,
	s ScreenHandler,
) (
	cnv fyne.CanvasObject,
	decorator fyne.CanvasObject,
	err error,
)

func (*Canvas) BuildImageCanvas

func (c *Canvas) BuildImageCanvas(
	e *Element,
	s ScreenHandler,
) (obj fyne.CanvasObject, err error)

func (Canvas) BuildRectangleCanvas

func (c Canvas) BuildRectangleCanvas(
	e *Element,
	s ScreenHandler,
) (obj fyne.CanvasObject, err error)

func (Canvas) BuildTextCanvas

func (c Canvas) BuildTextCanvas(
	e *Element,
	s ScreenHandler,
) (obj fyne.CanvasObject, err error)

type CheckHandlerFn

type CheckHandlerFn func(bool)

type ClickHandlerFn

type ClickHandlerFn func()

type Color

type Color struct {
	Red   uint8 `yaml:"red"`
	Green uint8 `yaml:"green"`
	Blue  uint8 `yaml:"blue"`
	Alpha uint8 `yaml:"alpha"`
}

type Container

type Container string

The constants for the Containers

Available yaml options for all containers:

  • id: The ID for exporting the container to code
  • decorators: The decorators to wrap the container into
  • hidden: Wether the container is hidden or not
const (
	// HScroll Container
	//
	// Available yaml options:
	//	- content: The content of the container
	HScroll Container = "HScroll"

	// Scroll Container
	//
	// Available yaml options:
	//	- content: The content of the container
	Scroll Container = "Scroll"

	// VScroll Container
	//
	// Available yaml options:
	//	- content: The content of the container
	VScroll Container = "VScroll"
)

func (Container) Build

func (cnt Container) Build(
	e *Element,
	s ScreenHandler,
) (
	cont fyne.CanvasObject,
	decorator fyne.CanvasObject,
	err error,
)

Build builds the container and decorator for the given Container and Element, using the provided ScreenHandler to fetch functions, data bindings, etc.

Parameters: - e *Element - the element to build the container for - s ScreenHandler - the screen handler for the container

Returns the CanvasObject for the widget, the CanvasObject for the decorator I fno decorators are specified, the widget and decorator will be the same.

type DateSelectedHandlerFn

type DateSelectedHandlerFn func(time.Time)

type DialogScreen

type DialogScreen struct {
	*Screen
}

func NewDialogScreen

func NewDialogScreen(
	filesystem embed.FS,
	name string,
	screenHandler ScreenHandler,
) (src *DialogScreen, err error)

func (*DialogScreen) Initialize

func (s *DialogScreen) Initialize() (obj fyne.CanvasObject, err error)

func (*DialogScreen) Move

func (s *DialogScreen) Move(p fyne.Position)

type Element

type Element struct {
	ID string `yaml:"id"`

	Container Container `yaml:"container"`
	Layout    Layout    `yaml:"layout"`
	Widget    Widget    `yaml:"widget"`
	Canvas    Canvas    `yaml:"canvas"`

	Padding Padding `yaml:"padding"`
	Margins Margins `yaml:"margins"`

	// Border Layout Elements
	Top    *Element   `yaml:"top"`
	Bottom *Element   `yaml:"bottom"`
	Left   *Element   `yaml:"left"`
	Right  *Element   `yaml:"right"`
	Center []*Element `yaml:"center"`

	// Other Layout Elements
	Children []*Element `yaml:"children"`
	Content  *Element   `yaml:"content"`

	// Form Element
	Label *Element `yaml:"label"`
	Field *Element `yaml:"field"`

	// Grid configuration
	Columns     *int  `yaml:"columns"`
	Rows        *int  `yaml:"rows"`
	RowColumns  *int  `yaml:"rowColumns"`
	ElementSize *Size `yaml:"elementSize"`

	// MinSize configuration
	MinSize *Size `yaml:"minSize"`

	// Relative Size configuration
	// Only valid for certain widgets:
	//	- ScoreDisplay
	RelativeSize *RelativeSize `yaml:"relativeSize"`

	// Widget Properties
	Text       string         `yaml:"text"`
	Localized  bool           `yaml:"localized"`
	Icon       string         `yaml:"icon"`
	Binding    string         `yaml:"binding"`
	Decorators []string       `yaml:"decorators"`
	Options    map[string]any `yaml:"options"`
	Disabled   bool           `yaml:"disabled"`
	Hidden     bool           `yaml:"hidden"`
	ToolTip    *ToolTip       `yaml:"tooltip"`

	// Properties shared by most widgets
	Placeholder          string `yaml:"placeholder"`
	PlaceholderLocalized bool   `yaml:"placeholderLocalized"`

	// Calendar Properties
	Time       *string `yaml:"time"`
	TimeFormat *string `yaml:"timeFormat"`

	// Entry Properties
	MultiLine bool   `yaml:"multiLine"`
	Validator string `yaml:"validator"`

	// List Properties
	ItemTemplate string `yaml:"itemTemplate"`
	ItemRenderer string `yaml:"itemRenderer"`
	ListLength   string `yaml:"listLength"`

	// Check Properties
	Checked bool `yaml:"checked"`

	// ScoreDisplay Properties
	Score     int `yaml:"score"`
	NumDigits int `yaml:"numDigits"`

	// Select Properties
	SelectOptionsBinding string   `yaml:"selectOptionsBinding"`
	SelectOptions        []string `yaml:"selectOptions"`

	// Spacer Properties
	FixHorizontal bool `yaml:"fixHorizontal"`
	FixVertical   bool `yaml:"fixVertical"`

	// Canvas Properties
	FillColor    *Color   `yaml:"fillColor"`
	StrokeColor  *Color   `yaml:"strokeColor"`
	TextColor    *Color   `yaml:"textColor"`
	StrokeWidth  *float32 `yaml:"strokeWidth"`
	CornerRadius *float32 `yaml:"cornerRadius"`
	TextSize     *float32 `yaml:"textSize"`
	ImageName    string   `yaml:"imageName"`
	Translucency *float64 `yaml:"translucency"`

	// Widgets requiring a set of resources (e.g ScoreDisplay)
	ResourceSet map[string]string `yaml:"resourceSet"`

	// Handlers
	OnClicked           string `yaml:"onClicked"`
	OnUpClicked         string `yaml:"onUpClicked"`
	OnDownClicked       string `yaml:"onDownClicked"`
	OnChanged           string `yaml:"onChanged"`
	OnSelected          string `yaml:"onSelected"`
	OnUnselected        string `yaml:"onUnselected"`
	OnDateSelected      string `yaml:"onDateSelected"`
	OnOptionSelected    string `yaml:"onOptionSelected"`
	OnValidationChanged string `yaml:"onValidationChanged"`
}

Element represents the yaml description of a ui element

func (*Element) BuildUI

func (e *Element) BuildUI(s ScreenHandler) (obj fyne.CanvasObject, err error)

BuildUI generates the UI for the Element.

It takes a ScreenHandler parameter and returns a fyne.CanvasObject and an error.

type Layout

type Layout string

The constants for the Layouts

Available yaml options for all layouts:

  • id: The ID for exporting the layout to code
  • decorators: The decorators to wrap the layout into
  • hidden: Wether the layout is hidden or not
const (
	// Border Layout
	//
	// Available yaml options
	//	- top: The top pane (contains 1 widget)
	//	- bottom: The bottom pane (contains 1 widget)
	//	- left: The left pane (contains 1 widget)
	//	- right: The right pane (contains 1 widget)
	//	- center: The center pane (contains multiple widgets)
	Border Layout = "Border"

	// Form Layout
	//
	// Available yaml options
	//	- children: The children of the form
	//		- label: The label of the form element
	//		- field: The field of the form element
	Form Layout = "Form"

	// Grid Layout
	//
	// Available yaml options
	//	- columns: The number of columns (GridWithColumns)
	//	- rows: The number of rows (GridWithRows)
	//	- rowColumns: The number of rows and columns (AdaptiveGrid)
	//	- elementSize: The size of the elements (GridWrap)
	//	- children: The children of the grid
	Grid Layout = "Grid"

	// HBox Layout
	//
	// Available yaml options
	//	- children: The children of the HBox
	HBox Layout = "HBox"

	// MinSize Layout
	//
	// Available yaml options
	//	- minSize: The minimum size of the layout
	//  - children: The children of the MinSize
	MinSize Layout = "MinSize"

	// Stack Layout
	//
	// Available yaml options
	// - children: The children of the Stack
	Stack Layout = "Stack"

	// VBox Layout
	//
	// Available yaml options
	//	- children: The children of the VBox
	VBox Layout = "VBox"
)

func (Layout) Build

func (l Layout) Build(
	e *Element,
	s ScreenHandler,
) (
	lay fyne.CanvasObject,
	decorator fyne.CanvasObject,
	err error,
)

Build builds the layout based on the given Layout and Element using the provided ScreenHandler to fetch functions, data bindings, etc.

Parameters: - e: The Element to build the Layout for - s: The ScreenHandler to use to fetch functions, data bindings, etc. Returns the CanvasObject for the Layout, the CanvasObject for the decorator and an error if any. If no decorators are specified, the widget and decorator will be the same.

type ListDataItemRendererFn

type ListDataItemRendererFn func(binding.DataItem, fyne.CanvasObject)

type ListItemHandlerFn

type ListItemHandlerFn func(widget.ListItemID)

type ListItemRendererFn

type ListItemRendererFn func(int, fyne.CanvasObject)

type ListItemTemplate

type ListItemTemplate struct {
	fyne.CanvasObject
	*TemplateScreenHandler
}

ListItemTemplate is a template for a list item. It implements the fyne.CanvasObject interface and TemplateScreenHandler

func NewListItemTemplate

func NewListItemTemplate(
	obj fyne.CanvasObject,
	screenHandler *TemplateScreenHandler,
) *ListItemTemplate

NewListItemTemplate creates a new ListItemTemplate

func (*ListItemTemplate) CreateRenderer

func (i *ListItemTemplate) CreateRenderer() fyne.WidgetRenderer

CreateRenderer implements the fyne.CanvasObject interface

type ListItemTemplateFn

type ListItemTemplateFn func() fyne.CanvasObject

type ListLengthFn

type ListLengthFn func() int

type Margins

type Margins struct {
	Top    float32 `yaml:"top"`
	Bottom float32 `yaml:"bottom"`
	Left   float32 `yaml:"left"`
	Right  float32 `yaml:"right"`
}

func (*Margins) HasMargins

func (m *Margins) HasMargins() bool

type OptionSelectedHandlerFn

type OptionSelectedHandlerFn func(string)

type Padding

type Padding struct {
	Top    float32 `yaml:"top"`
	Bottom float32 `yaml:"bottom"`
	Left   float32 `yaml:"left"`
	Right  float32 `yaml:"right"`
}

func (*Padding) HasPadding

func (p *Padding) HasPadding() bool

type RelativeSize

type RelativeSize struct {
	Width  float32 `yaml:"width"`
	Height float32 `yaml:"height"`
}

type Screen

type Screen struct {
	fyne.CanvasObject
	// contains filtered or unexported fields
}

func New

func New(
	filesystem embed.FS,
	name string,
	screenHandler ScreenHandler,
) (scr *Screen, err error)

func (*Screen) AsContainer

func (s *Screen) AsContainer() *fyne.Container

func (*Screen) CreateRenderer

func (s *Screen) CreateRenderer() fyne.WidgetRenderer

func (*Screen) Initialize

func (s *Screen) Initialize() (obj fyne.CanvasObject, err error)

func (*Screen) MinSize

func (s *Screen) MinSize() fyne.Size

func (*Screen) Move

func (s *Screen) Move(p fyne.Position)

func (*Screen) RegisterMoveCallback

func (s *Screen) RegisterMoveCallback(cb func(fyne.Position))

func (*Screen) RegisterResizeCallback

func (s *Screen) RegisterResizeCallback(cb func(fyne.Size))

func (*Screen) Resize

func (s *Screen) Resize(sz fyne.Size)

type ScreenHandler

type ScreenHandler interface {
	RegisterElement(string, fyne.CanvasObject, fyne.CanvasObject)

	LoadAsset(string) (fs.File, error)

	GetLocalizer() *i18n.Localizer
	GetIcon(string) fyne.Resource
	GetBinding(string) binding.DataItem
	GetValidator(string) fyne.StringValidator
	GetListItemTemplate(string) ListItemTemplateFn
	GetListDataItemRenderer(string) ListDataItemRendererFn
	GetListItemRenderer(string) ListItemRendererFn
	GetListLength(string) ListLengthFn

	GetOnListItemSelectedHandler(string) ListItemHandlerFn
	GetOnListItemUnselectedHandler(string) ListItemHandlerFn
	GetOnClickedHandler(string) ClickHandlerFn
	GetOnCheckChangedHandler(string) CheckHandlerFn
	GetOnDateSelectedHandler(string) DateSelectedHandlerFn
	GetOnOptionSelectedHandler(string) OptionSelectedHandlerFn
	GetOnValidationChangedHandler(string) ValidationChangedHandlerFn
}

type Size

type Size struct {
	Width  float32 `yaml:"width"`
	Height float32 `yaml:"height"`
}

Size represents the yaml description of a ui size

type TemplateScreenHandler

type TemplateScreenHandler struct {
	// contains filtered or unexported fields
}

func NewTemplateScreenHandler

func NewTemplateScreenHandler(
	localizer *i18n.Localizer,
) *TemplateScreenHandler

func (*TemplateScreenHandler) GetBinding

func (*TemplateScreenHandler) GetElement

func (d *TemplateScreenHandler) GetElement(name string) *UIElement

func (*TemplateScreenHandler) GetIcon

func (d *TemplateScreenHandler) GetIcon(iconName string) fyne.Resource

func (*TemplateScreenHandler) GetListDataItemRenderer

func (*TemplateScreenHandler) GetListDataItemRenderer(string) ListDataItemRendererFn

func (*TemplateScreenHandler) GetListItemRenderer

func (*TemplateScreenHandler) GetListItemRenderer(string) ListItemRendererFn

func (*TemplateScreenHandler) GetListItemTemplate

func (*TemplateScreenHandler) GetListItemTemplate(string) ListItemTemplateFn

func (*TemplateScreenHandler) GetListLength

func (*TemplateScreenHandler) GetListLength(string) ListLengthFn

func (*TemplateScreenHandler) GetLocalizer

func (d *TemplateScreenHandler) GetLocalizer() *i18n.Localizer

func (*TemplateScreenHandler) GetOnCheckChangedHandler

func (*TemplateScreenHandler) GetOnCheckChangedHandler(string) CheckHandlerFn

func (*TemplateScreenHandler) GetOnClickedHandler

func (*TemplateScreenHandler) GetOnClickedHandler(string) ClickHandlerFn

func (*TemplateScreenHandler) GetOnDateSelectedHandler

func (*TemplateScreenHandler) GetOnDateSelectedHandler(string) DateSelectedHandlerFn

func (*TemplateScreenHandler) GetOnListItemSelectedHandler

func (*TemplateScreenHandler) GetOnListItemSelectedHandler(string) ListItemHandlerFn

func (*TemplateScreenHandler) GetOnListItemUnselectedHandler

func (*TemplateScreenHandler) GetOnListItemUnselectedHandler(string) ListItemHandlerFn

func (*TemplateScreenHandler) GetOnOptionSelectedHandler

func (*TemplateScreenHandler) GetOnOptionSelectedHandler(string) OptionSelectedHandlerFn

func (*TemplateScreenHandler) GetOnValidationChangedHandler

func (*TemplateScreenHandler) GetOnValidationChangedHandler(string) ValidationChangedHandlerFn

func (*TemplateScreenHandler) GetValidator

func (*TemplateScreenHandler) GetValidator(string) fyne.StringValidator

func (*TemplateScreenHandler) LoadAsset

func (d *TemplateScreenHandler) LoadAsset(name string) (fs.File, error)

func (*TemplateScreenHandler) RegisterElement

func (d *TemplateScreenHandler) RegisterElement(
	name string,
	element fyne.CanvasObject,
	decorator fyne.CanvasObject,
)

type ToolTip

type ToolTip struct {
	Content   string `yaml:"content"`
	Localized bool   `yaml:"localized"`
}

type UIElement

type UIElement struct {
	Object    fyne.CanvasObject
	Decorator fyne.CanvasObject
}

type ValidationChangedHandlerFn

type ValidationChangedHandlerFn func(error)

type Widget

type Widget string

The constants for the Widgets

Available yaml options for all widgets:

  • id: The ID for exporting the widget to code
  • decorators: The decorators to wrap the widget into
  • hidden: Wether the widget is hidden or not
const (
	// Button Widget
	//
	// Available yaml options:
	//	- text: The text for the button
	//	- localized: If the text represents a localization key
	//	- icon: The icon for the button
	//	- disabled: Wether the button is disabled or not
	//	- options: Additional options for the button
	//		- alignment: The alignment of the button
	//		- iconPlacement: The icon placement of the button
	//		- importance: The importance of the button
	//	- onclicked: The function to call when the button is clicked
	Button Widget = "Button"

	// Calendar Widget
	//
	// Available yaml options:
	//	- time: The current time to use for the calendar
	//	- timeFormat: The format to use to interpret the time field (default time.DateOnly)
	//	- onDateSelected: The function to call when a date is selected
	Calendar Widget = "Calendar"

	// Checkbox Widget
	//
	// Available yaml options:
	//	- text: The text for the checkbox
	//	- localized: If the text represents a localization key
	//	- binding: The databinding for the checkbox
	//	- checked: The checked state of the checkbox
	//	- disabled: Wether the button is disabled or not
	//	- onChanged: The function to call when the checkbox is changed
	Check Widget = "Check"

	DateEntry Widget = "DateEntry"

	// Entry Widget
	//
	// Available yaml options:
	//	- text: The text for the entry
	//	- localized: If the text represents a localization key
	//	- binding: The databinding for the entry
	//	- placeholder: The placeholder for the entry
	//	- placeholderLocalized: If the placeholder represents a localization key
	//	- multiLine: If the entry is multiline
	//	- disabled: Wether the button is disabled or not
	//	- validator: The validator for the entry
	//	- onValidationChanged: The function to call when the validation changes
	Entry Widget = "Entry"

	// H1 Widget
	//
	// Available yaml options:
	//	- text: The text for the H1
	//	- localized: If the text represents a localization key
	// 	- binding: The databinding for the H1
	//	- options: The options for the H1
	//		- wrapping: The wrapping option for the H1
	//		- truncation: The truncation option for the H1
	H1 Widget = "H1"

	// H2 Widget
	//
	// Available yaml options:
	//	- text: The text for the H2
	//	- localized: If the text represents a localization key
	// 	- binding: The databinding for the H2
	//	- options: The options for the H2
	//		- wrapping: The wrapping option for the H2
	//		- truncation: The truncation option for the H2
	H2 Widget = "H2"

	// H3 Widget
	//
	// Available yaml options:
	//	- text: The text for the H3
	//	- localized: If the text represents a localization key
	// 	- binding: The databinding for the H3
	//	- options: The options for the H3
	//		- wrapping: The wrapping option for the H3
	//		- truncation: The truncation option for the H3
	H3 Widget = "H3"

	// H4 Widget
	//
	// Available yaml options:
	//	- text: The text for the H4
	//	- localized: If the text represents a localization key
	// 	- binding: The databinding for the H4
	//	- options: The options for the H4
	//		- wrapping: The wrapping option for the H4
	//		- truncation: The truncation option for the H4
	H4 Widget = "H4"

	// H5 Widget
	//
	// Available yaml options:
	//	- text: The text for the H5
	//	- localized: If the text represents a localization key
	// 	- binding: The databinding for the H5
	//	- options: The options for the H5
	//		- wrapping: The wrapping option for the H5
	//		- truncation: The truncation option for the H5
	H5 Widget = "H5"

	// H6 Widget
	//
	// Available yaml options:
	//	- text: The text for the H6
	//	- localized: If the text represents a localization key
	// 	- binding: The databinding for the H6
	//	- options: The options for the H6
	//		- wrapping: The wrapping option for the H6
	//		- truncation: The truncation option for the H6
	H6 Widget = "H6"

	// Icon Widget
	//
	// Available yaml options:
	//	- icon: The icon for the icon
	Icon Widget = "Icon"

	// Label Widget
	//
	// Available yaml options:
	//	- text: The text for the label
	//	- localized: If the text represents a localization key
	// 	- binding: The databinding for the label
	//	- options: The options for the label
	//		- alignment: The alignment option for the label
	//		- wrapping: The wrapping option for the label
	// 		- textStyle: The text style option for the label
	//		- truncation: The truncation option for the label
	Label Widget = "Label"

	// List Widget
	//
	// Available yaml options:
	//	- binding: The databinding for the list
	//	- listLength: The length of the list
	//	- itemTemplate: The item template for the list
	//	- itemRenderer: The item renderer for the list
	//	- onSelect: The on select function for the list
	//	- onUnselect: The on unselect function for the list
	List Widget = "List"

	RichText Widget = "RichText"

	// ScoreDisplay Widget
	ScoreDisplay Widget = "ScoreDisplay"

	// Select Widget
	Select Widget = "Select"

	// SelectEntry Widget
	SelectEntry Widget = "SelectEntry"

	// Separator Widget
	Separator Widget = "Separator"

	// Spacer Widget
	Spacer Widget = "Spacer"

	// UpDownLabel Widget
	//
	// Available yaml options:
	//	- binding: The databinding for the up down label
	//	- onUpClicked: The on up clicked function for the up down label
	//	- onDownClicked: The on down clicked function for the up down label
	UpDownLabel Widget = "UpDownLabel"
)

func (Widget) Build

func (w Widget) Build(
	e *Element,
	s ScreenHandler,
) (
	widget fyne.CanvasObject,
	decorator fyne.CanvasObject,
	err error,
)

Build builds a fyne.CanvasObject for the given Widget and Element, using the provided ScreenHandler to fetch functions, data bindings, etc.

Arguments: - e: The Element to build the Widget for. - s: The ScreenHandler to use to fetch functions, data bindings, etc.

Returns the CanvasObject for the widget, the CanvasObject for the decorator, and an error if any. If no decorators are specified, the widget and decorator will be the same.

Jump to

Keyboard shortcuts

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