frame

package
v0.0.0-...-b574800 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2018 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ColBack = iota
	ColHigh
	ColBord
	ColText
	ColHText
	NumColours
)

Variables

View Source
var (
	DELTA   = 25
	TMPSIZE = 256
)

Functions

func Rpt

func Rpt(min, max image.Point) image.Rectangle

Types

type Fontmetrics

type Fontmetrics interface {
	BytesWidth([]byte) int
	DefaultHeight() int
	Impl() *draw.Font
	StringWidth(string) int
	RunesWidth(r []rune) int
}

Fontmetrics lets tests mock the calls into draw for measuring the width of UTF8 slices.

type Frame

type Frame struct {
	// TODO(rjk): Remove public access if possible.
	Font       Fontmetrics
	Display    *draw.Display           // on which the frame is displayed
	Background *draw.Image             // on which the frame appears
	Cols       [NumColours]*draw.Image // background and text colours
	Rect       image.Rectangle         // in which the text appears
	Entire     image.Rectangle         // size of full frame

	// TODO(rjk): Figure out what.
	Scroll func(*Frame, int) // function provided by application
	// contains filtered or unexported fields
}

func NewFrame

func NewFrame(r image.Rectangle, ft *draw.Font, b *draw.Image, cols [NumColours]*draw.Image) *Frame

NewFrame creates a new Frame with Font ft, background image b, colours cols, and of the size r

func (*Frame) Charofpt

func (f *Frame) Charofpt(pt image.Point) int

func (*Frame) Clear

func (f *Frame) Clear(freeall bool)

Clear frees the internal structures associated with f, permitting another Init or SetRects on the Frame. It does not clear the associated display. If f is to be deallocated, the associated Font and Image must be freed separately. The resize argument should be non-zero if the frame is to be redrawn with a different font; otherwise the frame will maintain some data structures associated with the font.

/To resize a Frame, use Clear and Init and then Insert to recreate the /display. If a Frame is being moved but not resized, that is, if the /shape of its containing rectangle is unchanged, it is sufficient to /use Draw to copy the containing rectangle from the old to the new /location and then call SetRects to establish the new geometry. (It is /unnecessary to call InitTick unless the font size has changed.) No /redrawing is necessary.

func (*Frame) Delete

func (f *Frame) Delete(p0, p1 int) int

Delete deletes from the Frame the text between p0 and p1; p1 points at the first rune beyond the deletion.

func (*Frame) DrawSel

func (f *Frame) DrawSel(pt image.Point, p0, p1 int, highlighted bool)

DrawSel repaints a section of the frame, delimited by character positions p0 and p1, either with plain background or entirely highlighted, according to the flag highlighted, managing the tick appropriately. The point pt0 is the geometrical location of p0 on the screen; like all of the selection-helper routines' Point arguments, it must be a value generated by Ptofchar.

Clarification of semantics: the point of this routine is to redraw the state of the Frame with selection p0,p1. In particular, this requires updating f.p0 and f.p1 so that other entry points (e.g. Insert) can (transparently) remove a pre-existing selection.

Note that the original code does not remove the pre-existing selection. I (rjk) claim that this is clearly the wrong semantics. This function should arrange for the drawn selection on return to be p0, p1

func (*Frame) Drawsel0

func (f *Frame) Drawsel0(pt image.Point, p0, p1 int, back *draw.Image, text *draw.Image) image.Point

TODO(rjk): This function is convoluted. Drawsel0 is a lower-level routine, taking as arguments a background color back and text color text. It assumes that the tick is being handled (removed beforehand, replaced afterwards, as required) by its caller. The selection is delimited by character positions p0 and p1. The point pt0 is the geometrical location of p0 on the screen and must be a value generated by Ptofchar.

Commentary: this function should conceivably not be part of the public API

Function does not mutate f.p0, f.p1 (well... actually, it does.)

func (*Frame) GetFrameFillStatus

func (f *Frame) GetFrameFillStatus() FrameFillStatus

GetFrameFillStatus returns a snapshot of the capacity of the frame.

func (*Frame) GetSelectionExtent

func (f *Frame) GetSelectionExtent() (int, int)

GetSelectionExtent returns the rune offsets of the selection maintained by the Frame.

func (*Frame) Init

func (f *Frame) Init(r image.Rectangle, ft *draw.Font, b *draw.Image, cols [NumColours]*draw.Image)

Init prepares the Frame f so characters drawn in it will appear in the single Font ft. It then calls SetRects and InitTick to initialize the geometry for the Frame. The Image b is where the Frame is to be drawn; Rectangle r defines the limit of the portion of the Image the text will occupy. The Image pointer may be null, allowing the other routines to be called to maintain the associated data structure in, for example, an obscured window.

func (*Frame) InitTick

func (f *Frame) InitTick()

InitTick sets up the tick (e.g. cursor)

func (*Frame) Insert

func (f *Frame) Insert(r []rune, p0 int)

Insert inserts r into Frame f starting at index p0. If a NUL (0) character is inserted, chaos will ensue. Tabs and newlines are handled by the library, but all other characters, including control characters, are just displayed. For example, backspaces are printed; to erase a character, use Delete.

Insert manages the tick and selection.

func (*Frame) Insure

func (f *Frame) Insure(bn int, n uint)

func (*Frame) Logboxes

func (f *Frame) Logboxes(message string)

Logboxes shows the box model to the log for debugging convenience.

func (*Frame) Maxtab

func (f *Frame) Maxtab(m int)

Maxtab sets the maximum size of a tab in pixels.

func (*Frame) Ptofchar

func (f *Frame) Ptofchar(p int) image.Point

func (*Frame) Redraw

func (f *Frame) Redraw()

This function is not part of the documented libframe entrypoints. TODO(rjk): discern purpose of this code.

func (*Frame) Select

func (f *Frame) Select(mc draw.Mousectl)

called when mouse 1 is down

func (*Frame) SelectPaint

func (f *Frame) SelectPaint(p0, p1 image.Point, col *draw.Image)

func (*Frame) SetRects

func (f *Frame) SetRects(r image.Rectangle, b *draw.Image)

SetRects initializes the geometry of the frame.

func (*Frame) SetSelectionExtent

func (f *Frame) SetSelectionExtent(p0, p1 int)

SetSelectionExtent sets the rune offsets of the selection maintained by the Frame. p0 and p1 must be values that could be returned by Charofpt. TODO(rjk): It is conceivable that we don't need this. It seems like an egregious abstraction violation that it exists.

func (*Frame) Tick

func (f *Frame) Tick(pt image.Point, ticked bool)

Tick draws (if up is non-zero) or removes (if up is zero) the tick at the screen position indicated by pt.

Commentary: because this code ignores selections, it is conceivably undesirable to use it in the public API.

type FrameFillStatus

type FrameFillStatus struct {
	Nchars   int
	Nlines   int
	Maxlines int
}

FrameFillStatus is a snapshot of the capacity of the Frame.

Directories

Path Synopsis
Demonstrates that the fraame package works.
Demonstrates that the fraame package works.

Jump to

Keyboard shortcuts

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