Introduce a new BlockStyle field for blocks
This new field allows blocks to specify how they want to be laid out: - If `Fixed` they can take up all the width they want and they will impact the scroll width of the editor. This is useful for diagnostic messages and allows scrolling the editor further to the right to visualize the entire message. - If `Flex` they can extend all the way to the scroll width without impacting it any further. This is useful for the rename editor that we insert as a block decoration when hitting `F2`. - If `Sticky`, they will be as wide as the editor element and won't participate in the horizontal scrolling of the editor. This is useful for headers in general, where we want e.g. the filename and the jump button to always be visible independently of how much the user has scrolled to the right.
This commit is contained in:
@@ -56,6 +56,7 @@ pub struct Block {
|
||||
id: BlockId,
|
||||
position: Anchor,
|
||||
height: u8,
|
||||
style: BlockStyle,
|
||||
render: Mutex<RenderBlock>,
|
||||
disposition: BlockDisposition,
|
||||
}
|
||||
@@ -67,10 +68,18 @@ where
|
||||
{
|
||||
pub position: P,
|
||||
pub height: u8,
|
||||
pub style: BlockStyle,
|
||||
pub render: Arc<dyn Fn(&mut BlockContext) -> ElementBox>,
|
||||
pub disposition: BlockDisposition,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
|
||||
pub enum BlockStyle {
|
||||
Fixed,
|
||||
Flex,
|
||||
Sticky,
|
||||
}
|
||||
|
||||
pub struct BlockContext<'a, 'b> {
|
||||
pub cx: &'b mut RenderContext<'a, crate::Editor>,
|
||||
pub anchor_x: f32,
|
||||
@@ -513,6 +522,7 @@ impl<'a> BlockMapWriter<'a> {
|
||||
height: block.height,
|
||||
render: Mutex::new(block.render),
|
||||
disposition: block.disposition,
|
||||
style: block.style,
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -940,6 +950,10 @@ impl Block {
|
||||
pub fn position(&self) -> &Anchor {
|
||||
&self.position
|
||||
}
|
||||
|
||||
pub fn style(&self) -> BlockStyle {
|
||||
self.style
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for Block {
|
||||
@@ -1018,18 +1032,21 @@ mod tests {
|
||||
let mut writer = block_map.write(wraps_snapshot.clone(), Default::default());
|
||||
let block_ids = writer.insert(vec![
|
||||
BlockProperties {
|
||||
style: BlockStyle::Fixed,
|
||||
position: buffer_snapshot.anchor_after(Point::new(1, 0)),
|
||||
height: 1,
|
||||
disposition: BlockDisposition::Above,
|
||||
render: Arc::new(|_| Empty::new().named("block 1")),
|
||||
},
|
||||
BlockProperties {
|
||||
style: BlockStyle::Fixed,
|
||||
position: buffer_snapshot.anchor_after(Point::new(1, 2)),
|
||||
height: 2,
|
||||
disposition: BlockDisposition::Above,
|
||||
render: Arc::new(|_| Empty::new().named("block 2")),
|
||||
},
|
||||
BlockProperties {
|
||||
style: BlockStyle::Fixed,
|
||||
position: buffer_snapshot.anchor_after(Point::new(3, 3)),
|
||||
height: 3,
|
||||
disposition: BlockDisposition::Below,
|
||||
@@ -1183,12 +1200,14 @@ mod tests {
|
||||
let mut writer = block_map.write(wraps_snapshot.clone(), Default::default());
|
||||
writer.insert(vec![
|
||||
BlockProperties {
|
||||
style: BlockStyle::Fixed,
|
||||
position: buffer_snapshot.anchor_after(Point::new(1, 12)),
|
||||
disposition: BlockDisposition::Above,
|
||||
render: Arc::new(|_| Empty::new().named("block 1")),
|
||||
height: 1,
|
||||
},
|
||||
BlockProperties {
|
||||
style: BlockStyle::Fixed,
|
||||
position: buffer_snapshot.anchor_after(Point::new(1, 1)),
|
||||
disposition: BlockDisposition::Below,
|
||||
render: Arc::new(|_| Empty::new().named("block 2")),
|
||||
@@ -1286,6 +1305,7 @@ mod tests {
|
||||
height
|
||||
);
|
||||
BlockProperties {
|
||||
style: BlockStyle::Fixed,
|
||||
position,
|
||||
height,
|
||||
disposition,
|
||||
|
||||
Reference in New Issue
Block a user