mirror of
https://github.com/Drezil/dear-imgui.hs.git
synced 2024-11-22 16:57:00 +00:00
Add more text widgets (#59)
- Text replaced with TextUnformatted - TextColored - TextDisabled - TextWrapped - LabelText - BulletText
This commit is contained in:
parent
6ccee5234b
commit
f584319577
@ -90,6 +90,11 @@ module DearImGui
|
|||||||
-- * Widgets
|
-- * Widgets
|
||||||
-- ** Text
|
-- ** Text
|
||||||
, text
|
, text
|
||||||
|
, textColored
|
||||||
|
, textDisabled
|
||||||
|
, textWrapped
|
||||||
|
, labelText
|
||||||
|
, bulletText
|
||||||
|
|
||||||
-- ** Main
|
-- ** Main
|
||||||
, button
|
, button
|
||||||
@ -318,13 +323,43 @@ withChildOpen :: MonadUnliftIO m => String -> m () -> m ()
|
|||||||
withChildOpen name action =
|
withChildOpen name action =
|
||||||
withChild name (`when` action)
|
withChild name (`when` action)
|
||||||
|
|
||||||
-- | Formatted text.
|
-- | Plain text.
|
||||||
--
|
|
||||||
-- Wraps @ImGui::Text()@.
|
|
||||||
text :: MonadIO m => String -> m ()
|
text :: MonadIO m => String -> m ()
|
||||||
text t = liftIO do
|
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.
|
-- | A button. Returns 'True' when clicked.
|
||||||
--
|
--
|
||||||
|
@ -79,7 +79,12 @@ module DearImGui.Raw
|
|||||||
|
|
||||||
-- * Widgets
|
-- * Widgets
|
||||||
-- ** Text
|
-- ** Text
|
||||||
, text
|
, textUnformatted
|
||||||
|
, textColored
|
||||||
|
, textDisabled
|
||||||
|
, textWrapped
|
||||||
|
, labelText
|
||||||
|
, bulletText
|
||||||
|
|
||||||
-- ** Main
|
-- ** Main
|
||||||
, button
|
, button
|
||||||
@ -357,14 +362,64 @@ sameLine :: (MonadIO m) => m ()
|
|||||||
sameLine = liftIO do
|
sameLine = liftIO do
|
||||||
[C.exp| void { SameLine(); } |]
|
[C.exp| void { SameLine(); } |]
|
||||||
|
|
||||||
|
-- | Raw text without formatting.
|
||||||
-- | Formatted text.
|
|
||||||
--
|
--
|
||||||
-- Wraps @ImGui::Text()@.
|
-- Roughly equivalent to Text("%s", text) but:
|
||||||
text :: (MonadIO m) => CString -> m ()
|
-- A) doesn't require null terminated string if 'text_end' is specified,
|
||||||
text textPtr = liftIO do
|
-- B) it's faster, no memory copy is done, no buffer size limits, recommended for long chunks of text.
|
||||||
[C.exp| void { Text("%s", $(char* textPtr)) } |]
|
--
|
||||||
|
-- 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.
|
-- | A button. Returns 'True' when clicked.
|
||||||
--
|
--
|
||||||
|
Loading…
Reference in New Issue
Block a user