Skip to content

Commit

Permalink
fix lonly inline boxes in inline contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharktheone committed Sep 13, 2024
1 parent 3b0acff commit 27811f5
Showing 1 changed file with 118 additions and 115 deletions.
233 changes: 118 additions & 115 deletions crates/gosub_taffy/src/compute/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,144 +274,147 @@ pub fn compute_inline_layout<LT: LayoutTree<TaffyLayouter>>(
height: layout.height().ceil(),
};

let mut current_node_idx = 0;
let mut current_node_id = LT::NodeId::from(0);
let mut current_to = 0;

if let Some(first) = text_node_data.first() {
let mut current_node_idx = 0;
let mut current_node_id = LT::NodeId::from(first.id.into());
let mut current_to = first.to;
current_node_id = LT::NodeId::from(first.id.into());
current_to = first.to;
}

let mut current_glyph_idx = 0;
let mut current_glyph_idx = 0;

'lines: for line in layout.lines() {
let metrics = line.metrics();
'lines: for line in layout.lines() {
let metrics = line.metrics();

let height = metrics.line_height;
let height = metrics.line_height;

for item in line.items() {
match item {
PositionedLayoutItem::GlyphRun(run) => {
let mut offset = 0.0;
for item in line.items() {
match item {
PositionedLayoutItem::GlyphRun(run) => {
let mut offset = 0.0;

let grun = run.run();
let fs = grun.font_size();
let grun = run.run();
let fs = grun.font_size();

let glyphs = run
.glyphs()
.map(|g| {
let gl = Glyph {
id: g.id,
x: g.x + offset,
y: g.y,
};
let glyphs = run
.glyphs()
.map(|g| {
let gl = Glyph {
id: g.id,
x: g.x + offset,
y: g.y,
};

offset += g.advance;
offset += g.advance;

gl
})
.collect::<Vec<_>>();
gl
})
.collect::<Vec<_>>();

let run_y = run.baseline();
let run_y = run.baseline();

if current_node_id.into() == 161 || current_node_id.into() == 163 {
println!("current_node_id: {:?}", current_node_id.into());
println!("first glyph: {:?}", glyphs.get(2));
}
if current_node_id.into() == 161 || current_node_id.into() == 163 {
println!("current_node_id: {:?}", current_node_id.into());
println!("first glyph: {:?}", glyphs.get(2));
}

current_glyph_idx += glyphs.len();
current_glyph_idx += glyphs.len();

if current_glyph_idx > current_to {
current_node_idx += 1;
if current_glyph_idx > current_to {
current_node_idx += 1;

if let Some(next) = text_node_data.get(current_node_idx) {
current_to = next.to;
current_node_id = LT::NodeId::from(next.id.into());
} else {
break 'lines;
}
if let Some(next) = text_node_data.get(current_node_idx) {
current_to = next.to;
current_node_id = LT::NodeId::from(next.id.into());
} else {
break 'lines;
}
}

let size = geo::Size {
width: run.advance(),
height,
};

let coords = grun.normalized_coords().to_owned();
let size = geo::Size {
width: run.advance(),
height,
};

let coords = grun.normalized_coords().to_owned();

let text_layout = TextLayout {
size,
font_size: fs,
font: Font(grun.font().clone()),
glyphs,
coords,
};

let Some(node) = tree.0.get_node(current_node_id) else {
continue;
};

node.set_text_layout(text_layout);

let size = Size {
width: size.width,
height: size.height,
};

if current_node_id.into() == 160 {
println!("current_node_id: {:?}", current_node_id.into());
println!("size: {:?}", size);

println!(
"location: {:?}",
Point {
x: run.offset(),
y: run_y,
}
);
}

let text_layout = TextLayout {
tree.set_unrounded_layout(
NodeId::new(current_node_id.into()),
&Layout {
size,
font_size: fs,
font: Font(grun.font().clone()),
glyphs,
coords,
};

let Some(node) = tree.0.get_node(current_node_id) else {
continue;
};

node.set_text_layout(text_layout);

let size = Size {
width: size.width,
height: size.height,
};

if current_node_id.into() == 160 {
println!("current_node_id: {:?}", current_node_id.into());
println!("size: {:?}", size);

println!(
"location: {:?}",
Point {
x: run.offset(),
y: run_y,
}
);
}

tree.set_unrounded_layout(
NodeId::new(current_node_id.into()),
&Layout {
size,
content_size: size,
scrollbar_size: Size::ZERO,
border: Rect::ZERO,
location: Point {
x: run.offset(),
y: run_y,
},
order: 0,
padding: Rect::ZERO,
content_size: size,
scrollbar_size: Size::ZERO,
border: Rect::ZERO,
location: Point {
x: run.offset(),
y: run_y,
},
);
order: 0,
padding: Rect::ZERO,
},
);
}
PositionedLayoutItem::InlineBox(inline_box) => {
let id = NodeId::from(inline_box.id);

if inline_box.id == 162 {
println!("inline_box: {:?}", inline_box);
}
PositionedLayoutItem::InlineBox(inline_box) => {
let id = NodeId::from(inline_box.id);

if inline_box.id == 162 {
println!("inline_box: {:?}", inline_box);
}
let size = Size {
width: inline_box.width,
height: inline_box.height,
};

let size = Size {
width: inline_box.width,
height: inline_box.height,
};

tree.set_unrounded_layout(
id,
&Layout {
size,
content_size: size,
scrollbar_size: Size::ZERO,
border: Rect::ZERO,
location: Point {
x: inline_box.x,
y: 0.0,
},
order: 0,
padding: Rect::ZERO,
tree.set_unrounded_layout(
id,
&Layout {
size,
content_size: size,
scrollbar_size: Size::ZERO,
border: Rect::ZERO,
location: Point {
x: inline_box.x,
y: 0.0,
},
);
}
order: 0,
padding: Rect::ZERO,
},
);
}
}
}
Expand Down

0 comments on commit 27811f5

Please sign in to comment.