Skip to content

Commit 562b29f

Browse files
committed
fix: text-slot bug in testing framework
1 parent c445d4d commit 562b29f

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

float-pigment-forest/src/node.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,9 @@ impl Node {
315315
pub(crate) unsafe fn baseline_func(&self) -> Option<&BaselineFn<Len>> {
316316
(*self.baseline_func.get()).as_deref()
317317
}
318-
pub unsafe fn set_baseline_func(&self, baseline_func: Option<Box<BaselineFn<Len>>>) {
318+
pub fn set_baseline_func(&self, baseline_func: Option<Box<BaselineFn<Len>>>) {
319319
drop(std::mem::replace(
320-
&mut *self.baseline_func.get(),
320+
unsafe { &mut *self.baseline_func.get() },
321321
baseline_func,
322322
));
323323
}

float-pigment-forest/tests/custom/css_margin.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,20 @@ fn margin_collapse_between_sibling_and_empty_block_4() {
365365
)
366366
}
367367

368+
#[test]
369+
fn margin_collapse_between_sibling_and_empty_block_5() {
370+
assert_xml!(
371+
r#"
372+
<div style="height: 300px;">
373+
<div style="height: 30px; margin-bottom: 50px" expect_height="30" expect_top="0"></div>
374+
<text-slot len="0"></text-slot>
375+
<div style="height: 30px; margin-top: 100px" expect_height="30" expect_top="130"></div>
376+
</div>
377+
"#,
378+
true
379+
)
380+
}
381+
368382
#[test]
369383
fn margin_collapse_between_parent_and_empty_block_1() {
370384
assert_xml!(

float-pigment-forest/tests/mod.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ impl TextInfo {
125125
max_content_height: Len,
126126
) -> Size<Len> {
127127
let text_len = self.text_len;
128+
if text_len == 0 {
129+
println!(
130+
"text_info: {self:?}, width: {min_width:?} ~ {max_width:?}, height: {min_height:?} ~ {max_height:?}, max_content_width: {max_content_width:?}, max_content_height: {max_content_height:?}, measured_width: 0, measured_height: 0",
131+
);
132+
return Size::new(Len::zero(), Len::zero());
133+
}
128134
let text_width = self.font_size * text_len as f32;
129135
let max_w = max_width.min(max_content_width);
130136
let max_h = max_height.min(max_content_height);
@@ -188,6 +194,11 @@ fn convert_font_size_to_px(font_size: float_pigment_css::typing::Length) -> f32
188194
#[inline(always)]
189195
fn prepare_measure_node(node: *mut Node, text_info: TextInfo) {
190196
let node = unsafe { &mut *node };
197+
unsafe {
198+
node.set_display(Display::Inline);
199+
node.set_node_type(float_pigment_forest::NodeType::Text);
200+
}
201+
node.set_baseline_func(Some(Box::new(|_, _, _| Len::from_f32(16.))));
191202
node.set_measure_func(Some(Box::new(
192203
move |_,
193204
max_width,
@@ -208,11 +219,6 @@ fn prepare_measure_node(node: *mut Node, text_info: TextInfo) {
208219
)
209220
},
210221
)));
211-
unsafe {
212-
node.set_display(Display::Inline);
213-
node.set_baseline_func(Some(Box::new(|_, _, _| Len::from_f32(16.))));
214-
node.set_node_type(float_pigment_forest::NodeType::Text);
215-
}
216222
}
217223

218224
impl TestCtx {
@@ -385,7 +391,6 @@ impl TestCtx {
385391
self.set_expect_layout_pos(node, e.attributes());
386392

387393
if is_measure_text_slot(e.tag()) {
388-
let node = Node::new_ptr();
389394
let text_len = e
390395
.attributes()
391396
.get("len")

0 commit comments

Comments
 (0)