From 2701117f944bae76592a3dfeda8b2d79da721eda Mon Sep 17 00:00:00 2001 From: Brian Hicks Date: Fri, 10 Jan 2020 10:59:30 -0500 Subject: [PATCH] allow attributes in images --- src/Image.elm | 22 ++++++++++++---------- src/Main.elm | 8 +++++--- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/Image.elm b/src/Image.elm index 79cdc39..6d6b578 100644 --- a/src/Image.elm +++ b/src/Image.elm @@ -4,7 +4,7 @@ import Array exposing (Array) import Color.Transparent as Color exposing (Color) import Css import Grid exposing (Grid) -import Html.Styled as Html exposing (Html) +import Html.Styled as Html exposing (Attribute, Html) import Html.Styled.Attributes as Attrs exposing (css, style) import Set @@ -13,19 +13,21 @@ type alias Image = Grid Color -viewColor : Color -> Html msg -viewColor color = +viewColor : List (Attribute msg) -> Color -> Html msg +viewColor attrs color = Html.td - [ style "background-color" (Color.toRGBAString color) - , Attrs.width 10 - , Attrs.height 10 - ] + ([ style "background-color" (Color.toRGBAString color) + , Attrs.width 10 + , Attrs.height 10 + ] + ++ attrs + ) [] -view : Image -> Html msg -view = - Grid.view viewColor +view : List (Attribute msg) -> Image -> Html msg +view attrs image = + Grid.view (viewColor attrs) image recurse : Image diff --git a/src/Main.elm b/src/Main.elm index 3e8bd32..b8cd49b 100644 --- a/src/Main.elm +++ b/src/Main.elm @@ -181,7 +181,7 @@ view model = , Reset.borderBoxV201408 , h1 [ Html.text "Wave Function Collapse" ] , h2 [ Html.text "Source Image" ] - , Image.view model.image + , Image.view [] model.image , Html.details [] [ Html.summary [] [ Html.text "Windows" ] , model.windows @@ -194,7 +194,7 @@ view model = , Css.margin (Css.px 5) ] ] - [ Image.view window ] + [ Image.view [] window ] ) ] , h2 [ Html.text "Wave" ] @@ -204,6 +204,8 @@ view model = else Html.button [ Events.onClick Start ] [ Html.text "Start" ] , Html.button [ Events.onClick Step ] [ Html.text "Step" ] + , Html.button [ Events.onClick (Reset { width = 2, height = 2 }) ] [ Html.text "Reset (2x2)" ] + , Html.button [ Events.onClick (Reset { width = 5, height = 5 }) ] [ Html.text "Reset (5x5)" ] , Html.button [ Events.onClick (Reset { width = 10, height = 10 }) ] [ Html.text "Reset (10x10)" ] , Html.button [ Events.onClick (Reset { width = 20, height = 20 }) ] [ Html.text "Reset (20x20)" ] , Wave.view @@ -231,7 +233,7 @@ view model = average items = List.sum items / toFloat (List.length items) in - Image.viewColor + Image.viewColor [] (Color.fromRGBA { red = average reds , green = average greens