Add font utils (#56)

- clearFontAtlas
- addFontDefault
- addFontFromFileTTF
- addFontFromMemoryTTF (raw only)
- buildFontAtlas

Vulkan example updated to use on f the imgui-distributed ttf files.
This commit is contained in:
Alexander Bondarenko
2021-09-12 18:41:42 +03:00
committed by GitHub
parent e3f7fbfd6f
commit 24345bb8f3
5 changed files with 112 additions and 6 deletions

View File

@ -245,6 +245,13 @@ module DearImGui
, Raw.wantCaptureMouse
, Raw.wantCaptureKeyboard
-- * Fonts
, Raw.Font
, addFontFromFileTTF
, Raw.addFontDefault
, Raw.buildFontAtlas
, Raw.clearFontAtlas
-- * Types
, module DearImGui.Enums
, module DearImGui.Structs
@ -1664,3 +1671,22 @@ pushStyleVar style valRef = liftIO do
popStyleVar :: (MonadIO m) => Int -> m ()
popStyleVar n = liftIO do
Raw.popStyleVar (fromIntegral n)
-- | Load a font from TTF file.
--
-- Specify font path and atlas glyph size.
--
-- Use 'addFontDefault' if you want to retain built-in font too.
--
-- Call 'buildFontAtlas' after adding all the fonts.
--
-- Call backend-specific `CreateFontsTexture` before using 'newFrame'.
addFontFromFileTTF :: MonadIO m => FilePath -> Float -> m (Maybe Raw.Font)
addFontFromFileTTF font size = liftIO do
res@(Raw.Font ptr) <- withCString font \fontPtr ->
Raw.addFontFromFileTTF fontPtr (CFloat size)
pure $
if castPtr ptr == nullPtr
then Nothing
else Just res