packages feed

dear-imgui-raw-1.0.0: src/DearImGui/Raw/ImFont.hsc

{-# LANGUAGE CApiFFI #-}
{-# LANGUAGE PatternSynonyms #-}

-- This file was generated by dear-bindings-ffi. Do not edit by hand.

module DearImGui.Raw.ImFont
  ( ImFont
  , addRemapCodepoint
  , addRemapCodepointToGlyphIndex
  , c_calcTextSizeA
  , c_renderChar
  , c_renderText
  , calcTextSizeA
  , calcWordWrapPosition
  , clearOutputData
  , destroy
  , getDebugName
  , getFontBaked
  , init
  , isGlyphInFont
  , isGlyphRangeUnused
  , isLoaded
  , renderChar
  , renderText
  , used8kPagesMapLength
  , withDefault
  ) where

import Control.Exception (bracket_)
import DearImGui.Raw (ImDrawTextFlags, ImGuiID, ImU32, ImU8, ImWchar)
import DearImGui.Raw.Enums.ImFontFlags (ImFontFlags)
import {-# SOURCE #-} DearImGui.Raw.ImDrawList (ImDrawList)
import DearImGui.Raw.ImFontAtlas (ImFontAtlas)
import {-# SOURCE #-} DearImGui.Raw.ImFontBaked (ImFontBaked)
import {-# SOURCE #-} DearImGui.Raw.ImFontConfig (ImFontConfig)
import DearImGui.Raw.ImGuiStorage (ImGuiStorage)
import DearImGui.Raw.ImVec2 (ImVec2)
import DearImGui.Raw.ImVec4 (ImVec4)
import DearImGui.Raw.ImVector (ImVector)
import Foreign.C.String (CString)
import Foreign.C.Types
import Foreign.Marshal.Alloc (alloca)
import Foreign.Marshal.Utils (with)
import Foreign.Ptr (Ptr, plusPtr)
import Foreign.Storable (Storable (..))
import GHC.Records (HasField (..))
import Prelude hiding (init)

#include "dcimgui_nodefaultargfunctions.h"

-- structs (opaque)

data ImFont
instance Storable ImFont where
  sizeOf _    = #{size ImFont}
  alignment _ = #{alignment ImFont}
  peek _ = error "ImFont: opaque struct, peek not supported in v0"
  poke _ _ = error "ImFont: opaque struct, poke not supported in v0"

instance HasField "lastBaked" (Ptr ImFont) (Ptr (Ptr ImFontBaked)) where
  getField = #{ptr ImFont, LastBaked}

instance HasField "ownerAtlas" (Ptr ImFont) (Ptr (Ptr ImFontAtlas)) where
  getField = #{ptr ImFont, OwnerAtlas}

instance HasField "flags" (Ptr ImFont) (Ptr ImFontFlags) where
  getField = #{ptr ImFont, Flags}

instance HasField "currentRasterizerDensity" (Ptr ImFont) (Ptr Float) where
  getField = #{ptr ImFont, CurrentRasterizerDensity}

instance HasField "fontId" (Ptr ImFont) (Ptr ImGuiID) where
  getField = #{ptr ImFont, FontId}

instance HasField "legacySize" (Ptr ImFont) (Ptr Float) where
  getField = #{ptr ImFont, LegacySize}

instance HasField "sources" (Ptr ImFont) (Ptr (ImVector (Ptr ImFontConfig))) where
  getField = #{ptr ImFont, Sources}

instance HasField "ellipsisChar" (Ptr ImFont) (Ptr ImWchar) where
  getField = #{ptr ImFont, EllipsisChar}

instance HasField "fallbackChar" (Ptr ImFont) (Ptr ImWchar) where
  getField = #{ptr ImFont, FallbackChar}

instance HasField "used8kPagesMap" (Ptr ImFont) (Ptr ImU8) where
  getField = #{ptr ImFont, Used8kPagesMap}

used8kPagesMapLength :: Int
used8kPagesMapLength = #{const (IM_UNICODE_CODEPOINT_MAX +1)/8192/8}

instance HasField "ellipsisAutoBake" (Ptr ImFont) (Ptr CBool) where
  getField = #{ptr ImFont, EllipsisAutoBake}

instance HasField "remapPairs" (Ptr ImFont) (Ptr ImGuiStorage) where
  getField = #{ptr ImFont, RemapPairs}

foreign import capi unsafe "DearImGuiWrappers.h ImFont_Init_wrap"
  init
    :: Ptr ImFont
    -> IO ()

foreign import capi unsafe "DearImGuiWrappers.h ImFont_Destroy_wrap"
  destroy
    :: Ptr ImFont
    -> IO ()

withDefault :: (Ptr ImFont -> IO a) -> IO a
withDefault k = alloca $ \p -> bracket_ (init p) (destroy p) (k p)

-- functions

-- C: void AddRemapCodepoint(ImFont* self, ImWchar from_codepoint, ImWchar to_codepoint)
foreign import capi unsafe "dcimgui_nodefaultargfunctions.h ImFont_AddRemapCodepoint"
  addRemapCodepoint
    :: (Ptr ImFont) -- ^ self
    -> ImWchar -- ^ from_codepoint
    -> ImWchar -- ^ to_codepoint
    -> IO ()

-- C: void AddRemapCodepointToGlyphIndex(ImFont* self, ImWchar from_codepoint, int font_src_idx, int glyph_idx)
foreign import capi unsafe "dcimgui_nodefaultargfunctions.h ImFont_AddRemapCodepointToGlyphIndex"
  addRemapCodepointToGlyphIndex
    :: (Ptr ImFont) -- ^ self
    -> ImWchar -- ^ from_codepoint
    -> CInt -- ^ font_src_idx
    -> CInt -- ^ glyph_idx
    -> IO ()

foreign import capi unsafe "DearImGuiWrappers.h ImFont_CalcTextSizeA_wrap"
  c_calcTextSizeA
    :: (Ptr ImFont) -- ^ self
    -> Float -- ^ size
    -> Float -- ^ max_width
    -> Float -- ^ wrap_width
    -> CString -- ^ text_begin
    -> CString -- ^ text_end
    -> (Ptr CString) -- ^ out_remaining
    -> (Ptr ImVec2) -- ^ out
    -> IO ()

calcTextSizeA
  :: (Ptr ImFont) -- ^ self
  -> Float -- ^ size
  -> Float -- ^ max_width
  -> Float -- ^ wrap_width
  -> CString -- ^ text_begin
  -> CString -- ^ text_end
  -> (Ptr CString) -- ^ out_remaining
  -> IO ImVec2
calcTextSizeA self size max_width wrap_width text_begin text_end out_remaining =
  alloca $ \outPtr -> c_calcTextSizeA self size max_width wrap_width text_begin text_end out_remaining outPtr >> peek outPtr

-- C: const char* CalcWordWrapPosition(ImFont* self, float size, const char* text, const char* text_end, float wrap_width)
foreign import capi unsafe "dcimgui_nodefaultargfunctions.h ImFont_CalcWordWrapPosition"
  calcWordWrapPosition
    :: (Ptr ImFont) -- ^ self
    -> Float -- ^ size
    -> CString -- ^ text
    -> CString -- ^ text_end
    -> Float -- ^ wrap_width
    -> IO CString

-- C: void ClearOutputData(ImFont* self)
foreign import capi unsafe "dcimgui_nodefaultargfunctions.h ImFont_ClearOutputData"
  clearOutputData
    :: (Ptr ImFont) -- ^ self
    -> IO ()

-- C: const char* GetDebugName(const ImFont* self)
foreign import capi unsafe "dcimgui_nodefaultargfunctions.h ImFont_GetDebugName"
  getDebugName
    :: (Ptr ImFont) -- ^ self
    -> IO CString

-- C: ImFontBaked* GetFontBaked(ImFont* self, float font_size, float density)
foreign import capi unsafe "dcimgui_nodefaultargfunctions.h ImFont_GetFontBaked"
  getFontBaked
    :: (Ptr ImFont) -- ^ self
    -> Float -- ^ font_size
    -> Float -- ^ density
    -> IO (Ptr ImFontBaked)

-- C: bool IsGlyphInFont(ImFont* self, ImWchar c)
foreign import capi unsafe "dcimgui_nodefaultargfunctions.h ImFont_IsGlyphInFont"
  isGlyphInFont
    :: (Ptr ImFont) -- ^ self
    -> ImWchar -- ^ c
    -> IO CBool

-- C: bool IsGlyphRangeUnused(ImFont* self, unsigned int c_begin, unsigned int c_last)
foreign import capi unsafe "dcimgui_nodefaultargfunctions.h ImFont_IsGlyphRangeUnused"
  isGlyphRangeUnused
    :: (Ptr ImFont) -- ^ self
    -> CUInt -- ^ c_begin
    -> CUInt -- ^ c_last
    -> IO CBool

-- C: bool IsLoaded(const ImFont* self)
foreign import capi unsafe "dcimgui_nodefaultargfunctions.h ImFont_IsLoaded"
  isLoaded
    :: (Ptr ImFont) -- ^ self
    -> IO CBool

foreign import capi unsafe "DearImGuiWrappers.h ImFont_RenderChar_wrap"
  c_renderChar
    :: (Ptr ImFont) -- ^ self
    -> (Ptr ImDrawList) -- ^ draw_list
    -> Float -- ^ size
    -> (Ptr ImVec2) -- ^ pos
    -> ImU32 -- ^ col
    -> ImWchar -- ^ c
    -> (Ptr ImVec4) -- ^ cpu_fine_clip
    -> IO ()

renderChar
  :: (Ptr ImFont) -- ^ self
  -> (Ptr ImDrawList) -- ^ draw_list
  -> Float -- ^ size
  -> ImVec2 -- ^ pos
  -> ImU32 -- ^ col
  -> ImWchar -- ^ c
  -> (Ptr ImVec4) -- ^ cpu_fine_clip
  -> IO ()
renderChar self draw_list size pos col c cpu_fine_clip =
  with pos $ \posPtr -> c_renderChar self draw_list size posPtr col c cpu_fine_clip

foreign import capi unsafe "DearImGuiWrappers.h ImFont_RenderText_wrap"
  c_renderText
    :: (Ptr ImFont) -- ^ self
    -> (Ptr ImDrawList) -- ^ draw_list
    -> Float -- ^ size
    -> (Ptr ImVec2) -- ^ pos
    -> ImU32 -- ^ col
    -> (Ptr ImVec4) -- ^ clip_rect
    -> CString -- ^ text_begin
    -> CString -- ^ text_end
    -> Float -- ^ wrap_width
    -> ImDrawTextFlags -- ^ flags
    -> IO ()

renderText
  :: (Ptr ImFont) -- ^ self
  -> (Ptr ImDrawList) -- ^ draw_list
  -> Float -- ^ size
  -> ImVec2 -- ^ pos
  -> ImU32 -- ^ col
  -> ImVec4 -- ^ clip_rect
  -> CString -- ^ text_begin
  -> CString -- ^ text_end
  -> Float -- ^ wrap_width
  -> ImDrawTextFlags -- ^ flags
  -> IO ()
renderText self draw_list size pos col clip_rect text_begin text_end wrap_width flags =
  with pos $ \posPtr -> with clip_rect $ \clip_rectPtr -> c_renderText self draw_list size posPtr col clip_rectPtr text_begin text_end wrap_width flags