Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. type alias Model =
  2. {
  3. scrolled: Int
  4. , layout: BrickOrientation
  5. , itemCount: Int
  6. , columns: Int
  7. , testSizes: List (Int, Int)
  8. }
  9.  
  10.  
  11. view : Model -> Html Msg
  12. view model =
  13. let
  14. cols = List.repeat model.columns (div [style
  15. [
  16. ("width", (toString (toFloat model.columns / 100)) ++ "%")
  17. ]]
  18. [])
  19. in
  20. case model.layout of
  21. Vertical ->
  22. List.repeat model.columns (div [style
  23. [
  24. ("width", (toString (toFloat model.columns / 100)) ++ "%")
  25. ]
  26. ]
  27. (List.foldl (\a b -> Tpl.second <|
  28. List.foldl (\current (newval, output) ->
  29. let
  30. addition = case (List.head newval) of
  31. Just x ->
  32. current ++ [x]
  33. Nothing ->
  34. current
  35. newsie = output ++ addition
  36. replacer = if isEmpty newval then
  37. []
  38. else
  39. drop 1 newval
  40. in
  41. (replacer, newsie)) (a, []) b)
  42. (List.repeat model.columns [])
  43. (splitUp (List.map generateGridBox model.testSizes)
  44. (ceiling <| (toFloat model.itemCount) / (toFloat model.columns)) [])))
  45. _ ->
  46. div [] []
  47.  
  48. splitUp : List a -> Int -> List (List a) -> List (List a)
  49. splitUp input splitAmount output =
  50. let
  51. outtie = if List.length input < splitAmount then
  52. input
  53. else
  54. take splitAmount input
  55. innie = if List.length input <= splitAmount then
  56. []
  57. else
  58. drop splitAmount input
  59. newie = if isEmpty output then
  60. singleton outtie
  61. else
  62. output ++ [outtie]
  63. in
  64. if isEmpty innie then
  65. newie
  66. else
  67. splitUp innie splitAmount newie
  68.  
  69. generateGridBox : (Int, Int) -> Html Msg
  70. generateGridBox (wid, hei) =
  71. div [style [
  72. ("background", "#eee")
  73. , ("display", "inline-block")
  74. , ("width", "100%")
  75. , ("height", "auto")
  76. , ("margin", "0")
  77. --, ("vertical-align", "top")
  78. , ("box-shadow", "inset 5px 5px blue")
  79. ]] [img [src <| "http://placehold.it/" ++ (toString wid)
  80. ++ "x" ++ (toString hei)
  81. ] []]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement