semicongine/text

Types

DefaultFontShader[T] = object
  vertexCode* = """void main() {
  gl_Position = vec4(position * vec3(textbox.scale, 1) + textbox.position, 1.0);
  fragmentUv = uv;
}  """
  fragmentCode* = """void main() {
    float v = texture(fontAtlas, fragmentUv).r;
    // CARFULL: This can lead to rough edges at times
    if(v == 0) {
      discard;
    }
    color = vec4(textbox.color.rgb, textbox.color.a * v);
}"""
FontObj = object
  glyphs*: Table[Rune, GlyphInfo]
  fontAtlas*: Image[Gray]
  maxHeight*: int
  kerning*: Table[(Rune, Rune), float32]
  fontscale*: float32
  lineHeight*: float32
  lineAdvance*: float32
  capHeight*: float32
  xHeight*: float32
GlyphInfo = object
  uvs*: array[4, Vec2f]
  dimension*: Vec2f
  topOffset*: float32
  leftOffset*: float32
  advance*: float32
Textbox = object
  font*: Font
  maxLen*: int

Procs

func `$`(textbox: Textbox): string {....raises: [], tags: [], forbids: [].}
proc horizontalAlignment(textbox: Textbox): HorizontalAlignment {....raises: [],
    tags: [], forbids: [].}
proc horizontalAlignment=(textbox: var Textbox; value: HorizontalAlignment) {.
    ...raises: [], tags: [], forbids: [].}
proc initTextbox[T: string | seq[Rune]](renderdata: var RenderData;
    descriptorSetLayout: VkDescriptorSetLayout; font: Font; baseScale: float32;
                                        text: T = default(T);
                                        maxLen: int = text.len;
    verticalAlignment: VerticalAlignment = Center; horizontalAlignment: HorizontalAlignment = Center;
                                        maxWidth = 0.0'f32): Textbox
proc loadFont(path: string; lineHeightPixels = 80.0'f32;
              additional_codepoints: openArray[Rune] = [];
              charset = ASCII_CHARSET; package = DEFAULT_PACKAGE): Font {.
    ...raises: [IOError, OSError, Exception, KeyError],
    tags: [ReadIOEffect, RootEffect], forbids: [].}
proc refresh(textbox: var Textbox) {....raises: [KeyError, Exception],
                                     tags: [RootEffect], forbids: [].}
proc render(commandbuffer: VkCommandBuffer; pipeline: Pipeline;
            textbox: Textbox; position: Vec3f; color: Vec4f;
            scale: Vec2f = vec2(1, 1))
func text(textbox: Textbox): seq[Rune] {....raises: [], tags: [], forbids: [].}
proc text=(textbox: var Textbox; newText: seq[Rune]) {....raises: [KeyError],
    tags: [], forbids: [].}
proc text=(textbox: var Textbox; newText: string) {....raises: [KeyError],
    tags: [], forbids: [].}
func textWidth(theText: seq[Rune] | string; font: FontObj): float32
proc verticalAlignment(textbox: Textbox): VerticalAlignment {....raises: [],
    tags: [], forbids: [].}
proc verticalAlignment=(textbox: var Textbox; value: VerticalAlignment) {.
    ...raises: [], tags: [], forbids: [].}
func WordWrapped(text: seq[Rune]; font: FontObj; maxWidth: float32): seq[Rune] {.
    ...raises: [KeyError], tags: [], forbids: [].}