Skip to content

Commit

Permalink
can specify number of rows for text code widgets in view system
Browse files Browse the repository at this point in the history
  • Loading branch information
dktr0 committed Oct 5, 2018
1 parent 926a44d commit e4404bd
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 95 deletions.
185 changes: 99 additions & 86 deletions Estuary/Types/View.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ data View =
ViewDiv String View |
LabelView Int |
StructureView Int |
TidalTextView Int |
TidalTextView Int Int | -- first int is zone to edit, second int is number of lines in editor
EvaluableTextView Int |
SvgDisplayView
deriving (Show,Eq)
Expand All @@ -19,14 +19,14 @@ instance JSON View where
showJSON (ViewDiv c v) = encJSDict [("ViewDiv",showJSON c),("v",showJSON v)]
showJSON (LabelView n) = encJSDict [("LabelView",n)]
showJSON (StructureView n) = encJSDict [("StructureView",n)]
showJSON (TidalTextView n) = encJSDict [("TidalTextView",n)]
showJSON (TidalTextView n rows) = encJSDict [("TidalTextView",n),("rows",rows)]
showJSON (EvaluableTextView n) = encJSDict [("EvaluableTextView",n)]
showJSON (SvgDisplayView) = encJSDict [("SvgDisplayView",0::Int)]
readJSON (JSObject x) | firstKey x == "Views" = Views <$> valFromObj "Views" x
readJSON (JSObject x) | firstKey x == "ViewDiv" = ViewDiv <$> valFromObj "ViewDiv" x <*> valFromObj "v" x
readJSON (JSObject x) | firstKey x == "LabelView" = LabelView <$> valFromObj "LabelView" x
readJSON (JSObject x) | firstKey x == "StructureView" = StructureView <$> valFromObj "StructureView" x
readJSON (JSObject x) | firstKey x == "TidalTextView" = TidalTextView <$> valFromObj "TidalTextView" x
readJSON (JSObject x) | firstKey x == "TidalTextView" = TidalTextView <$> valFromObj "TidalTextView" x <*> valFromObj "rows" x
readJSON (JSObject x) | firstKey x == "EvaluableTextView" = EvaluableTextView <$> valFromObj "EvaluableTextView" x
readJSON (JSObject x) | firstKey x == "SvgDisplayView" = return $ SvgDisplayView
readJSON (JSObject x) | otherwise = Error $ "Unable to parse JSObject as Estuary.Protocol.View: " ++ (show x)
Expand All @@ -36,9 +36,9 @@ standardView :: View
standardView = Views [
ViewDiv "eightTopL" (Views [LabelView 1, StructureView 2]),
ViewDiv "eightTopR" (Views [LabelView 3, StructureView 4]),
ViewDiv "eightMiddleL" (Views [LabelView 5, TidalTextView 6]),
ViewDiv "eightMiddleR" (Views [LabelView 7, TidalTextView 8]),
ViewDiv "eightBottomL" (Views [LabelView 9, TidalTextView 10]),
ViewDiv "eightMiddleL" (Views [LabelView 5, TidalTextView 6 3]),
ViewDiv "eightMiddleR" (Views [LabelView 7, TidalTextView 8 3]),
ViewDiv "eightBottomL" (Views [LabelView 9, TidalTextView 10 3]),
ViewDiv "eightBottomR" (Views [LabelView 11, EvaluableTextView 12])
]

Expand Down Expand Up @@ -73,114 +73,127 @@ viewDiv = between (char '{') (char '}') $ do
labelView = string "label:" >> (read <$> many1 digit) >>= return . LabelView
structureView = string "structure:" >> (read <$> many1 digit) >>= return . StructureView
evaluableTextView = string "evaluable:" >> (read <$> many1 digit) >>= return . EvaluableTextView
tidalTextView = string "tidal:" >> (read <$> many1 digit) >>= return . TidalTextView
tidalTextView = do
string "tidal:"
x <- read <$> many1 digit
skipMany1 space
y <- read <$> many1 digit
return $ TidalTextView x y
svgDisplayView = string "svgDisplayView:" >> return SvgDisplayView

