-
Notifications
You must be signed in to change notification settings - Fork 56
Enable floats and other advanced layouts #421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
dedeb30
aa4c989
a50f635
8df2efb
142c3c7
ef8f1ff
3be1d47
fab77ce
c60a9eb
ad43bcf
ba64a39
562097f
258f0c4
d0a9240
278e4b2
89a5f67
c46145e
377501c
01c0796
5a63a85
9f1629e
3ffdfb0
accd36d
7ff5da1
0da1cdd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,8 @@ pub struct InlineBox { | |
| /// User-specified identifier for the box, which can be used by the user to determine which box in | ||
| /// parley's output corresponds to which box in its input. | ||
| pub id: u64, | ||
| /// Whether the box is in-flow (takes up space in the layout) or out-of-flow (e.g. absolutely positioned or floated) | ||
| pub kind: InlineBoxKind, | ||
| /// The byte offset into the underlying text string at which the box should be placed. | ||
| /// This must not be within a Unicode code point. | ||
| pub index: usize, | ||
|
|
@@ -15,3 +17,24 @@ pub struct InlineBox { | |
| /// The height of the box in pixels | ||
| pub height: f32, | ||
| } | ||
|
|
||
| /// Whether a box is in-flow (takes up space in the layout) or out-of-flow (e.g. absolutely positioned) | ||
| /// or custom-out-of-flow (line-breaking should yield control flow) | ||
| #[derive(PartialEq, Debug, Clone, Copy)] | ||
| pub enum InlineBoxKind { | ||
| /// `InFlow` boxes take up space in the layout and flow in line with text | ||
| /// | ||
| /// They correspond to `display: inline-block` boxes in CSS. | ||
| InFlow, | ||
| /// `OutOfFlow` boxes are assigned a position as if they were a zero-sized inline box, but | ||
| /// do not take up space in the layout. | ||
| /// | ||
| /// They correspond to `position: absolute` boxes in CSS. | ||
| OutOfFlow, | ||
|
Comment on lines
+25
to
+33
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we add tests for |
||
| /// `CustomOutOfFlow` boxes also do not take up space in the layout, but they are not assigned a position | ||
| /// by Parley. When they are encountered, control flow is yielded back to the caller who is then responsible | ||
| /// for laying out the box. | ||
| /// | ||
| /// They can be used to implement advanced layout modes such as CSS's `float` | ||
| CustomOutOfFlow, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suspect the |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,11 @@ impl<B: Brush> Layout<B> { | |
| &self.data.styles | ||
| } | ||
|
|
||
| /// Returns available width of the layout. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please expand the documentation of |
||
| pub fn available_width(&self) -> f32 { | ||
| self.data.alignment_width | ||
| } | ||
|
|
||
| /// Returns the width of the layout. | ||
| pub fn width(&self) -> f32 { | ||
| self.data.width | ||
|
|
@@ -126,14 +131,9 @@ impl<B: Brush> Layout<B> { | |
| /// You must perform line breaking prior to aligning, through [`Layout::break_lines`] or | ||
| /// [`Layout::break_all_lines`]. If `container_width` is not specified, the layout's | ||
| /// [`Layout::width`] is used. | ||
| pub fn align( | ||
| &mut self, | ||
| container_width: Option<f32>, | ||
| alignment: Alignment, | ||
| options: AlignmentOptions, | ||
| ) { | ||
| pub fn align(&mut self, alignment: Alignment, options: AlignmentOptions) { | ||
| unjustify(&mut self.data); | ||
| align(&mut self.data, container_width, alignment, options); | ||
| align(&mut self.data, alignment, options); | ||
| } | ||
|
|
||
| /// Returns the index and `Line` object for the line containing the | ||
|
|
@@ -166,9 +166,9 @@ impl<B: Brush> Layout<B> { | |
| return Some((0, self.get(0)?)); | ||
| } | ||
| let maybe_line_index = self.data.lines.binary_search_by(|line| { | ||
| if offset < line.metrics.min_coord { | ||
| if offset < line.metrics.block_min_coord { | ||
| Ordering::Greater | ||
| } else if offset >= line.metrics.max_coord { | ||
| } else if offset >= line.metrics.block_max_coord { | ||
| Ordering::Less | ||
| } else { | ||
| Ordering::Equal | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you been able to confirm that these changes do not regress performance (either via
parley_benchor in Blitz)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have (both
parley_benchand in Blitz), although this was prior to being rebased on top of the ICU work. It is slightly slower if you use the new APIs to implement float like layout (although actually less than I was expecting - this is partly because I am able to track whether there are "active floats" and skip the expensive bit when there aren't), but the performance is unchanged if you're usingbreak_all_lines()