packages feed

coin-1.1: src/Coin/UI/Builder/GtkUIBuilderState.hs

{-
 *  Programmer:	Piotr Borek
 *  E-mail:     piotrborek@op.pl
 *  Copyright 2015 Piotr Borek
 *
 *  Distributed under the terms of the GPL (GNU Public License)
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-}

{-# LANGUAGE TemplateHaskell #-}

{-# OPTIONS_GHC -fno-warn-missing-signatures #-}

module Coin.UI.Builder.GtkUIBuilderState where

import qualified Data.Map.Strict as Map
import qualified Graphics.UI.Gtk as Gtk

import Control.Monad.State.Strict
import Control.Lens

import Coin.UI.Builder.GtkUIAttributes

data WidgetData = WidgetData {
    _wdWidget  :: Gtk.Widget,
    _wdPacking :: Gtk.Packing,
    _wdPadding :: Int
}

data UIBuilderState = UIBuilderState {
    _uiStateMap   :: Map.Map String Gtk.Widget,
    _uiStateList  :: [WidgetData],
    _uiStatePack  :: (Gtk.Packing, Int),
    _uiStateAttrs :: Attrs,
    _uiStateCss   :: [String]
}

data UINotebookState = UINotebookState {
    _uiNSBuilderState :: UIBuilderState,
    _uiNSMap          :: Map.Map String Gtk.Widget,
    _uiNSList         :: [(Gtk.Widget, Gtk.Widget)]
}

data UIGridData = UIGridData {
    _uiGridDataWidget :: Gtk.Widget,
    _uiGridDataLeft   :: Int,
    _uiGridDataRight  :: Int,
    _uiGridDataWidth  :: Int,
    _uiGridDataHeight :: Int
}

data UIGridState = UIGridState {
    _uiGridBuilderState :: UIBuilderState,
    _uiGridMap          :: Map.Map String Gtk.Widget,
    _uiGridList         :: [UIGridData]
}

makeLenses ''WidgetData
makeLenses ''UIBuilderState
makeLenses ''UINotebookState
makeLenses ''UIGridData
makeLenses ''UIGridState

builderStateEmpty :: UIBuilderState
builderStateEmpty = UIBuilderState {
                         _uiStateMap   = Map.empty,
                         _uiStateList  = [],
                         _uiStatePack  = (Gtk.PackGrow, 0),
                         _uiStateAttrs = EmptyAttrs,
                         _uiStateCss   = []
                     }

uiNotebookStateEmpty = UINotebookState {
                           _uiNSBuilderState = builderStateEmpty,
                           _uiNSMap          = Map.empty,
                           _uiNSList         = []
                       }

uiGridStateEmpty = UIGridState {
                        _uiGridBuilderState = builderStateEmpty,
                        _uiGridMap = Map.empty,
                        _uiGridList = []
                    }

type UIBuilder a = StateT UIBuilderState IO ()
type UINotebookBuilder a = StateT UINotebookState IO ()
type UIGridBuilder a = StateT UIGridState IO ()

execUIBuilder :: UIBuilder a -> IO UIBuilderState
execUIBuilder builder = execStateT builder builderStateEmpty

execUINotebookBuilder :: UINotebookBuilder a -> IO UINotebookState
execUINotebookBuilder builder = execStateT builder uiNotebookStateEmpty

execUIGridBuilder :: UIGridBuilder a -> IO UIGridState
execUIGridBuilder builder = execStateT builder uiGridStateEmpty