@@ -12,11 +12,12 @@ module Graphics.Element (widthOf, heightOf, sizeOf,
12 spacer, newElement
12 spacer, newElement
15−import Native.Utils (guid, max, htmlHeight)
15+import open Basics
16−import JavaScript as JS
16+import Native.Utils as Native
17+import open JavaScript
17import List as List
18import List as List
18−import Color
19+import Color (Color)
19−import Maybe (Just, Nothing)
20+import Maybe (Maybe, Just, Nothing)
21type Properties = {
22type Properties = {
@@ -45,18 +46,18 @@ sizeOf e = (e.props.width, e.props.height)
46-- Create an `Element` with a given width.
47-- Create an `Element` with a given width.
47width : Int -> Element -> Element
48width : Int -> Element -> Element
48−width nw e = let p = e.props
49+width nw e = let p = e.props
49− props = case e.element of
50+ props = case e.element of
50− Image _ w h _ -> {p| height <- h/w*nw }
51+ Image _ w h _ -> {p| height <- h `div` w * nw }
51− RawHtml html -> {p| height <- let (w,h) = htmlHeight nw html in h}
52+ RawHtml html -> {p| height <- let (w,h) = Native.htmlHeight nw html in h}
53− in { element=e.element, props={props| width <- nw} }
54+ in { element=e.element, props={ props | width <- nw } }
55-- Create an `Element` with a given height.
56-- Create an `Element` with a given height.
56height : Int -> Element -> Element
57height : Int -> Element -> Element
57height nh e = let p = e.props
58height nh e = let p = e.props
58 props = case e.element of
59 props = case e.element of
59− Image _ w h _ -> {p| width <- w/h*nh }
60+ Image _ w h _ -> {p| width <- w `div` h * nh }
61 in { element=e.element, props={p| height <- nh} }
62 in { element=e.element, props={p| height <- nh} }
@@ -71,24 +72,26 @@ opacity o e = let p = e.props in { element=e.element, props={p| opacity <- o} }
72-- Create an `Element` with a given background color.
73-- Create an `Element` with a given background color.
73color : Color -> Element -> Element
74color : Color -> Element -> Element
74−color c e = let p = e.props in
75+color c e = let p = e.props in
76+ { element = e.element
75− { element=e.element, props={p| color <- Just c} }
77+ , props = { p | color <- Just c}
77-- Create an `Element` with a tag. This lets you link directly to it.
80-- Create an `Element` with a tag. This lets you link directly to it.
78-- The element `(tag "all-about-badgers" thirdParagraph)` can be reached
81-- The element `(tag "all-about-badgers" thirdParagraph)` can be reached
79-- with a link lik this: `/facts-about-animals.elm#all-about-badgers`
82-- with a link lik this: `/facts-about-animals.elm#all-about-badgers`
80tag : String -> Element -> Element
83tag : String -> Element -> Element
81tag name e = let p = e.props in
84tag name e = let p = e.props in
82− { element=e.element, props={p| tag <- JS.fromString name} }
85+ { element=e.element, props={p | tag <- fromString name} }
84-- Create an `Element` that is a hyper-link.
87-- Create an `Element` that is a hyper-link.
85link : String -> Element -> Element
88link : String -> Element -> Element
86link href e = let p = e.props in
89link href e = let p = e.props in
87− { element=e.element, props={p| href <- JS.fromString href} }
90+ { element=e.element, props={p | href <- fromString href} }
89−emptyStr = JS.fromString ""
92+emptyStr = fromString ""
90newElement w h e =
93newElement w h e =
91− { props = Properties (guid ()) w h 1 Nothing emptyStr emptyStr (), element = e }
94+ { props = Properties (Native.guid ()) w h 1 Nothing emptyStr emptyStr (), element = e }
93data ElementPrim
96data ElementPrim
94 = Image ImageStyle Int Int JSString
97 = Image ImageStyle Int Int JSString
@@ -102,12 +105,12 @@ data ImageStyle = Plain | Fitted | Cropped (Int,Int) | Tiled
103-- Create an image given a width, height, and image source.
106-- Create an image given a width, height, and image source.
104image : Int -> Int -> String -> Element
107image : Int -> Int -> String -> Element
105−image w h src = newElement w h (Image Plain w h (JS.fromString src))
108+image w h src = newElement w h (Image Plain w h (fromString src))
107-- Create a fitted image given a width, height, and image source.
110-- Create a fitted image given a width, height, and image source.
108-- This will crop the picture to best fill the given dimensions.
111-- This will crop the picture to best fill the given dimensions.
109fittedImage : Int -> Int -> String -> Element
112fittedImage : Int -> Int -> String -> Element
110−fittedImage w h src = newElement w h (Image Fitted w h (JS.fromString src))
113+fittedImage w h src = newElement w h (Image Fitted w h (fromString src))
112-- Create a cropped image. Take a rectangle out of the picture starting
115-- Create a cropped image. Take a rectangle out of the picture starting
113-- at the given top left coordinate. If you have a 140-by-140 image,
116-- at the given top left coordinate. If you have a 140-by-140 image,
@@ -116,11 +119,11 @@ fittedImage w h src = newElement w h (Image Fitted w h (JS.fromString src))
116-- croppedImage (20,20) 100 100 "yogi.jpg"
119-- croppedImage (20,20) 100 100 "yogi.jpg"
117croppedImage : (Int,Int) -> Int -> Int -> String -> Element
120croppedImage : (Int,Int) -> Int -> Int -> String -> Element
118croppedImage pos w h src =
121croppedImage pos w h src =
119− newElement w h (Image (Cropped pos) w h (JS.fromString src))
122+ newElement w h (Image (Cropped pos) w h (fromString src))
121tiledImage : Int -> Int -> String -> Element
124tiledImage : Int -> Int -> String -> Element
122tiledImage w h src =
125tiledImage w h src =
123− newElement w h (Image Tiled w h (JS.fromString src))
126+ newElement w h (Image Tiled w h (fromString src))
125data Three = P | Z | N
128data Three = P | Z | N
126data Pos = Absolute Int | Relative Float
129data Pos = Absolute Int | Relative Float