Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

Additional ImGui functions #81

Merged
merged 4 commits into from
Feb 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 101 additions & 1 deletion DrawList.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package imgui

// #include "DrawListWrapper.h"
import "C"
import "unsafe"
import (
"unsafe"
)

// DrawList is a draw-command list.
// This is the low-level list of polygons that ImGui functions are filling.
Expand Down Expand Up @@ -83,3 +85,101 @@ func (list DrawList) IndexBuffer() (unsafe.Pointer, int) {

return data, int(size)
}

// WindowDrawList returns the DrawList for the current window.
func WindowDrawList() DrawList {
return DrawList(C.iggGetWindowDrawList())
}

// List of DrawCornerFlags
const (
DrawCornerFlagsNone = 0 << iota
DrawCornerFlagsTopLeft
DrawCornerFlagsTopRight
DrawCornerFlagsBotLeft
DrawCornerFlagsBotRight
DrawCornerFlagsTop = DrawCornerFlagsTopLeft | DrawCornerFlagsTopRight
DrawCornerFlagsBot = DrawCornerFlagsBotLeft | DrawCornerFlagsBotRight
DrawCornerFlagsLeft = DrawCornerFlagsTopLeft | DrawCornerFlagsBotLeft
DrawCornerFlagsRight = DrawCornerFlagsTopRight | DrawCornerFlagsBotRight
DrawCornerFlagsAll = 0x0f
)

// AddRect calls AddRectV with rounding and thickness values of 1.0 and
// DrawCornerFlagsAll
func (list DrawList) AddRect(min Vec2, max Vec2, col uint32) {
list.AddRectV(min, max, col, 1.0, DrawCornerFlagsAll, 1.0)
}

// AddRectV adds a rectangle to draw list. min is the upper-left corner of the
// rectangle, and max is the lower right corner. rectangles with dimensions of
// 1 pixel are not rendererd properly.
//
// drawCornerFlags indicate which corners of the rectanble are to be rounded.
func (list DrawList) AddRectV(min Vec2, max Vec2, col uint32, rounding float32, drawCornerFlags int, thickness float32) {
minArg, _ := min.wrapped()
maxArg, _ := max.wrapped()
C.iggAddRect(list.handle(), minArg, maxArg, C.ImU32(col), C.float(rounding), C.int(drawCornerFlags), C.float(thickness))
}

// AddRectFilled calls AddRectFilledV with a radius value of 1.0 and
// DrawCornerFlagsAll
func (list DrawList) AddRectFilled(min Vec2, max Vec2, col uint32) {
list.AddRectFilledV(min, max, col, 1.0, DrawCornerFlagsAll)
}

// AddRectFilledV adds a filled rectangle to the draw list. min is the
// upper-left corner of the rectangle, and max is the lower right corner.
// rectangles with dimensions of 1 pixel are not rendererd properly.
func (list DrawList) AddRectFilledV(min Vec2, max Vec2, col uint32, rounding float32, drawCornerFlags int) {
minArg, _ := min.wrapped()
maxArg, _ := max.wrapped()
C.iggAddRectFilled(list.handle(), minArg, maxArg, C.ImU32(col), C.float(rounding), C.int(drawCornerFlags))
}

// AddCircleFilled calls addCircleFilledV with a numSegments value of 12
func (list DrawList) AddCircleFilled(center Vec2, radius float32, col uint32) {
list.AddCircleFilledV(center, radius, col, 12)
}

// AddCircleFilledV adds a filled circle to the draw list. min is the
// upper-left corner of the rectangle, and max is the lower right corner.
func (list DrawList) AddCircleFilledV(center Vec2, radius float32, col uint32, numSegments int) {
centerArg, _ := center.wrapped()
C.iggAddCircleFilled(list.handle(), centerArg, C.float(radius), C.ImU32(col), C.int(numSegments))
}

// AddCircle calls addCircleV with a numSegments value of 12
func (list DrawList) AddCircle(center Vec2, radius float32, col uint32) {
list.AddCircleV(center, radius, col, 12, 1.0)
}

// AddCircleV adds a unfilled circle to the draw list. min is the upper-left
// corner of the rectangle, and max is the lower right corner.
func (list DrawList) AddCircleV(center Vec2, radius float32, col uint32, numSegments int, thickness float32) {
centerArg, _ := center.wrapped()
C.iggAddCircle(list.handle(), centerArg, C.float(radius), C.ImU32(col), C.int(numSegments), C.float(thickness))
}

// AddTriangle calls addTriangleV with a thickness of 1.0
func (list DrawList) AddTriangle(p1 Vec2, p2 Vec2, p3 Vec2, col uint32) {
list.AddTriangleV(p1, p2, p3, col, 1.0)
}

// AddTriangleV adds an unfilled triangle of points p1, p2, p3 to the draw
// list.
func (list DrawList) AddTriangleV(p1 Vec2, p2 Vec2, p3 Vec2, col uint32, thickness float32) {
p1Arg, _ := p1.wrapped()
p2Arg, _ := p2.wrapped()
p3Arg, _ := p3.wrapped()
C.iggAddTriangle(list.handle(), p1Arg, p2Arg, p3Arg, C.ImU32(col), C.float(thickness))
}

// AddTriangleFilled adds an filled triangle of points p1, p2, p3 to the draw
// list.
func (list DrawList) AddTriangleFilled(p1 Vec2, p2 Vec2, p3 Vec2, col uint32) {
p1Arg, _ := p1.wrapped()
p2Arg, _ := p2.wrapped()
p3Arg, _ := p3.wrapped()
C.iggAddTriangleFilled(list.handle(), p1Arg, p2Arg, p3Arg, C.ImU32(col))
}
56 changes: 56 additions & 0 deletions DrawListWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,59 @@ void iggGetVertexBufferLayout(size_t *entrySize, size_t *posOffset, size_t *uvOf
*uvOffset = IM_OFFSETOF(ImDrawVert, uv);
*colOffset = IM_OFFSETOF(ImDrawVert, col);
}

void iggAddRect(IggDrawList handle, IggVec2 const *min, IggVec2 const *max, ImU32 col, float rounding, int flags, float thickness)
{
Vec2Wrapper minArg(min);
Vec2Wrapper maxArg(max);

ImDrawList *list = reinterpret_cast<ImDrawList *>(handle);
list->AddRect(*minArg, *maxArg, col, rounding, flags, thickness);
}

void iggAddRectFilled(IggDrawList handle, IggVec2 const *min, IggVec2 const *max, ImU32 col, float rounding, int flags)
{
Vec2Wrapper minArg(min);
Vec2Wrapper maxArg(max);

ImDrawList *list = reinterpret_cast<ImDrawList *>(handle);
list->AddRectFilled(*minArg, *maxArg, col, rounding, flags);
}

void iggAddCircle(IggDrawList handle, IggVec2 const *center, float radius, ImU32 col, int numSegments, float thickness)
{
Vec2Wrapper centerArg(center);

ImDrawList *list = reinterpret_cast<ImDrawList *>(handle);
list->AddCircle(*centerArg, radius, col, numSegments, thickness);
}

void iggAddCircleFilled(IggDrawList handle, IggVec2 const *center, float radius, ImU32 col, int numSegments)
{
Vec2Wrapper centerArg(center);

ImDrawList *list = reinterpret_cast<ImDrawList *>(handle);
list->AddCircleFilled(*centerArg, radius, col, numSegments);
}

void iggAddTriangle(IggDrawList handle, IggVec2 *p1, IggVec2 *p2, IggVec2 *p3, ImU32 col, float thickness) {
Vec2Wrapper p1Arg(p1);
Vec2Wrapper p2Arg(p2);
Vec2Wrapper p3Arg(p3);

ImDrawList *list = reinterpret_cast<ImDrawList *>(handle);
list->AddTriangle(*p1Arg, *p2Arg, *p3Arg, col, thickness);
}

void iggAddTriangleFilled(IggDrawList handle, IggVec2 *p1, IggVec2 *p2, IggVec2 *p3, ImU32 col) {
Vec2Wrapper p1Arg(p1);
Vec2Wrapper p2Arg(p2);
Vec2Wrapper p3Arg(p3);

ImDrawList *list = reinterpret_cast<ImDrawList *>(handle);
list->AddTriangleFilled(*p1Arg, *p2Arg, *p3Arg, col);
}

