pub struct Block {
id: usize,
rows: usize,
contains: (Option<usize>, Option<usize>),
expanded: bool,
typ: String,
lbl: String,
inputs: Vec<Option<String>>,
outputs: Vec<Option<String>>,
color: usize,
}
Expand description
This structure represents a block inside the BlockArea of a BlockFun. It stores everything required for calculating a node of the AST.
A BlockType::instanciate_block is used to create a new instance of this structure.
You usually don’t use this structure directly, but you use the
position of it inside the BlockFun. The position of a block
is specified by the area_id
, and the x
and y
coordinates.
Fields
id: usize
An ID to track this block.
rows: usize
How many rows this block spans. A Block can only be 1 cell wide.
contains: (Option<usize>, Option<usize>)
Up to two sub BlockArea can be specified here by their ID.
expanded: bool
Whether the sub areas are visible/drawn.
typ: String
The type of this block. It’s just a string set by the BlockType and it should be everything that determines what this block is going to end up as in the AST.
lbl: String
The label of the block.
inputs: Vec<Option<String>>
outputs: Vec<Option<String>>
color: usize
The color index of this block.
Implementations
sourceimpl Block
impl Block
pub fn clone_with_new_id(&self, new_id: usize) -> Self
sourcepub fn shift_port(&mut self, idx: usize, output: bool)
pub fn shift_port(&mut self, idx: usize, output: bool)
Takes the (input) port at row idx
and pushed it one row further
down, wrapping around at the end. If output
is true, the
output port at idx
is shifted.
sourcepub fn for_output_ports<F: FnMut(usize, &str)>(&self, f: F)
pub fn for_output_ports<F: FnMut(usize, &str)>(&self, f: F)
Calls f
for every output port that is available.
f
gets passed the row index.
sourcepub fn count_outputs(&self) -> usize
pub fn count_outputs(&self) -> usize
Returns the number of output ports of this Block.
sourcepub fn for_input_ports<F: FnMut(usize, &str)>(&self, f: F)
pub fn for_input_ports<F: FnMut(usize, &str)>(&self, f: F)
Calls f
for every input port that is available.
f
gets passed the row index.
sourcepub fn for_input_ports_reverse<F: FnMut(usize, &str)>(&self, f: F)
pub fn for_input_ports_reverse<F: FnMut(usize, &str)>(&self, f: F)
Calls f
for every input port that is available.
f
gets passed the row index.
sourcepub fn serialize(&self) -> Value
pub fn serialize(&self) -> Value
Serializes this Block into a Value. Called by BlockArea::serialize.
sourcepub fn deserialize(v: &Value) -> Result<Box<Block>, Error>
pub fn deserialize(v: &Value) -> Result<Box<Block>, Error>
Deserializes this Block from a Value. Called by BlockArea::deserialize.