Skip to content

Commit

Permalink
feat: added option to set the size of the UI's font in the new UI
Browse files Browse the repository at this point in the history
FossilOrigin-Name: 8c7797fc28c5fd0718f5b3ff3c8a0902724c3866f6aec154a32b99106f31ba26
  • Loading branch information
thindil committed Oct 25, 2024
1 parent d0be547 commit 0da166e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/newui/nuklear/nuklear_sdl_renderer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ var
win: WindowPtr ## The main X window of the program
renderer: RendererPtr ## The SDL renderer

proc nuklearInit*(windowWidth, windowHeight: cint;
name: cstring = ""; fontPath: cstring = ""): PContext {.discardable.} =
proc nuklearInit*(windowWidth, windowHeight: cint; name: cstring = "";
fontPath: cstring = ""; fontSize: cint = 14): PContext {.discardable.} =
## Initialize Nuklear library, create the main program's window with the
## selected parameters.
##
Expand All @@ -107,6 +107,7 @@ proc nuklearInit*(windowWidth, windowHeight: cint;
## * name - the title of the main window
## * fontPath - the full path to the default UI font. If empty, use the
## default system font. Default value is empty.
## * fontSize - the size of the font used in the UI. Default values is 14.
SDL_SetHint("SDL_HINT_VIDEO_HIGHDPI_DISABLED", "0")
discard SDL_Init(SDL_INIT_VIDEO)
win = SDL_CreateWindow(name, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
Expand All @@ -132,11 +133,11 @@ proc nuklearInit*(windowWidth, windowHeight: cint;
font: ptr nk_font
nk_sdl_font_stash_begin(atlas.unsafeAddr)
if fontPath.len == 0:
font = nk_font_atlas_add_default(atlas, 24 * fontScale,
font = nk_font_atlas_add_default(atlas, fontSize.cfloat * fontScale,
config.unsafeAddr)
else:
font = nk_font_atlas_add_from_file(atlas, fontPath, 24 * fontScale,
config.unsafeAddr)
font = nk_font_atlas_add_from_file(atlas, fontPath, fontSize.cfloat *
fontScale, config.unsafeAddr)
nk_sdl_font_stash_end()
nk_style_set_font(getContext(), font.handle.unsafeAddr)
return getContext()
Expand Down

0 comments on commit 0da166e

Please sign in to comment.