shiny/text: add SetFace and SetMaxWidth.

Change-Id: Ie9df2b656843de1bf9ed66d6751bccb5a0622d79
Reviewed-on: https://go-review.googlesource.com/18958
Reviewed-by: Andrew Gerrand <adg@golang.org>
This commit is contained in:
Nigel Tao 2016-01-28 10:46:04 +11:00
Родитель 0e12372a22
Коммит 8f91cc95a8
1 изменённых файлов: 32 добавлений и 2 удалений

Просмотреть файл

@ -36,6 +36,11 @@
// such modifications. // such modifications.
package text package text
import (
"golang.org/x/image/font"
"golang.org/x/image/math/fixed"
)
// These constants are equal to os.SEEK_SET, os.SEEK_CUR and os.SEEK_END, // These constants are equal to os.SEEK_SET, os.SEEK_CUR and os.SEEK_END,
// understood by the io.Seeker interface, and are provided so that users of // understood by the io.Seeker interface, and are provided so that users of
// this package don't have to explicitly import "os". // this package don't have to explicitly import "os".
@ -73,6 +78,9 @@ type Frame struct {
firstParagraph int32 firstParagraph int32
maxWidth fixed.Int26_6
face font.Face
// len is the total length of the Frame's current textual content, in // len is the total length of the Frame's current textual content, in
// bytes. It can be smaller then len(text), since that []byte can contain // bytes. It can be smaller then len(text), since that []byte can contain
// 'holes' of deleted content. // 'holes' of deleted content.
@ -85,6 +93,30 @@ type Frame struct {
text []byte text []byte
} }
// TODO: allow multiple font faces, i.e. rich text?
// SetFace sets the font face for measuring text.
func (f *Frame) SetFace(face font.Face) {
f.face = face
if f.len != 0 {
panic("TODO: re-layout existing textual content")
}
}
// SetMaxWidth sets the target maximum width of a Line of text. Text will be
// broken so that a Line's width is less than or equal to this maximum width.
// This line breaking is not strict. A Line containing asingleverylongword
// combined with a narrow maximum width will not be broken and will remain
// longer than the target maximum width; soft hyphens are not inserted.
//
// A non-positive argument is treated as an infinite maximum width.
func (f *Frame) SetMaxWidth(m fixed.Int26_6) {
f.maxWidth = m
if f.len != 0 {
panic("TODO: re-layout existing textual content")
}
}
func (f *Frame) newParagraph() int32 { func (f *Frame) newParagraph() int32 {
if len(f.paragraphs) == 0 { if len(f.paragraphs) == 0 {
// The 1 is because the 0'th index is a special case. // The 1 is because the 0'th index is a special case.
@ -132,8 +164,6 @@ func (f *Frame) NewCaret() *Caret {
panic("TODO") panic("TODO")
} }
// TODO: be able to set a frame's max width, and font face.
// Paragraph holds Lines of text. // Paragraph holds Lines of text.
type Paragraph struct { type Paragraph struct {
firstLine, next, prev int32 firstLine, next, prev int32