|
1 | 1 | use parley::{AlignmentOptions, BreakerState, YieldData}; |
| 2 | +use style::computed_values::width; |
2 | 3 | use taffy::{ |
3 | 4 | AvailableSpace, BlockContext, BlockFormattingContext, Clear, Float, LayoutPartialTree as _, |
4 | 5 | MaybeMath as _, MaybeResolve as _, NodeId, Position, ResolveOrZero as _, Size, |
@@ -110,14 +111,61 @@ impl BaseDocument { |
110 | 111 | // and a min-content or max-content constraint. So if we want to compute both widths in one pass then |
111 | 112 | // we need to store both a min-content and max-content size on each box. |
112 | 113 | let content_sizes = inline_layout.layout.calculate_content_widths(); |
| 114 | + |
| 115 | + let float_width = match available_space.width { |
| 116 | + AvailableSpace::Definite(_) => 0.0, |
| 117 | + AvailableSpace::MinContent => { |
| 118 | + let mut width: f32 = 0.0; |
| 119 | + for ibox in inline_layout.layout.inline_boxes_mut() { |
| 120 | + let style = &self.nodes[ibox.id as usize].style; |
| 121 | + |
| 122 | + if let Some(direction) = style.float.float_direction() { |
| 123 | + let margin = style.margin.resolve_or_zero( |
| 124 | + inputs.parent_size, |
| 125 | + resolve_calc_value, |
| 126 | + ); |
| 127 | + let output = self.compute_child_layout( |
| 128 | + NodeId::from(ibox.id), |
| 129 | + child_inputs, |
| 130 | + ); |
| 131 | + width = width |
| 132 | + .max(output.size.width + margin.left + margin.right); |
| 133 | + } |
| 134 | + } |
| 135 | + |
| 136 | + width * scale |
| 137 | + } |
| 138 | + AvailableSpace::MaxContent => { |
| 139 | + let mut width: f32 = 0.0; |
| 140 | + for ibox in inline_layout.layout.inline_boxes_mut() { |
| 141 | + let style = &self.nodes[ibox.id as usize].style; |
| 142 | + |
| 143 | + if let Some(direction) = style.float.float_direction() { |
| 144 | + let margin = style.margin.resolve_or_zero( |
| 145 | + inputs.parent_size, |
| 146 | + resolve_calc_value, |
| 147 | + ); |
| 148 | + let output = self.compute_child_layout( |
| 149 | + NodeId::from(ibox.id), |
| 150 | + child_inputs, |
| 151 | + ); |
| 152 | + width += output.size.width + margin.left + margin.right; |
| 153 | + } |
| 154 | + } |
| 155 | + |
| 156 | + width * scale |
| 157 | + } |
| 158 | + }; |
| 159 | + |
113 | 160 | let computed_width = match available_space.width { |
114 | | - AvailableSpace::MinContent => content_sizes.min, |
115 | | - AvailableSpace::MaxContent => content_sizes.max, |
| 161 | + AvailableSpace::MinContent => content_sizes.min.max(float_width), |
| 162 | + AvailableSpace::MaxContent => content_sizes.max + float_width, |
116 | 163 | AvailableSpace::Definite(limit) => (limit * scale) |
117 | | - .min(content_sizes.max) |
| 164 | + .min(content_sizes.max + float_width) |
118 | 165 | .max(content_sizes.min), |
119 | 166 | } |
120 | 167 | .ceil(); |
| 168 | + |
121 | 169 | let style_width = style |
122 | 170 | .size |
123 | 171 | .width |
|
0 commit comments