Add withFullscreen and related machinery (#55)

- `fullscreenFlags` available for those who want an alternative
  to `withFullscreen` without reinventing too much.
- Raw.begin got `open` and `flags` arguments.
- Added Raw.setNextWindowFullscreen combo block.
This commit is contained in:
Alexander Bondarenko 2021-06-04 23:18:16 +03:00 committed by GitHub
parent 73eee5fc9e
commit 6ccee5234b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 5 deletions

View File

@ -43,10 +43,14 @@ module DearImGui
-- * Windows -- * Windows
, withWindow , withWindow
, withWindowOpen , withWindowOpen
, withFullscreen
, fullscreenFlags
, begin , begin
, Raw.end , Raw.end
, setNextWindowPos , setNextWindowPos
, setNextWindowSize , setNextWindowSize
, Raw.setNextWindowFullscreen
, setNextWindowContentSize , setNextWindowContentSize
, setNextWindowSizeConstraints , setNextWindowSizeConstraints
, setNextWindowCollapsed , setNextWindowCollapsed
@ -200,6 +204,8 @@ module DearImGui
import Control.Monad import Control.Monad
( when ) ( when )
import Data.Bool import Data.Bool
import Data.Foldable
( foldl' )
import Foreign import Foreign
import Foreign.C import Foreign.C
@ -238,10 +244,11 @@ getVersion = liftIO do
-- may early out and omit submitting anything to the window. Always call a -- may early out and omit submitting anything to the window. Always call a
-- matching 'end' for each 'begin' call, regardless of its return value! -- matching 'end' for each 'begin' call, regardless of its return value!
-- --
-- Wraps @ImGui::Begin()@. -- Wraps @ImGui::Begin()@ with default options.
begin :: MonadIO m => String -> m Bool begin :: MonadIO m => String -> m Bool
begin name = liftIO do begin name = liftIO do
withCString name Raw.begin withCString name \namePtr ->
Raw.begin namePtr nullPtr (ImGuiWindowFlags 0)
-- | Append items to a window. -- | Append items to a window.
-- --
@ -260,6 +267,37 @@ withWindowOpen :: MonadUnliftIO m => String -> m () -> m ()
withWindowOpen name action = withWindowOpen name action =
withWindow name (`when` action) withWindow name (`when` action)
-- | Append items to a fullscreen window.
--
-- The action runs inside a window that is set to behave as a backdrop.
-- It has no typical window decorations, ignores events and does not jump to front.
--
-- You may append multiple times to it during the same frame
-- by calling 'withFullscreen' in multiple places.
withFullscreen :: MonadUnliftIO m => m () -> m ()
withFullscreen action = bracket open close (`when` action)
where
open = liftIO do
Raw.setNextWindowFullscreen
withCString "FullScreen" \namePtr ->
Raw.begin namePtr nullPtr fullscreenFlags
close = liftIO . const Raw.end
fullscreenFlags :: ImGuiWindowFlags
fullscreenFlags = foldl' (.|.) zeroBits
[ ImGuiWindowFlags_NoBackground
, ImGuiWindowFlags_NoBringToFrontOnFocus
, ImGuiWindowFlags_NoDecoration
, ImGuiWindowFlags_NoFocusOnAppearing
, ImGuiWindowFlags_NoMove
, ImGuiWindowFlags_NoResize
, ImGuiWindowFlags_NoSavedSettings
, ImGuiWindowFlags_NoScrollbar
, ImGuiWindowFlags_NoScrollWithMouse
, ImGuiWindowFlags_NoTitleBar
]
-- | Wraps @ImGui::BeginChild()@. -- | Wraps @ImGui::BeginChild()@.
beginChild :: MonadIO m => String -> m Bool beginChild :: MonadIO m => String -> m Bool
beginChild name = liftIO do beginChild name = liftIO do

View File

@ -45,6 +45,7 @@ module DearImGui.Raw
, end , end
, setNextWindowPos , setNextWindowPos
, setNextWindowSize , setNextWindowSize
, setNextWindowFullscreen
, setNextWindowContentSize , setNextWindowContentSize
, setNextWindowSizeConstraints , setNextWindowSizeConstraints
, setNextWindowCollapsed , setNextWindowCollapsed
@ -312,9 +313,12 @@ styleColorsClassic = liftIO do
-- matching 'end' for each 'begin' call, regardless of its return value! -- matching 'end' for each 'begin' call, regardless of its return value!
-- --
-- Wraps @ImGui::Begin()@. -- Wraps @ImGui::Begin()@.
begin :: (MonadIO m) => CString -> m Bool --
begin namePtr = liftIO do -- Passing non-null @Ptr CBool@ shows a window-closing widget in the upper-right corner of the window,
(0 /=) <$> [C.exp| bool { Begin($(char* namePtr)) } |] -- wich clicking will set the boolean to false when clicked.
begin :: (MonadIO m) => CString -> Ptr CBool -> ImGuiWindowFlags -> m Bool
begin namePtr openPtr flags = liftIO do
(0 /=) <$> [C.exp| bool { Begin($(char* namePtr), $(bool* openPtr), $(ImGuiWindowFlags flags)) } |]
-- | Pop window from the stack. -- | Pop window from the stack.
@ -721,6 +725,20 @@ setNextWindowSize sizePtr cond = liftIO do
[C.exp| void { SetNextWindowSize(*$(ImVec2* sizePtr), $(ImGuiCond cond)) } |] [C.exp| void { SetNextWindowSize(*$(ImVec2* sizePtr), $(ImGuiCond cond)) } |]
-- | Set next window size and position to match current display size.
--
-- Call before `begin`.
--
-- Wraps @ImGui::SetNextWindowPos()@, @ImGui::SetNextWindowSize()@
setNextWindowFullscreen :: (MonadIO m) => m ()
setNextWindowFullscreen = liftIO
[C.block|
void {
SetNextWindowPos(ImVec2(0, 0));
SetNextWindowSize(GetIO().DisplaySize);
}
|]
-- | Set next window content size (~ scrollable client area, which enforce the range of scrollbars). Not including window decorations (title bar, menu bar, etc.) nor WindowPadding. call before `begin` -- | Set next window content size (~ scrollable client area, which enforce the range of scrollbars). Not including window decorations (title bar, menu bar, etc.) nor WindowPadding. call before `begin`
-- --
-- Wraps @ImGui::SetNextWindowContentSize()@ -- Wraps @ImGui::SetNextWindowContentSize()@