Prepare to make operation labels more flexible

This commit is contained in:
Hanno Braun 2025-02-05 20:40:31 +01:00
parent d14ba5399e
commit 6d6affee53
2 changed files with 19 additions and 2 deletions

View File

@ -1,4 +1,4 @@
use std::{ops::Deref, rc::Rc};
use std::{fmt, ops::Deref, rc::Rc};
use super::tri_mesh::TriMesh;
@ -15,6 +15,23 @@ pub trait Operation {
fn display(&self) -> &'static str;
fn tri_mesh(&self) -> TriMesh;
fn children(&self) -> Vec<AnyOp>;
fn label(&self) -> OperationDisplay
where
Self: Sized,
{
OperationDisplay { op: self as &_ }
}
}
pub struct OperationDisplay<'r> {
pub op: &'r dyn Operation,
}
impl fmt::Display for OperationDisplay<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.op.display())
}
}
#[derive(Debug, Eq, Ord, PartialEq, PartialOrd)]

View File

@ -91,7 +91,7 @@ impl TextRenderer {
write!(line, "\t")?;
}
write!(line, "{}", op.display())?;
write!(line, "{}", op.label())?;
buffer.lines.push(glyphon::BufferLine::new(
line,