Pass a &mut BlockContext when rendering blocks

This wraps and derefs to `RenderContext<Editor>`, so that we can
easily use `MouseEventHandler`s in blocks.
This commit is contained in:
Antonio Scandurra
2022-05-31 15:50:34 +02:00
parent 9fa03b2f28
commit aefdde66a6
4 changed files with 83 additions and 82 deletions
+16 -8
View File
@@ -755,6 +755,12 @@ impl EditorElement {
line_layouts: &[text_layout::Line],
cx: &mut LayoutContext,
) -> Vec<(u32, ElementBox)> {
let editor = if let Some(editor) = self.view.upgrade(cx) {
editor
} else {
return Default::default();
};
let scroll_x = snapshot.scroll_position.x();
snapshot
.blocks_in_range(rows.clone())
@@ -774,14 +780,16 @@ impl EditorElement {
.x_for_index(align_to.column() as usize)
};
block.render(&BlockContext {
cx,
anchor_x,
gutter_padding,
line_height,
scroll_x,
gutter_width,
em_width,
cx.render(&editor, |_, cx| {
block.render(&mut BlockContext {
cx,
anchor_x,
gutter_padding,
line_height,
scroll_x,
gutter_width,
em_width,
})
})
}
TransformBlock::ExcerptHeader {