ui

package
v0.0.0-...-dbc7887 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2019 License: MIT Imports: 31 Imported by: 1

Documentation

Overview

Package ui is the user interface of the editor.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Col

type Col struct {
	Row // focus
	// contains filtered or unexported fields
}

A Col is a column of sheets.

func NewCol

func NewCol(w *Win) *Col

NewCol returns a new column.

func (*Col) Add

func (c *Col) Add(row Row)

Add adds an element to the column.

func (*Col) Click

func (c *Col) Click(pt image.Point, button int)

Click handles click events.

func (*Col) Del

func (c *Col) Del(r Row)

Del deletes a row from the column.

func (*Col) Draw

func (c *Col) Draw(dirty bool, drawImage draw.Image)

Draw draws the column.

func (*Col) HandleBounds

func (c *Col) HandleBounds() image.Rectangle

HandleBounds returns the bounding box of the handle.

func (*Col) Move

func (c *Col) Move(pt image.Point)

Move handles mouse move events.

func (*Col) Resize

func (c *Col) Resize(size image.Point)

Resize handles resize events.

func (*Col) Tick

func (c *Col) Tick() bool

Tick handles tick events.

func (*Col) Wheel

func (c *Col) Wheel(pt image.Point, x, y int)

Wheel handles mouse wheel events.

type Row

type Row interface {
	// Draw draws the element to the image.
	// If dirty is true the element should redraw itself in its entirity.
	// If dirty is false, the element need only redraw
	// parts that have changed since the last call to Draw.
	Draw(dirty bool, img draw.Image)

	// Focus handles a focus state change.
	// The focus is either true (in focus) or false (out of focus).
	Focus(focus bool)

	// Resize handles a resize event.
	Resize(size image.Point)

	// Tick returns whether the row need be redrawn.
	// It is intended to be called at regular intervals
	// in order to drive asynchronous events.
	Tick() bool

	// Move handles mouse cursor moving events.
	Move(pt image.Point)

	// Click handles mouse button events.
	//
	// The absolute value of the argument indicates the mouse button.
	// A positive value indicates the button was pressed.
	// A negative value indicates the button was released.
	//
	// The first return value is the button ultimately pressed
	// (this can differ from the argument button, for example,
	// if modifier keys are being held).
	// If the button is < 0, the second return value is the clicked address.
	Click(pt image.Point, button int) (int, [2]int64)

	// Wheel handles mouse wheel events.
	// 	-y is roll up.
	// 	+y is roll down.
	// 	-x is roll left.
	// 	+x is roll right.
	Wheel(pt image.Point, x, y int)

	// Dir handles keyboard directional events.
	//
	// These events are generated by the arrow keys,
	// page up and down keys, and the home and end keys.
	// Exactly one of x or y must be non-zero.
	//
	// If the absolute value is 1, then it is treated as an arrow key
	// in the corresponding direction (x-horizontal, y-vertical,
	// negative-left/up, positive-right/down).
	// If the absolute value is math.MinInt16, it is treated as a home event.
	// If the absolute value is math.MathInt16, it is end.
	// Otherwise, if the value for y is non-zero it is page up/down.
	// Other non-zero values for x are currently ignored.
	//
	// Dir only handles key press events, not key releases.
	Dir(x, y int)

	// Mod handles modifier key state change events.
	//
	// The absolute value of the argument indicates the modifier key.
	// A positive value indicates the key was pressed.
	// A negative value indicates the key was released.
	Mod(m int)

	// Rune handles typing events.
	//
	// The argument is a rune indicating the glyph typed
	// after interpretation by any system-dependent
	// keyboard/layout mapping.
	// For example, if the 'a' key is pressed
	// while the shift key is held,
	// the argument would be the letter 'A'.
	//
	// If the rune is positive, the event is a key press,
	// if negative, a key release.
	Rune(r rune)
}

The Row interface is implemented by UI elements that sit in a column, draw, and react to user input events.

