OpenPine C++ API
C++ wrapper for the OpenPine Pine Script VM
Loading...
Searching...
No Matches
label.hpp
Go to the documentation of this file.
1#pragma once
2
7
8#if (defined(_MSVC_LANG) ? _MSVC_LANG : __cplusplus) < 201703L
9#error \
10 "OpenPine C++ wrapper headers require C++17 (std::optional, std::string_view)."
11#endif
12
13#include <cstdint>
14#include <optional>
15#include <string_view>
16
17#include "../ffi.hpp"
18#include "../string_ref.hpp"
19#include "../types.hpp"
20
21namespace openpine {
22namespace graph {
23
27class Label {
28 private:
29 const ffi::Label* p_;
30
31 public:
32 Label(const ffi::Label* p) : p_(p) {}
33
37 int64_t x() const { return ffi::labelX(p_); }
38
42 double y() const { return ffi::labelY(p_); }
43
47 std::string_view text() const {
48 ffi::PineStringRef ref;
49 ffi::labelText(p_, &ref);
50 return detail::refToView(ref);
51 }
52
56 XLocation xloc() const { return ffi::labelXloc(p_); }
57
61 YLocation yloc() const { return ffi::labelYloc(p_); }
62
66 std::optional<uint32_t> color() const {
67 uint32_t v;
68 if (ffi::labelColor(p_, &v)) {
69 return v;
70 } else {
71 return std::nullopt;
72 }
73 }
74
78 LabelStyle style() const { return ffi::labelStyle(p_); }
79
83 std::optional<uint32_t> textColor() const {
84 uint32_t v;
85 if (ffi::labelTextColor(p_, &v)) {
86 return v;
87 } else {
88 return std::nullopt;
89 }
90 }
91
95 uint32_t size() const { return ffi::labelSize(p_); }
96
100 HorizontalAlign textAlign() const { return ffi::labelTextAlign(p_); }
101
105 std::optional<std::string_view> tooltip() const {
106 ffi::PineStringRef ref;
107 if (ffi::labelTooltip(p_, &ref)) {
108 return detail::refToView(ref);
109 } else {
110 return std::nullopt;
111 }
112 }
113
117 FontFamily textFontFamily() const { return ffi::labelTextFontFamily(p_); }
118
122 TextFormatting textFormatting() const { return ffi::labelTextFormatting(p_); }
123
127 bool forceOverlay() const { return ffi::labelForceOverlay(p_); }
128};
129
130} // namespace graph
131} // namespace openpine
FontFamily textFontFamily() const
Gets the font family.
Definition label.hpp:117
bool forceOverlay() const
Gets whether the label is forced to render as overlay.
Definition label.hpp:127
uint32_t size() const
Gets the label text size.
Definition label.hpp:95
std::optional< std::string_view > tooltip() const
Gets the optional tooltip.
Definition label.hpp:105
TextFormatting textFormatting() const
Gets the text formatting (bold/italic).
Definition label.hpp:122
XLocation xloc() const
Gets the X-axis coordinate system used by x().
Definition label.hpp:56
std::optional< uint32_t > color() const
Gets the optional label background color.
Definition label.hpp:66
std::optional< uint32_t > textColor() const
Gets the optional label text color.
Definition label.hpp:83
HorizontalAlign textAlign() const
Gets the horizontal text alignment.
Definition label.hpp:100
std::string_view text() const
Gets the label text.
Definition label.hpp:47
LabelStyle style() const
Gets the label shape/style.
Definition label.hpp:78
int64_t x() const
Gets the label X position.
Definition label.hpp:37
Label(const ffi::Label *p)
Definition label.hpp:32
double y() const
Gets the label Y position.
Definition label.hpp:42
YLocation yloc() const
Gets the Y-axis coordinate system used by y().
Definition label.hpp:61
std::string_view refToView(const ffi::PineStringRef &ref)
Shared helpers for converting C ABI string refs to std::string_view.
Re-exports FFI types into the openpine namespace.