mirror of
https://github.com/Drezil/dear-imgui.hs.git
synced 2024-11-26 10:37:00 +00:00
Add remaining BeginChild arguments as required (#93)
Old behaviour with all default arguments is a special case to run some action scoped to a different child window. This now handled by `beginChildContext`/`withChildContext`.
This commit is contained in:
parent
c219f8eb4f
commit
c7a694bce8
2
Main.hs
2
Main.hs
@ -120,7 +120,7 @@ loop window checked color slider r pos size' selected tab1Ref tab2Ref = do
|
|||||||
|
|
||||||
progressBar 0.314 (Just "Pi")
|
progressBar 0.314 (Just "Pi")
|
||||||
|
|
||||||
beginChild "Child"
|
beginChild "Child" (ImVec2 0 0) True ImGuiWindowFlags_None
|
||||||
|
|
||||||
beginCombo "Label" "Preview" >>= whenTrue do
|
beginCombo "Label" "Preview" >>= whenTrue do
|
||||||
selectable "Testing 1"
|
selectable "Testing 1"
|
||||||
|
@ -71,6 +71,7 @@ module DearImGui
|
|||||||
-- ** Child Windows
|
-- ** Child Windows
|
||||||
, withChild
|
, withChild
|
||||||
, withChildOpen
|
, withChildOpen
|
||||||
|
, withChildContext
|
||||||
, beginChild
|
, beginChild
|
||||||
, Raw.endChild
|
, Raw.endChild
|
||||||
|
|
||||||
@ -350,25 +351,52 @@ fullscreenFlags = foldl' (.|.) zeroBits
|
|||||||
, ImGuiWindowFlags_NoTitleBar
|
, ImGuiWindowFlags_NoTitleBar
|
||||||
]
|
]
|
||||||
|
|
||||||
-- | Wraps @ImGui::BeginChild()@.
|
|
||||||
beginChild :: MonadIO m => String -> m Bool
|
|
||||||
beginChild name = liftIO do
|
|
||||||
withCString name Raw.beginChild
|
|
||||||
|
|
||||||
-- | Child windows used for self-contained independent scrolling/clipping regions
|
-- | Begin a self-contained independent scrolling/clipping regions within a host window.
|
||||||
-- within a host window. Child windows can embed their own child.
|
--
|
||||||
|
-- Child windows can embed their own child.
|
||||||
|
--
|
||||||
|
-- For each independent axis of @size@:
|
||||||
|
-- * ==0.0f: use remaining host window size
|
||||||
|
-- * >0.0f: fixed size
|
||||||
|
-- * <0.0f: use remaining window size minus abs(size)
|
||||||
|
--
|
||||||
|
-- Each axis can use a different mode, e.g. @ImVec2 0 400@.
|
||||||
|
--
|
||||||
|
-- @BeginChild()@ returns `False` to indicate the window is collapsed or fully clipped, so you may early out and omit submitting anything to the window.
|
||||||
|
--
|
||||||
|
-- Always call a matching `endChild` for each `beginChild` call, regardless of its return value.
|
||||||
|
--
|
||||||
|
-- Wraps @ImGui::BeginChild()@.
|
||||||
|
beginChild :: MonadIO m => String -> ImVec2 -> Bool -> ImGuiWindowFlags -> m Bool
|
||||||
|
beginChild name size border flags = liftIO do
|
||||||
|
withCString name \namePtr ->
|
||||||
|
with size \sizePtr ->
|
||||||
|
Raw.beginChild namePtr sizePtr (bool 0 1 border) flags
|
||||||
|
|
||||||
|
-- | Action wrapper for child windows.
|
||||||
--
|
--
|
||||||
-- Action will get 'False' if the child region is collapsed or fully clipped.
|
-- Action will get 'False' if the child region is collapsed or fully clipped.
|
||||||
withChild :: MonadUnliftIO m => String -> (Bool -> m a) -> m a
|
withChild :: MonadUnliftIO m => String -> ImVec2 -> Bool -> ImGuiWindowFlags -> (Bool -> m a) -> m a
|
||||||
withChild name = bracket (beginChild name) (const Raw.endChild)
|
withChild name size border flags = bracket (beginChild name size border flags) (const Raw.endChild)
|
||||||
|
|
||||||
-- | Child windows used for self-contained independent scrolling/clipping regions
|
-- | Action-skipping wrapper for child windows.
|
||||||
-- within a host window. Child windows can embed their own child.
|
|
||||||
--
|
--
|
||||||
-- Action will be skipped if the child region is collapsed or fully clipped.
|
-- Action will be skipped if the child region is collapsed or fully clipped.
|
||||||
withChildOpen :: MonadUnliftIO m => String -> m () -> m ()
|
withChildOpen :: MonadUnliftIO m => String -> ImVec2 -> Bool -> ImGuiWindowFlags -> m () -> m ()
|
||||||
withChildOpen name action =
|
withChildOpen name size border flags action =
|
||||||
withChild name (`when` action)
|
withChild name size border flags (`when` action)
|
||||||
|
|
||||||
|
-- | Action wrapper to run in a context of another child window addressed by its name.
|
||||||
|
--
|
||||||
|
-- Action will get 'False' if the child region is collapsed or fully clipped.
|
||||||
|
withChildContext :: MonadUnliftIO m => String -> (Bool -> m a) -> m a
|
||||||
|
withChildContext name action =
|
||||||
|
bracket
|
||||||
|
(liftIO $ withCString name Raw.beginChildContext)
|
||||||
|
(const Raw.endChild)
|
||||||
|
action
|
||||||
|
|
||||||
|
|
||||||
-- | Plain text.
|
-- | Plain text.
|
||||||
text :: MonadIO m => String -> m ()
|
text :: MonadIO m => String -> m ()
|
||||||
|
@ -66,6 +66,7 @@ module DearImGui.Raw
|
|||||||
|
|
||||||
-- ** Child Windows
|
-- ** Child Windows
|
||||||
, beginChild
|
, beginChild
|
||||||
|
, beginChildContext
|
||||||
, endChild
|
, endChild
|
||||||
|
|
||||||
-- * Parameter stacks
|
-- * Parameter stacks
|
||||||
@ -390,11 +391,47 @@ end = liftIO do
|
|||||||
[C.exp| void { End(); } |]
|
[C.exp| void { End(); } |]
|
||||||
|
|
||||||
|
|
||||||
-- | Wraps @ImGui::BeginChild()@.
|
-- | Begin a self-contained independent scrolling/clipping regions within a host window.
|
||||||
beginChild :: (MonadIO m) => CString -> m Bool
|
--
|
||||||
beginChild namePtr = liftIO do
|
-- Child windows can embed their own child.
|
||||||
(0 /=) <$> [C.exp| bool { BeginChild($(char* namePtr)) } |]
|
--
|
||||||
|
-- For each independent axis of @size@:
|
||||||
|
-- * ==0.0f: use remaining host window size
|
||||||
|
-- * >0.0f: fixed size
|
||||||
|
-- * <0.0f: use remaining window size minus abs(size)
|
||||||
|
--
|
||||||
|
-- Each axis can use a different mode, e.g. @ImVec2 0 400@.
|
||||||
|
--
|
||||||
|
-- @BeginChild()@ returns `False` to indicate the window is collapsed or fully clipped, so you may early out and omit submitting anything to the window.
|
||||||
|
--
|
||||||
|
-- Always call a matching `endChild` for each `beginChild` call, regardless of its return value.
|
||||||
|
--
|
||||||
|
-- Wraps @ImGui::BeginChild()@.
|
||||||
|
beginChild :: (MonadIO m) => CString -> Ptr ImVec2 -> CBool -> ImGuiWindowFlags -> m Bool
|
||||||
|
beginChild namePtr sizePtr border flags = liftIO do
|
||||||
|
(0 /=) <$> [C.exp|
|
||||||
|
bool {
|
||||||
|
BeginChild(
|
||||||
|
$(char* namePtr),
|
||||||
|
*$(ImVec2* sizePtr),
|
||||||
|
$(bool border),
|
||||||
|
$(ImGuiWindowFlags flags)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|]
|
||||||
|
|
||||||
|
-- | Switch context to another child window by its ID
|
||||||
|
--
|
||||||
|
-- Wraps @ImGui::BeginChild()@.
|
||||||
|
beginChildContext :: (MonadIO m) => CString -> m Bool
|
||||||
|
beginChildContext namePtr = liftIO do
|
||||||
|
(0 /=) <$> [C.exp|
|
||||||
|
bool {
|
||||||
|
BeginChild(
|
||||||
|
$(char* namePtr)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|]
|
||||||
|
|
||||||
-- | Wraps @ImGui::EndChild()@.
|
-- | Wraps @ImGui::EndChild()@.
|
||||||
endChild :: (MonadIO m) => m ()
|
endChild :: (MonadIO m) => m ()
|
||||||
|
Loading…
Reference in New Issue
Block a user