module Graphics.UI.Gtk.WtkGui
where
import Data.Time
import Data.IORef (IORef)
import Data.Lenses
import Data.Lenses.Template
data InputFieldType =
Fl { flValue_ :: Maybe Double
}
| In { inValue_ :: Maybe Int }
| Str { stValue_ :: String }
| Da { daValue_ :: Maybe Day }
| Selection { selValue_ :: Maybe Int
, selString_ :: [String]
}
| CheckBox { cbValue_ :: Bool }
| Action { action_ :: IO () }
| NoDataJustAttributes
instance Show InputFieldType where
show (Fl x) = "Fl " ++ show x
show (In x) = "In " ++ show x
show (Str x) = "St " ++ x
show (Da x) = "Da " ++ show x
show (Selection x y) = "Sel " ++ show x ++ " " ++ show y
show (CheckBox x) = "CB " ++ show x
show (Action _) = "Action"
$( deriveLenses ''InputFieldType )
isSelectionJust (Selection (Just _) _) = True
isSelectionJust _ = False
isInputJust (Fl (Just _)) = True
isInputJust (In (Just _)) = True
isInputJust (Da (Just _)) = True
isInputJust _ = False
isCheckBox (CheckBox _) = True
isCheckBox _ = False
setCheckBox v (CheckBox _) = CheckBox v
setCheckBox _ x = x
newSelection :: Int -> InputFieldType -> InputFieldType
newSelection i s@(Selection _ xs) | length xs < i1 || i < 0 = s
| otherwise = Selection (Just i) xs
data Attributes = Attributes {
rawValue_ :: String
, validated_ :: Bool
, visible_ :: Bool
, editable_ :: Bool
, isError_ :: Bool
, errMssg_ :: String
}
deriving (Show, Eq, Ord)
$( deriveLenses ''Attributes )
data InputField = InputField {idOf_ :: Int
,val_ :: InputFieldType
,att_ :: Attributes
}
deriving Show
$( deriveLenses ''InputField )
val_flValue = val . flValue
val_inValue = val . inValue
val_stValue = val . stValue
val_daValue = val . daValue
val_cbValue = val . cbValue
val_selValue = val . selValue
val_selString = val . selString
val_action = val . action
att_rawValue = att . rawValue
att_validated = att . validated
att_visible = att . visible
att_editable = att . editable
att_isError = att . isError
att_errMssg = att . errMssg