pub struct YamlGraph { /* private fields */ }Expand description
A graph kept in a YAML file: the editor’s model, changed by
apply, written back by text.
use egui_pop_viewport::graph::yaml::YamlGraph;
use egui_pop_viewport::graph::{Edit, GraphModel, Moved};
let src = "nodes:\n - id: a # the first\n pos: [0, 0]\n";
let mut graph = YamlGraph::parse(src).unwrap();
assert_eq!(graph.text(), src);
graph.apply(&Edit::Move {
moves: vec![Moved { node: "a".into(), from: [0.0, 0.0], to: [40.0, 10.0] }],
});
assert_eq!(graph.text(), "nodes:\n - id: a # the first\n pos: [40, 10]\n");
assert_eq!(graph.nodes()[0].pos, [40.0, 10.0]);Implementations§
Source§impl YamlGraph
impl YamlGraph
Sourcepub fn empty() -> YamlGraph
pub fn empty() -> YamlGraph
A graph without nodes, its file stamped with FORMAT_VERSION.
Sourcepub fn parse(text: &str) -> Result<YamlGraph, YamlGraphError>
pub fn parse(text: &str) -> Result<YamlGraph, YamlGraphError>
Reads a graph file. Its text is kept as it is: text
gives it back byte for byte until an edit.
Sourcepub fn version(&self) -> u64
pub fn version(&self) -> u64
The format version the file is stamped with (FORMAT_VERSION
without a stamp).
Sourcepub fn warnings(&self) -> &[String]
pub fn warnings(&self) -> &[String]
What reading the file noticed without failing (a stamp newer than this egui-pop knows).
Sourcepub fn apply(&mut self, edit: &Edit) -> bool
pub fn apply(&mut self, edit: &Edit) -> bool
Applies an edit: the one place the graph changes. Returns whether it did (an edit naming a node, port or parameter the file does not have, or a kind it does not declare, changes nothing).
The text changes only where the edit lands: a moved node’s pos,
a parameter’s value, the items of the nodes and wires deleted, new
items after the last of their list. A part that is not in block
style (a flow mapping or sequence) is written again whole, in
block style, when an edit reaches into it; comments inside it are
lost.
Each edit is one gesture (a drag’s Move comes at its end; a
slider’s frames come with done: false): an application that
keeps an undo history records text before an edit
and reads it back to undo.
Trait Implementations§
Source§impl GraphModel for YamlGraph
impl GraphModel for YamlGraph
Auto Trait Implementations§
impl Freeze for YamlGraph
impl RefUnwindSafe for YamlGraph
impl Send for YamlGraph
impl Sync for YamlGraph
impl Unpin for YamlGraph
impl UnsafeUnpin for YamlGraph
impl UnwindSafe for YamlGraph
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<F, T, S> SimdInto<T, S> for Fwhere
T: SimdFrom<F, S>,
S: Simd,
impl<F, T, S> SimdInto<T, S> for Fwhere
T: SimdFrom<F, S>,
S: Simd,
§impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
§fn to_owned_obj(&self, data: FontData<'_>) -> U
fn to_owned_obj(&self, data: FontData<'_>) -> U
T, using the provided data to resolve any offsets.