{"route":"/en-US-v0.14.1/reference/layout/measure/","title":"Measure","description":"Documentation for the `measure` function.","part":null,"outline":[{"id":"summary","name":"Summary","children":[]},{"id":"example","name":"Example","children":[]},{"id":"parameters","name":"Parameters","children":[{"id":"parameters-width","name":"width","children":[]},{"id":"parameters-height","name":"height","children":[]},{"id":"parameters-content","name":"content","children":[]}]}],"body":{"kind":"func","content":{"path":[],"name":"measure","title":"Measure","keywords":[],"oneliner":"Measures the layouted size of content.","element":false,"contextual":true,"deprecationMessage":null,"deprecationUntil":null,"details":[{"kind":"html","content":"<p>Measures the layouted size of content.</p>\n<p>The <code>measure</code> function lets you determine the layouted size of content.\nBy default an infinite space is assumed, so the measured dimensions may\nnot necessarily match the final dimensions of the content.\nIf you want to measure in the current layout dimensions, you can combine\n<code>measure</code> and <a href=\"/en-US-v0.14.1/reference/layout/layout/\" title=\"`layout`\"><code>layout</code></a>.</p>\n<h2 id=\"example\">Example</h2>\n<p>The same content can have a different size depending on the <a href=\"/en-US-v0.14.1/reference/context/\" title=\"context\">context</a> that\nit is placed into. In the example below, the <code><span class=\"typ-pol\">#</span><span class=\"typ-pol\">content</span></code> is of course\nbigger when we increase the font size.</p>\n<div class=\"previewed-code\"><pre><code><span class=\"typ-key\">#</span><span class=\"typ-key\">let</span> content <span class=\"typ-op\">=</span> <span class=\"typ-punct\">[</span>Hello!<span class=\"typ-punct\">]</span>\n<span class=\"typ-pol\">#</span><span class=\"typ-pol\">content</span>\n<span class=\"typ-key\">#</span><span class=\"typ-key\">set</span> <span class=\"typ-func\">text</span><span class=\"typ-punct\">(</span><span class=\"typ-num\">14pt</span><span class=\"typ-punct\">)</span>\n<span class=\"typ-pol\">#</span><span class=\"typ-pol\">content</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/213f7d67a16c2b7124176f09e63be87.png\" alt=\"Preview\"></div></div>\n<p>For this reason, you can only measure when context is available.</p>\n<div class=\"previewed-code\"><pre><code><span class=\"typ-key\">#</span><span class=\"typ-key\">let</span> <span class=\"typ-func\">thing</span><span class=\"typ-punct\">(</span>body<span class=\"typ-punct\">)</span> <span class=\"typ-op\">=</span> <span class=\"typ-key\">context</span> <span class=\"typ-punct\">{</span>\n  <span class=\"typ-key\">let</span> size <span class=\"typ-op\">=</span> <span class=\"typ-func\">measure</span><span class=\"typ-punct\">(</span>body<span class=\"typ-punct\">)</span>\n  <span class=\"typ-punct\">[</span>Width of &quot;<span class=\"typ-pol\">#</span><span class=\"typ-pol\">body</span>&quot; is <span class=\"typ-pol\">#</span><span class=\"typ-pol\">size</span><span class=\"typ-punct\">.</span><span class=\"typ-pol\">width</span><span class=\"typ-punct\">]</span>\n<span class=\"typ-punct\">}</span>\n\n<span class=\"typ-func\">#</span><span class=\"typ-func\">thing</span><span class=\"typ-punct\">[</span>Hey<span class=\"typ-punct\">]</span> <span class=\"typ-escape\">\\</span>\n<span class=\"typ-func\">#</span><span class=\"typ-func\">thing</span><span class=\"typ-punct\">[</span>Welcome<span class=\"typ-punct\">]</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/fb2e80b8ddc9deb97b1b3d71fd54638f.png\" alt=\"Preview\"></div></div>\n<p>The measure function returns a dictionary with the entries <code>width</code> and\n<code>height</code>, both of type <a href=\"/en-US-v0.14.1/reference/layout/length/\" title=\"`length`\"><code>length</code></a>.</p>"}],"self":false,"params":[{"name":"width","details":[{"kind":"html","content":"<p>The width available to layout the content.</p>\n<p>Setting this to <code><span class=\"typ-key\">auto</span></code> indicates infinite available width.</p>\n<p>Note that using the <code>width</code> and <code>height</code> parameters of this function is\ndifferent from measuring a sized <a href=\"/en-US-v0.14.1/reference/layout/block/\" title=\"`block`\"><code>block</code></a> containing the content. In\nthe following example, the former will get the dimensions of the inner\ncontent instead of the dimensions of the block.</p>"},{"kind":"example","content":{"body":"<div class=\"previewed-code\"><pre><code><span class=\"typ-key\">#</span><span class=\"typ-key\">context</span> <span class=\"typ-func\">measure</span><span class=\"typ-punct\">(</span><span class=\"typ-func\">lorem</span><span class=\"typ-punct\">(</span><span class=\"typ-num\">100</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">,</span> width<span class=\"typ-punct\">:</span> <span class=\"typ-num\">400pt</span><span class=\"typ-punct\">)</span>\n\n<span class=\"typ-key\">#</span><span class=\"typ-key\">context</span> <span class=\"typ-func\">measure</span><span class=\"typ-punct\">(</span><span class=\"typ-func\">block</span><span class=\"typ-punct\">(</span><span class=\"typ-func\">lorem</span><span class=\"typ-punct\">(</span><span class=\"typ-num\">100</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">,</span> width<span class=\"typ-punct\">:</span> <span class=\"typ-num\">400pt</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">)</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/9063ce7197f1cd611fa96cca40225a16.png\" alt=\"Preview\"></div></div>","title":null}}],"types":["auto","length"],"strings":[],"default":"<code><span class=\"typ-key\">auto</span></code>","positional":false,"named":true,"required":false,"variadic":false,"settable":false},{"name":"height","details":[{"kind":"html","content":"<p>The height available to layout the content.</p>\n<p>Setting this to <code><span class=\"typ-key\">auto</span></code> indicates infinite available height.</p>"}],"types":["auto","length"],"strings":[],"default":"<code><span class=\"typ-key\">auto</span></code>","positional":false,"named":true,"required":false,"variadic":false,"settable":false},{"name":"content","details":[{"kind":"html","content":"<p>The content whose size to measure.</p>"}],"types":["content"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["dictionary"],"scope":[]}}}