diff --git a/src/DearImGui.hs b/src/DearImGui.hs index d2bb0bf..a0dd9d0 100644 --- a/src/DearImGui.hs +++ b/src/DearImGui.hs @@ -90,6 +90,11 @@ module DearImGui -- * Widgets -- ** Text , text + , textColored + , textDisabled + , textWrapped + , labelText + , bulletText -- ** Main , button @@ -318,13 +323,43 @@ withChildOpen :: MonadUnliftIO m => String -> m () -> m () withChildOpen name action = withChild name (`when` action) --- | Formatted text. --- --- Wraps @ImGui::Text()@. +-- | Plain text. text :: MonadIO m => String -> m () text t = liftIO do - withCString t Raw.text + withCString t \textPtr -> + Raw.textUnformatted textPtr nullPtr +-- | Colored text. +textColored :: (HasGetter ref ImVec4, MonadIO m) => ref -> String -> m () +textColored ref t = liftIO do + currentValue <- get ref + with currentValue \refPtr -> + withCString t $ Raw.textColored refPtr + +-- | Plain text in a "disabled" color according to current style. +textDisabled :: MonadIO m => String -> m () +textDisabled t = liftIO do + withCString t Raw.textDisabled + +-- | Plain text with a word-wrap capability. +-- +-- Note that this won't work on an auto-resizing window if there's no other widgets to extend the window width, +-- you may need to set a size using 'setNextWindowSize'. +textWrapped :: MonadIO m => String -> m () +textWrapped t = liftIO do + withCString t Raw.textWrapped + +-- | Label+text combo aligned to other label+value widgets. +labelText :: MonadIO m => String -> String -> m () +labelText label t = liftIO do + withCString label \labelPtr -> + withCString t \textPtr -> + Raw.labelText labelPtr textPtr + +-- | Text with a little bullet aligned to the typical tree node. +bulletText :: MonadIO m => String -> m () +bulletText t = liftIO do + withCString t Raw.bulletText -- | A button. Returns 'True' when clicked. -- diff --git a/src/DearImGui/Raw.hs b/src/DearImGui/Raw.hs index a9871cb..8648f0f 100644 --- a/src/DearImGui/Raw.hs +++ b/src/DearImGui/Raw.hs @@ -79,7 +79,12 @@ module DearImGui.Raw -- * Widgets -- ** Text - , text + , textUnformatted + , textColored + , textDisabled + , textWrapped + , labelText + , bulletText -- ** Main , button @@ -357,14 +362,64 @@ sameLine :: (MonadIO m) => m () sameLine = liftIO do [C.exp| void { SameLine(); } |] - --- | Formatted text. +-- | Raw text without formatting. -- --- Wraps @ImGui::Text()@. -text :: (MonadIO m) => CString -> m () -text textPtr = liftIO do - [C.exp| void { Text("%s", $(char* textPtr)) } |] +-- Roughly equivalent to Text("%s", text) but: +-- A) doesn't require null terminated string if 'text_end' is specified, +-- B) it's faster, no memory copy is done, no buffer size limits, recommended for long chunks of text. +-- +-- Wraps @ImGui::TextUnformatted()@. +textUnformatted :: (MonadIO m) => CString -> CString -> m () +textUnformatted textPtr textEndPtr = liftIO do + [C.exp| void { TextUnformatted($(char* textPtr), $(char* textEndPtr)) } |] +-- | Shortcut for @PushStyleColor(ImGuiCol_Text, col); Text(fmt, ...); PopStyleColor();@. +-- +-- XXX: Unlike the original, does not do string formatting. +-- +-- Wraps @ImGui::TextColored()@. +textColored :: (MonadIO m) => Ptr ImVec4 -> CString -> m () +textColored colorPtr textPtr = liftIO do + [C.exp| void { TextColored(*$(ImVec4 *colorPtr), "%s", $(char* textPtr)) } |] + +-- | Shortcut for @PushStyleColor(ImGuiCol_Text, style.Colors[ImGuiCol_TextDisabled]); Text(fmt, ...); PopStyleColor();@. +-- +-- XXX: Unlike the original, does not do string formatting. +-- +-- Wraps @ImGui::TextWrapped()@. +textDisabled :: (MonadIO m) => CString -> m () +textDisabled textPtr = liftIO do + [C.exp| void { TextDisabled("%s", $(char* textPtr)) } |] + +-- | Shortcut for @PushTextWrapPos(0.0f); Text(fmt, ...); PopTextWrapPos();@. +-- +-- Note that this won't work on an auto-resizing window if there's no other widgets to extend the window width, +-- you may need to set a size using 'setNextWindowSize'. +-- +-- XXX: Unlike the original, does not do string formatting. +-- +-- Wraps @ImGui::TextWrapped()@. +textWrapped :: (MonadIO m) => CString -> m () +textWrapped textPtr = liftIO do + [C.exp| void { TextWrapped("%s", $(char* textPtr)) } |] + +-- | Label+text combo aligned to other label+value widgets. +-- +-- XXX: Unlike the original, does not do string formatting. +-- +-- Wraps @ImGui::LabelText()@. +labelText :: (MonadIO m) => CString -> CString -> m () +labelText labelPtr textPtr = liftIO do + [C.exp| void { LabelText($(char* labelPtr), "%s", $(char* textPtr)) } |] + +-- | Text with a little bullet aligned to the typical tree node. +-- +-- XXX: Unlike the original, does not do string formatting. +-- +-- Wraps @ImGui::BulletText()@. +bulletText :: (MonadIO m) => CString -> m () +bulletText textPtr = liftIO do + [C.exp| void { BulletText("%s", $(char* textPtr)) } |] -- | A button. Returns 'True' when clicked. --