frame
概要
包装frame实现了与计划9的Lib frame兼容的图形,可编辑的文本小部件(3)。与lib frame不同,文本是字节加深的,并保留了nul终止字符串。相关的github.com/as/font软件包提供了golang.org/x/font.face接口的超集,并实现了使用GO字体和frame s的其他功能。
安装
go get -d -u github.com/as/ frame /...
更新
注意:自此readme.md更新以来,API已更改。
- 字体功能不再嵌入到frame软件包中
- frame .NEW构造函数包函数已修改以采用配置结构
运行提供的Gofix程序以编程更新您的软件包:
frame/…
go install github.com/as/ frame / frame fix
frame fix github.com/as/ui\”>
go get -u github.com/as/ frame /... go install github.com/as/ frame / frame fix frame fix github.com/as/ui
描述
frame是图形文本容器。它使用先前绘制的文本作为缓存,在位图上绘制文本。
使用New创建一个:
frame.New(dst, dst.Bounds(), &Config struct {
Color: frame .Mono,
Font : font.NewFace(12),
}\”>
dst := image.NewRGBA( image.Rect(0,0,100,100),
f := frame .New(dst, dst.Bounds(), &Config struct {
Color: frame .Mono,
Font : font.NewFace(12),
}
渲染
最常见的操作是插入和删除。插入以给定偏移量的文本,而无需覆盖现有文本。删除删除一系列文本,并将现有文本移至其范围之后。范围由两个整数定义,并且表现为切片索引。
插入和删除是对话。
f.Insert([]byte(\"hello world.\"), 0) f.Delete(0, 11)
投影
Pointof将字符的索引投影到2D图像。图像上的点。 Indexof做了相反的事情,将索引投射到一个点。
它们也是反操作。
f.InsertString(\"hello\") f.IndexOf(f.PointOf(4)) // returns: 4 f.PointOf(f.IndexOf(image.Pt(25,25))) // returns: (25, 25)
没有方法可以提取frame中字符的值。数据结构被设计为快速写入的容器。
选择
frame S选择一个连续的文本范围。当前选择的范围与DOT查询。
f.InsertString(\"hello\") f.Select(0,2) f.Dot() // returns (0,2)
绘画
因为位图是一个任意图像,也是字形的活库,因此在渲染操作之间的位图持续存在于基础字形上。有几种方法可以重新呈现位图或区域的区域。
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.\”>
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.
例子
-
基本https://gi**th*ub.com/as/frame/blob/master/example/basic/basic.go
-
UTF-8 https://githu*b**.com/as/frame/blob/master/example/example/utf8/utf8.go
-
弹性https://g*ithub.c**om/as/frame/blob/master/example/elastic/elastic.go
功能集
- UTF8
- ASCII
- 弹性ta列
- 语义替换字符
笔记
frame的文本是不可解决的。一旦字符写入frame ,就没有机制可以从frame内检索值。使用缓冲区存储文本进行读取以及frame的范围地址,以访问该缓冲区的字节。
有关示例,请参见github.com/as/ui/win。
参见
http://doc.c***at-v.org/plan_9/4th_edition/papers/sam/
具体而言,终端中的部分数据结构是指导
