openpine_vm/visuals/
label.rs

1use openpine_compiler::instructions::Color;
2use openpine_macros::Enum;
3use serde::{Deserialize, Serialize};
4
5use crate::visuals::{FontFamily, HorizontalAlign, TextFormatting, XLocation, YLocation};
6
7/// Label shape/style.
8#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Enum, Serialize, Deserialize)]
9#[openpine(rename_all = "snake")]
10pub enum LabelStyle {
11    /// No label shape.
12    None,
13    /// Down arrow.
14    #[openpine(name = "arrowdown")]
15    ArrowDown,
16    /// Up arrow.
17    #[openpine(name = "arrowup")]
18    ArrowUp,
19    /// Circle.
20    Circle,
21    /// Cross.
22    Cross,
23    /// Diamond.
24    Diamond,
25    /// Flag.
26    Flag,
27    /// Centered label.
28    LabelCenter,
29    /// Label below the bar.
30    #[default]
31    LabelDown,
32    /// Label to the left.
33    LabelLeft,
34    /// Label in the lower-left corner.
35    LabelLowerLeft,
36    /// Label in the lower-right corner.
37    LabelLowerRight,
38    /// Label to the right.
39    LabelRight,
40    /// Label above the bar.
41    LabelUp,
42    /// Label in the upper-left corner.
43    LabelUpperLeft,
44    /// Label in the upper-right corner.
45    LabelUpperRight,
46    /// Square.
47    Square,
48    /// Text outline.
49    TextOutline,
50    /// Down-pointing triangle.
51    #[openpine(name = "triangledown")]
52    TriangleDown,
53    /// Up-pointing triangle.
54    #[openpine(name = "triangleup")]
55    TriangleUp,
56    /// X-cross.
57    #[openpine(name = "xcross")]
58    XCross,
59}
60
61/// A label visual primitive.
62#[derive(Debug, Clone, Serialize, Deserialize)]
63pub struct Label {
64    /// X position.
65    pub x: i64,
66    /// Y position.
67    pub y: f64,
68    /// Label text.
69    pub text: String,
70    /// X axis reference.
71    pub xloc: XLocation,
72    /// Y axis reference.
73    pub yloc: YLocation,
74    /// Optional background color.
75    pub color: Option<Color>,
76    /// Label shape.
77    pub style: LabelStyle,
78    /// Optional text color.
79    pub text_color: Option<Color>,
80    /// Text size.
81    pub size: u32,
82    /// Horizontal text alignment.
83    pub text_align: HorizontalAlign,
84    /// Optional tooltip.
85    pub tooltip: Option<String>,
86    /// Font family.
87    pub text_font_family: FontFamily,
88    /// Whether to force overlay rendering.
89    pub force_overlay: bool,
90    /// Text formatting options.
91    pub text_formatting: TextFormatting,
92}