OpenPine C++ API
C++ wrapper for the OpenPine Pine Script VM
Loading...
Searching...
No Matches
table.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
24class TableCell {
25 private:
26 const ffi::TableCell* p_;
27
28 public:
29 TableCell(const ffi::TableCell* p) : p_(p) {}
30
34 std::string_view text() const {
35 ffi::PineStringRef ref;
36 ffi::tableCellText(p_, &ref);
37 return detail::refToView(ref);
38 }
39
43 float width() const { return ffi::tableCellWidth(p_); }
44
48 float height() const { return ffi::tableCellHeight(p_); }
49
53 std::optional<uint32_t> textColor() const {
54 uint32_t v;
55 if (ffi::tableCellTextColor(p_, &v)) {
56 return v;
57 } else {
58 return std::nullopt;
59 }
60 }
61
65 HorizontalAlign textHalign() const { return ffi::tableCellTextHalign(p_); }
66
70 VerticalAlign textValign() const { return ffi::tableCellTextValign(p_); }
71
75 uint32_t textSize() const { return ffi::tableCellTextSize(p_); }
76
80 std::optional<uint32_t> backgroundColor() const {
81 uint32_t v;
82 if (ffi::tableCellBackgroundColor(p_, &v)) {
83 return v;
84 } else {
85 return std::nullopt;
86 }
87 }
88
92 std::optional<std::string_view> tooltip() const {
93 ffi::PineStringRef ref;
94 if (ffi::tableCellTooltip(p_, &ref)) {
95 return detail::refToView(ref);
96 } else {
97 return std::nullopt;
98 }
99 }
100
104 FontFamily textFontFamily() const { return ffi::tableCellTextFontFamily(p_); }
105
109 TextFormatting textFormatting() const {
110 return ffi::tableCellTextFormatting(p_);
111 }
112
116 uintptr_t colspan() const { return ffi::tableCellColspan(p_); }
117
121 uintptr_t rowspan() const { return ffi::tableCellRowspan(p_); }
122};
123
127class Table {
128 private:
129 const ffi::Table* p_;
130
131 public:
132 Table(const ffi::Table* p) : p_(p) {}
133
137 TablePosition position() const { return ffi::tablePosition(p_); }
138
142 uintptr_t numColumns() const { return ffi::tableNumColumns(p_); }
143
147 uintptr_t numRows() const { return ffi::tableNumRows(p_); }
148
152 std::optional<uint32_t> backgroundColor() const {
153 uint32_t v;
154 if (ffi::tableBackgroundColor(p_, &v)) {
155 return v;
156 } else {
157 return std::nullopt;
158 }
159 }
160
164 std::optional<uint32_t> frameColor() const {
165 uint32_t v;
166 if (ffi::tableFrameColor(p_, &v)) {
167 return v;
168 } else {
169 return std::nullopt;
170 }
171 }
172
176 int32_t frameWidth() const { return ffi::tableFrameWidth(p_); }
177
181 std::optional<uint32_t> borderColor() const {
182 uint32_t v;
183 if (ffi::tableBorderColor(p_, &v)) {
184 return v;
185 } else {
186 return std::nullopt;
187 }
188 }
189
193 int32_t borderWidth() const { return ffi::tableBorderWidth(p_); }
194
198 bool forceOverlay() const { return ffi::tableForceOverlay(p_); }
199
203 std::optional<TableCell> cell(uintptr_t row, uintptr_t col) const {
204 const ffi::TableCell* c = ffi::tableCell(p_, row, col);
205 if (c) {
206 return TableCell(c);
207 } else {
208 return std::nullopt;
209 }
210 }
211};
212
213} // namespace graph
214} // namespace openpine
float width() const
Gets the cell width.
Definition table.hpp:43
std::string_view text() const
Gets the cell text.
Definition table.hpp:34
uintptr_t colspan() const
Gets the number of columns spanned.
Definition table.hpp:116
uintptr_t rowspan() const
Gets the number of rows spanned.
Definition table.hpp:121
VerticalAlign textValign() const
Gets the vertical text alignment.
Definition table.hpp:70
TableCell(const ffi::TableCell *p)
Definition table.hpp:29
std::optional< uint32_t > backgroundColor() const
Gets the optional background color.
Definition table.hpp:80
HorizontalAlign textHalign() const
Gets the horizontal text alignment.
Definition table.hpp:65
TextFormatting textFormatting() const
Gets the text formatting (bold/italic).
Definition table.hpp:109
std::optional< uint32_t > textColor() const
Gets the optional cell text color.
Definition table.hpp:53
std::optional< std::string_view > tooltip() const
Gets the optional tooltip.
Definition table.hpp:92
uint32_t textSize() const
Gets the text size.
Definition table.hpp:75
FontFamily textFontFamily() const
Gets the font family.
Definition table.hpp:104
float height() const
Gets the cell height.
Definition table.hpp:48
std::optional< uint32_t > backgroundColor() const
Gets the optional table background color.
Definition table.hpp:152
int32_t frameWidth() const
Gets the frame width.
Definition table.hpp:176
bool forceOverlay() const
Gets whether the table is forced to render as overlay.
Definition table.hpp:198
int32_t borderWidth() const
Gets the border width.
Definition table.hpp:193
std::optional< TableCell > cell(uintptr_t row, uintptr_t col) const
Gets the cell wrapper at row/col.
Definition table.hpp:203
Table(const ffi::Table *p)
Definition table.hpp:132
uintptr_t numRows() const
Gets the number of rows.
Definition table.hpp:147
std::optional< uint32_t > borderColor() const
Gets the optional border color.
Definition table.hpp:181
TablePosition position() const
Gets the table anchor position.
Definition table.hpp:137
std::optional< uint32_t > frameColor() const
Gets the optional table frame color.
Definition table.hpp:164
uintptr_t numColumns() const
Gets the number of columns.
Definition table.hpp:142
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.