summaryrefslogtreecommitdiff
path: root/library/src/layout
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-03-20 18:21:05 +0100
committerLaurenz <laurmaedje@gmail.com>2023-03-20 18:21:05 +0100
commit22bf0117a0613dc63ace4c495f97bd980db0140c (patch)
tree820adff54114d69d83a33fd2cb1e9294ebcbcc29 /library/src/layout
parent420eebe191bea782fe5af1fc48ddd69f486f8638 (diff)
Documentation for measure, locate, and style
Diffstat (limited to 'library/src/layout')
-rw-r--r--library/src/layout/measure.rs35
1 files changed, 32 insertions, 3 deletions
diff --git a/library/src/layout/measure.rs b/library/src/layout/measure.rs
index df66d67f..3bd11ce6 100644
--- a/library/src/layout/measure.rs
+++ b/library/src/layout/measure.rs
@@ -1,10 +1,39 @@
use crate::prelude::*;
-/// Measure the size of content.
+/// Measure the layouted size of content.
+///
+/// The `measure` function lets you determine the layouted size of content.
+/// The same content can have a different size depending on the styles that
+/// are active when it is layouted. For example, in the example below
+/// `[#content]` is of course bigger when we increase the font size.
+///
+/// ```example
+/// #let content = [Hello!]
+/// #content
+/// #set text(14pt)
+/// #content
+/// ```
+///
+/// To do a meaningful measurement, you therefore first need to retrieve the
+/// active styles with the [`style`]($func/style) function. You can then pass
+/// them to the `measure` function.
+///
+/// ```example
+/// #let thing(body) = style(styles => {
+/// let size = measure(body, styles)
+/// [Width of "#body" is #size.width]
+/// })
+///
+/// #thing[Hey] \
+/// #thing[Welcome]
+/// ```
+///
+/// The measure function returns a dictionary with the entries `width` and
+/// `height`, both of type [`length`]($type/length).
///
/// Display: Measure
/// Category: layout
-/// Returns: array
+/// Returns: dictionary
#[func]
pub fn measure(
/// The content whose size to measure.
@@ -16,5 +45,5 @@ pub fn measure(
let styles = StyleChain::new(&styles);
let frame = content.measure(&mut vm.vt, styles, pod)?.into_frame();
let Size { x, y } = frame.size();
- Value::Array(array![x, y])
+ dict! { "width" => x, "height" => y }.into()
}