presetView :: String -> View

presetView "iclc2017" = Views [
ViewDiv "eightMiddleL" (Views [LabelView 0,TidalTextView 1]),
ViewDiv "eightMiddleR" (Views [LabelView 2,TidalTextView 3]),
ViewDiv "eightMiddleL" (Views [LabelView 4,TidalTextView 5]),
ViewDiv "eightMiddleR" (Views [LabelView 6,TidalTextView 7]),
ViewDiv "eightMiddleL" (Views [LabelView 8,TidalTextView 9]),
ViewDiv "eightMiddleR" (Views [LabelView 10,TidalTextView 11]),
ViewDiv "eightMiddleL" (Views [LabelView 12,TidalTextView 13]),
ViewDiv "eightMiddleR" (Views [LabelView 14,TidalTextView 15]),
ViewDiv "eightMiddleL" (Views [LabelView 16,TidalTextView 17]),
ViewDiv "eightMiddleR" (Views [LabelView 18,TidalTextView 19]),
ViewDiv "eightMiddleL" (Views [LabelView 20,TidalTextView 21]),
ViewDiv "eightMiddleR" (Views [LabelView 22,TidalTextView 23]),
ViewDiv "eightMiddleL" (Views [LabelView 24,TidalTextView 25]),
ViewDiv "eightMiddleR" (Views [LabelView 26,TidalTextView 27]),
ViewDiv "eightMiddleL" (Views [LabelView 28,TidalTextView 29]),
ViewDiv "eightMiddleR" (Views [LabelView 30,TidalTextView 31]),
ViewDiv "eightMiddleL" (Views [LabelView 32,TidalTextView 33]),
ViewDiv "eightMiddleR" (Views [LabelView 34,TidalTextView 35])
ViewDiv "eightMiddleL" (Views [LabelView 0,TidalTextView 1 2]),
ViewDiv "eightMiddleR" (Views [LabelView 2,TidalTextView 3 2]),
ViewDiv "eightMiddleL" (Views [LabelView 4,TidalTextView 5 2]),
ViewDiv "eightMiddleR" (Views [LabelView 6,TidalTextView 7 2]),
ViewDiv "eightMiddleL" (Views [LabelView 8,TidalTextView 9 2]),
ViewDiv "eightMiddleR" (Views [LabelView 10,TidalTextView 11 2]),
ViewDiv "eightMiddleL" (Views [LabelView 12,TidalTextView 13 2]),
ViewDiv "eightMiddleR" (Views [LabelView 14,TidalTextView 15 2]),
ViewDiv "eightMiddleL" (Views [LabelView 16,TidalTextView 17 2]),
ViewDiv "eightMiddleR" (Views [LabelView 18,TidalTextView 19 2]),
ViewDiv "eightMiddleL" (Views [LabelView 20,TidalTextView 21 2]),
ViewDiv "eightMiddleR" (Views [LabelView 22,TidalTextView 23 2]),
ViewDiv "eightMiddleL" (Views [LabelView 24,TidalTextView 25 2]),
ViewDiv "eightMiddleR" (Views [LabelView 26,TidalTextView 27 2]),
ViewDiv "eightMiddleL" (Views [LabelView 28,TidalTextView 29 2]),
ViewDiv "eightMiddleR" (Views [LabelView 30,TidalTextView 31 2]),
ViewDiv "eightMiddleL" (Views [LabelView 32,TidalTextView 33 2]),
ViewDiv "eightMiddleR" (Views [LabelView 34,TidalTextView 35 2])
]

presetView "Bogota" = Views [
ViewDiv "eightMiddleL" (Views [LabelView 0,TidalTextView 1]),
ViewDiv "eightMiddleR" (Views [LabelView 2,TidalTextView 3]),
ViewDiv "eightMiddleL" (Views [LabelView 4,TidalTextView 5]),
ViewDiv "eightMiddleR" (Views [LabelView 6,TidalTextView 7]),
ViewDiv "eightMiddleL" (Views [LabelView 8,TidalTextView 9]),
ViewDiv "eightMiddleR" (Views [LabelView 10,TidalTextView 11]),
ViewDiv "eightMiddleL" (Views [LabelView 12,TidalTextView 13]),
ViewDiv "eightMiddleR" (Views [LabelView 14,TidalTextView 15]),
ViewDiv "eightMiddleL" (Views [LabelView 16,TidalTextView 17]),
ViewDiv "eightMiddleR" (Views [LabelView 18,TidalTextView 19]),
ViewDiv "eightMiddleL" (Views [LabelView 20,TidalTextView 21]),
ViewDiv "eightMiddleR" (Views [LabelView 22,TidalTextView 23]),
ViewDiv "eightMiddleL" (Views [LabelView 24,TidalTextView 25]),
ViewDiv "eightMiddleR" (Views [LabelView 26,TidalTextView 27]),
ViewDiv "eightMiddleL" (Views [LabelView 28,TidalTextView 29]),
ViewDiv "eightMiddleR" (Views [LabelView 30,TidalTextView 31]),
ViewDiv "eightMiddleL" (Views [LabelView 32,TidalTextView 33]),
ViewDiv "eightMiddleR" (Views [LabelView 34,TidalTextView 35])
ViewDiv "eightMiddleL" (Views [LabelView 0,TidalTextView 1 2]),
ViewDiv "eightMiddleR" (Views [LabelView 2,TidalTextView 3 2]),
ViewDiv "eightMiddleL" (Views [LabelView 4,TidalTextView 5 2]),
ViewDiv "eightMiddleR" (Views [LabelView 6,TidalTextView 7 2]),
ViewDiv "eightMiddleL" (Views [LabelView 8,TidalTextView 9 2]),
ViewDiv "eightMiddleR" (Views [LabelView 10,TidalTextView 11 2]),
ViewDiv "eightMiddleL" (Views [LabelView 12,TidalTextView 13 2]),
ViewDiv "eightMiddleR" (Views [LabelView 14,TidalTextView 15 2]),
ViewDiv "eightMiddleL" (Views [LabelView 16,TidalTextView 17 2]),
ViewDiv "eightMiddleR" (Views [LabelView 18,TidalTextView 19 2]),
ViewDiv "eightMiddleL" (Views [LabelView 20,TidalTextView 21 2]),
ViewDiv "eightMiddleR" (Views [LabelView 22,TidalTextView 23 2]),
ViewDiv "eightMiddleL" (Views [LabelView 24,TidalTextView 25 2]),
ViewDiv "eightMiddleR" (Views [LabelView 26,TidalTextView 27 2]),
ViewDiv "eightMiddleL" (Views [LabelView 28,TidalTextView 29 2]),
ViewDiv "eightMiddleR" (Views [LabelView 30,TidalTextView 31 2]),
ViewDiv "eightMiddleL" (Views [LabelView 32,TidalTextView 33 2]),
ViewDiv "eightMiddleR" (Views [LabelView 34,TidalTextView 35 2])
]

presetView "Manizales" = Views [
ViewDiv "eightMiddleL" (Views [LabelView 0,TidalTextView 1]),
ViewDiv "eightMiddleR" (Views [LabelView 2,TidalTextView 3]),
ViewDiv "eightMiddleL" (Views [LabelView 4,TidalTextView 5]),
ViewDiv "eightMiddleR" (Views [LabelView 6,TidalTextView 7])
ViewDiv "eightMiddleL" (Views [LabelView 0,TidalTextView 1 10]),
ViewDiv "eightMiddleR" (Views [LabelView 2,TidalTextView 3 10]),
ViewDiv "eightMiddleL" (Views [LabelView 4,TidalTextView 5 10]),
ViewDiv "eightMiddleR" (Views [LabelView 6,TidalTextView 7 10])
]

presetView "Medellin" = Views [
ViewDiv "eightMiddleL" (Views [LabelView 0,TidalTextView 1]),
ViewDiv "eightMiddleR" (Views [LabelView 2,TidalTextView 3]),
ViewDiv "eightMiddleL" (Views [LabelView 4,TidalTextView 5]),
ViewDiv "eightMiddleR" (Views [LabelView 6,TidalTextView 7])
]
presetView "Medellin" = presetView "Manizales"

presetView "Lima" = Views [
ViewDiv "eightMiddleL" (Views [LabelView 0,TidalTextView 1]),
ViewDiv "eightMiddleR" (Views [LabelView 2,TidalTextView 3]),
ViewDiv "eightMiddleL" (Views [LabelView 4,TidalTextView 5]),
ViewDiv "eightMiddleR" (Views [LabelView 6,TidalTextView 7]),
ViewDiv "eightMiddleL" (Views [LabelView 8,TidalTextView 9]),
ViewDiv "eightMiddleR" (Views [LabelView 10,TidalTextView 11]),
ViewDiv "eightMiddleL" (Views [LabelView 12,TidalTextView 13]),
ViewDiv "eightMiddleR" (Views [LabelView 14,TidalTextView 15])
ViewDiv "eightMiddleL" (Views [LabelView 0,TidalTextView 1 5]),
ViewDiv "eightMiddleR" (Views [LabelView 2,TidalTextView 3 5]),
ViewDiv "eightMiddleL" (Views [LabelView 4,TidalTextView 5 5]),
ViewDiv "eightMiddleR" (Views [LabelView 6,TidalTextView 7 5]),
ViewDiv "eightMiddleL" (Views [LabelView 8,TidalTextView 9 5]),
ViewDiv "eightMiddleR" (Views [LabelView 10,TidalTextView 11 5]),
ViewDiv "eightMiddleL" (Views [LabelView 12,TidalTextView 13 5]),
ViewDiv "eightMiddleR" (Views [LabelView 14,TidalTextView 15 5])
]

presetView "Uio" = Views [
ViewDiv "eightMiddleL" (Views [LabelView 0,TidalTextView 1]),
ViewDiv "eightMiddleR" (Views [LabelView 2,TidalTextView 3]),
ViewDiv "eightMiddleL" (Views [LabelView 4,TidalTextView 5]),
ViewDiv "eightMiddleR" (Views [LabelView 6,TidalTextView 7]),
ViewDiv "eightMiddleL" (Views [LabelView 8,TidalTextView 9]),
ViewDiv "eightMiddleR" (Views [LabelView 10,TidalTextView 11]),
ViewDiv "eightMiddleL" (Views [LabelView 12,TidalTextView 13]),
ViewDiv "eightMiddleR" (Views [LabelView 14,TidalTextView 15]),
ViewDiv "eightMiddleL" (Views [LabelView 16,TidalTextView 17]),
ViewDiv "eightMiddleR" (Views [LabelView 18,TidalTextView 19]),
ViewDiv "eightMiddleL" (Views [LabelView 20,TidalTextView 21]),
ViewDiv "eightMiddleR" (Views [LabelView 22,TidalTextView 23]),
ViewDiv "eightMiddleL" (Views [LabelView 24,TidalTextView 25]),
ViewDiv "eightMiddleR" (Views [LabelView 26,TidalTextView 27]),
ViewDiv "eightMiddleL" (Views [LabelView 28,TidalTextView 29]),
ViewDiv "eightMiddleR" (Views [LabelView 30,TidalTextView 31]),
ViewDiv "eightMiddleL" (Views [LabelView 32,TidalTextView 33]),
ViewDiv "eightMiddleR" (Views [LabelView 34,TidalTextView 35])
ViewDiv "eightMiddleL" (Views [LabelView 0,TidalTextView 1 2]),
ViewDiv "eightMiddleR" (Views [LabelView 2,TidalTextView 3 2]),
ViewDiv "eightMiddleL" (Views [LabelView 4,TidalTextView 5 2]),
ViewDiv "eightMiddleR" (Views [LabelView 6,TidalTextView 7 2]),
ViewDiv "eightMiddleL" (Views [LabelView 8,TidalTextView 9 2]),
ViewDiv "eightMiddleR" (Views [LabelView 10,TidalTextView 11 2]),
ViewDiv "eightMiddleL" (Views [LabelView 12,TidalTextView 13 2]),
ViewDiv "eightMiddleR" (Views [LabelView 14,TidalTextView 15 2]),
ViewDiv "eightMiddleL" (Views [LabelView 16,TidalTextView 17 2]),
ViewDiv "eightMiddleR" (Views [LabelView 18,TidalTextView 19 2]),
ViewDiv "eightMiddleL" (Views [LabelView 20,TidalTextView 21 2]),
ViewDiv "eightMiddleR" (Views [LabelView 22,TidalTextView 23 2]),
ViewDiv "eightMiddleL" (Views [LabelView 24,TidalTextView 25 2]),
ViewDiv "eightMiddleR" (Views [LabelView 26,TidalTextView 27 2]),
ViewDiv "eightMiddleL" (Views [LabelView 28,TidalTextView 29 2]),
ViewDiv "eightMiddleR" (Views [LabelView 30,TidalTextView 31 2]),
ViewDiv "eightMiddleL" (Views [LabelView 32,TidalTextView 33 2]),
ViewDiv "eightMiddleR" (Views [LabelView 34,TidalTextView 35 2])
]


presetView "RGGTRN" = Views [
ViewDiv "eightMiddleL" (Views [LabelView 0,TidalTextView 1]),
ViewDiv "eightMiddleR" (Views [LabelView 2,TidalTextView 3]),
ViewDiv "eightMiddleL" (Views [LabelView 4,TidalTextView 5]),
ViewDiv "eightMiddleR" (Views [LabelView 6,TidalTextView 7])
ViewDiv "eightMiddleL" (Views [LabelView 0,TidalTextView 1 10]),
ViewDiv "eightMiddleR" (Views [LabelView 2,TidalTextView 3 10]),
ViewDiv "eightMiddleL" (Views [LabelView 4,TidalTextView 5 10]),
ViewDiv "eightMiddleR" (Views [LabelView 6,TidalTextView 7 10])
]

presetView "working" = Views [
ViewDiv "eightTopL" (Views [LabelView 1, StructureView 2]),
ViewDiv "eightTopR" (Views [LabelView 3, SvgDisplayView]),
ViewDiv "eightMiddleL" (Views [LabelView 5, TidalTextView 6]),
ViewDiv "eightMiddleR" (Views [LabelView 7, TidalTextView 8]),
ViewDiv "eightBottomL" (Views [LabelView 9, TidalTextView 10]),
ViewDiv "eightMiddleL" (Views [LabelView 5, TidalTextView 6 7]),
ViewDiv "eightMiddleR" (Views [LabelView 7, TidalTextView 8 7]),
ViewDiv "eightBottomL" (Views [LabelView 9, TidalTextView 10 7]),
ViewDiv "eightBottomR" (Views [LabelView 11, EvaluableTextView 12])
]

presetView "cybernetic" = Views [
ViewDiv "eightMiddleL" (Views [LabelView 1, TidalTextView 2 5]),
ViewDiv "eightMiddleR" (Views [LabelView 3, TidalTextView 4 5]),
ViewDiv "eightMiddleL" (Views [LabelView 5, TidalTextView 6 5]),
ViewDiv "eightMiddleR" (Views [LabelView 7, TidalTextView 8 5]),
ViewDiv "eightMiddleL" (Views [LabelView 9, TidalTextView 10 5]),
ViewDiv "eightMiddleR" (Views [LabelView 11, TidalTextView 12 5]),
ViewDiv "eightMiddleL" (Views [LabelView 13, TidalTextView 14 5]),
ViewDiv "eightMiddleR" (Views [LabelView 15, TidalTextView 16 5]),
ViewDiv "eightMiddleL" (Views [LabelView 17, TidalTextView 18 5]),
ViewDiv "eightMiddleR" (Views [LabelView 19, TidalTextView 20 5])
]

presetView _ = standardView
14 changes: 8 additions & 6 deletions Estuary/Widgets/Text.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import Control.Monad
import GHCJS.DOM.EventM
import Data.Maybe
import Data.Map (fromList)
import Data.Monoid