All corrdinates below are relative to the row, with 0,0 in the upper left.

type Sheet

type Sheet struct {
	*TextBox // the focus element: the tag or the body.
	// contains filtered or unexported fields
}

A Sheet is a tag and a body. TODO: better document the Sheet type.

func NewSheet

func NewSheet(w *Win, title string) *Sheet

NewSheet returns a new sheet.

func (*Sheet) Body

func (s *Sheet) Body() *TextBox

Body returns the sheet's body text box.

func (*Sheet) Click

func (s *Sheet) Click(pt image.Point, button int) (int, [2]int64)

Click handles click events.

func (*Sheet) Draw

func (s *Sheet) Draw(dirty bool, drawImg draw.Image)

Draw draws the sheet.

func (*Sheet) Get

func (s *Sheet) Get() error

Get loads the body of the sheet with the contents of the file at the path of the sheet's title.

func (*Sheet) HandleBounds

func (s *Sheet) HandleBounds() image.Rectangle

HandleBounds returns the bounding box of the handle.

func (*Sheet) Move

func (s *Sheet) Move(pt image.Point)

Move handles movement events.

func (*Sheet) Put

func (s *Sheet) Put() error

Put writes the contents of the body of the sheet to the file at the path of the sheet's title.

func (*Sheet) Resize

func (s *Sheet) Resize(size image.Point)

Resize handles resize events.

func (*Sheet) SetTitle

func (s *Sheet) SetTitle(title string)

SetTitle sets the title of the sheet.

func (*Sheet) Tick

func (s *Sheet) Tick() bool

Tick handles tic events.

func (*Sheet) Title

func (s *Sheet) Title() string

Title returns the title of the sheet. The title is the first space-terminated string in the tag, or if the first rune of the tag is ' , it is the first ' terminated string with \' as an escaped ' and \\ as an escaped \.

func (*Sheet) Update

Update watches for updates to the tag and resizes it to fit the text height.

func (*Sheet) Wheel

func (s *Sheet) Wheel(pt image.Point, x, y int)

Wheel handles mouse wheel events.

type TextBox

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

TextBox is an editable text box UI widget.

func NewTextBox

func NewTextBox(w *Win, styles [4]text.Style, size image.Point) *TextBox

NewTextBox returns a new, empty text box. The styles are:

0: default style
1: 1-click selection style
2: 2-click selection style
3: 3-click selection style

func (*TextBox) Change

func (b *TextBox) Change(diffs edit.Diffs)

Change applies a set of diffs to the text box.

func (*TextBox) Click

func (b *TextBox) Click(pt image.Point, button int) (int, [2]int64)

Click handles a mouse button press or release event. The first return value is the button ultimately pressed (this can differ from the argument button, for example, if modifier keys are being held). If the button is < 0, the second return value is the clicked address. The third return value is whether the text box image needs to be redrawn.

The absolute value of the argument indicates the mouse button. A positive value indicates the button was pressed. A negative value indicates the button was released.

func (*TextBox) Copy

func (b *TextBox) Copy() error

Copy copies the selected text into the system clipboard.

func (*TextBox) Cut

func (b *TextBox) Cut() error

Cut copies the selected text into the system clipboard and deletes it from the text box.

func (*TextBox) Dir

func (b *TextBox) Dir(x, y int)

Dir handles a keyboard directional event and returns whether the text box image needs to be redrawn.

These events are generated by the arrow keys, page up and down keys, and the home and end keys. Exactly one of x or y must be non-zero.

If the absolute value is 1, then it is treated as an arrow key in the corresponding direction (x-horizontal, y-vertical, negative-left/up, positive-right/down). If the absolute value is math.MinInt16, it is treated as a home event. If the absolute value is math.MathInt16, it is end. Otherwise, if the value for y is non-zero it is page up/down. Other non-zero values for x are currently ignored.

Dir only handles key press events, not key releases.

func (*TextBox) Draw

