Commit d26ecb02 authored by David Davó's avatar David Davó

Finished reimplementing class hierarchy

parent c05da985
...@@ -48,6 +48,7 @@ pattern B64Value = S.SB64Value ...@@ -48,6 +48,7 @@ pattern B64Value = S.SB64Value
pattern ImageFormat = S.SImageFormat pattern ImageFormat = S.SImageFormat
pattern BoolValue = S.SBoolValue pattern BoolValue = S.SBoolValue
pattern Options = S.SOptions pattern Options = S.SOptions
pattern OptionalIndex = S.SOptionalIndex
pattern Index = S.SIndex pattern Index = S.SIndex
pattern SelectionHandler = S.SSelectionHandler pattern SelectionHandler = S.SSelectionHandler
pattern Tooltips = S.STooltips pattern Tooltips = S.STooltips
......
...@@ -36,9 +36,7 @@ mkDropdown :: IO Dropdown ...@@ -36,9 +36,7 @@ mkDropdown :: IO Dropdown
mkDropdown = do mkDropdown = do
-- Default properties, with a random uuid -- Default properties, with a random uuid
wid <- U.random wid <- U.random
let selectionAttrs = defaultSelectionWidget "DropdownView" "DropdownModel" let widgetState = WidgetState $ defaultSelectionWidget "DropdownView" "DropdownModel"
dropdownAttrs = (ButtonStyle =:: DefaultButton) :& RNil
widgetState = WidgetState $ selectionAttrs <+> dropdownAttrs
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
...@@ -55,6 +53,6 @@ instance IHaskellWidget Dropdown where ...@@ -55,6 +53,6 @@ instance IHaskellWidget Dropdown where
comm widget val _ = comm widget val _ =
case nestedObjectLookup val ["state", "index"] of case nestedObjectLookup val ["state", "index"] of
Just (Number index) -> do Just (Number index) -> do
void $ setField' widget Index (Sci.coefficient index) void $ setField' widget OptionalIndex (Just $ Sci.coefficient index)
triggerSelection widget triggerSelection widget
_ -> pure () _ -> pure ()
...@@ -52,6 +52,6 @@ instance IHaskellWidget RadioButtons where ...@@ -52,6 +52,6 @@ instance IHaskellWidget RadioButtons where
comm widget val _ = comm widget val _ =
case nestedObjectLookup val ["state", "index"] of case nestedObjectLookup val ["state", "index"] of
Just (Number index) -> do Just (Number index) -> do
void $ setField' widget Index (Sci.coefficient index) void $ setField' widget OptionalIndex (Just $ Sci.coefficient index)
triggerSelection widget triggerSelection widget
_ -> pure () _ -> pure ()
...@@ -19,6 +19,7 @@ import Control.Monad (void) ...@@ -19,6 +19,7 @@ import Control.Monad (void)
import Data.Aeson import Data.Aeson
import Data.IORef (newIORef) import Data.IORef (newIORef)
import qualified Data.Scientific as Sci import qualified Data.Scientific as Sci
import Data.Vinyl (Rec(..), (<+>))
import IHaskell.Display import IHaskell.Display
import IHaskell.Eval.Widgets import IHaskell.Eval.Widgets
...@@ -35,7 +36,10 @@ mkSelect :: IO Select ...@@ -35,7 +36,10 @@ mkSelect :: IO Select
mkSelect = do mkSelect = do
-- Default properties, with a random uuid -- Default properties, with a random uuid
wid <- U.random wid <- U.random
let widgetState = WidgetState $ defaultSelectionWidget "SelectView" "SelectModel" let selectionAttrs = defaultSelectionWidget "SelectView" "SelectModel"
selectAttrs = (Rows =:: Just 5)
:& RNil
widgetState = WidgetState $ selectionAttrs <+> selectAttrs
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
...@@ -52,6 +56,6 @@ instance IHaskellWidget Select where ...@@ -52,6 +56,6 @@ instance IHaskellWidget Select where
comm widget val _ = comm widget val _ =
case nestedObjectLookup val ["state", "index"] of case nestedObjectLookup val ["state", "index"] of
Just (Number index) -> do Just (Number index) -> do
void $ setField' widget Index (Sci.coefficient index) void $ setField' widget OptionalIndex (Just $ Sci.coefficient index)
triggerSelection widget triggerSelection widget
_ -> pure () _ -> pure ()
...@@ -20,6 +20,7 @@ import Data.Aeson ...@@ -20,6 +20,7 @@ import Data.Aeson
import Data.IORef (newIORef) import Data.IORef (newIORef)
import qualified Data.Scientific as Sci import qualified Data.Scientific as Sci
import qualified Data.Vector as V import qualified Data.Vector as V
import Data.Vinyl (Rec(..), (<+>))
import IHaskell.Display import IHaskell.Display
import IHaskell.Eval.Widgets import IHaskell.Eval.Widgets
...@@ -36,7 +37,10 @@ mkSelectMultiple :: IO SelectMultiple ...@@ -36,7 +37,10 @@ mkSelectMultiple :: IO SelectMultiple
mkSelectMultiple = do mkSelectMultiple = do
-- Default properties, with a random uuid -- Default properties, with a random uuid
wid <- U.random wid <- U.random
let widgetState = WidgetState $ defaultMultipleSelectionWidget "SelectMultipleView" "SelectMultipleModel" let multipleSelectionAttrs = defaultMultipleSelectionWidget "SelectMultipleView" "SelectMultipleModel"
selectMultipleAttrs = (Rows =:: Just 5)
:& RNil
widgetState = WidgetState $ multipleSelectionAttrs <+> selectMultipleAttrs
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
......
...@@ -37,9 +37,11 @@ mkSelectionRangeSlider :: IO SelectionRangeSlider ...@@ -37,9 +37,11 @@ mkSelectionRangeSlider :: IO SelectionRangeSlider
mkSelectionRangeSlider = do mkSelectionRangeSlider = do
wid <- U.random wid <- U.random
let selectionAttrs = defaultMultipleSelectionWidget "SelectionRangeSliderView" "SelectionRangeSliderModel" let selectionAttrs = defaultMultipleSelectionWidget "SelectionRangeSliderView" "SelectionRangeSliderModel"
widgetState = WidgetState $ rput (Indices =:: [0,0]) $ selectionAttrs <+> selectionRangeSliderAttrs = (Orientation =:: HorizontalOrientation)
(Orientation =:: HorizontalOrientation) :& (ReadOut =:: True)
:& RNil :& (ContinuousUpdate =:: True)
:& RNil
widgetState = WidgetState $ rput (Indices =:: [0,0]) $ selectionAttrs <+> selectionRangeSliderAttrs
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
......
...@@ -35,10 +35,12 @@ type SelectionSlider = IPythonWidget 'SelectionSliderType ...@@ -35,10 +35,12 @@ type SelectionSlider = IPythonWidget 'SelectionSliderType
mkSelectionSlider :: IO SelectionSlider mkSelectionSlider :: IO SelectionSlider
mkSelectionSlider = do mkSelectionSlider = do
wid <- U.random wid <- U.random
let selectionAttrs = defaultSelectionWidget "SelectionSliderView" "SelectionSliderModel" let selectionAttrs = defaultSelectionNonemptyWidget "SelectionSliderView" "SelectionSliderModel"
widgetState = WidgetState $ selectionAttrs <+> selectionSliderAttrs = (Orientation =:: HorizontalOrientation)
(Orientation =:: HorizontalOrientation) :& (ReadOut =:: True)
:& RNil :& (ContinuousUpdate =:: True)
:& RNil
widgetState = WidgetState $ selectionAttrs <+> selectionSliderAttrs
stateIO <- newIORef widgetState stateIO <- newIORef widgetState
......
...@@ -58,6 +58,6 @@ instance IHaskellWidget ToggleButtons where ...@@ -58,6 +58,6 @@ instance IHaskellWidget ToggleButtons where
comm widget val _ = comm widget val _ =
case nestedObjectLookup val ["state", "index"] of case nestedObjectLookup val ["state", "index"] of
Just (Number index) -> do Just (Number index) -> do
void $ setField' widget Index (Sci.coefficient index) void $ setField' widget OptionalIndex (Just $ Sci.coefficient index)
triggerSelection widget triggerSelection widget
_ -> pure () _ -> pure ()
...@@ -55,6 +55,7 @@ singletons ...@@ -55,6 +55,7 @@ singletons
| BoolValue | BoolValue
| Options | Options
| Index | Index
| OptionalIndex
| SelectionHandler | SelectionHandler
| Tooltips | Tooltips
| Icons | Icons
......
...@@ -134,11 +134,11 @@ type StringClass = DescriptionWidgetClass :++ ['S.StringValue, 'S.Placeholder] ...@@ -134,11 +134,11 @@ type StringClass = DescriptionWidgetClass :++ ['S.StringValue, 'S.Placeholder]
type BoolClass = DescriptionWidgetClass :++ ['S.BoolValue, 'S.Disabled, 'S.ChangeHandler] type BoolClass = DescriptionWidgetClass :++ ['S.BoolValue, 'S.Disabled, 'S.ChangeHandler]
type SelectionClass = DOMWidgetClass :++ ['S.Options, 'S.Index, 'S.Disabled, type SelectionClass = DescriptionWidgetClass :++ ['S.Options, 'S.OptionalIndex, 'S.Disabled, 'S.SelectionHandler]
'S.Description, 'S.SelectionHandler]
type MultipleSelectionClass = DOMWidgetClass :++ ['S.Options, 'S.Indices, 'S.Disabled, type SelectionNonemptyClass = DescriptionWidgetClass :++ ['S.Options, 'S.Index, 'S.Disabled, 'S.SelectionHandler]
'S.Description, 'S.SelectionHandler]
type MultipleSelectionClass = DescriptionWidgetClass :++ ['S.Options, 'S.Indices, 'S.Disabled, 'S.SelectionHandler]
type IntClass = DescriptionWidgetClass :++ [ 'S.IntValue, 'S.ChangeHandler ] type IntClass = DescriptionWidgetClass :++ [ 'S.IntValue, 'S.ChangeHandler ]
...@@ -189,6 +189,7 @@ type family FieldType (f :: Field) :: * where ...@@ -189,6 +189,7 @@ type family FieldType (f :: Field) :: * where
FieldType 'S.BoolValue = Bool FieldType 'S.BoolValue = Bool
FieldType 'S.Options = SelectionOptions FieldType 'S.Options = SelectionOptions
FieldType 'S.Index = Integer FieldType 'S.Index = Integer
FieldType 'S.OptionalIndex = Maybe Integer
FieldType 'S.SelectionHandler = IO () FieldType 'S.SelectionHandler = IO ()
FieldType 'S.Tooltips = [Text] FieldType 'S.Tooltips = [Text]
FieldType 'S.Icons = [Text] FieldType 'S.Icons = [Text]
...@@ -315,14 +316,14 @@ type family WidgetFields (w :: WidgetType) :: [Field] where ...@@ -315,14 +316,14 @@ type family WidgetFields (w :: WidgetType) :: [Field] where
WidgetFields 'CheckBoxType = BoolClass :++ '[ 'S.Indent ] WidgetFields 'CheckBoxType = BoolClass :++ '[ 'S.Indent ]
WidgetFields 'ToggleButtonType = BoolClass :++ ['S.Icon, 'S.ButtonStyle] WidgetFields 'ToggleButtonType = BoolClass :++ ['S.Icon, 'S.ButtonStyle]
WidgetFields 'ValidType = BoolClass :++ '[ 'S.ReadOutMsg ] WidgetFields 'ValidType = BoolClass :++ '[ 'S.ReadOutMsg ]
WidgetFields 'DropdownType = SelectionClass :++ '[ 'S.ButtonStyle] WidgetFields 'DropdownType = SelectionClass
WidgetFields 'RadioButtonsType = SelectionClass WidgetFields 'RadioButtonsType = SelectionClass
WidgetFields 'SelectType = SelectionClass WidgetFields 'SelectType = SelectionClass :++ '[ 'S.Rows ]
WidgetFields 'SelectionSliderType = SelectionClass :++ '[ 'S.Orientation ] WidgetFields 'SelectionSliderType = SelectionNonemptyClass :++ '[ 'S.Orientation, 'S.ReadOut, 'S.ContinuousUpdate ]
WidgetFields 'SelectionRangeSliderType = MultipleSelectionClass :++ '[ 'S.Orientation ] WidgetFields 'SelectionRangeSliderType = MultipleSelectionClass :++ '[ 'S.Orientation, 'S.ReadOut, 'S.ContinuousUpdate ]
WidgetFields 'ToggleButtonsType = WidgetFields 'ToggleButtonsType =
SelectionClass :++ ['S.Tooltips, 'S.Icons, 'S.ButtonStyle] SelectionClass :++ ['S.Tooltips, 'S.Icons, 'S.ButtonStyle]
WidgetFields 'SelectMultipleType = MultipleSelectionClass WidgetFields 'SelectMultipleType = MultipleSelectionClass ++ '[ S.Rows ]
WidgetFields 'IntTextType = IntClass :++ [ 'S.Disabled, 'S.ContinuousUpdate, 'S.StepInt ] WidgetFields 'IntTextType = IntClass :++ [ 'S.Disabled, 'S.ContinuousUpdate, 'S.StepInt ]
WidgetFields 'BoundedIntTextType = BoundedIntClass :++ [ 'S.Disabled, 'S.ContinuousUpdate, 'S.StepInt ] WidgetFields 'BoundedIntTextType = BoundedIntClass :++ [ 'S.Disabled, 'S.ContinuousUpdate, 'S.StepInt ]
WidgetFields 'IntSliderType = WidgetFields 'IntSliderType =
...@@ -449,6 +450,9 @@ instance ToPairs (Attr 'S.BoolValue) where ...@@ -449,6 +450,9 @@ instance ToPairs (Attr 'S.BoolValue) where
instance ToPairs (Attr 'S.Index) where instance ToPairs (Attr 'S.Index) where
toPairs x = ["index" .= toJSON x] toPairs x = ["index" .= toJSON x]
instance ToPairs (Attr 'S.OptionalIndex) where
toPairs x = ["index" .= toJSON x]
instance ToPairs (Attr 'S.Options) where instance ToPairs (Attr 'S.Options) where
toPairs x = toPairs x =
case _value x of case _value x of
...@@ -657,23 +661,31 @@ defaultBoolWidget viewName modelName = defaultDescriptionWidget viewName modelNa ...@@ -657,23 +661,31 @@ defaultBoolWidget viewName modelName = defaultDescriptionWidget viewName modelNa
-- | A record representing a widget of the _Selection class from IPython -- | A record representing a widget of the _Selection class from IPython
defaultSelectionWidget :: FieldType 'S.ViewName -> FieldType 'S.ModelName -> Rec Attr SelectionClass defaultSelectionWidget :: FieldType 'S.ViewName -> FieldType 'S.ModelName -> Rec Attr SelectionClass
defaultSelectionWidget viewName modelName = defaultDOMWidget viewName modelName <+> selectionAttrs defaultSelectionWidget viewName modelName = defaultDescriptionWidget viewName modelName <+> selectionAttrs
where
selectionAttrs = (Options =:: OptionLabels [])
:& (OptionalIndex =:: Nothing)
:& (Disabled =:: False)
:& (SelectionHandler =:: return ())
:& RNil
-- | A record representing a widget of the _SelectionNonempty class from IPython
defaultSelectionNonemptyWidget :: FieldType 'S.ViewName -> FieldType 'S.ModelName -> Rec Attr SelectionNonemptyClass
defaultSelectionNonemptyWidget viewName modelName = defaultDescriptionWidget viewName modelName <+> selectionAttrs
where where
selectionAttrs = (Options =:: OptionLabels []) selectionAttrs = (Options =:: OptionLabels [])
:& (Index =:: 0) :& (Index =:: 0)
:& (Disabled =:: False) :& (Disabled =:: False)
:& (Description =:: "")
:& (SelectionHandler =:: return ()) :& (SelectionHandler =:: return ())
:& RNil :& RNil
-- | A record representing a widget of the _MultipleSelection class from IPython -- | A record representing a widget of the _MultipleSelection class from IPython
defaultMultipleSelectionWidget :: FieldType 'S.ViewName -> FieldType 'S.ModelName -> Rec Attr MultipleSelectionClass defaultMultipleSelectionWidget :: FieldType 'S.ViewName -> FieldType 'S.ModelName -> Rec Attr MultipleSelectionClass
defaultMultipleSelectionWidget viewName modelName = defaultDOMWidget viewName modelName <+> mulSelAttrs defaultMultipleSelectionWidget viewName modelName = defaultDescriptionWidget viewName modelName <+> mulSelAttrs
where where
mulSelAttrs = (Options =:: OptionLabels []) mulSelAttrs = (Options =:: OptionLabels [])
:& (Indices =:: []) :& (Indices =:: [])
:& (Disabled =:: False) :& (Disabled =:: False)
:& (Description =:: "")
:& (SelectionHandler =:: return ()) :& (SelectionHandler =:: return ())
:& RNil :& RNil
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment