Commit 2c1b5401 authored by Thorsten Wißmann's avatar Thorsten Wißmann 🐧
Browse files

Use Svg.Lazy for all static elements

parent 49448280
......@@ -70,7 +70,7 @@ type alias RawModel render_cache =
type alias RenderingCache =
{ train_preview : (SvgUtils.BoundedSvg TrainPreview.EmptyType)
, shunt_labels : List (Svg.Svg TrainPreview.EmptyType)
, rendered_rail_tree : List (Svg.Svg Msg)
, rendered_rail_tree : Svg.Svg Msg
, bbox_rail_tree : SvgUtils.BoundingRect
}
......@@ -400,6 +400,7 @@ fillRenderCache model =
|> List.filter (not << List.isEmpty)
|> List.indexedMap (Shunt.view model.rt Shunt.showTrackIdx)
, rendered_rail_tree =
Svg.g [] <|
RT.renderRailTree
(singleton << Svg.Events.onMouseUp << RailClicked << Has.witness)
model.rt
......@@ -414,6 +415,18 @@ render_car rt idx car =
C.renderCarriage
rt [Svg.Events.onMouseDown (CarIdxClicked idx)] car
cached_rail_tree : RenderingCache -> Svg.Svg Msg
cached_rail_tree =
-- Debug.log "new rail tree" <<
(.rendered_rail_tree)
cached_train_preview : RenderingCache -> Svg.Svg Msg
cached_train_preview render_cache =
-- let _ = Debug.log "New train preview" "!" in
render_cache.train_preview
|> snd
|> Html.App.map TrainPreview.exfalso
view : Model -> Html Msg
view model =
let
......@@ -441,19 +454,17 @@ view model =
-- ]
-- [])
mapSnd f (a,b) = (a,f b)
train_preview : (SvgUtils.BoundedSvg a)
train_preview =
model.render_cache.train_preview
|> mapSnd (Html.App.map TrainPreview.exfalso)
shunt_labels : List (Svg.Svg any)
shunt_labels =
if model.show_shunt_labels
then List.map (Html.App.map TrainPreview.exfalso) model.render_cache.shunt_labels
else []
train_preview : SvgUtils.BoundedSvg Msg
train_preview =
( fst model.render_cache.train_preview
, Svg.lazy cached_train_preview model.render_cache
)
in
SvgUtils.boundedSvg
[ SvgAttr.class <|
......@@ -462,12 +473,15 @@ view model =
]
<| SvgUtils.addMargin { x = 10, y = 10 }
<| (if model.show_train_preview
then (SvgUtils.aboveOf SvgUtils.Center 20.0 train_preview)
then (SvgUtils.aboveOf SvgUtils.Center 20.0 <| train_preview)
else identity)
<| ( model.render_cache.bbox_rail_tree
, Svg.g []
(shunt_labels
++ [Svg.lazy (always <| Svg.g [] model.render_cache.rendered_rail_tree) ()]
++ [Svg.lazy
cached_rail_tree
model.render_cache
]
++ cars)
)
......
Supports Markdown
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