Giter VIP home page Giter VIP logo

frame's Introduction

Frame

Go Report Card

Synopsis

Package frame implements graphical, editable text widgets compatible with Plan 9's libframe(3). Unlike libframe, the text is byte-addressed and preserves NUL terminated strings. The related github.com/as/font package provides a superset of the golang.org/x/font.Face interface and implements additional functionality for working with Go fonts and frames.

paint

Installation

	go get -d -u github.com/as/frame/...

Updates

NOTE: The API has changed since this README.md was updated.

  • The font functionality is no longer embedded in the frame package
  • The frame.New constructor package function has been modified to take a Config struct

Run the provided gofix program under to programatically update your packages:

	go get -u github.com/as/frame/...
	go install github.com/as/frame/framefix
	framefix github.com/as/ui

Description

A Frame is a graphical text container. It draws text on a bitmap, using previously-drawn text as a cache.

Create one using New:

  dst := image.NewRGBA( image.Rect(0,0,100,100), 
  f := frame.New(dst, dst.Bounds(), &Config struct {
		Color: frame.Mono,
        Font : font.NewFace(12), 
   }

Rendering

The most frequent operations are Insert and Delete. Insert renders text at a given offset without overwriting existing text. Delete deletes a range of text and moves existing text after it into its range. Ranges are defined by two integers and behave equivalently to Go slice indices.

Insert and delete are inverses.

f.Insert([]byte("hello world."), 0)
f.Delete(0, 11)

Projection

PointOf projects the index of a character to a 2D image.Point on the image. IndexOf does the opposite, projecting an index to a point.

They are also inverse operations.

	f.InsertString("hello")
	f.IndexOf(f.PointOf(4))	// returns: 4
	f.PointOf(f.IndexOf(image.Pt(25,25))) // returns: (25, 25)

There is no method for extracting the values of characters in the frame. The data structures are designed to be fast write-only containers.

Selection

Frames select a continuous range of text with Select. The currently-selected range is queried with Dot.

	f.InsertString("hello")
	f.Select(0,2)
	f.Dot()	// returns (0,2)

Drawing

Because the bitmap is an arbitrary image and also a living cache of glyphs, drawing on the bitmap between rendering operations persists on the underlying glyphs. There are a few ways to re-render the bitmap or a region of it.

Recolor(pt image.Point, p0, p1 int64, cols Palette)
  Recolor colors the range p0:p1 by redrawing the foreground, background, and font glyphs

Redraw(pt image.Point, p0, p1 int64, issel bool)
  Redraw redraws the characters between p0:p1. It accesses the cache of drawn glyph widths
  to avoid remeasuring strings

RedrawAt(pt image.Point, text, back image.Image)
  RedrawAt refreshes the entire image to the right of the given pt. Everything below is redrawn.

Refresh()
  Refresh recomputes the state of the frame from scratch. This is an expensive operation compared
  to redraw

Paint(pt0, pt1 image.Point, col image.Image)
  Paint paints the color col on the frame at points pt0-pt1. The result is a Z shaped fill
  consisting of at-most 3 rectangles. No text is redrawn.

Examples

Feature Set

  • UTF8
  • ASCII
  • Elastic tabstops
  • Semantic replacement characters

Note

A frame's text is not addressable. Once the characters are written to the frame, there is no mechanism to retrieve value from within the frame. Use a buffer to store text for reading and the range addresses of the frame to access bytes from that buffer.

See github.com/as/ui/win for an example.

See Also

http://doc.cat-v.org/plan_9/4th_edition/papers/sam/

Specifically, the section Data structures in the terminal served as a guide

frame's People

Contributors

as avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

frame's Issues

frame: projection: hard-coded magic numbers can underflow for long lines

Under certain conditions a hard-coded constant is used to calculate the 1-D x-max point at the end of the frame. If the actual number of characters in the frame exceeds this limit some rendering operations may be limited to the value of the constant.

This is an issue primarily for extremely long runs of text missing hard newline characters.

as/frame/delete.go:133: pt2 := f.pointOf(65536, pt1, n1)

frame: support kerning

Kerning is a correlation of letter spacing between certain characters to make type more legible. It is currently not supported or implemented due to the structure of frame/box.Run and frame/box.Box.

Supporting a kerning pair would require a one-box lookbehind during the insertion and deletion into a frame.Frame.

frame: API update checklist

Checklist for upcoming API update.

  • Write go-fix for incompatible API changes (frame)
  • Write go-fix for incompatible API changes (font)
  • Fix UTF8 support
  • Add tests for cached and uncached
  • Remove shiny references from the API documentation
  • Update README.md with instructions for running go-fix
  • Update README.md with API changes and package changes
  • Merge flusher branch with master
  • Round up and close related issues resolved by this change
  • #37
  • #25
  • #21
  • #17
  • #3
  • #2

frame: overlap: Reproduction Font

Impossible to upload current reproduction font to github due to license restrictions. Create or use an open font without these restrictions so regression tests can run and pass from a cloned version of the local git repository.

example/basic: redraw glitches

hi,

first of all, great library! thanks a lot.

I have tried the basic example, and I noticed that when resizing the window passed its original size, there were a few display glitches (see attached screenshot).

I am on ArchLinux.

Is it just a glitch b/c basic doesn't do all that a robust app should do?
(TBH, I have also noticed the same behaviour in my own little app that's based on exp/shiny as well)

screenshot

frame: tests: fix reference images for tests

Issue #34 fixed tick scaling with a side effect of changing what the tick's wings look like. This, in turn, makes some of the graphical tests fail erroneously, as they rely on image comparison to check the test results.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.