on master help sign in
Merge branch 'text' into dev
commit5e7ed2bec5a5412f1cc428800a3dc4029d8db778 authorEvan Czaplicki <info@elm-lang.org> dateSun 2 Mar 2014, 12:43 (13 years ago) parent74d04824c43439
11 files changed+363−163
libraries/Graphics/Input.elm+4−57 libraries/Graphics/Input/Field.elm+130 libraries/Native/Color.js+9−2 libraries/Native/Graphics/Input.js+60−8 libraries/Native/String.js−2 libraries/Native/Text.js+58−42 libraries/Native/Utils.js−7 libraries/String.elm+2−1 libraries/Text.elm+79−40 runtime/Init.js+1−1 runtime/Render/Element.js+20−3
libraries/Graphics/Input.elm+4−57
@@ -19,14 +19,15 @@ examples in this library, so just read on to get a better idea of how it works!
1919@docs Input, input
2020
2121# Basic Input Elements
22−Text fields come later.
22+
23+To learn about text fields, see the
24+[`Graphics.Input.Field`](Graphics-Input-Field) library.
25+
2326@docs button, customButton, checkbox, dropDown
2427
2528# Clicks and Hovers
2629@docs clickable, hoverable
2730
28−# Text Fields
29−@docs field, password, email, noContent, FieldContent, Selection, Direction
3031-}
3132
3233import Signal (Signal)
@@ -175,57 +176,3 @@ distinguished with IDs or more complex data structures.
175176-}
176177clickable : Handle a -> a -> Element -> Element
177178clickable = Native.Graphics.Input.clickable
178−
179−{-| Represents the current content of a text field. For example:
180−
181− FieldContent "She sells sea shells" (Selection 0 3 Backward)
182−
183−This means the user highlighted the substring `"She"` backwards.
184−-}
185−type FieldContent = { string:String, selection:Selection }
186−
187−{-| The selection within a text field. `start` is never greater than `end`:
188−
189− Selection 0 0 Forward -- cursor precedes all characters
190−
191− Selection 5 9 Backward -- highlighting characters starting after
192− -- the 5th and ending after the 9th
193−-}
194−type Selection = { start:Int, end:Int, direction:Direction }
195−
196−{-| The direction of selection.-}
197−data Direction = Forward | Backward
198−
199−{-| A field with no content:
200−
201− FieldContent "" (Selection 0 0 Forward)
202−-}
203−noContent : FieldContent
204−noContent = FieldContent "" (Selection 0 0 Forward)
205−
206−{-| Create a text field. The following example creates a time-varying element
207−called `nameField`. As the user types their name, the field will be updated
208−to match what they have entered.
209−
210− name : Input FieldContent
211− name = input noContent
212−
213− nameField : Signal Element
214− nameField = field name.handle id "Name" <~ name.signal
215−-}
216−field : Handle a -> (FieldContent -> a) -> String -> FieldContent -> Element
217−field = Native.Graphics.Input.field
218−
219−{-| Same as `field` but the UI element blocks out each characters. -}
220−password : Handle a -> (FieldContent -> a) -> String -> FieldContent -> Element
221−password = Native.Graphics.Input.password
222−
223−{-| Same as `field` but it adds an annotation that this field is for email
224−addresses. This is helpful for auto-complete and for mobile users who may
225−get a custom keyboard with an `@` and `.com` button.
226−-}
227−email : Handle a -> (FieldContent -> a) -> String -> FieldContent -> Element
228−email = Native.Graphics.Input.email
229−
230−-- area : Handle a -> (FieldContent -> a) -> Handle b -> ((Int,Int) -> b) -> (Int,Int) -> String -> FieldContent -> Element
231−-- area = Native.Graphics.Input.area
libraries/Graphics/Input/Field.elmnew file+130
@@ -0,0 +1,130 @@
1+module Graphics.Input.Field where
2+{-| This library specifically addresses text fields. It uses the same genral
3+approach as the [`Graphics.Input`](Graphics-Input) module for describing an
4+`Input`, so this library focuses on creating and styling text fields.
5+
6+# Create Fields
7+@docs field, password, email
8+
9+# Field Content
10+@docs Content, Selection, Direction, noContent
11+
12+# Field Style
13+@docs Style, Outline, noOutline, Highlight, noHighlight, Dimensions, uniformly
14+-}
15+
16+import Color (Color)
17+import Color
18+import Graphics.Element (Element)
19+import Graphics.Input (Input, Handle)
20+import Native.Graphics.Input
21+import Text
22+
23+{-| Easily create uniform dimensions:
24+
25+ uniformly 4 == { left=4, right=4, top=4, bottom=4 }
26+-}
27+uniformly : Int -> Dimensions
28+uniformly n = Dimensions n n n n
29+
30+{-| For setting dimensions of a fields padding or border. The left, right, top,
31+and bottom may all have different sizes.
32+-}
33+type Dimensions = { left:Int, right:Int, top:Int, bottom:Int }
34+
35+{-| A field can have a outline around it. This lets you set its color, width,
36+and radius. The radius allows you to round the corners of your field. Set the
37+width to zero to make it invisible.
38+-}
39+type Outline = { color:Color, width:Dimensions, radius:Int }
40+
41+{-| An outline with zero width, so you cannot see it. -}
42+noOutline : Outline
43+noOutline = Outline Color.grey (uniformly 0) 0
44+
45+{-| When a field is selected, it has an highlight around it by default. Set the
46+width of the `Highlight` to zero to make it go away.
47+-}
48+type Highlight = { color:Color, width:Int }
49+
50+{-| An highlight with zero width, so you cannot see it. -}
51+noHighlight : Highlight
52+noHighlight = Highlight Color.blue 0
53+
54+{-| Describes the style of a text box. The `style` field describes the style
55+of the text itself. The `outline` field describes the glowing blue outline that
56+shows up when the field has focus. Turn off `outline` by setting its width to
57+zero. The
58+-}
59+type Style =
60+ { padding : Dimensions
61+ , outline : Outline
62+ , highlight : Highlight
63+ , style : Text.Style
64+ }
65+
66+{-| The default style for a text field. The outline is `Color.grey` with width
67+1 and radius 2. The highlight is `Color.blue` with width 1, and the default
68+text color is black.
69+-}
70+defaultStyle : Style
71+defaultStyle =
72+ { padding = uniformly 4
73+ , outline = Outline Color.grey (uniformly 1) 2
74+ , highlight = Highlight Color.blue 1
75+ , style = Text.defaultStyle
76+ }
77+
78+{-| Represents the current content of a text field. For example:
79+
80+ Content "She sells sea shells" (Selection 0 3 Backward)
81+
82+This means the user highlighted the substring `"She"` backwards.
83+-}
84+type Content = { string:String, selection:Selection }
85+
86+{-| The selection within a text field. `start` is never greater than `end`:
87+
88+ Selection 0 0 Forward -- cursor precedes all characters
89+
90+ Selection 5 9 Backward -- highlighting characters starting after
91+ -- the 5th and ending after the 9th
92+-}
93+type Selection = { start:Int, end:Int, direction:Direction }
94+
95+{-| The direction of selection.-}
96+data Direction = Forward | Backward
97+
98+{-| A field with no content:
99+
100+ Content "" (Selection 0 0 Forward)
101+-}
102+noContent : Content
103+noContent = Content "" (Selection 0 0 Forward)
104+
105+{-| Create a text field. The following example creates a time-varying element
106+called `nameField`. As the user types their name, the field will be updated
107+to match what they have entered.
108+
109+ name : Input Content
110+ name = input noContent
111+
112+ nameField : Signal Element
113+ nameField = field name.handle id "Name" <~ name.signal
114+-}
115+field : Handle a -> (Content -> a) -> Style -> String -> Content -> Element
116+field = Native.Graphics.Input.field
117+
118+{-| Same as `field` but the UI element blocks out each characters. -}
119+password : Handle a -> (Content -> a) -> Style -> String -> Content -> Element
120+password = Native.Graphics.Input.password
121+
122+{-| Same as `field` but it adds an annotation that this field is for email
123+addresses. This is helpful for auto-complete and for mobile users who may
124+get a custom keyboard with an `@` and `.com` button.
125+-}
126+email : Handle a -> (Content -> a) -> Style -> String -> Content -> Element
127+email = Native.Graphics.Input.email
128+
129+-- area : Handle a -> (Content -> a) -> Handle b -> ((Int,Int) -> b) -> (Int,Int) -> String -> Content -> Element
130+-- area = Native.Graphics.Input.area
libraries/Native/Color.js+9−2
@@ -6,6 +6,12 @@ Elm.Native.Color.make = function(elm) {
66
77 var Utils = Elm.Native.Utils.make(elm);
88
9+ function toCss(c) {
10+ return (c._3 === 1)
11+ ? ('rgb(' + c._0 + ', ' + c._1 + ', ' + c._2 + ')')
12+ : ('rgba(' + c._0 + ', ' + c._1 + ', ' + c._2 + ', ' + c._3 + ')');
13+ }
14+
915 function complement(rgb) {
1016 var hsv = toHSV(rgb);
1117 hsv.hue = (hsv.hue + 180) % 360;
@@ -63,7 +69,8 @@ Elm.Native.Color.make = function(elm) {
6369 return elm.Native.Color.values = {
6470 hsva:F4(hsva),
6571 hsv:F3(hsv),
66− complement:complement
72+ complement:complement,
73+ toCss:toCss
6774 };
6875
69−};
76+};
libraries/Native/Graphics/Input.js+60−8
@@ -8,6 +8,8 @@ Elm.Native.Graphics.Input.make = function(elm) {
88 var Render = ElmRuntime.use(ElmRuntime.Render.Element);
99 var newNode = ElmRuntime.use(ElmRuntime.Render.Utils).newElement;
1010
11+ var toCss = Elm.Native.Color.make(elm).toCss;
12+ var Text = Elm.Native.Text.make(elm);
1113 var Signal = Elm.Signal.make(elm);
1214 var newElement = Elm.Graphics.Element.make(elm).newElement;
1315 var JS = Elm.Native.JavaScript.make(elm);
@@ -78,7 +80,7 @@ Elm.Native.Graphics.Input.make = function(elm) {
7880
7981 function updateButton(node, oldModel, newModel) {
8082 node.elm_signal = newModel.signal;
81− node.elm_value = nemModel.value;
83+ node.elm_value = newModel.value;
8284 var txt = newModel.text;
8385 if (oldModel.text !== txt) node.innerHTML = txt;
8486 }
@@ -215,11 +217,52 @@ Elm.Native.Graphics.Input.make = function(elm) {
215217 }
216218 }
217219
220+ function updateIfNeeded(css, attribute, latestAttribute) {
221+ if (css[attribute] !== latestAttribute) {
222+ css[attribute] = latestAttribute;
223+ }
224+ }
225+ function cssDimensions(dimensions) {
226+ return dimensions.top + 'px ' +
227+ dimensions.right + 'px ' +
228+ dimensions.bottom + 'px ' +
229+ dimensions.left + 'px';
230+ }
231+ function updateFieldStyle(css, style) {
232+ updateIfNeeded(css, 'padding', cssDimensions(style.padding));
233+
234+ var outline = style.outline;
235+ updateIfNeeded(css, 'border-width', cssDimensions(outline.width));
236+ updateIfNeeded(css, 'border-color', toCss(outline.color));
237+ updateIfNeeded(css, 'border-radius', outline.radius + 'px');
238+
239+ var highlight = style.highlight;
240+ if (highlight.width === 0) {
241+ css.outline = 'none';
242+ } else {
243+ updateIfNeeded(css, 'outline-width', highlight.width + 'px');
244+ updateIfNeeded(css, 'outline-color', toCss(highlight.color));
245+ }
246+
247+ var textStyle = style.style;
248+ updateIfNeeded(css, 'color', toCss(textStyle.color));
249+ if (textStyle.typeface.ctor !== '[]') {
250+ updateIfNeeded(css, 'font-family', Text.toTypefaces(textStyle.typeface));
251+ }
252+ if (textStyle.height.ctor !== "Nothing") {
253+ updateIfNeeded(css, 'font-size', textStyle.height._0 + 'px');
254+ }
255+ updateIfNeeded(css, 'font-weight', textStyle.bold ? 'bold' : 'normal');
256+ updateIfNeeded(css, 'font-style', textStyle.italic ? 'italic' : 'normal');
257+ if (textStyle.line.ctor !== 'Nothing') {
258+ updateIfNeeded(css, 'text-decoration', Text.toLine(textStyle.line._0));
259+ }
260+ }
261+
218262 function renderField(model) {
219263 var field = newNode('input');
220− field.style.border = 'none';
221− field.style.outline = 'none';
222− field.style.backgroundColor = 'transparent';
264+ updateFieldStyle(field.style, model.style);
265+ field.style.borderStyle = 'solid';
223266 field.style.pointerEvents = 'auto';
224267
225268 field.type = model.type;
@@ -302,6 +345,9 @@ Elm.Native.Graphics.Input.make = function(elm) {
302345 }
303346
304347 function updateField(field, oldModel, newModel) {
348+ if (oldModel.style !== newModel.style) {
349+ updateFieldStyle(field.style, newModel.style);
350+ }
305351 field.elm_signal = newModel.signal;
306352 field.elm_handler = newModel.handler;
307353
@@ -316,10 +362,16 @@ Elm.Native.Graphics.Input.make = function(elm) {
316362 }
317363
318364 function mkField(type) {
319− function field(signal, handler, placeHolder, content) {
365+ function field(signal, handler, style, placeHolder, content) {
366+ var padding = style.padding;
367+ var outline = style.outline.width;
368+ var adjustWidth = padding.left + padding.right + outline.left + outline.right;
369+ var adjustHeight = padding.top + padding.bottom + outline.top + outline.bottom;
320370 return A3(newElement, 200, 30, {
321371 ctor: 'Custom',
322− type: type + 'Input',
372+ type: type + 'Field',
373+ adjustWidth: adjustWidth,
374+ adjustHeight: adjustHeight,
323375 render: renderField,
324376 update: updateField,
325377 model: {
@@ -327,14 +379,14 @@ Elm.Native.Graphics.Input.make = function(elm) {
327379 handler:handler,
328380 placeHolder:placeHolder,
329381 content:content,
382+ style:style,
330383 type:type
331384 }
332385 });
333386 }
334− return F4(field);
387+ return F5(field);
335388 }
336389
337−
338390 function hoverable(signal, handler, elem) {
339391 function onHover(bool) {
340392 elm.notify(signal.id, handler(bool));
libraries/Native/String.js−2
@@ -10,7 +10,6 @@ Elm.Native.String.make = function(elm) {
1010 var Maybe = Elm.Maybe.make(elm);
1111 var JS = Elm.JavaScript.make(elm);
1212 var Utils = Elm.Native.Utils.make(elm);
13− var show = Elm.Native.Show.make(elm);
1413
1514 function isEmpty(str) {
1615 return str.length === 0;
@@ -244,7 +243,6 @@ Elm.Native.String.make = function(elm) {
244243 endsWith: F2(endsWith),
245244 indexes: F2(indexes),
246245
247− show:show,
248246 toInt: toInt,
249247 toFloat: toFloat,
250248 toList: toList,
libraries/Native/Text.js+58−42
@@ -4,11 +4,10 @@ Elm.Native.Text.make = function(elm) {
44 elm.Native.Text = elm.Native.Text || {};
55 if (elm.Native.Text.values) return elm.Native.Text.values;
66
7− var JS = Elm.JavaScript.make(elm);
8− var Utils = Elm.Native.Utils.make(elm);
9− var Color = Elm.Native.Color.make(elm);
7+ var toCss = Elm.Native.Color.make(elm).toCss;
108 var Element = Elm.Graphics.Element.make(elm);
11− var show = Elm.Native.Show.make(elm).show;
9+ var List = Elm.Native.List.make(elm);
10+ var Utils = Elm.Native.Utils.make(elm);
1211
1312 function makeSpaces(s) {
1413 if (s.length == 0) { return s; }
@@ -51,13 +50,51 @@ Elm.Native.Text.make = function(elm) {
5150 return arr.join('<br/>');
5251 }
5352
54− function toText(str) { return Utils.txt(properEscape(JS.fromString(str))); }
53+ function toText(str) { return Utils.txt(properEscape(str)); }
54+
55+ // conversions from Elm values to CSS
56+ function toTypefaces(list) {
57+ var typefaces = List.toArray(list);
58+ for (var i = typefaces.length; i--; ) {
59+ var typeface = typefaces[i];
60+ if (typeface.contains(' ')) {
61+ typefaces[i] = "'" + typeface + "'";
62+ }
63+ }
64+ return typefaces.join(',');
65+ }
66+ function toLine(line) {
67+ var ctor = line.ctor;
68+ return ctor === 'Under' ? 'underline' :
69+ ctor === 'Over' ? 'overline' : 'line-through';
70+ }
5571
72+ // setting styles of Text
73+ function style(style, text) {
74+ var newText = '<span style="color:' + toCss(style.color) + ';'
75+ if (style.typeface.ctor !== '[]') {
76+ newText += 'font-family:' + toTypefaces(style.typeface) + ';'
77+ }
78+ if (style.height.ctor !== "Nothing") {
79+ newText += 'font-size:' + style.height._0 + 'px;';
80+ }
81+ if (style.bold) {
82+ newText += 'font-weight:bold;';
83+ }
84+ if (style.italic) {
85+ newText += 'font-style:italic;';
86+ }
87+ if (style.line.ctor !== 'Nothing') {
88+ newText += 'text-decoration:' + toLine(style.line._0) + ';';
89+ }
90+ newText += '">' + Utils.makeText(text) + '</span>'
91+ return Utils.txt(newText);
92+ }
5693 function height(px, text) {
5794 return { style: 'font-size:' + px + 'px;', text:text }
5895 }
59− function typeface(name, text) {
60− return { style: 'font-family:' + name + ';', text:text }
96+ function typeface(names, text) {
97+ return { style: 'font-family:' + toTypefaces(names) + ';', text:text }
6198 }
6299 function monospace(text) {
63100 return { style: 'font-family:monospace;', text:text }
@@ -71,25 +108,16 @@ Elm.Native.Text.make = function(elm) {
71108 function link(href, text) {
72109 return { href: toText(href), text:text };
73110 }
74− function underline(text) {
75− return { line: ' underline', text:text };
76− }
77− function overline(text) {
78− return { line: ' overline', text:text };
79− }
80− function strikeThrough(text) {
81− return { line: ' line-through', text:text };
111+ function line(line, text) {
112+ return { style: 'text-decoration:' + toLine(line) + ';', text:text };
82113 }
83114
84− function color(c, text) {
85− var color = (c._3 === 1)
86− ? ('rgb(' + c._0 + ', ' + c._1 + ', ' + c._2 + ')')
87− : ('rgba(' + c._0 + ', ' + c._1 + ', ' + c._2 + ', ' + c._3 + ')');
88− return { style: 'color:' + color + ';', text:text };
115+ function color(color, text) {
116+ return { style: 'color:' + toCss(color) + ';', text:text };
89117 }
90118
91− function position(align) {
92− function create(text) {
119+ function block(align) {
120+ return function(text) {
93121 var raw = {
94122 ctor :'RawHtml',
95123 html : Utils.makeText(text),
@@ -100,7 +128,6 @@ Elm.Native.Text.make = function(elm) {
100128 var pos = A2(Utils.htmlHeight, 0, raw);
101129 return A3(Element.newElement, pos._0, pos._1, raw);
102130 }
103− return create;
104131 }
105132
106133 function markdown(text, guid) {
@@ -115,36 +142,25 @@ Elm.Native.Text.make = function(elm) {
115142 return A3(Element.newElement, pos._0, pos._1, raw);
116143 }
117144
118− var text = position('left');
119− function asText(v) {
120− return text(monospace(toText(show(v))));
121− }
122−
123− function plainText(v) {
124− return text(toText(v));
125− }
126−
127145 return elm.Native.Text.values = {
128146 toText: toText,
129147
130148 height : F2(height),
131149 italic : italic,
132150 bold : bold,
133− underline : underline,
134− overline : overline,
135− strikeThrough : strikeThrough,
151+ line : F2(line),
136152 monospace : monospace,
137153 typeface : F2(typeface),
138154 color : F2(color),
139155 link : F2(link),
140156
141− justified : position('justify'),
142− centered : position('center'),
143− righted : position('right'),
144− text : text,
145− plainText : plainText,
146− markdown : markdown,
157+ leftAligned : block('left'),
158+ rightAligned : block('right'),
159+ centered : block('center'),
160+ justified : block('justify'),
161+ markdown : markdown,
147162
148− asText : asText,
163+ toTypefaces:toTypefaces,
164+ toLine:toLine,
149165 };
150166};
libraries/Native/Utils.js−7
@@ -76,14 +76,8 @@ Elm.Native.Utils.make = function(elm) {
7676
7777 function makeText(text) {
7878 var style = '';
79− var line = '';
8079 var href = '';
8180 while (true) {
82− if (text.line) {
83− line += text.line;
84− text = text.text;
85− continue;
86− }
8781 if (text.style) {
8882 style += text.style;
8983 text = text.text;
@@ -95,7 +89,6 @@ Elm.Native.Utils.make = function(elm) {
9589 continue;
9690 }
9791 if (href) text = '<a href="' + href + '">' + text + '</a>';
98− if (line) style += 'text-decoration:' + line + ';';
9992 if (style) text = '<span style="' + style + '">' + text + '</span>';
10093 return text;
10194 }
libraries/String.elm+2−1
@@ -28,6 +28,7 @@ Cosmetic operations such as padding with extra characters or trimming whitespace
2828@docs map, filter, foldl, foldr, any, all
2929-}
3030
31+import Native.Show
3132import Native.String
3233import Maybe (Maybe)
3334
@@ -284,7 +285,7 @@ indices = Native.String.indexes
284285 show [1,2] == "[1,2]"
285286-}
286287show : a -> String
287−show = Native.String.show
288+show = Native.Show.show
288289
289290{-| Try to convert a string into an int, failing on improperly formatted strings.
290291
libraries/Text.elm+79−40
@@ -6,94 +6,132 @@ module Text where
66@docs toText
77
88# Creating Elements
9−@docs plainText, asText, text, centered, justified, righted
9+@docs leftAligned, rightAligned, centered, justified
1010
11−# Formatting
12−@docs color, typeface, height, link
11+# Links and Style
12+@docs link, Style, style, Line, defaultStyle
1313
14−# Simple Formatting
15−@docs monospace, bold, italic, underline, overline, strikeThrough
14+# Convenience Functions
15+
16+There are two convenience functions for creating an `Element` which can be
17+useful when debugging or prototyping:
18+
19+@docs plainText, asText
20+
21+There are also a bunch of functions to set parts of a `Style` individually:
22+
23+@docs typeface, monospace, height, color, bold, italic, line
1624
1725-}
1826
1927import Basics (..)
20−import Color (Color)
28+import String
29+import Color (Color, black)
2130import Graphics.Element (Element, Three, Pos, ElementPrim, Properties)
22−import Maybe (Maybe)
31+import Maybe (Maybe, Nothing)
2332import JavaScript (JSString)
33+import Native.Show
2434import Native.Text
2535
2636data Text = Text
2737
38+data Line = Under | Over | Through
39+
40+{-| Representation of all the ways you can style `Text`.
41+-}
42+type Style =
43+ { typeface : [String]
44+ , height : Maybe Float
45+ , color : Color
46+ , bold : Bool
47+ , italic : Bool
48+ , line : Maybe Line
49+ }
50+
51+{-| Plain black text. It uses the browsers default typeface and text height.
52+No decorations are used:
53+
54+ { typeface = []
55+ , height = Nothing
56+ , color = black
57+ , bold = False
58+ , italic = False
59+ , line = Nothing
60+ }
61+-}
62+defaultStyle : Style
63+defaultStyle =
64+ { typeface = []
65+ , height = Nothing
66+ , color = black
67+ , bold = False
68+ , italic = False
69+ , line = Nothing
70+ }
71+
2872{-| Convert a string into text which can be styled and displayed. -}
2973toText : String -> Text
3074toText = Native.Text.toText
3175
32−{-| Set the typeface of some text. The first argument should be a comma
33−separated listing of the desired typefaces:
76+{-| Set the style of some text.
77+-}
78+style : Style -> Text -> Text
79+style = Native.Text.style
80+
81+{-| Provide a list of prefered typefaces for some text.
3482
35− "helvetica, arial, sans-serif"
83+ ["helvetica","arial","sans-serif"]
3684
37−Works the same as the CSS font-family property.
85+Not everyone has access to the same typefaces, so rendering will use the first
86+typeface in the list that is found on the user's computer. If there are no
87+matches, it will use their default typeface. Works the same as the CSS
88+font-family property.
3889-}
39−typeface : String -> Text -> Text
90+typeface : [String] -> Text -> Text
4091typeface = Native.Text.typeface
4192
4293{-| Switch to a monospace typeface. Good for code snippets. -}
4394monospace : Text -> Text
4495monospace = Native.Text.monospace
4596
46−{-| Create a link. -}
97+{-| Create a link.
98+
99+ link "http://elm-lang.org" (toText "Elm Website")
100+-}
47101link : String -> Text -> Text
48102link = Native.Text.link
49103
50−{-| Set the height of text in pixels. -}
51104height : Float -> Text -> Text
52105height = Native.Text.height
53106
54−{-| Set the color of a string. -}
55107color : Color -> Text -> Text
56108color = Native.Text.color
57109
58−{-| Make a string bold. -}
59110bold : Text -> Text
60111bold = Native.Text.bold
61112
62−{-| Italicize a string. -}
63113italic : Text -> Text
64114italic = Native.Text.italic
65115
66−{-| Draw a line above a string. -}
67−overline : Text -> Text
68−overline = Native.Text.overline
116+line : Line -> Text -> Text
117+line = Native.Text.line
69118
70−{-| Underline a string. -}
71−underline : Text -> Text
72−underline = Native.Text.underline
119+leftAligned : Text -> Element
120+leftAligned = Native.Text.leftAligned
73121
74−{-| Draw a line through a string. -}
75−strikeThrough : Text -> Text
76−strikeThrough = Native.Text.strikeThrough
122+rightAligned : Text -> Element
123+rightAligned = Native.Text.rightAligned
77124
78−{-| Display justified, styled text. -}
79−justified : Text -> Element
80−justified = Native.Text.justified
81−
82−{-| Display centered, styled text. -}
83125centered : Text -> Element
84126centered = Native.Text.centered
85127
86−{-| Display right justified, styled text. -}
87−righted : Text -> Element
88−righted = Native.Text.righted
89−
90−{-| Display styled text. -}
91−text : Text -> Element
92−text = Native.Text.text
128+justified : Text -> Element
129+justified = Native.Text.justified
93130
94131{-| Display a plain string. -}
95132plainText : String -> Element
96−plainText = Native.Text.plainText
133+plainText str =
134+ leftAligned (toText str)
97135
98136{-| for internal use only -}
99137markdown : Element
@@ -107,4 +145,5 @@ the browser:
107145Excellent for debugging.
108146-}
109147asText : a -> Element
110−asText = Native.Text.asText
148+asText value =
149+ leftAligned (monospace (toText (Native.Show.show value)))
runtime/Init.js+1−1
@@ -91,7 +91,7 @@ function init(display, container, module, ports, moduleToReplace) {
9191 checkPorts(elm);
9292 } catch(e) {
9393 var directions = "<br/>&nbsp; &nbsp; Open the developer console for more details."
94− Module.main = Elm.Text.make(elm).text('<code>' + e.message + directions + '</code>');
94+ Module.main = Elm.Text.make(elm).leftAligned('<code>' + e.message + directions + '</code>');
9595 reportAnyErrors = function() { throw e; }
9696 }
9797 inputs = ElmRuntime.filterDeadInputs(inputs);
runtime/Render/Element.js+20−3
@@ -7,7 +7,15 @@ var newElement = Utils.newElement, extract = Utils.extract,
77 addTransform = Utils.addTransform, removeTransform = Utils.removeTransform,
88 fromList = Utils.fromList, eq = Utils.eq;
99
10−function setProps(props, e) {
10+function setProps(elem, e) {
11+ var props = elem.props;
12+ var element = elem.element;
13+ if (element.adjustWidth) {
14+ props.width -= element.adjustWidth;
15+ }
16+ if (element.adjustHeight) {
17+ props.height -= element.adjustHeight;
18+ }
1119 e.style.width = (props.width |0) + 'px';
1220 e.style.height = (props.height|0) + 'px';
1321 if (props.opacity !== 1) { e.style.opacity = props.opacity; }
@@ -200,7 +208,7 @@ function rawHtml(elem) {
200208 return div;
201209}
202210
203−function render(elem) { return setProps(elem.props, makeElement(elem)); }
211+function render(elem) { return setProps(elem, makeElement(elem)); }
204212function makeElement(e) {
205213 var elem = e.element;
206214 switch(elem.ctor) {
@@ -308,7 +316,16 @@ function update(node, curr, next) {
308316}
309317
310318function updateProps(node, curr, next) {
311− var props = next.props, currP = curr.props, e = node;
319+ var props = next.props;
320+ var currP = curr.props;
321+ var e = node;
322+ var element = next.element;
323+ if (element.adjustWidth) {
324+ props.width -= element.adjustWidth;
325+ }
326+ if (element.adjustHeight) {
327+ props.height -= element.adjustHeight;
328+ }
312329 if (props.width !== currP.width) e.style.width = (props.width |0) + 'px';
313330 if (props.height !== currP.height) e.style.height = (props.height|0) + 'px';
314331 if (props.opacity !== 1 && props.opacity !== currP.opacity) {