MCPcopy Create free account
hub / github.com/cogentcore/core / SetRunePosTB

Method SetRunePosTB

paint/span.go:385–446  ·  view source on GitHub ↗

SetRunePosTB sets relative positions of each rune using a flat top-to-bottom text layout -- i.e., letters are in their normal upright orientation, but arranged vertically.

(letterSpace, wordSpace, chsz float32, tabSize int)

Source from the content-addressed store, hash-verified

383// top-to-bottom text layout -- i.e., letters are in their normal
384// upright orientation, but arranged vertically.
385func (sr *Span) SetRunePosTB(letterSpace, wordSpace, chsz float32, tabSize int) {
386 if err := sr.IsValid(); err != nil {
387 // log.Println(err)
388 return
389 }
390 sr.Dir = styles.TB
391 sz := len(sr.Text)
392 lspc := letterSpace
393 wspc := wordSpace
394 if tabSize == 0 {
395 tabSize = 4
396 }
397 var fpos float32
398 curFace := sr.Render[0].Face
399 TextFontRenderMu.Lock()
400 defer TextFontRenderMu.Unlock()
401 col := 0 // current column position -- todo: does NOT deal with indent
402 for i, r := range sr.Text {
403 rr := &(sr.Render[i])
404 curFace = rr.CurFace(curFace)
405
406 fht := math32.FromFixed(curFace.Metrics().Height)
407 rr.RelPos.X = 0
408 rr.RelPos.Y = fpos
409
410 if rr.Deco.HasFlag(styles.DecoSuper) {
411 rr.RelPos.Y = -0.45 * math32.FromFixed(curFace.Metrics().Ascent)
412 }
413 if rr.Deco.HasFlag(styles.DecoSub) {
414 rr.RelPos.Y = 0.15 * math32.FromFixed(curFace.Metrics().Ascent)
415 }
416
417 // todo: could check for various types of special unicode space chars here
418 a, _ := curFace.GlyphAdvance(r)
419 a32 := math32.FromFixed(a)
420 if a32 == 0 {
421 a32 = .1 * fht // something..
422 }
423 rr.Size = math32.Vec2(a32, fht)
424
425 if r == '\t' {
426 curtab := col / tabSize
427 curtab++
428 col = curtab * tabSize
429 cpos := chsz * float32(col)
430 if cpos > fpos {
431 fpos = cpos
432 }
433 } else {
434 fpos += fht
435 col++
436 if i < sz-1 {
437 fpos += lspc
438 if unicode.IsSpace(r) {
439 fpos += wspc
440 }
441 }
442 }

Callers

nothing calls this directly

Calls 7

IsValidMethod · 0.95
FromFixedFunction · 0.92
Vec2Function · 0.92
CurFaceMethod · 0.80
LockMethod · 0.65
UnlockMethod · 0.65
HasFlagMethod · 0.65

Tested by

no test coverage detected