Skip to content

Commit

Permalink
Fixed font loading
Browse files Browse the repository at this point in the history
  • Loading branch information
smilefx committed Nov 30, 2024
1 parent 4de855a commit 96947c3
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 13 deletions.
11 changes: 8 additions & 3 deletions bgw-gui/src/jsMain/kotlin/tools/aqua/bgw/elements/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,22 @@ internal val App = FC<AppProps> { props ->
useEffect {
webSocket?.send("Hello from Client!")
}
Global {
styles {
props.data.fonts.forEach { font ->

props.data.fonts.forEach { font ->
Global {
styles {
fontFace {
fontFamily = font.second
fontStyle = FontStyle.normal
fontWeight = integer(font.third)
src = "url(static/${font.first})"
}
}
}
}

Global {
styles {
".bgw-root-container" {
width = 100.pct
height = 100.pct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import TextInputUIComponentData
import UIComponentData
import VisualData
import csstype.PropertiesBuilder
import csstype.RuleBuilder
import web.cssom.*
import org.w3c.dom.css.CSSRule

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,19 @@ open class BoardGameApplication(
}

/**
* Loads a font file and registers it in the JFX graphics system.
* @param font The font file off type .ttf which is to be loaded
* @throws NoSuchFileException if the file doesn't exist
* @throws AccessDeniedException if the file can't be read
* Loads a font file and registers it in the GUI.
* @param path The font file path relative to resources and with file extension which is to be loaded
* @param fontName The name of the font which is to be used in the GUI
* @param weight The weight of the font which is to be used in the GUI
* @return A boolean weather the file could be loaded or not
*/
fun loadFont(path : String, fontName : String, weight : Font.FontWeight): Boolean = Frontend.loadFont(path, fontName, weight)

/**
* Loads a font file and registers it in the GUI.
* @param path The font file path relative to resources and with file extension which is to be loaded
* @return A boolean weather the file could be loaded or not
*/
fun loadFont(path : String): Boolean = Frontend.loadFont(path, path.substringAfterLast('/').substringBeforeLast('.'), Font.FontWeight.NORMAL)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ internal object Application : BoardGameApplication() {
private val cardLayoutScene = CardLayoutScene()

init {
loadFont("Rubik.ttf", "Rubik", Font.FontWeight.EXTRA_BOLD)
loadFont("Rubik.ttf")
loadFont("Staatliches-Regular.ttf", "Staatliches", Font.FontWeight.NORMAL)
loadFont("JetBrainsMono-ExtraBold.ttf", "JetBrainsMono", Font.FontWeight.EXTRA_BOLD)
// showGameScene(cardLayoutScene)
// showGameScene(hexGrid)
showGameScene(animation)
// showGameScene(animation)
// showGameScene(grid)
// showGameScene(dragDropScene)
// showMenuScene(uiScene)
showMenuScene(uiScene)
// showGameScene(visualScene)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal class UIScene : MenuScene() {
height = 50,
items = listOf(TestObject("Test1"), TestObject("Test2"), TestObject("Test3"), TestObject("Test4")),
prompt = "Select an item",
font = Font(20.0, Color.BLACK, "Rubik", Font.FontWeight.SEMI_BOLD),
font = Font(20.0, Color.BLACK, "Staatliches", Font.FontWeight.NORMAL),
formatFunction = { it.name }
)

Expand Down Expand Up @@ -50,7 +50,7 @@ internal class UIScene : MenuScene() {
width = 800,
height = 50,
text = "Passwortbox",
font = Font(20.0, Color.BLACK, "Rubik", Font.FontWeight.SEMI_BOLD),
font = Font(20.0, Color.BLACK, "JetBrainsMono", Font.FontWeight.EXTRA_BOLD),
prompt = "Enter password here",
).apply {
visual = ColorVisual(Color.LIGHT_GRAY)
Expand All @@ -62,7 +62,7 @@ internal class UIScene : MenuScene() {
width = 800,
height = 600,
text = "Test\nArea",
font = Font(20.0, Color.GREEN, "Rubik", Font.FontWeight.SEMI_BOLD),
font = Font(20.0, Color.BLACK, "JetBrainsMono", Font.FontWeight.EXTRA_BOLD),
prompt = "Enter text here",
).apply {
visual = ColorVisual(Color.BLUE)
Expand All @@ -87,6 +87,8 @@ internal class UIScene : MenuScene() {


combo.select(2)

println("UIScene initialized")
}

inner class TestObject(val name : String) {}
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit 96947c3

Please sign in to comment.