IggDrawList iggGetWindowDrawList() {
return static_cast<IggDrawList>(const_cast<ImDrawList *>(ImGui::GetWindowDrawList()));
}
9 changes: 9 additions & 0 deletions DrawListWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ extern void iggDrawListGetRawVertexBuffer(IggDrawList handle, void **data, int *
extern void iggGetIndexBufferLayout(size_t *entrySize);
extern void iggGetVertexBufferLayout(size_t *entrySize, size_t *posOffset, size_t *uvOffset, size_t *colOffset);

extern void iggAddRect(IggDrawList handle, IggVec2 const *min, IggVec2 const *max, ImU32 col, float rounding, int flags, float thickness);
extern void iggAddRectFilled(IggDrawList handle, IggVec2 const *min, IggVec2 const *max, ImU32 col, float rounding, int flags);
extern void iggAddCircle(IggDrawList handle, IggVec2 const *center, float radius, ImU32 col, int numSegments, float thickness);
extern void iggAddCircleFilled(IggDrawList handle, IggVec2 const *center, float radius, ImU32 col, int numSegments);
extern void iggAddTriangle(IggDrawList handle, IggVec2 *p1, IggVec2 *p2, IggVec2 *p3, ImU32 col, float thickness);
extern void iggAddTriangleFilled(IggDrawList handle, IggVec2 *p1, IggVec2 *p2, IggVec2 *p3, ImU32 col);

extern IggDrawList iggGetWindowDrawList();

#ifdef __cplusplus
}
#endif
9 changes: 9 additions & 0 deletions Style.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@ func (style Style) ItemInnerSpacing() Vec2 {
return value
}

// FramePadding is the padding within a framed rectangle (used by most widgets)
func (style Style) FramePadding() Vec2 {
var value Vec2
valueArg, valueFin := value.wrapped()
C.iggStyleGetFramePadding(style.handle(), valueArg)
valueFin()
return value
}

// SetColor sets a color value of the UI style.
func (style Style) SetColor(id StyleColorID, value Vec4) {
valueArg, _ := value.wrapped()
Expand Down
6 changes: 6 additions & 0 deletions StyleWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ void iggStyleGetItemInnerSpacing(IggGuiStyle handle, IggVec2 *value)
exportValue(*value, style->ItemInnerSpacing);
}

void iggStyleGetFramePadding(IggGuiStyle handle, IggVec2 *value)
{
ImGuiStyle *style = reinterpret_cast<ImGuiStyle *>(handle);
exportValue(*value, style->FramePadding);
}

