Skip to content

Commit 190757e

Browse files
committed
Canvas: Add IMGUIEX_CANVAS_API to support building canvas as a shared library (#189)
1 parent 268e5fe commit 190757e

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

docs/CHANGELOG.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ v0.9.2 (WIP):
44

55
NEW: Editor: Add IMGUI_NODE_EDITOR_API to support building editor as a shared library (#189)
66

7+
NEW: Canvas: Add IMGUIEX_CANVAS_API to support building canvas as a shared library (#189)
8+
79
CHANGE: Editor: Support ImGui r18836 after SetItemUsingMouseWheel removal (#218), thanks @ocornut
810

911
CHANGE: Editor: Define IMGUI_DEFINE_MATH_OPERATORS before <imgui.h> (#209), thanks @ocornut

imgui_canvas.h

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
# include <imgui.h>
5252
# include <imgui_internal.h> // ImRect, ImFloor
5353

54+
#ifndef IMGUIEX_CANVAS_API
55+
#define IMGUIEX_CANVAS_API
56+
#endif
57+
5458
namespace ImGuiEx {
5559

5660
struct CanvasView
@@ -106,64 +110,64 @@ struct Canvas
106110
//
107111
// You can query size of the canvas while it is being drawn
108112
// by calling Rect().
109-
bool Begin(const char* id, const ImVec2& size);
110-
bool Begin(ImGuiID id, const ImVec2& size);
113+
IMGUIEX_CANVAS_API bool Begin(const char* id, const ImVec2& size);
114+
IMGUIEX_CANVAS_API bool Begin(ImGuiID id, const ImVec2& size);
111115

112116
// Ends interaction with canvas plane.
113117
//
114118
// Must be called only when Begin() retuned true.
115-
void End();
119+
IMGUIEX_CANVAS_API void End();
116120

117121
// Sets visible region of canvas plane.
118122
//
119123
// Origin is an offset of infinite plane origin from top left
120124
// corner of the canvas.
121125
//
122126
// Scale greater than 1 make canvas content be bigger, less than 1 smaller.
123-
void SetView(const ImVec2& origin, float scale);
124-
void SetView(const CanvasView& view);
127+
IMGUIEX_CANVAS_API void SetView(const ImVec2& origin, float scale);
128+
IMGUIEX_CANVAS_API void SetView(const CanvasView& view);
125129

126130
// Centers view over specific point on canvas plane.
127131
//
128132
// View will be centered on specific point by changing origin
129133
// but not scale.
130-
void CenterView(const ImVec2& canvasPoint);
134+
IMGUIEX_CANVAS_API void CenterView(const ImVec2& canvasPoint);
131135

132136
// Calculates view over specific point on canvas plane.
133-
CanvasView CalcCenterView(const ImVec2& canvasPoint) const;
137+
IMGUIEX_CANVAS_API CanvasView CalcCenterView(const ImVec2& canvasPoint) const;
134138

135139
// Centers view over specific rectangle on canvas plane.
136140
//
137141
// Whole rectangle will fit in canvas view. This will affect both
138142
// origin and scale.
139-
void CenterView(const ImRect& canvasRect);
143+
IMGUIEX_CANVAS_API void CenterView(const ImRect& canvasRect);
140144

141145
// Calculates view over specific rectangle on canvas plane.
142-
CanvasView CalcCenterView(const ImRect& canvasRect) const;
146+
IMGUIEX_CANVAS_API CanvasView CalcCenterView(const ImRect& canvasRect) const;
143147

144148
// Suspends canvas by returning to normal ImGui transformation space.
145149
// While suspended UI will not be drawn on canvas plane.
146150
//
147151
// Calls to Suspend()/Resume() are symetrical. Each call to Suspend()
148152
// must be matched with call to Resume().
149-
void Suspend();
150-
void Resume();
153+
IMGUIEX_CANVAS_API void Suspend();
154+
IMGUIEX_CANVAS_API void Resume();
151155

152156
// Transforms point from canvas plane to ImGui.
153-
ImVec2 FromLocal(const ImVec2& point) const;
154-
ImVec2 FromLocal(const ImVec2& point, const CanvasView& view) const;
157+
IMGUIEX_CANVAS_API ImVec2 FromLocal(const ImVec2& point) const;
158+
IMGUIEX_CANVAS_API ImVec2 FromLocal(const ImVec2& point, const CanvasView& view) const;
155159

156160
// Transforms vector from canvas plant to ImGui.
157-
ImVec2 FromLocalV(const ImVec2& vector) const;
158-
ImVec2 FromLocalV(const ImVec2& vector, const CanvasView& view) const;
161+
IMGUIEX_CANVAS_API ImVec2 FromLocalV(const ImVec2& vector) const;
162+
IMGUIEX_CANVAS_API ImVec2 FromLocalV(const ImVec2& vector, const CanvasView& view) const;
159163

160164
// Transforms point from ImGui to canvas plane.
161-
ImVec2 ToLocal(const ImVec2& point) const;
162-
ImVec2 ToLocal(const ImVec2& point, const CanvasView& view) const;
165+
IMGUIEX_CANVAS_API ImVec2 ToLocal(const ImVec2& point) const;
166+
IMGUIEX_CANVAS_API ImVec2 ToLocal(const ImVec2& point, const CanvasView& view) const;
163167

164168
// Transforms vector from ImGui to canvas plane.
165-
ImVec2 ToLocalV(const ImVec2& vector) const;
166-
ImVec2 ToLocalV(const ImVec2& vector, const CanvasView& view) const;
169+
IMGUIEX_CANVAS_API ImVec2 ToLocalV(const ImVec2& vector) const;
170+
IMGUIEX_CANVAS_API ImVec2 ToLocalV(const ImVec2& vector, const CanvasView& view) const;
167171

168172
// Returns widget bounds.
169173
//
@@ -175,7 +179,7 @@ struct Canvas
175179
const ImRect& ViewRect() const { return m_ViewRect; }
176180

177181
// Calculates visible region for view.
178-
ImRect CalcViewRect(const CanvasView& view) const;
182+
IMGUIEX_CANVAS_API ImRect CalcViewRect(const CanvasView& view) const;
179183

180184
// Returns current view.
181185
const CanvasView& View() const { return m_View; }

0 commit comments

Comments
 (0)