-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBeginEnd.go
187 lines (176 loc) · 6.96 KB
/
BeginEnd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
package implot
// #include <stdlib.h>
// #include "wrapper/BeginEnd.h"
import "C"
import (
"unsafe"
"github.com/inkyblackness/imgui-go/v4"
)
// BeginPlot starts a 2D plotting context with only the title specified.
// It calls BeginPlotV(title, Vec2{-1, 0}, Flags_None).
//
// If this function returns true, then EndPlot() MUST be called! You can do:
// if igwrap.BeginPlot(...) {
// igwrap.PlotXXX(...)
// ...
// igwrap.EndPlot()
// }
//
// Note that:
// - title must be unique to the current ImGui ID scope. If you need
// to avoid ID collisions or don't want to display a title in the plot,
// use double hashes (e.g. "MyPlot##HiddenIdText" or "##NoTitle").
// - size is the **frame** size of the plot widget, not the plot area.
// The default size of plots (i.e. when ImVec2(0,0)) can be modified
// in your ImPlotStyle.
func BeginPlot(title string) bool {
return BeginPlotV(title, imgui.Vec2{X: -1, Y: 0}, Flags_None)
}
// BeginPlotV starts a 2D plotting context with all the parameters specified.
//
// If this function returns true, then EndPlot() MUST be called! You can do:
// if igwrap.BeginPlot(...) {
// igwrap.PlotXXX(...)
// ...
// igwrap.EndPlot()
// }
//
// Note that:
// - title must be unique to the current ImGui ID scope. If you need
// to avoid ID collisions or don't want to display a title in the plot,
// use double hashes (e.g. "MyPlot##HiddenIdText" or "##NoTitle").
// - size is the **frame** size of the plot widget, not the plot area.
// The default size of plots (i.e. when ImVec2(0,0)) can be modified
// in your ImPlotStyle.
func BeginPlotV(title string, size imgui.Vec2, flags Flags) bool {
ctitle := C.CString(title)
defer C.free(unsafe.Pointer(ctitle))
return bool(C.igpBeginPlot(ctitle, wrapVec2(size), C.igpFlags(flags)))
}
// EndPlot marks the end of an active plot.
//
// Only call EndPlot() if BeginPlot() returns true! Typically called at the end
// of an if statement conditioned on BeginPlot(). See example above.
func EndPlot() {
C.igpEndPlot()
// Discard temp data
// from Setup.go:69
for k := range axisFormatCb {
delete(axisFormatCb, k)
}
for _, f := range axisEndPlotCb {
f()
}
axisEndPlotCb = axisEndPlotCb[0:0]
}
// BeginSubplots starts a subdivided plotting context with onle the required parameters.
// It calls BeginSubplotsV(title, rows, cols, Vec2{-1, 0}, SubplotFlags_None, nil, nil).
//
// If the function returns true, EndSubplots() MUST be called! Call BeginPlot/EndPlot
// AT MOST [rows*cols] times in between the begining and end of the subplot context.
// Plots are added in row major order. Example:
//
// if BeginSubplots("My Subplot",2,3) {
// for i := 0; i < 6; i++ {
// if BeginPlot(...) {
// PlotLine(...);
// ...
// EndPlot();
// }
// }
// EndSubplots();
// }
//
// Produces:
//
// [0] | [1] | [2]
// ----|-----|----
// [3] | [4] | [5]
//
// Important notes:
//
// - #title must be unique to the current ImGui ID scope. If you need to avoid ID
// collisions or don't want to display a title in the plot, use double hashes
// (e.g. "MySubplot##HiddenIdText" or "##NoTitle").
// - #rows and #cols must be greater than 0.
// - #size is the size of the entire grid of subplots, not the individual plots
// - #row_ratios and #col_ratios must have AT LEAST #rows and #cols elements,
// respectively. These are the sizes of the rows and columns expressed in ratios.
// If the user adjusts the dimensions, the arrays are updated with new ratios.
//
// Important notes regarding BeginPlot from inside of BeginSubplots:
//
// - The #title parameter of _BeginPlot_ (see above) does NOT have to be
// unique when called inside of a subplot context. Subplot IDs are hashed
// for your convenience so you don't have call PushID or generate unique title
// strings. Simply pass an empty string to BeginPlot unless you want to title
// each subplot.
// - The #size parameter of _BeginPlot_ (see above) is ignored when inside of a
// subplot context. The actual size of the subplot will be based on the
// #size value you pass to _BeginSubplots_ and #row/#col_ratios if provided.
func BeginSubplots(title string, rows, cols int) bool {
return BeginSubplotsV(title, rows, cols, imgui.Vec2{X: -1, Y: 0}, SubplotFlags_None, nil, nil)
}
// BeginSubplotsV starts a subdivided plotting context with all parameters.
//
// If the function returns true, EndSubplots() MUST be called! Call BeginPlot/EndPlot
// AT MOST [rows*cols] times in between the begining and end of the subplot context.
// Plots are added in row major order. Example:
//
// if BeginSubplots("My Subplot",2,3) {
// for i := 0; i < 6; i++ {
// if BeginPlot(...) {
// PlotLine(...);
// ...
// EndPlot();
// }
// }
// EndSubplots();
// }
//
// Produces:
//
// [0] | [1] | [2]
// ----|-----|----
// [3] | [4] | [5]
//
// Important notes:
//
// - #title must be unique to the current ImGui ID scope. If you need to avoid ID
// collisions or don't want to display a title in the plot, use double hashes
// (e.g. "MySubplot##HiddenIdText" or "##NoTitle").
// - #rows and #cols must be greater than 0.
// - #size is the size of the entire grid of subplots, not the individual plots
// - #row_ratios and #col_ratios must have AT LEAST #rows and #cols elements,
// respectively. These are the sizes of the rows and columns expressed in ratios.
// If the user adjusts the dimensions, the arrays are updated with new ratios.
//
// Important notes regarding BeginPlot from inside of BeginSubplots:
//
// - The #title parameter of _BeginPlot_ (see above) does NOT have to be
// unique when called inside of a subplot context. Subplot IDs are hashed
// for your convenience so you don't have call PushID or generate unique title
// strings. Simply pass an empty string to BeginPlot unless you want to title
// each subplot.
// - The #size parameter of _BeginPlot_ (see above) is ignored when inside of a
// subplot context. The actual size of the subplot will be based on the
// #size value you pass to _BeginSubplots_ and #row/#col_ratios if provided.
func BeginSubplotsV(title string, rows, cols int, size imgui.Vec2, flags SubplotFlags, rowRatios, colRatios []float32) bool {
var rf, cf *C.float
if rowRatios != nil && len(rowRatios) >= rows {
rf = (*C.float)(unsafe.Pointer(&rowRatios[0]))
}
if colRatios != nil && len(colRatios) >= cols {
cf = (*C.float)(unsafe.Pointer(&colRatios[0]))
}
ctitle := C.CString(title)
defer C.free(unsafe.Pointer(ctitle))
return bool(C.igpBeginSubplots(ctitle, C.int(rows), C.int(cols), wrapVec2(size), C.igpSubplotFlags(flags), rf, cf))
}
// EndSubplots marks the end of a subdivided plotting area.
//
// Only call EndSubplots() if BeginSubplots() returns true! Typically called at the end
// of an if statement conditioned on BeginSublots(). See example above.
func EndSubplots() {
C.igpEndSubplots()
}