import Estuary.Utility (lastOrNothing)
import Estuary.Types.Definition
Expand All @@ -29,18 +31,18 @@ textWidgetForPatternChain i delta = do
let value = _textInput_value x
return (value,edits)

textAreaWidgetForPatternChain :: MonadWidget t m => String -> Event t String -> m (Dynamic t String, Event t String)
textAreaWidgetForPatternChain i delta = do
let attrs = constDyn $ ("class" =: "textInputToEndOfLine")
textAreaWidgetForPatternChain :: MonadWidget t m => Int -> String -> Event t String -> m (Dynamic t String, Event t String)
textAreaWidgetForPatternChain rows i delta = do
let attrs = constDyn $ ("class" =: "textInputToEndOfLine" <> "rows" =: show rows)
x <- textArea $ def & textAreaConfig_setValue .~ delta & textAreaConfig_attributes .~ attrs & textAreaConfig_initialValue .~ i
let edits = _textArea_input x
let value = _textArea_value x
return (value,edits)

tidalTextWidget :: forall t m. MonadWidget t m =>
TransformedPattern -> Event t [TransformedPattern] ->
Int -> TransformedPattern -> Event t [TransformedPattern] ->
m (Dynamic t TransformedPattern,Event t TransformedPattern,Event t Hint)
tidalTextWidget i delta = divClass "textPatternChain" $ do -- *** TODO: css class name should be tidalTextWidget (in CSS also)
tidalTextWidget rows i delta = divClass "textPatternChain" $ do -- *** TODO: css class name should be tidalTextWidget (in CSS also)
let i' = transformedPatternToTidalTextPatternContents i
let delta' = fmap transformedPatternToTidalTextPatternContents $ fmapMaybe lastOrNothing delta
let deltaFuture = fmap forEditing delta'
Expand All @@ -54,7 +56,7 @@ tidalTextWidget i delta = divClass "textPatternChain" $ do -- *** TODO: css clas
let parserEvent = _dropdown_change d
b <- divClass "textInputLabel" $ button "eval"
let initialText = snd $ forEditing i'
(textValue,textEvent) <- textAreaWidgetForPatternChain initialText textFuture
(textValue,textEvent) <- textAreaWidgetForPatternChain rows initialText textFuture
v' <- combineDyn (,) parserValue textValue
let editEvent = tagDyn v' $ leftmost [() <$ parserEvent,() <$ textEvent]
let evalEvent = tagDyn v' b
Expand Down
4 changes: 2 additions & 2 deletions Estuary/Widgets/View.hs
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ viewWidget (StructureView n) i deltasDown = do
where f (Structure x) = x
f _ = EmptyTransformedPattern

viewWidget (TidalTextView n) i deltasDown = do
viewWidget (TidalTextView n rows) i deltasDown = do
let i' = f $ Map.findWithDefault (Structure (TidalTextPattern (Live (MiniTidal,"") L3))) n i
let deltasDown' = fmap (justStructures . justEditsInZone n) deltasDown
(value,edits,hints) <- tidalTextWidget i' deltasDown'
(value,edits,hints) <- tidalTextWidget rows i' deltasDown'
value' <- mapDyn (Map.singleton n . Structure) value
let edits' = fmap (ZoneRequest . Sited n . Edit . Structure) edits
return (value',edits',hints)
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ prodReleaseClient: # make prodInstallClient first!

curlReleaseClient: # this uses curl to download and unzip a recent pre-built client from a GitHub release
rm -rf Estuary.jsexe
curl -o temp.zip -L https://github.com/d0kt0r0/estuary/releases/download/20181002/estuary-client-20181002.zip
curl -o temp.zip -L https://github.com/d0kt0r0/estuary/releases/download/20181005/estuary-client-20181005.zip
unzip temp.zip
rm -rf temp.zip
cp -Rf static/Dirt Estuary.jsexe
Expand Down

0 comments on commit e4404bd

Please sign in to comment.