Skip to content

Commit

Permalink
letter spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
Hobbyshop committed Apr 7, 2024
1 parent 7618c4d commit 4894742
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ import java.nio.file.Path
class TextStyleSheet(
color: Color,
val font: Path,
val size: Int
val size: Int,
val letterSpacing: Int = 0
) : StyleSheet(color)
2 changes: 1 addition & 1 deletion src/main/kotlin/com/neptuneclient/voidui/utils/Font.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import java.io.IOException
import java.nio.ByteBuffer
import java.nio.file.Path

class Font(void: VoidUI, val identifier: String, filePath: Path, val size: Int) {
class Font(void: VoidUI, val identifier: String, filePath: Path, val size: Int, val letterSpacing: Int) {

val data: ByteBuffer = try {
getBufferData(filePath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ abstract class AbstractText(private val label: String) : Element<TextStyleSheet>

override fun init(screen: Screen, parent: Widget?) {
super.init(screen, parent)
font = Font(screen.void, this.toString(), styles.font, styles.size)
font = Font(screen.void, this.toString(), styles.font, styles.size, styles.letterSpacing)
screen.void.renderer.registerFont(font)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ class TestRenderer : Renderer {
NanoVG.nvgFillColor(vg, it)
NanoVG.nvgFontFace(vg, font.identifier)
NanoVG.nvgFontSize(vg, font.size.toFloat())
NanoVG.nvgTextLetterSpacing(vg, font.letterSpacing.toFloat())

val bounds = BufferUtils.createFloatBuffer(4)
NanoVG.nvgTextBounds(vg, x, y, text, bounds)
Expand All @@ -216,6 +217,7 @@ class TestRenderer : Renderer {

NanoVG.nvgFontSize(vg, font.size.toFloat())
NanoVG.nvgFontFace(vg, font.identifier)
NanoVG.nvgTextLetterSpacing(vg, font.letterSpacing.toFloat())
NanoVG.nvgTextBounds(vg, 0f, 0f, text, buffer)
return Size(buffer[2] - buffer[0], buffer[3] - buffer[1])
}
Expand Down
6 changes: 4 additions & 2 deletions src/test/kotlin/com/neptuneclient/voidui/tests/TestTheme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ class TestTheme : Theme(
normal = TextStyleSheet(
color = Color.WHITE,
font = Path.of("fonts/Jost-SemiBold.ttf"),
size = 32
size = 32,
letterSpacing = 12
)
),
smallTitle = Styles(
normal = TextStyleSheet(
color = Color.WHITE,
font = Path.of("fonts/Jost-SemiBold.ttf"),
size = 22
size = 22,
letterSpacing = 8
)
),
heading = Styles(
Expand Down

0 comments on commit 4894742

Please sign in to comment.