Skip to content

Commit

Permalink
fix: text rendering symbol bounds bug
Browse files Browse the repository at this point in the history
  • Loading branch information
levovix0 committed Nov 5, 2024
1 parent f49c8b6 commit c975e9c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
17 changes: 17 additions & 0 deletions src/sigui/cvmath.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pkg/[vmath, chroma]

proc vec4*(color: chroma.Color): Vec4 =
vec4(color.r, color.g, color.b, color.a)

proc color*(v: Vec4): chroma.Color =
chroma.Color(r: v.x, g: v.y, b: v.z, a: v.w)


proc round*(v: Vec2): Vec2 =
vec2(round(v.x), round(v.y))

proc ceil*(v: Vec2): Vec2 =
vec2(ceil(v.x), ceil(v.y))

proc floor*(v: Vec2): Vec2 =
vec2(floor(v.x), floor(v.y))
3 changes: 3 additions & 0 deletions src/sigui/render/contexts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,10 @@ proc drawText*(ctx: DrawContext, pos: Vec2, arrangement: Arrangement, color: Vec

for i, rune in arrangement.runes:
var rect = arrangement.selectionRects[i]
rect.wh = rect.wh + vec2(2, 2)

# todo: force pixie to adjust text to pixel grid while generating arrangement, for better alligning

ctx.passTransform(shader, pos = pos + rect.xy, size = rect.wh, angle=0)

let placement = family[].renderIfNeeded(rune, arrangement.fonts[0], rect.wh)
Expand Down
21 changes: 2 additions & 19 deletions src/sigui/uibase.nim
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import times, macros, tables, unicode, strutils
import vmath, bumpy, siwin, shady, fusion/[matching, astdsl], pixie, pixie/fileformats/svg
import ./[events, properties]
import ./[events, properties, cvmath]
import ./render/[gl, contexts]
when hasImageman:
import imageman except Rect, color, Color

export vmath, bumpy, gl, pixie, events, properties, tables, contexts
export vmath, cvmath, bumpy, gl, pixie, events, properties, tables, contexts

when defined(sigui_debug_useLogging):
import logging
Expand Down Expand Up @@ -212,23 +212,6 @@ var registredReflection {.compileTime.}: seq[tuple[f: NimNode, filter: NimNode]]
# callable syms


proc vec4*(color: chroma.Color): Vec4 =
vec4(color.r, color.g, color.b, color.a)

proc color*(v: Vec4): chroma.Color =
chroma.Color(r: v.x, g: v.y, b: v.z, a: v.w)


proc round*(v: Vec2): Vec2 =
vec2(round(v.x), round(v.y))

proc ceil*(v: Vec2): Vec2 =
vec2(ceil(v.x), ceil(v.y))

proc floor*(v: Vec2): Vec2 =
vec2(floor(v.x), floor(v.y))


proc containsShift*(keyboardPressed: set[Key]): bool =
Key.lshift in keyboardPressed or Key.rshift in keyboardPressed

Expand Down

0 comments on commit c975e9c

Please sign in to comment.