module Brillo.Interface.Environment where
import Data.IORef (newIORef)
import Data.Text qualified as T
import Brillo.Data.FileDialog (FileDialog)
import Brillo.Internals.Interface.Backend (defaultBackendState)
import Brillo.Internals.Interface.Backend.Types qualified as Backend.Types
import Brillo.Internals.TinyFileDialogs qualified as TinyFileDialogs
getScreenSize :: IO (Int, Int)
getScreenSize :: IO (Int, Int)
getScreenSize = do
IORef GLFWState
backendStateRef <- GLFWState -> IO (IORef GLFWState)
forall a. a -> IO (IORef a)
newIORef GLFWState
defaultBackendState
IORef GLFWState -> Bool -> IO ()
forall a. Backend a => IORef a -> Bool -> IO ()
Backend.Types.initializeBackend IORef GLFWState
backendStateRef Bool
False
IORef GLFWState -> IO (Int, Int)
forall a. Backend a => IORef a -> IO (Int, Int)
Backend.Types.getScreenSize IORef GLFWState
backendStateRef
openFileDialog :: FileDialog -> IO (Maybe [FilePath])
openFileDialog :: FileDialog -> IO (Maybe [FilePath])
openFileDialog FileDialog
fileDialog = do
IORef GLFWState
backendStateRef <- GLFWState -> IO (IORef GLFWState)
forall a. a -> IO (IORef a)
newIORef GLFWState
defaultBackendState
IORef GLFWState -> Bool -> IO ()
forall a. Backend a => IORef a -> Bool -> IO ()
Backend.Types.initializeBackend IORef GLFWState
backendStateRef Bool
False
IORef GLFWState -> FileDialog -> IO (Maybe [FilePath])
forall a.
Backend a =>
IORef a -> FileDialog -> IO (Maybe [FilePath])
Backend.Types.openFileDialog IORef GLFWState
backendStateRef FileDialog
fileDialog
saveFileDialog ::
T.Text ->
T.Text ->
[T.Text] ->
T.Text ->
IO (Maybe FilePath)
saveFileDialog :: Text -> Text -> [Text] -> Text -> IO (Maybe FilePath)
saveFileDialog Text
title Text
defaultPath [Text]
filterPatterns Text
filterDescription = do
Maybe Text
result <-
Text -> Text -> [Text] -> Text -> IO (Maybe Text)
TinyFileDialogs.saveFileDialog
Text
title
Text
defaultPath
[Text]
filterPatterns
Text
filterDescription
Maybe FilePath -> IO (Maybe FilePath)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe FilePath -> IO (Maybe FilePath))
-> Maybe FilePath -> IO (Maybe FilePath)
forall a b. (a -> b) -> a -> b
$ (Text -> FilePath) -> Maybe Text -> Maybe FilePath
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> FilePath
T.unpack Maybe Text
result