-
Notifications
You must be signed in to change notification settings - Fork 55
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
10e86a6
737590d
c0bd291
0b67074
29dfdd1
4578bc7
cc73a42
5a09f0e
0e7dc91
409fd30
2f76006
516f3e1
8dac047
f7de6e9
114b68f
93a38d0
f2f84cf
9ed24c0
ef46f6b
42a9715
341f0a0
f6a8485
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)?