dali

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2020 License: MIT Imports: 11 Imported by: 0

README

Dali

Summary

Dali is a pure Golang library built on lorca in order to provide Go developers a way to create GUI-based applications using idiomatic Go.

Lorca provides a minimal binding between Go and Chrome via the Chrome Developer API. The output of Dali is a Chrome application.

The goal is remove the need for Go developers to embed HTML or Javascript within their applications. Dali produces the HTML, passes it to Lorca, which serves up the application.

What Need Does Dali Fulfill?

I am a fan of data science and infographics. I see a huge potential for Golang to supplant R, Python and C++ as solutions for data scientists, but it lacks the out-of-the box tools that Python and R have accumulated over time.

Go is much more readable than R and C++. It is much more peformant than Python. It supports code paralellization and includes built-in garbage collection - two challenges that data science applications can suffer from.

My hope is that Dali will help reduce the learning curve for Go, and pave the way to making Go teachable and usable within the context of interdisceplnary data sciance classrooms and laboratories.

What is In A Name?

Dali, well known as a surrealist artist, was intimate friends with the poet, Lorca. The lorca project explains its name, but you can learn more about the men here.

License

The Dali project is licensed under the MIT Licesnse

Examples

The examples are in the examples directory. Read through the code, run them, change them!

  1. cd examples/one
  2. go run example_one.go

A simplified example that shows the nature of building a UI, giving it components, and launching it:

package main

import (
	"github.com/matthewapeters/dali"
)


func main() {
	/**
	 * Example one shows the creation of a window with a title.
	 */
	Window := dali.NewWindow(600, 400, "", "")
	Title := &dali.TitleElement{Text: "Dali Example One"}
	Head := dali.NewHeadElement()
	Head.Elements.AddElement(Title)
	Window.Elements.AddElement(Head)

	/*Add a body with no on-load function, and a blue background*/
	Body := dali.NewBodyElement("")
	Body.Style = "background:#5080FF;"

	/*Add an H1 banner named pageBanner to the GUI*/
	Banner := dali.NewHeader(dali.H1, "pageBanner", "This is Example One")
 
    /*Add the banner to body, and add the body to the window*/
    Body.Elements.AddElement(Banner)
	Window.Elements.AddElement(Body)

	/*Start the GUI*/
	Window.Start()

	/*Wait for the GUI to close*/
	<-Window.GetUI().Done()
	fmt.Println("The GUI has closed."))
Example One

example one _Example One illustrates the ease of creating a desktop app with Dali. The Pick A Number function is written in Go, then displayed on the window. Project objective is to eliminate library users' need to write JavaScript.

Exaple Two

exampel two Example Two streams images of randomly sized, colored, and positioned dots. The multiple example_two processes show these are being produced asynchronoushly and in parallel

Example Three

With collaborative help from Christopher R Peters on use of HSV coloring, viewport panning and coding and testing. exampel three exampel three

Example Three will help you discover the Mandelbrot set. The automated "Start Iteration" uses an increasingly higher-resolution fractal drawing through increased iteration. Each pixel is iterated over n times from 0 to 5000. The "Pause Iterations"/"Resume Iterations" button allows you to stop and change your focal point on the Imaginary Number Place. For performance, chunks of the image are processed in their own go routine. Chunks quantities are based on the number of CPUs available and the number of iterations requested. Each of the variables is also directly editable, and buttons provide point-and-click exploration of the Mandelbrot set. You can save your favorite views and come back to them later. A number of palettes are provided to delight the user in their exploration.

Example Three is more complex to build than the first two examples:

$ cd examples/three
$ go build .
$ ./three

The objective for this example was to identify highly used Javascripting in order to improve the Dali feature set, and to produce an application which exercised the power of Golang's concurrency and speed.

Contributing to Dali

