2020-08-05 20:23:16 +00:00
|
|
|
{-# LANGUAGE BlockArguments #-}
|
|
|
|
{-# LANGUAGE MonoLocalBinds #-}
|
|
|
|
|
2020-08-04 06:15:06 +00:00
|
|
|
module MetaBrush.Render.Util
|
|
|
|
( withRGBA, showRGBA
|
2020-08-05 20:23:16 +00:00
|
|
|
, widgetAddClasses, widgetAddClass
|
|
|
|
)
|
2020-08-04 06:15:06 +00:00
|
|
|
where
|
|
|
|
|
|
|
|
-- base
|
2020-08-05 20:23:16 +00:00
|
|
|
import Data.Foldable
|
|
|
|
( for_ )
|
2020-08-04 06:15:06 +00:00
|
|
|
import GHC.Stack
|
|
|
|
( HasCallStack )
|
|
|
|
|
|
|
|
-- gi-gdk
|
|
|
|
import qualified GI.Gdk as GDK
|
|
|
|
|
2020-08-05 20:23:16 +00:00
|
|
|
-- gi-gtk
|
|
|
|
import qualified GI.Gtk as GTK
|
|
|
|
|
2020-08-04 06:15:06 +00:00
|
|
|
-- text
|
|
|
|
import Data.Text
|
|
|
|
( Text )
|
|
|
|
|
|
|
|
-- transformers
|
|
|
|
import Control.Monad.IO.Class
|
2020-08-05 20:23:16 +00:00
|
|
|
( MonadIO )
|
2020-08-04 06:15:06 +00:00
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
withRGBA :: MonadIO m => GDK.RGBA -> ( Double -> Double -> Double -> Double -> m b ) -> m b
|
|
|
|
withRGBA rgba f = do
|
|
|
|
r <- GDK.getRGBARed rgba
|
|
|
|
g <- GDK.getRGBAGreen rgba
|
|
|
|
b <- GDK.getRGBABlue rgba
|
|
|
|
a <- GDK.getRGBAAlpha rgba
|
|
|
|
f r g b a
|
|
|
|
|
|
|
|
showRGBA :: MonadIO m => GDK.RGBA -> m String
|
|
|
|
showRGBA rgba = withRGBA rgba \ r g b a ->
|
|
|
|
pure $ "rgba(" ++ show r ++ "," ++ show g ++ "," ++ show b ++ "," ++ show a ++ ")"
|
|
|
|
|
|
|
|
widgetAddClasses :: ( HasCallStack, GTK.IsWidget widget, MonadIO m ) => widget -> [Text] -> m ()
|
|
|
|
widgetAddClasses widget classNames = do
|
|
|
|
styleContext <- GTK.widgetGetStyleContext widget
|
|
|
|
for_ classNames ( GTK.styleContextAddClass styleContext )
|
|
|
|
|
|
|
|
widgetAddClass :: ( HasCallStack, GTK.IsWidget widget, MonadIO m ) => widget -> Text -> m ()
|
|
|
|
widgetAddClass widget className = GTK.widgetGetStyleContext widget >>= ( `GTK.styleContextAddClass` className )
|