mirror of
https://github.com/bloeys/nterm.git
synced 2025-12-29 06:28:20 +00:00
Wrapped text drawing
This commit is contained in:
@ -90,11 +90,18 @@ func (gr *GlyphRend) DrawTextOpenGLAbs(text []rune, screenPos *gglm.Vec3, color
|
|||||||
run := &runs[runIndex]
|
run := &runs[runIndex]
|
||||||
prevRune := invalidRune
|
prevRune := invalidRune
|
||||||
|
|
||||||
|
screenWidthF32 := float32(gr.ScreenWidth)
|
||||||
if run.IsLtr {
|
if run.IsLtr {
|
||||||
|
|
||||||
for i := 0; i < len(run.Runes); i++ {
|
for i := 0; i < len(run.Runes); i++ {
|
||||||
gr.drawRune(run, i, prevRune, screenPos, pos, color, lineHeightF32, &bufIndex)
|
gr.drawRune(run, i, prevRune, screenPos, pos, color, lineHeightF32, &bufIndex)
|
||||||
prevRune = run.Runes[i]
|
prevRune = run.Runes[i]
|
||||||
|
|
||||||
|
//Wrap
|
||||||
|
if pos.X()+gr.Atlas.SpaceAdvance >= screenWidthF32 {
|
||||||
|
screenPos.SetY(screenPos.Y() - lineHeightF32)
|
||||||
|
*pos = *screenPos.Clone()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -102,6 +109,12 @@ func (gr *GlyphRend) DrawTextOpenGLAbs(text []rune, screenPos *gglm.Vec3, color
|
|||||||
for i := len(run.Runes) - 1; i >= 0; i-- {
|
for i := len(run.Runes) - 1; i >= 0; i-- {
|
||||||
gr.drawRune(run, i, prevRune, screenPos, pos, color, lineHeightF32, &bufIndex)
|
gr.drawRune(run, i, prevRune, screenPos, pos, color, lineHeightF32, &bufIndex)
|
||||||
prevRune = run.Runes[i]
|
prevRune = run.Runes[i]
|
||||||
|
|
||||||
|
//Wrap
|
||||||
|
if pos.X()+gr.Atlas.SpaceAdvance >= screenWidthF32 {
|
||||||
|
screenPos.SetY(screenPos.Y() - lineHeightF32)
|
||||||
|
*pos = *screenPos.Clone()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
7
main.go
7
main.go
@ -562,13 +562,6 @@ func (p *program) DrawCursor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
p.rend.Draw(p.gridMesh, gglm.NewTrMatId().Translate(pos).Scale(gglm.NewVec3(0.1*p.GlyphRend.Atlas.SpaceAdvance, p.GlyphRend.Atlas.LineHeight, 1)), p.gridMat)
|
p.rend.Draw(p.gridMesh, gglm.NewTrMatId().Translate(pos).Scale(gglm.NewVec3(0.1*p.GlyphRend.Atlas.SpaceAdvance, p.GlyphRend.Atlas.LineHeight, 1)), p.gridMat)
|
||||||
|
|
||||||
// @Debug draw line indicating last char in line
|
|
||||||
// pos = p.lastCmdCharPos.Clone()
|
|
||||||
// p.ScreenPosToGridPos(pos)
|
|
||||||
// p.gridMat.SetUnifVec4("color", gglm.NewVec4(1, 0, 0, 1))
|
|
||||||
// p.rend.Draw(p.gridMesh, gglm.NewTrMatId().Translate(pos).Scale(gglm.NewVec3(0.1*p.GlyphRend.Atlas.SpaceAdvance, p.GlyphRend.Atlas.LineHeight, 1)), p.gridMat)
|
|
||||||
// p.gridMat.SetUnifVec4("color", gglm.NewVec4(1, 1, 1, 1))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *program) ScreenPosToGridPos(screenPos *gglm.Vec3) {
|
func (p *program) ScreenPosToGridPos(screenPos *gglm.Vec3) {
|
||||||
|
|||||||
Reference in New Issue
Block a user