void iggStyleSetColor(IggGuiStyle handle, int colorID, IggVec4 const *value)
{
ImGuiStyle *style = reinterpret_cast<ImGuiStyle *>(handle);
Expand Down
2 changes: 2 additions & 0 deletions StyleWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ extern "C"

extern void iggStyleGetItemInnerSpacing(IggGuiStyle handle, IggVec2 *value);

extern void iggStyleGetFramePadding(IggGuiStyle handle, IggVec2 *value);

extern void iggStyleSetColor(IggGuiStyle handle, int index, IggVec4 const *color);

extern void iggStyleScaleAllSizes(IggGuiStyle handle, float scale);
Expand Down
37 changes: 37 additions & 0 deletions imgui.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,19 @@ func Button(id string) bool {
return ButtonV(id, Vec2{})
}

// InvisibleButtonV returning true if it is pressed.
func InvisibleButtonV(id string, size Vec2) bool {
idArg, idFin := wrapString(id)
defer idFin()
sizeArg, _ := size.wrapped()
return C.iggInvisibleButton(idArg, sizeArg) != 0
}

// InvisibleButton calls InvisibleButtonV(id, Vec2{0,0}).
func InvisibleButton(id string) bool {
return InvisibleButtonV(id, Vec2{})
}

// ImageV adds an image based on given texture ID.
// Refer to TextureID what this represents and how it is drawn.
func ImageV(id TextureID, size Vec2, uv0, uv1 Vec2, tintCol, borderCol Vec4) {
Expand Down Expand Up @@ -716,6 +729,19 @@ func TextLineHeightWithSpacing() float32 {
return float32(C.iggGetTextLineHeightWithSpacing())
}

// FrameHeight returns the height of the current frame. This is equal to the
// font size plus the padding at the top and bottom.
func FrameHeight() float32 {
return float32(C.iggGetFrameHeight())
}

// FrameHeightWithSpacing returns the height of the current frame with the item
// spacing added. This is equal to the font size plus the padding at the top
// and bottom, plus the value of style.ItemSpacing.y
func FrameHeightWithSpacing() float32 {
return float32(C.iggGetFrameHeightWithSpacing())
}

// TreeNodeV returns true if the tree branch is to be rendered. Call TreePop() in this case.
func TreeNodeV(label string, flags int) bool {
labelArg, labelFin := wrapString(label)
Expand Down Expand Up @@ -982,6 +1008,12 @@ func CloseCurrentPopup() {
C.iggCloseCurrentPopup()
}

// IsItemClicked returns true if the current item is clicked with the left
// mouse button.
func IsItemClicked() bool {
return C.iggIsItemClicked() != 0
}

// IsItemHoveredV returns true if the last item is hovered.
// (and usable, aka not blocked by a popup, etc.). See HoveredFlags for more options.
func IsItemHoveredV(flags int) bool {
Expand All @@ -1003,6 +1035,11 @@ func IsAnyItemActive() bool {
return C.iggIsAnyItemActive() != 0
}

// IsItemVisible returns true if the last item is visible
func IsItemVisible() bool {
return C.iggIsItemVisible() != 0
}

// IsWindowAppearing returns whether the current window is appearing.
func IsWindowAppearing() bool {
return C.iggIsWindowAppearing() != 0
Expand Down
26 changes: 26 additions & 0 deletions imguiWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,12 @@ IggBool iggButton(char const *label, IggVec2 const *size)
return ImGui::Button(label, *sizeArg) ? 1 : 0;
}

IggBool iggInvisibleButton(char const *label, IggVec2 const *size)
{
Vec2Wrapper sizeArg(size);
return ImGui::InvisibleButton(label, *sizeArg) ? 1 : 0;
}

void iggImage(IggTextureID textureID,
IggVec2 const *size, IggVec2 const *uv0, IggVec2 const *uv1,
IggVec4 const *tintCol, IggVec4 const *borderCol)
Expand Down Expand Up @@ -444,6 +450,16 @@ float iggGetTextLineHeightWithSpacing(void)
return ImGui::GetTextLineHeightWithSpacing();
}

float iggGetFrameHeight(void)
{
return ImGui::GetFrameHeight();
}

float iggGetFrameHeightWithSpacing(void)
{
return ImGui::GetFrameHeightWithSpacing();
}

IggBool iggTreeNode(char const *label, int flags)
{
return ImGui::TreeNodeEx(label, flags) ? 1 : 0;
Expand Down Expand Up @@ -563,6 +579,11 @@ void iggCloseCurrentPopup(void)
ImGui::CloseCurrentPopup();
}

IggBool iggIsItemClicked()
{
return ImGui::IsItemClicked() ? 1 : 0;
}

IggBool iggIsItemHovered(int flags)
{
return ImGui::IsItemHovered(flags) ? 1 : 0;
Expand All @@ -578,6 +599,11 @@ IggBool iggIsAnyItemActive()
return ImGui::IsAnyItemActive() ? 1 : 0;
}

IggBool iggIsItemVisible()
{
return ImGui::IsItemVisible() ? 1 : 0;
}

IggBool iggIsWindowAppearing() {
return ImGui::IsWindowAppearing() ? 1 : 0;
}
Expand Down
5 changes: 5 additions & 0 deletions imguiWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ extern void iggTextUnformatted(char const *text);
extern void iggLabelText(char const *label, char const *text);

extern IggBool iggButton(char const *label, IggVec2 const *size);
extern IggBool iggInvisibleButton(char const *label, IggVec2 const *size);
extern void iggImage(IggTextureID textureID,
IggVec2 const *size, IggVec2 const *uv0, IggVec2 const *uv1,
IggVec4 const *tintCol, IggVec4 const *borderCol);
Expand Down Expand Up @@ -113,6 +114,8 @@ extern void iggSetCursorScreenPos(IggVec2 const *absPos);
extern void iggAlignTextToFramePadding();
extern float iggGetTextLineHeight(void);
extern float iggGetTextLineHeightWithSpacing(void);
extern float iggGetFrameHeight(void);
extern float iggGetFrameHeightWithSpacing(void);

extern IggBool iggTreeNode(char const *label, int flags);
extern void iggTreePop(void);
Expand Down Expand Up @@ -143,9 +146,11 @@ extern IggBool iggBeginPopupContextItem(char const *label, int mouseButton);
extern void iggEndPopup(void);
extern void iggCloseCurrentPopup(void);

extern IggBool iggIsItemClicked();
extern IggBool iggIsItemHovered(int flags);
extern IggBool iggIsItemActive();
extern IggBool iggIsAnyItemActive();
extern IggBool iggIsItemVisible();

extern IggBool iggIsWindowAppearing();
extern IggBool iggIsWindowCollapsed();
Expand Down
1 change: 1 addition & 0 deletions imguiWrapperTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ typedef void *IggGlyphRanges;
typedef void *IggGuiStyle;
typedef void *IggInputTextCallbackData;
typedef void *IggIO;
typedef unsigned int ImU32; // 32-bit unsigned integer (often used to store packed colors)

typedef struct tagIggVec2
{
Expand Down