Skip to main content

blockworx/document/
label.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Copy, Clone, PartialEq, Eq, Default, Debug, Serialize, Deserialize)]
4pub enum LabelSide {
5    Top,
6    Center,
7    #[default]
8    Bottom,
9}
10
11/// A user-editable text label attached to a block. The block's title (the source
12/// of truth for its name) and its type label are both `BlockLabel`s; the only
13/// difference is how each is anchored when drawn.
14#[derive(Clone, PartialEq, Default, Debug, Serialize, Deserialize)]
15pub struct BlockLabel {
16    pub name: String,
17    /// Whether this label is hidden (not drawn). Kept beside `name` since it
18    /// governs it. The flag lives on `BlockLabel` so a title-visibility toggle
19    /// can reuse it later.
20    pub hidden: bool,
21    pub side: LabelSide,
22    pub offset: f32,
23}
24
25impl BlockLabel {
26    /// Empty label parked in the upper-left corner. Used as the default for a
27    /// block's type label, which is left-anchored (see `block_type_position`).
28    pub fn upper_left() -> Self {
29        Self {
30            name: String::new(),
31            hidden: false,
32            side: LabelSide::Top,
33            offset: 0.0,
34        }
35    }
36}