I am happy to incorporate contributions and improvements. As a rule, I am hoping to accomplish the following with this project:

  1. Make a library that allows for idiomatic Golang GUI creation
  2. Provide for all of the styling and interactability that HTML5 allows for
  3. For the library user:
    1. Minimize magic and secrets
    2. Minimize necessary JavaScript
    3. Minimize necessary HTML
  4. Quickly spin up distributable graphical applications that allow developers to leverage the power of Go
  5. Allow the stength of diverse teams to make applications better:
    1. Support the incorporation of sophisticated stylesheets
    2. Support the incorporation of sophisticated javascript behaviors
    3. Support the separation of layers: do not require the embedding of scripts and stylesheets

Things that are out-of-scope and that dali is not concerned with

  1. Creating websites
  2. Creating webservers
  3. Creating enterprise-scale applications / concurrent user sessions

Funding and Supporting Dali

Dali is not my full-time effort. My employer is not funding my Dali efforts, and I do not want to compromise either their or my intellectual properties. If you find Dali useful or full of potential for your efforts, I am accepting patronage support at Patreon

Documentation

Index

Constants

View Source
const (
	//H1 header
	H1 = HeaderLevel(1)
	//H2 header
	H2 = HeaderLevel(2)
	//H3 header
	H3 = HeaderLevel(3)
	//H4 header
	H4 = HeaderLevel(4)
)
View Source
const (
	ButtonInput        = InputType("button")
	CheckboxInput      = InputType("checkbox")
	ColorInput         = InputType("color")
	DateInput          = InputType("date")
	DatetimeLocalInput = InputType("datetime-local")
	EmailInput         = InputType("email")
	FileInput          = InputType("file")
	HiddenInput        = InputType("hidden")
	ImageInput         = InputType("image")
	MonthInput         = InputType("month")
	NumberInput        = InputType("number")
	PasswordInput      = InputType("password")
	RadioInput         = InputType("radio")
	RangeInput         = InputType("range")
	ResetInput         = InputType("reset")
	SearchInput        = InputType("search")
	SubmitInput        = InputType("submit")
	TelInput           = InputType("tel")
	TextInput          = InputType("text")
	TimeInput          = InputType("time")
	URLInput           = InputType("url")
	WeekInput          = InputType("week")

	OnBlur        = InputEventType("onblur")
	OnChange      = InputEventType("onchange")
	OnFocus       = InputEventType("onfocus")
	OnInput       = InputEventType("oninput")
	OnInvalid     = InputEventType("oninvalid")
	OnReset       = InputEventType("onreset")
	OnSearch      = InputEventType("onsearch")
	OnSelect      = InputEventType("onselect")
	OnSubmit      = InputEventType("onsubmit")
	OnContextmenu = InputEventType("oncontextmenu")
)
View Source
const (
	//Default covers the whole area
	Default = AreaShape("default")
	// Rectangle Map
	Rectangle = AreaShape("rect")
	//Circle is a circular Map
	Circle = AreaShape("circle")
	//Polygon is a polygon
	Polygon = AreaShape("poly")
	//Function is a function link type
	Function = LinkType("function")
	//URL is an HREF link type
	URL = LinkType("url")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Area

type Area struct {
	Shape    AreaShape
	Coords   Coordinates
	Alt      string
	URL      string
	LinkType LinkType
}

Area is a component of a Map

func (Area) String

func (a Area) String() string

String html rendering of a map area

type AreaShape

type AreaShape string

AreaShape is a string type

type BR

type BR struct {
	StyleName string
	Base
}

BR a break tag

func LineBreak

func LineBreak() *BR

LineBreak generates a BR tag

func (*BR) Bindings

func (br *BR) Bindings() *Binding

Bindings returns nil

func (*BR) Children

func (br *BR) Children() *Elements

Children will return an empty Elements

func (*BR) Class

func (br *BR) Class() string

Class of the BR

func (*BR) String

func (br *BR) String() string

func (*BR) Style

func (br *BR) Style() string

Style of the BR

type Base

type Base struct {
	ID    string
	Style string
	UI    *lorca.UI
	Binding
	Element
}

Base is the common structure that all Elements have

func (*Base) Disable

func (b *Base) Disable()

Disable sets the base element disabledproperty to true

func (*Base) Enable

func (b *Base) Enable()

Enable sets the base element disabled property to false

func (*Base) GetUI

func (b *Base) GetUI() *lorca.UI

GetUI returns the UI from the Base

func (*Base) Name

func (b *Base) Name() string

Name return the ID of the Base

func (*Base) Set

func (b *Base) Set(v string)

Set assigns the value to the item

func (*Base) SetText

func (b *Base) SetText(s string) error

SetText replaces the inner text of the element after the Window has been started

func (*Base) SetUI

func (b *Base) SetUI(ui *lorca.UI)

SetUI adds the UI to the Base

func (*Base) Value

func (b *Base) Value() string

Value returns the value of an item

type Binding

type Binding struct {
	FunctionName  string
	BoundFunction func()
}

Binding defines which JavaScript functions should be bound to Go functions

type BodyElement

type BodyElement struct {
	Style    string
	Elements *Elements
	Binding  *Binding
	Base
}

BodyElement for holding the body of the page

func NewBodyElement

func NewBodyElement(onLoad string) *BodyElement

NewBodyElement creates a body element

func (*BodyElement) Bindings

func (b *BodyElement) Bindings() *Binding

Bindings returns the Binding

func (*BodyElement) Children

func (b *BodyElement) Children() *Elements

Children return the Elements

func (*BodyElement) String

func (b *BodyElement) String() string

type Button

type Button struct {
	ButtonText string
	Style      string
	Base
	Binding
}

Button type

func NewButton

func NewButton(label, name, funcName string) *Button

NewButton creates a new button

func (*Button) BindFunction

func (b *Button) BindFunction(f func())

BindFunction will bind the button to this go function

func (*Button) Bindings

func (b *Button) Bindings() *Binding

Bindings returns the bindings for the button

func (*Button) Children

func (b *Button) Children() *Elements

Children will return an empty Elements

func (*Button) Class

func (b *Button) Class() string

Class set the Class of the button

func (*Button) Clickable

func (b *Button) Clickable() bool

Clickable returns true for buttons

func (*Button) OnClick

func (b *Button) OnClick() string

OnClick returns the name of the onclick function

func (*Button) String

func (b *Button) String() string

type Canvas

type Canvas struct {
	Width, Height int
	Base
}

Canvas element

func NewCanvas

func NewCanvas(width, height int, name string) *Canvas

NewCanvas creates a new Canvas

func (*Canvas) Bindings

func (c *Canvas) Bindings() *Binding

Bindings returns nil

func (*Canvas) Children

func (c *Canvas) Children() *Elements

Children will return an empty Elements

func (*Canvas) Class

func (c *Canvas) Class() string

Class of the canvas

func (*Canvas) Clickable

func (c *Canvas) Clickable() bool

Clickable is false on Canvas

func (*Canvas) String

func (c *Canvas) String() string

type Coordinates

type Coordinates []int

Coordinates is an array of coordinates

func (Coordinates) String

func (c Coordinates) String() string

String representation of coordinates

type Div

type Div struct {
	Base
	Elements *Elements
	Binding
}

Div is a page within a Window

func NewDiv

func NewDiv(name string) *Div

NewDiv generates a new Div

func (*Div) Bindings

func (p *Div) Bindings() *Binding

Bindings returns the binding

func (*Div) Children

func (p *Div) Children() *Elements

Children returns the Elements

func (*Div) Class

func (p *Div) Class() string

Class of a div is DIV

func (*Div) String

func (p *Div) String() string

String for Div

type Element

type Element interface {
	String() string
	Class() string
	Name() string
	Clickable() bool
	Styles() Styles
	Children() *Elements
	Bindings() *Binding
	Value() string
	SetUI(*lorca.UI)
	GetUI() *lorca.UI
}

Element is an interface for describing an HTML element

type Elements

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

Elements is a slice of Elements

func (*Elements) AddElement

func (els *Elements) AddElement(e Element)

AddElement appends an element to the slice of elements

func (*Elements) String

func (els *Elements) String() string

String for Elements

type HeadElement

type HeadElement struct {
	Title    string
	Elements *Elements
	Base
}

HeadElement provides the Head

func NewHeadElement

func NewHeadElement() *HeadElement

NewHeadElement to create a new Head Element

func (*HeadElement) Bindings

func (h *HeadElement) Bindings() *Binding

Bindings returns nil

func (*HeadElement) Children

func (h *HeadElement) Children() *Elements

Children returns the Elements

func (*HeadElement) Class

func (h *HeadElement) Class() string

Class of the HeadElement

func (*HeadElement) String

func (h *HeadElement) String() string

String for Head

func (*HeadElement) Style

func (h *HeadElement) Style() string

Style - not applicable

type Header struct {
	StyleName string
	ID        string
	Level     HeaderLevel
	Text      string
	Element
}

Header is a header

func NewHeader

func NewHeader(level HeaderLevel, name, text string) *Header

NewHeader produces a new header element

func (*Header) Bindings

func (h *Header) Bindings() *Binding

Bindings return nil

func (*Header) Children

func (h *Header) Children() *Elements

Children will return an empty Elements

func (*Header) Class

func (h *Header) Class() string

Class returns the header class

func (*Header) String

func (h *Header) String() string

func (*Header) Style

func (h *Header) Style() string

Style returns the style of the Header

type HeaderLevel

type HeaderLevel int

HeaderLevel enums header sizes

type Image

type Image struct {
	Width, Height int
	URL           string
	Alt           string
	AreaMap       Map
	Base
}

Image element

func NewImage

func NewImage(name string, width, height int, url string) *Image

NewImage generates a new Image object

func (*Image) AddMapArea

func (i *Image) AddMapArea(shape AreaShape, coords Coordinates, alt string, linkType LinkType, link string) error

AddMapArea to the image map

func (*Image) Bindings

func (i *Image) Bindings() *Binding

Bindings returns nil

func (*Image) Children

func (i *Image) Children() *Elements

Children returns an empty Elements

func (*Image) Class

func (i *Image) Class() string

Class of image

func (*Image) Clickable

func (i *Image) Clickable() bool

Clickable attribute of image - is true if there are mapped areas

func (*Image) Load

func (i *Image) Load(img *image.RGBA) error

Load an *image.RGBA into the image element

func (*Image) String

func (i *Image) String() string

String for image

type InputElement

type InputElement struct {
	InputType
	Text string
	Base
	Binding
	InputEventType
}

InputElement is for inputting values

func NewInputElement

func NewInputElement(name string, inputType InputType) *InputElement

NewInputElement creates an input element

func (*InputElement) Bindings

func (tf *InputElement) Bindings() *Binding

Bindings returns the element Bindings

func (*InputElement) Children

func (tf *InputElement) Children() *Elements

Children returns the child elements

func (*InputElement) String

func (tf *InputElement) String() string

type InputEventType

type InputEventType string

InputEventType identifies the binding event type

type InputType

type InputType string

InputType identifies input element types

type LinkType

type LinkType string

LinkType is a constant of either Function or URL

type Map

type Map struct {
	Name  string
	Areas []Area
}

Map of regions on an image that are clickable

func (Map) String

func (m Map) String() string

String of Map

type OptionElement

type OptionElement struct {
	Text  string
	Value string
}

OptionElement for use in SelectElement

func (*OptionElement) String

func (oe *OptionElement) String() string

type OptionSlice

type OptionSlice []*OptionElement

OptionSlice is a slice of OptionElements

func (*OptionSlice) String

func (oes *OptionSlice) String() string

type ScriptElement

type ScriptElement struct {
	URL  string
	Text string
	Base
}

ScriptElement is for scripts

func (*ScriptElement) Bindings

func (scr *ScriptElement) Bindings() *Binding

Bindings returns nil

func (*ScriptElement) Children

func (scr *ScriptElement) Children() *Elements

Children returns an empty Elements

func (*ScriptElement) Class

func (scr *ScriptElement) Class() string

Class of script

func (*ScriptElement) String

func (scr *ScriptElement) String() string

func (*ScriptElement) Style

func (scr *ScriptElement) Style() string

Style of script

type SelectElement

type SelectElement struct {
	Base
	Binding
	InputEventType
	Options *OptionSlice
}

SelectElement provides a selection drop-down

func NewSelectElement

func NewSelectElement(name, functionName string) *SelectElement

NewSelectElement creates a new select element

func (*SelectElement) AddOption

func (se *SelectElement) AddOption(label, value string)

AddOption will add an option to the SelectElement

func (*SelectElement) Bindings

func (se *SelectElement) Bindings() *Binding

Bindings returns the Binding

func (*SelectElement) Children

func (se *SelectElement) Children() *Elements

Children returns an empty list

func (*SelectElement) String

func (se *SelectElement) String() string

type Span

type Span struct {
	Text string
	Base
}

Span element

func (*Span) Bindings

func (s *Span) Bindings() *Binding

Bindings returns nil

func (*Span) Children

func (s *Span) Children() *Elements

Children returns an empty Elements

func (*Span) Class

func (s *Span) Class() string

Class for span

func (*Span) String

func (s *Span) String() string

String for span

type StyleSheet

type StyleSheet struct {
	URL string
}

StyleSheet references an external stylesheet to load

func (StyleSheet) String

func (style StyleSheet) String() string

String for StyleSheet

type Styles

type Styles map[string]string

Styles is a map of style elements and values

func (Styles) String

func (s Styles) String() string

String for Styles

type TextElement

type TextElement struct {
	Base
	// contains filtered or unexported fields
}

TextElement is an element for plain old text - if you want style, use a Span

func Text

func Text(t string) *TextElement

Text creates a TextElement

func (*TextElement) Bindings

func (t *TextElement) Bindings() *Binding

Bindings returns nil

func (*TextElement) Children

func (t *TextElement) Children() *Elements

Children returns an empty Elements

func (*TextElement) Class

func (t *TextElement) Class() string

Class for TextElement

func (*TextElement) String

func (t *TextElement) String() string

String stringer for TextElement

func (*TextElement) Style

func (t *TextElement) Style() string

Style for Text Element

type TitleElement

type TitleElement struct {
	Text string
	Base
}

TitleElement for createing window titles

func (*TitleElement) Bindings

func (t *TitleElement) Bindings() *Binding

Bindings returns nil

func (*TitleElement) Children

func (t *TitleElement) Children() *Elements

Children will return an empty Elements

func (*TitleElement) Class

func (t *TitleElement) Class() string

Class for title

func (*TitleElement) String

func (t *TitleElement) String() string

String stringer for Title

func (*TitleElement) Style

func (t *TitleElement) Style() string

Style for title

type Window

type Window struct {
	Width, Height int
	Style         StyleSheet

	ProfileDir string
	Elements   *Elements
	Args       []string
	Bindings   []Binding
	// contains filtered or unexported fields
}

Window is the main application window

func NewWindow

func NewWindow(width, height int, profileDir string, styleSheet string, args ...string) *Window

NewWindow creates a new Window

func (*Window) Bind

func (w *Window) Bind(jscriptFunction string, golangFunction func())

Bind maps a javascript function to a golang function

func (*Window) BindChildren

func (w *Window) BindChildren(el *Element)

BindChildren is used to recursively

func (*Window) Close

func (w *Window) Close()

Close wraps lorca.UI.Close()

func (*Window) GetUI

func (w *Window) GetUI() lorca.UI

GetUI is a temporary wrapper for retrieving the lorca.UI

func (*Window) Start

func (w *Window) Start() error

Start extracts the application HTML and starts the UI

func (*Window) String

func (w *Window) String() string

String for Window

Directories

Path Synopsis
examples
one
two

Jump to

Keyboard shortcuts

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