func (b *TextBox) Draw(dirty bool, img draw.Image)

Draw draws the text box to the image with the upper-left of the box at 0,0.

func (*TextBox) Edit

func (b *TextBox) Edit(t string) (edit.Diffs, error)

Edit performs an edit on the text of the text box and returns the diffs applied to the text. If more than 0 diffs are returned, the text box needs to be redrawn.

func (*TextBox) Focus

func (b *TextBox) Focus(focus bool)

Focus handles a focus state change.

func (*TextBox) Mod

func (b *TextBox) Mod(m int)

Mod handles a modifier key state change event.

func (*TextBox) Move

func (b *TextBox) Move(pt image.Point)

Move handles the event of the mouse cursor moving to a point and returns whether the text box image needs to be redrawn.

func (*TextBox) Paste

func (b *TextBox) Paste() error

Paste pastes the text from the system clipboard to the selection.

func (*TextBox) Resize

func (b *TextBox) Resize(size image.Point)

Resize handles a resize event. The text box must always be redrawn after being resized.

func (*TextBox) Rune

func (b *TextBox) Rune(r rune)

Rune handles the event of a rune being typed and returns whether the text box image needs to be redrawn.

The argument is a rune indicating the glyph typed after interpretation by any system-dependent keyboard/layout mapping. For example, if the 'a' key is pressed while the shift key is held, the argument would be the letter 'A'.

If the rune is positive, the event is a key press, if negative, a key release.

func (*TextBox) SetText

func (b *TextBox) SetText(text rope.Rope)

SetText sets the text of the text box. The text box always must be redrawn after setting the text.

func (*TextBox) Text

func (b *TextBox) Text() rope.Rope

Text returns the current text of the text box.

func (*TextBox) Tick

func (b *TextBox) Tick() bool

Tick handles periodic ticks that drive asynchronous events for the text box. It returns whether the text box image needs to be redrawn.

Tick is intended to be called at regular intervals, fast enough to drive cursor blinking and mouse-drag scolling.

func (*TextBox) Wheel

func (b *TextBox) Wheel(_ image.Point, x, y int)

Wheel handles the event of the mouse wheel rolling and returns whether the text box image needs to be redrawn.

-y is roll up.
+y is roll down.
-x is roll left.
+x is roll right.

type Win

type Win struct {
	*Col // focus
	// contains filtered or unexported fields
}

A Win is a window of columns of sheets.

func NewWin

func NewWin(dpi float32) *Win

NewWin returns a new window.

func (*Win) Add

func (w *Win) Add() *Col

Add adds a new column to the window and returns it.

func (*Win) Click

func (w *Win) Click(pt image.Point, button int)

Click handles click events.

func (*Win) Del

func (w *Win) Del(c *Col)

Del deletes a column unless it is the last column.

func (*Win) Draw

func (w *Win) Draw(dirty bool, drawImg draw.Image)

Draw draws the window.

func (*Win) Focus

func (w *Win) Focus(focus bool)

Focus handles focus change events.

func (*Win) Mod

func (w *Win) Mod(m int)

Mod handles modifier key state change events.

func (*Win) Move

func (w *Win) Move(pt image.Point)

Move handles mouse move events.

func (*Win) OutputBytes

func (w *Win) OutputBytes(data []byte)

OutputBytes appends bytes to the Output sheet and ensures that the Output sheet is visible. It is safe for concurrent calls.

func (*Win) OutputString

func (w *Win) OutputString(str string)

OutputString appends a string to the Output sheet and ensures that the Output sheet is visible. It is safe for concurrent calls.

func (*Win) Resize

func (w *Win) Resize(size image.Point)

Resize handles resize events.

func (*Win) Tick

func (w *Win) Tick() bool

Tick handles tick events.

func (*Win) Wheel

func (w *Win) Wheel(pt image.Point, x, y int)

Wheel handles mouse wheel events.

Jump to

Keyboard shortcuts

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