{-# LANGUAGE OverloadedLabels #-}
module Reflex.GI.Gtk.Widget.Utils
( holdNotReadyWidget
, holdNotReadyDynamicWidget
, notReadyWidget
) where
import Control.Monad (join)
import GI.Gtk ( Widget
, spinnerNew
, toWidget
)
import Reflex ( Dynamic
, Event
, MonadHold
, Reflex
, holdDyn
)
import Reflex.GI.Gtk.Run.Class ( MonadRunGtk
, runGtk
)
notReadyWidget :: IO Widget
notReadyWidget :: IO Widget
notReadyWidget = do
Spinner
spinner <- IO Spinner
forall (m :: * -> *). (HasCallStack, MonadIO m) => m Spinner
spinnerNew
#start spinner
Spinner -> IO Widget
forall (m :: * -> *) o. (MonadIO m, IsWidget o) => o -> m Widget
toWidget Spinner
spinner
holdNotReadyWidget :: ( MonadRunGtk m
, MonadHold t m
)
=> Event t Widget -> m (Dynamic t Widget)
holdNotReadyWidget :: Event t Widget -> m (Dynamic t Widget)
holdNotReadyWidget newWidget :: Event t Widget
newWidget = do
Widget
spinner <- IO Widget -> m Widget
forall (m :: * -> *) a. MonadRunGtk m => IO a -> m a
runGtk IO Widget
notReadyWidget
Widget -> Event t Widget -> m (Dynamic t Widget)
forall k (t :: k) (m :: * -> *) a.
MonadHold t m =>
a -> Event t a -> m (Dynamic t a)
holdDyn Widget
spinner Event t Widget
newWidget
holdNotReadyDynamicWidget :: ( MonadRunGtk m
, MonadHold t m
, Reflex t
)
=> Event t (Dynamic t Widget) -> m (Dynamic t Widget)
holdNotReadyDynamicWidget :: Event t (Dynamic t Widget) -> m (Dynamic t Widget)
holdNotReadyDynamicWidget newWidget :: Event t (Dynamic t Widget)
newWidget = do
Widget
spinner <- IO Widget -> m Widget
forall (m :: * -> *) a. MonadRunGtk m => IO a -> m a
runGtk IO Widget
notReadyWidget
Dynamic t (Dynamic t Widget) -> Dynamic t Widget
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (Dynamic t (Dynamic t Widget) -> Dynamic t Widget)
-> m (Dynamic t (Dynamic t Widget)) -> m (Dynamic t Widget)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Dynamic t Widget
-> Event t (Dynamic t Widget) -> m (Dynamic t (Dynamic t Widget))
forall k (t :: k) (m :: * -> *) a.
MonadHold t m =>
a -> Event t a -> m (Dynamic t a)
holdDyn (Widget -> Dynamic t Widget
forall (f :: * -> *) a. Applicative f => a -> f a
pure Widget
spinner) Event t (Dynamic t Widget)
newWidget