Skip to content

Commit

Permalink
fixed text bounds in test renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
Hobbyshop committed Mar 13, 2024
1 parent e836a47 commit af41dc3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,10 @@ class TestRenderer : Renderer {

override fun getTextBounds(text: String, font: Font): Pair<Float, Float> {
val buffer: FloatBuffer = BufferUtils.createFloatBuffer(4)

NanoVG.nvgFontSize(vg, font.size.toFloat())
NanoVG.nvgFontFace(vg, font.identifier)
NanoVG.nvgTextBounds(vg, 0f, 0f, text, buffer)
return Pair(buffer.get(2), buffer.get(3))
return Pair(buffer[2] - buffer[0], buffer[3] - buffer[1])
}
}
4 changes: 3 additions & 1 deletion src/test/kotlin/com/neptuneclient/voidui/tests/TestScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ import com.neptuneclient.voidui.ui.Drawable
import com.neptuneclient.voidui.ui.Screen
import com.neptuneclient.voidui.ui.elements.Text
import com.neptuneclient.voidui.utils.Font
import java.awt.Color
import java.nio.file.Path

class TestScreen(void: VoidUI) : Screen(void) {

// temp
private val font = Font(void, "screen", Path.of("fonts/WorkSans-Regular.ttf"), 16)
private val font = Font(void, "screen", Path.of("fonts/WorkSans-Regular.ttf"), 40)

override fun build(): Drawable {
return Text(
text = "Deutschland über alle",
font = font,
backgroundColor = Color.RED,

x = 50.vw,
y = 50.vh
Expand Down

0 comments on commit af41dc3

Please sign in to comment.