tomo

package module
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2023 License: GPL-3.0 Imports: 13 Imported by: 14

README

tomo

WIP rewrite of tomo.

This module will serve as a wafer-thin collection of interfaces and glue code so that plugins will be an actual viable concept.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(priority int, factory Factory)

Register registers a backend factory with the given priority number.

func Run

func Run(callback func()) error

Run initializes a backend, runs the specified callback function, and runs the event loop in that order. This function blocks until Stop is called, or the backend experiences a fatal error.

func Stop

func Stop()

Stop stops the backend, unblocking run. Run may be called again after calling Stop.

Types

type Align

type Align int
const (
	AlignStart  Align = iota // similar to left-aligned text
	AlignMiddle              // similar to center-aligned text
	AlignEnd                 // similar to right-aligned text
	AlignEven                // similar to justified text
)

type Backend

type Backend interface {
	NewWindow(image.Rectangle) (MainWindow, error)
	NewBox() Box
	NewTextBox() TextBox
	NewCanvasBox() CanvasBox
	NewContainerBox() ContainerBox

	// Stop must unblock run.
	Run() error
	Stop()

	// Do performs a callback function in the main thread as soon as
	// possible. This method must be safe to call concurrently.
	Do(func())
}

func Initialize

func Initialize() (Backend, error)

Initialize instantiates a backend. The first backend (sorted by priority) that does not throw an error when initialized is used. If no backend could be instantiated, this function returns an error. This function should be called only once.

type Border

type Border struct {
	Width Inset
	Color [4]color.Color
}

type Box

type Box interface {
	Object

	Window() Window
	Bounds() image.Rectangle
	InnerBounds() image.Rectangle
	SetBounds(image.Rectangle)
	SetColor(color.Color)
	SetBorder(...Border)
	SetMinimumSize(int, int)
	SetPadding(Inset)

	SetDNDData(data.Data)
	SetDNDAccept(...data.Mime)
	SetFocused(bool)
	SetFocusable(bool)

	Focused() bool
	Modifiers() input.Modifiers
	MousePosition() image.Point

	OnFocusEnter(func()) event.Cookie
	OnFocusLeave(func()) event.Cookie
	OnDNDEnter(func()) event.Cookie
	OnDNDLeave(func()) event.Cookie
	OnDNDDrop(func(data.Data)) event.Cookie
	OnMouseEnter(func()) event.Cookie
	OnMouseLeave(func()) event.Cookie
	OnMouseMove(func()) event.Cookie
	OnMouseDown(func(input.Button)) event.Cookie
	OnMouseUp(func(input.Button)) event.Cookie
	OnScroll(func(deltaX, deltaY float64)) event.Cookie
	OnKeyDown(func(key input.Key, numberPad bool)) event.Cookie
	OnKeyUp(func(key input.Key, numberPad bool)) event.Cookie
}

Box is a basic styled box.

func NewBox

func NewBox() Box

type CanvasBox

type CanvasBox interface {
	Box
	SetDrawer(canvas.Drawer)
	Invalidate()
}

CanvasBox is a box that can be drawn to.

func NewCanvasBox

func NewCanvasBox() CanvasBox

type ContainerBox

type ContainerBox interface {
	ContentBox
	SetGap(image.Point)
	Add(Object)
	Delete(Object)
	Insert(child Object, before Object)
	Clear()
	Length() int
	At(int) Object
	SetLayout(Layout)
}

ContentBox is a box that can contain child objects. It arranges them according to a layout rule.

func NewContainerBox

func NewContainerBox() ContainerBox

type ContentBox added in v0.7.3

type ContentBox interface {
	Box
	SetOverflow(horizontal, vertical bool)
	ContentBounds() image.Rectangle
	ScrollTo(image.Point)
	OnContentBoundsChange(func()) event.Cookie
}

ContentBox is an abstract box that has some kind of content. Its only purpose is to be embedded into TextBox and ContainerBox.

type Factory

type Factory func() (Backend, error)

Factory is a function that attempts to instatiate a backend. If the instantiation process fails at any point, it must clean up all resources and return nil and an error explaining what happened.

type Inset

type Inset [4]int

func I added in v0.7.0

func I(sides ...int) Inset

I allows you to create an inset in a CSS-ish way:

  • One argument: all sides are set to this value
  • Two arguments: the top and bottom sides are set to the first value, and the left and right sides are set to the second value.
  • Three arguments: the top side is set by the first value, the left and right sides are set by the second vaue, and the bottom side is set by the third value.
  • Four arguments: each value corresponds to a side.

This function will panic if an argument count that isn't one of these is given.

func (Inset) Apply added in v0.7.0

func (inset Inset) Apply(bigger image.Rectangle) (smaller image.Rectangle)

Apply returns the given rectangle, shrunk on all four sides by the given inset. If a measurment of the inset is negative, that side will instead be expanded outward. If the rectangle's dimensions cannot be reduced any further, an empty rectangle near its center will be returned.

func (Inset) Horizontal added in v0.7.0

func (inset Inset) Horizontal() int

Horizontal returns the sum of SideRight and SideLeft.

func (Inset) Inverse added in v0.7.0

func (inset Inset) Inverse() (prime Inset)

Inverse returns a negated version of the inset.

func (Inset) Vertical added in v0.7.0

func (inset Inset) Vertical() int

Vertical returns the sum of SideTop and SideBottom.

type Layout

type Layout interface {
	MinimumSize(LayoutHints, []Box) image.Point
	Arrange(LayoutHints, []Box)
}

Layout can be given to a ContainerBox to arrange child objects.

type LayoutHints added in v0.9.0

type LayoutHints struct {
	Min image.Point
	Max *image.Point
	Gap image.Point
}

LayoutHints are passed to a layout to tell it how to arrange child boxes.

type MainWindow

type MainWindow interface {
	Window
	NewChild(image.Rectangle) (Window, error)
}

MainWindow is a top-level operating system window.

func NewWindow

func NewWindow(bounds image.Rectangle) (MainWindow, error)

type Object

type Object interface {
	Box() Box
}

Object is any obscreen object. Each object must be linked to a box, even if it is that box.

type Side added in v0.7.0

type Side int

Side represents one side of a rectangle.

const (
	SideTop Side = iota
	SideRight
	SideBottom
	SideLeft
)

type TextBox

type TextBox interface {
	ContentBox
	SetTextColor(color.Color)
	SetFace(font.Face)
	SetHAlign(Align)
	SetVAlign(Align)
}

TextBox is a box that contains text content.

func NewTextBox

func NewTextBox() TextBox

type Window

type Window interface {
	SetRoot(Object)
	SetTitle(string)
	SetIcon(sizes []image.Image)
	NewMenu(image.Rectangle) (Window, error)
	NewModal(image.Rectangle) (Window, error)
	Widget() (Window, error)
	Copy(data.Data)
	Paste(callback func(data.Data, error), accept ...data.Mime)
	Show()
	Hide()
	Close()
	OnClose(func()) event.Cookie
}

Window is an operating system window. It can contain one object.

Directories

Path Synopsis
Canvas defines a standard interface for images that support drawing primitives.
Canvas defines a standard interface for images that support drawing primitives.
Package data provides operations to deal with arbitrary data and MIME types.
Package data provides operations to deal with arbitrary data and MIME types.
Package event provides a system for broadcasting events to multiple event handlers.
Package event provides a system for broadcasting events to multiple event handlers.
Package input defines keyboard and mouse code constants.
Package input defines keyboard and mouse code constants.

Jump to

Keyboard shortcuts

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