mirror of
https://github.com/Drezil/dear-imgui.hs.git
synced 2025-07-06 04:58:48 +02:00
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:
committed by
GitHub
parent
e3f7fbfd6f
commit
24345bb8f3
@ -209,6 +209,14 @@ module DearImGui.Raw
|
||||
, wantCaptureMouse
|
||||
, wantCaptureKeyboard
|
||||
|
||||
-- * Fonts in default font atlas
|
||||
, Font(..)
|
||||
, addFontDefault
|
||||
, addFontFromFileTTF
|
||||
, addFontFromMemoryTTF
|
||||
, buildFontAtlas
|
||||
, clearFontAtlas
|
||||
|
||||
-- * Types
|
||||
, module DearImGui.Enums
|
||||
, module DearImGui.Structs
|
||||
@ -1514,3 +1522,54 @@ wantCaptureMouse = liftIO do
|
||||
wantCaptureKeyboard :: MonadIO m => m Bool
|
||||
wantCaptureKeyboard = liftIO do
|
||||
(0 /=) <$> [C.exp| bool { GetIO().WantCaptureKeyboard } |]
|
||||
|
||||
|
||||
-- | Wraps @ImFont*@.
|
||||
newtype Font = Font (Ptr ImFont)
|
||||
|
||||
addFontDefault :: MonadIO m => m Font
|
||||
addFontDefault = liftIO do
|
||||
Font <$> [C.block|
|
||||
ImFont* {
|
||||
return GetIO().Fonts->AddFontDefault();
|
||||
}
|
||||
|]
|
||||
|
||||
addFontFromFileTTF :: MonadIO m => CString -> CFloat -> m Font
|
||||
addFontFromFileTTF filenamePtr sizePixels = liftIO do
|
||||
Font <$> [C.block|
|
||||
ImFont* {
|
||||
return GetIO().Fonts->AddFontFromFileTTF(
|
||||
$(char* filenamePtr),
|
||||
$(float sizePixels));
|
||||
}
|
||||
|]
|
||||
|
||||
-- | Transfer a buffer with TTF data to font atlas builder.
|
||||
addFontFromMemoryTTF :: MonadIO m => CStringLen -> CFloat -> m Font
|
||||
addFontFromMemoryTTF (castPtr -> fontDataPtr, fromIntegral -> fontSize) sizePixels = liftIO do
|
||||
Font <$> [C.block|
|
||||
ImFont* {
|
||||
return GetIO().Fonts->AddFontFromMemoryTTF(
|
||||
$(void* fontDataPtr),
|
||||
$(int fontSize),
|
||||
$(float sizePixels)
|
||||
);
|
||||
}
|
||||
|]
|
||||
|
||||
buildFontAtlas :: MonadIO m => m ()
|
||||
buildFontAtlas = liftIO do
|
||||
[C.block|
|
||||
void {
|
||||
GetIO().Fonts->Build();
|
||||
}
|
||||
|]
|
||||
|
||||
clearFontAtlas :: MonadIO m => m ()
|
||||
clearFontAtlas = liftIO do
|
||||
[C.block|
|
||||
void {
|
||||
GetIO().Fonts->Clear();
|
||||
}
|
||||
|]
|
||||
|
Reference in New Issue
Block a user