Documentation ¶
Index ¶
- Constants
- Variables
- func LoadTTF(path string, size float64) (font.Face, error)
- type Align
- type Atlas
- func (a *Atlas) Ascent() float64
- func (a *Atlas) Contains(r rune) bool
- func (a *Atlas) Descent() float64
- func (a *Atlas) DrawRune(prevR, r rune, dot mat.Vec) (rect, frame, bounds mat.AABB, newDot mat.Vec)
- func (a *Atlas) Glyph(r rune) Glyph
- func (a *Atlas) Kern(r0, r1 rune) float64
- func (a *Atlas) LineHeight() float64
- type ColorEffect
- type Drawer
- type Effect
- type EffectBase
- type Effs
- func (v *Effs) Clear()
- func (v Effs) Clone() Effs
- func (v *Effs) Filter(filter func(e Effect) bool)
- func (v Effs) Find(find func(e Effect) bool) (idx int, res Effect)
- func (v Effs) ForEach(con func(i int, e Effect) Effect)
- func (v *Effs) Insert(idx int, val Effect)
- func (v *Effs) InsertSlice(idx int, val []Effect)
- func (v Effs) Last() Effect
- func (v *Effs) Pop() Effect
- func (v *Effs) PopFront() Effect
- func (v *Effs) Remove(idx int) (val Effect)
- func (v *Effs) RemoveSlice(start, end int)
- func (v Effs) Reverse()
- func (v Effs) Sort(comp func(a, b Effect) bool)
- func (v Effs) Swap(a, b int)
- func (v *Effs) Truncate(l int)
- type FEffs
- func (v *FEffs) Clear()
- func (v FEffs) Clone() FEffs
- func (v *FEffs) Filter(filter func(e *FontEffect) bool)
- func (v FEffs) Find(find func(e *FontEffect) bool) (idx int, res *FontEffect)
- func (v FEffs) ForEach(con func(i int, e *FontEffect) *FontEffect)
- func (v *FEffs) Insert(idx int, val *FontEffect)
- func (v *FEffs) InsertSlice(idx int, val []*FontEffect)
- func (v FEffs) Last() *FontEffect
- func (v *FEffs) Pop() *FontEffect
- func (v *FEffs) PopFront() *FontEffect
- func (v *FEffs) Remove(idx int) (val *FontEffect)
- func (v *FEffs) RemoveSlice(start, end int)
- func (v FEffs) Reverse()
- func (v FEffs) Sort(comp func(a, b *FontEffect) bool)
- func (v FEffs) Swap(a, b int)
- func (v *FEffs) Truncate(l int)
- type FontEffect
- type Glyph
- type Markdown
- type Paragraph
- func (p *Paragraph) AddEff(e Effect)
- func (p *Paragraph) Bounds() mat.AABB
- func (p *Paragraph) Changes() bool
- func (p *Paragraph) Clear()
- func (p *Paragraph) CursorFor(mouse mat.Vec) (global, local, line int)
- func (p *Paragraph) Dot(i int) mat.Vec
- func (p *Paragraph) Draw(t ggl.Target)
- func (p *Paragraph) Lines() int
- func (p *Paragraph) ProjectLine(i, line int) int
- func (p *Paragraph) SetCenter(pos mat.Vec)
- func (p *Paragraph) Sort()
- func (p *Paragraph) UnprojectLine(idx int) (local, line int)
- func (p *Paragraph) Update(delta float64)
- type Target
- type Text
- func (t *Text) Draw(tg ggl.Target, mat mat.Mat, color mat.RGBA)
- func (t *Text) DrawCentered(tg ggl.Target, mat mat.Mat, color mat.RGBA)
- func (t *Text) Fetch(tg ggl.Target)
- func (t *Text) Metrics() (mat.Vec, mat.AABB)
- func (t *Text) SetMetrics(dot mat.Vec, bounds mat.AABB)
- func (t *Text) Update(mat mat.Mat, color mat.RGBA)
Constants ¶
const ( Instant int8 = iota Changing TextType )
Effect types
Variables ¶
var ( MarkdownIdent = '!' ColorIdent = '#' BlockStart = '[' BlockEnd = ']' NullIdent = string([]rune{1}) DefaultFont = "default" )
key markdown sintax is stored in variable so it can be customized
var ASCII []rune
ASCII is a set of all ASCII runes. These runes are codepoints from 32 to 127 inclusive.
Functions ¶
Types ¶
type Atlas ¶
Atlas is a set of pre-drawn glyphs of a fixed set of runes. This allows for efficient text drawing.
var Atlas7x13 *Atlas
Atlas7x13 is an Atlas using basicfont.Face7x13 with the ASCII rune set
func NAtlas ¶ added in v0.2.9
NAtlas creates a new Atlas containing glyphs of the union of the given sets of runes (plus unicode.ReplacementChar) from the given font face. Spacing is space in pixels that is added around each glyph. This is very usefull when applying shaders to your text, mind that bigger sprites burdens gpu more.
Creating an Atlas is rather expensive, do not create a new Atlas each frame.
Do not destroy or close the font.Face after creating the Atlas. Atlas still uses it.
func (*Atlas) DrawRune ¶
DrawRune returns parameters necessary for drawing a rune glyph.
Rect is a rectangle where the glyph should be positioned. Frame is the glyph frame inside the Atlas's Picture. NewDot is the new position of the dot.
func (*Atlas) Kern ¶
Kern returns the kerning distance between runes r0 and r1. Positive distance means that the glyphs should be further apart.
func (*Atlas) LineHeight ¶
LineHeight returns the recommended vertical distance between two lines of text.
type ColorEffect ¶
type ColorEffect struct { EffectBase Color mat.RGBA }
ColorEffect is one shot effect that changes color of a text
func NColorEffect ¶
func NColorEffect(hex string, start int) (*ColorEffect, error)
NColorEffect constructs new color effect as long as s is valid hex color
type Drawer ¶
Drawer draws text for ContentBox
func (*Drawer) DrawParagraph ¶ added in v0.2.9
Draw draws a slice of p.Compiled to p.data, text continused where last draw stopped
type Effect ¶
type Effect interface { Apply(try ggl.Vertexes, delta float64) Kind() int8 Start() int Close(endIdx int) Copy(startIdx int) Effect }
Effect is interface for eny effect applied on text TriangleData is slice that should be modified, delta is to change state of effect in case this is permanent effect
type EffectBase ¶
type EffectBase struct { End int // contains filtered or unexported fields }
EffectBase hold properties that every effect has
type Effs ¶
type Effs []Effect
Effs is a standard Vector type with utility methods
func (Effs) Find ¶
Find returns first element for which find returns true along with index, if there is none, index equals -1
func (*Effs) InsertSlice ¶
InsertSlice inserts slice to given index
func (*Effs) RemoveSlice ¶
RemoveSlice removes sequence of slice
type FEffs ¶
type FEffs []*FontEffect
FEffs is a standard Vector type with utility methods
func (*FEffs) Filter ¶
func (v *FEffs) Filter(filter func(e *FontEffect) bool)
Filter leaves only elements for with filter returns true
func (FEffs) Find ¶
func (v FEffs) Find(find func(e *FontEffect) bool) (idx int, res *FontEffect)
Find returns first element for which find returns true along with index, if there is none, index equals -1
func (FEffs) ForEach ¶
func (v FEffs) ForEach(con func(i int, e *FontEffect) *FontEffect)
ForEach is a standard foreach method. Its shortcut for modifying all elements
func (*FEffs) Insert ¶
func (v *FEffs) Insert(idx int, val *FontEffect)
Insert inserts value to given index
func (*FEffs) InsertSlice ¶
func (v *FEffs) InsertSlice(idx int, val []*FontEffect)
InsertSlice inserts slice to given index
func (*FEffs) PopFront ¶
func (v *FEffs) PopFront() *FontEffect
PopFront removes first element and returns it
func (*FEffs) Remove ¶
func (v *FEffs) Remove(idx int) (val *FontEffect)
Remove removes element and returns it
func (*FEffs) RemoveSlice ¶
RemoveSlice removes sequence of slice
func (FEffs) Sort ¶
func (v FEffs) Sort(comp func(a, b *FontEffect) bool)
Sort is quicksort for FEffs, because this is part of a template comp function is necessary
type FontEffect ¶
type FontEffect struct { EffectBase Font string }
FontEffect stores what font should be used for given slice of text
func NFontEffect ¶
func NFontEffect(font string, start, end int) *FontEffect
NFontEffect is here for consistency
type Markdown ¶
type Markdown struct { Shortcuts map[rune]string Fonts map[string]*Drawer Effects map[string]Effect // contains filtered or unexported fields }
Markdown handles text markdown parsing, markdown sintax is as follows:
#FF0000[hello] // hello will appear ugly red #FF000099[hello] // hello will appear ugly red and slightly transparent
Now writing effects like this is maybe flexible but not always convenient to user thats why you can define your own effects by adding effects to Markdown.Effects. Name of the effect is a key in map thus:
m.Effects["red"] = ColorEffect{Color: mat.RGB(1, 0, 0)}
will do the trick. user then can use this effect like:
!red[hello] // witch does the same
now you can make any kind of triangle mutator you like, it even allows dinamic effects so something like fading text or exploding text is possible. You can also use multiple fonts in one paragraph by adding more atlases to your markdown. Pattern is same as for adding custom effects:
m.Effects["italic"] = NDrawer(italicFontAtlas)
User then can use font like:
!italic[hello] // hello will be italic, syntax will not appear
Last feature of markdown are shortcuts. After you have added all effects you wanted you can call GenerateShortcuts method. This will map all effect names to its starting rune thus user can be very lazy:
!i[hello] // hello will be italic with low effort
Markdown is only compatible with paragraph, mind that parsing markdown is slow and grows linearly with text length, O(n), if course if you want effects to even display you have to set DisplayEffects to true in paragraph
func NMarkdown ¶
func NMarkdown() *Markdown
NMarkdown initializes inner maps and adds default drawer
func (*Markdown) CollectEffects ¶
CollectEffects removes all valid effect syntax and stores parsed effects in paragraph
func (*Markdown) GenerateShortcuts ¶
func (m *Markdown) GenerateShortcuts()
GenerateShortcuts creates shortcuts for all effects, if names overlap random one is bind
func (*Markdown) MakeTriangles ¶
MakeTriangles creates triangles, these are not drawn to screen as only instant effects are applied on them and you have to call Update on paragraph for anything to show up
func (*Markdown) Parse ¶
Parse turns markdown stored in p.Content into final text with effects, for markdown syntax see struct documentation
func (*Markdown) ResolveChunks ¶
ResolveChunks gets rid of nested FontEffects as nesting of then does not make sense it turns ranges like 0-10 3-7 to 0-3 3-7 7-10 so no ranges overlap.
type Paragraph ¶
type Paragraph struct { // saves the paragraph transformation, you have to call Update to apply changes mat.Tran // this data can be freely modified red, serialized, after Update its overwritten // anyway Data ggl.Data // determines how text should wrap, Drawer will tri to display text so // it does not overflows Width, though it only breaks on spaces, if width // is 0 it will never wrap Width float64 // Fields are only relevent if Custom Lineheight is true, othervise they will // get overwritten LineHeight, Ascent, Descent float64 // if this is true no effects are displayed NoEffects bool // set this to true if you want it custom CustomLineheight bool // mask is what all triangles solors will be multiplied by Mask mat.RGBA // Font determinate base Font string // Content is only important to markdown, when you are drawing directly with // drawer, Content is not used Content str.String // Align defines how the text is aligned Align Compiled str.String // contains filtered or unexported fields }
Paragraph stores triangles that can form text, there is a lot of passive configurations and to apply changes you have to pass Paragraph to Markdown.Parse method thought you can also use Drawer directly to draw text though then you have to initialize lineheight
func (*Paragraph) Bounds ¶
Bounds returns bounding rectangle of untransformed text, bounds are valid only after Markdown.Parse call
func (*Paragraph) Clear ¶
func (p *Paragraph) Clear()
Clear is only usefull when drawing to paragraph directly with drawer it clears triangles
func (*Paragraph) CursorFor ¶
CursorFor returns index of a dot on witch the cursor is nad insertcion index that is where you should insert the text to make it look like cursor is writing. Then there is line local position and index of a line
func (*Paragraph) ProjectLine ¶
ProjectLine projects line and local index intro global index complexity is O(1)
func (*Paragraph) Sort ¶
func (p *Paragraph) Sort()
Sort is part of markdown building procedure, it sorts all effects so they can be applied properly
func (*Paragraph) UnprojectLine ¶
UnprojectLine does reverse of Project line complexity is O(n) where n is len(p.lines)
type Target ¶ added in v0.2.9
type Target interface { ggl.Target // Metrics returns current dot and bounds of Target Metrics() (mat.Vec, mat.AABB) // SetMetrics sets the metrics of Target to new ones SetMetrics(mat.Vec, mat.AABB) }
Target is something that Drawer can draw to
type Text ¶ added in v0.2.9
Text is a builtin Drawer target, it can act as sprite
func (*Text) DrawCentered ¶ added in v0.2.9
Draws the text centered on matrix center
func (*Text) SetMetrics ¶ added in v0.2.9
SetMetrics implements Target interface