From cc31246a6acde1e449eba9a4b53b5d997b493eb0 Mon Sep 17 00:00:00 2001 From: zlianon Date: Wed, 4 Nov 2020 13:36:57 +0100 Subject: [PATCH 1/6] Add SmallButtonWidget --- Widgets.go | 18 ++++++++++++++++++ examples/widgets/widgets.go | 5 +++++ imgui/imgui.go | 6 ++++++ imgui/imguiWrapper.cpp | 5 +++++ imgui/imguiWrapper.h | 1 + 5 files changed, 35 insertions(+) diff --git a/Widgets.go b/Widgets.go index 9da7cf79..6542755f 100644 --- a/Widgets.go +++ b/Widgets.go @@ -138,6 +138,24 @@ func PlotLinesV(label string, values []float32, valuesOffset int, overlayText st } } +type SmallButtonWidget struct { + id string + onClick func() +} + +func SmallButton(id string, onClick func()) *SmallButtonWidget { + return &SmallButtonWidget{ + id: id, + onClick: onClick, + } +} + +func (sb *SmallButtonWidget) Build() { + if imgui.SmallButton(sb.id) && sb.onClick != nil { + sb.onClick() + } +} + type InvisibleButtonWidget struct { id string width float32 diff --git a/examples/widgets/widgets.go b/examples/widgets/widgets.go index 8c91e7a2..c35499de 100644 --- a/examples/widgets/widgets.go +++ b/examples/widgets/widgets.go @@ -87,6 +87,11 @@ func loop() { g.Combo("Combo", items[itemSelected], items, &itemSelected, 0, 0, comboChanged), + g.Line( + g.Button("Button", nil), + g.SmallButton("SmallButton", nil), + ), + g.Line( g.Button("Popup Modal", btnPopupCLicked), g.PopupModal("Confirm", g.Layout{ diff --git a/imgui/imgui.go b/imgui/imgui.go index 99229a59..1a480148 100644 --- a/imgui/imgui.go +++ b/imgui/imgui.go @@ -368,6 +368,12 @@ func Button(id string) bool { return ButtonV(id, Vec2{}) } +func SmallButton(id string) bool { + idArg, idFin := wrapString(id) + defer idFin() + return C.iggSmallButton(idArg) != 0 +} + func InvisibleButton(id string, size Vec2) bool { idArg, idFin := wrapString(id) defer idFin() diff --git a/imgui/imguiWrapper.cpp b/imgui/imguiWrapper.cpp index d46bf28d..68a3d603 100644 --- a/imgui/imguiWrapper.cpp +++ b/imgui/imguiWrapper.cpp @@ -295,6 +295,11 @@ IggBool iggButton(char const *label, IggVec2 const *size) return ImGui::Button(label, *sizeArg) ? 1 : 0; } +IggBool iggSmallButton(char const *label) +{ + return ImGui::SmallButton(label) ? 1: 0; +} + IggBool iggInvisibleButton(char const *label, IggVec2 const *size) { Vec2Wrapper sizeArg(size); diff --git a/imgui/imguiWrapper.h b/imgui/imguiWrapper.h index 41114f94..867186e5 100644 --- a/imgui/imguiWrapper.h +++ b/imgui/imguiWrapper.h @@ -80,6 +80,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 iggSmallButton(char const *label); extern IggBool iggInvisibleButton(char const *label, IggVec2 const *size); extern void iggImage(IggTextureID textureID, IggVec2 const *size, IggVec2 const *uv0, IggVec2 const *uv1, From 5a0fd64d5b9008729875d97504cd3d5565bf9fe6 Mon Sep 17 00:00:00 2001 From: zlianon Date: Wed, 4 Nov 2020 13:40:46 +0100 Subject: [PATCH 2/6] Format --- imgui/imguiWrapper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui/imguiWrapper.cpp b/imgui/imguiWrapper.cpp index 68a3d603..143d3a38 100644 --- a/imgui/imguiWrapper.cpp +++ b/imgui/imguiWrapper.cpp @@ -297,7 +297,7 @@ IggBool iggButton(char const *label, IggVec2 const *size) IggBool iggSmallButton(char const *label) { - return ImGui::SmallButton(label) ? 1: 0; + return ImGui::SmallButton(label) ? 1 : 0; } IggBool iggInvisibleButton(char const *label, IggVec2 const *size) From 2f96651ca0207fdcc9ca668d513e333d7de695ab Mon Sep 17 00:00:00 2001 From: zlianon Date: Wed, 4 Nov 2020 14:10:29 +0100 Subject: [PATCH 3/6] Add BulletWidget/BulletTextWidget --- Widgets.go | 24 ++++++++++++++++++++++++ imgui/imgui.go | 12 ++++++++++++ imgui/imguiWrapper.cpp | 10 ++++++++++ imgui/imguiWrapper.h | 3 +++ 4 files changed, 49 insertions(+) diff --git a/Widgets.go b/Widgets.go index 6542755f..f5e1271b 100644 --- a/Widgets.go +++ b/Widgets.go @@ -138,6 +138,30 @@ func PlotLinesV(label string, values []float32, valuesOffset int, overlayText st } } +type BulletWidget struct{} + +func Bullet() *BulletWidget { + return &BulletWidget{} +} + +func (b *BulletWidget) Build() { + imgui.Bullet() +} + +type BulletTextWidget struct { + text string +} + +func BulletText(text string) *BulletTextWidget { + return &BulletTextWidget{ + text: text, + } +} + +func (bt *BulletTextWidget) Build() { + imgui.BulletText(bt.text) +} + type SmallButtonWidget struct { id string onClick func() diff --git a/imgui/imgui.go b/imgui/imgui.go index 1a480148..fe9abd46 100644 --- a/imgui/imgui.go +++ b/imgui/imgui.go @@ -381,6 +381,18 @@ func InvisibleButton(id string, size Vec2) bool { return C.iggInvisibleButton(idArg, sizeArg) != 0 } +func Bullet() { + C.iggBullet() +} + +// BulletText. +// Text with a little bullet aligned to the typical tree node. +func BulletText(text string) { + textArg, textFin := wrapString(text) + defer textFin() + C.iggBulletText(textArg) +} + // 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) { diff --git a/imgui/imguiWrapper.cpp b/imgui/imguiWrapper.cpp index 143d3a38..89788556 100644 --- a/imgui/imguiWrapper.cpp +++ b/imgui/imguiWrapper.cpp @@ -348,6 +348,16 @@ void iggProgressBar(float fraction, IggVec2 const *size, char const *overlay) ImGui::ProgressBar(fraction, *sizeArg, overlay); } +void iggBullet(void) +{ + ImGui::Bullet(); +} + +void iggBulletText(const char* text) +{ + ImGui::BulletText("%s", text); +} + IggBool iggBeginCombo(char const *label, char const *previewValue, int flags) { return ImGui::BeginCombo(label, previewValue, flags) ? 1 : 0; diff --git a/imgui/imguiWrapper.h b/imgui/imguiWrapper.h index 867186e5..c0915988 100644 --- a/imgui/imguiWrapper.h +++ b/imgui/imguiWrapper.h @@ -94,6 +94,9 @@ extern IggBool iggRadioButton(char const *label, IggBool active); extern void iggProgressBar(float fraction, IggVec2 const *size, char const *overlay); +extern void iggBullet(void); +extern void iggBulletText(const char* text); + extern IggBool iggBeginCombo(char const *label, char const *previewValue, int flags); extern void iggEndCombo(void); From 2ddff911801a0d5dbf0c1c4761826c1680b571d7 Mon Sep 17 00:00:00 2001 From: zlianon Date: Wed, 4 Nov 2020 15:36:09 +0100 Subject: [PATCH 4/6] Add ArrowButtonWidget --- Direction.go | 10 ++++++++++ SplitLayout.go | 8 ++++---- Widgets.go | 20 ++++++++++++++++++++ imgui/imgui.go | 6 ++++++ imgui/imguiWrapper.cpp | 5 +++++ imgui/imguiWrapper.h | 1 + 6 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 Direction.go diff --git a/Direction.go b/Direction.go new file mode 100644 index 00000000..ea3164a0 --- /dev/null +++ b/Direction.go @@ -0,0 +1,10 @@ +package giu + +type Direction uint8 + +const ( + DirectionLeft = iota + DirectionRight = iota + DirectionUp = iota + DirectionDown = iota +) diff --git a/SplitLayout.go b/SplitLayout.go index 113b7182..5026647c 100644 --- a/SplitLayout.go +++ b/SplitLayout.go @@ -2,10 +2,10 @@ package giu import "fmt" -type Direction uint8 +type SplitDirection uint8 const ( - DirectionHorizontal Direction = 1 << iota + DirectionHorizontal SplitDirection = 1 << iota DirectionVertical ) @@ -20,7 +20,7 @@ func (s *SplitLayoutState) Dispose() { type SplitLayoutWidget struct { id string - direction Direction + direction SplitDirection layout1 Widget layout2 Widget originItemSpacingX float32 @@ -31,7 +31,7 @@ type SplitLayoutWidget struct { border bool } -func SplitLayout(id string, direction Direction, border bool, sashPos float32, layout1, layout2 Widget) *SplitLayoutWidget { +func SplitLayout(id string, direction SplitDirection, border bool, sashPos float32, layout1, layout2 Widget) *SplitLayoutWidget { return &SplitLayoutWidget{ id: id, direction: direction, diff --git a/Widgets.go b/Widgets.go index f5e1271b..d4162570 100644 --- a/Widgets.go +++ b/Widgets.go @@ -162,6 +162,26 @@ func (bt *BulletTextWidget) Build() { imgui.BulletText(bt.text) } +type ArrowButtonWidget struct { + id string + dir Direction + onClick func() +} + +func ArrowButton(id string, dir Direction, onClick func()) *ArrowButtonWidget { + return &ArrowButtonWidget{ + id: id, + dir: dir, + onClick: onClick, + } +} + +func (ab *ArrowButtonWidget) Build() { + if imgui.ArrowButton(ab.id, uint8(ab.dir)) && ab.onClick != nil { + ab.onClick() + } +} + type SmallButtonWidget struct { id string onClick func() diff --git a/imgui/imgui.go b/imgui/imgui.go index fe9abd46..721f8fdf 100644 --- a/imgui/imgui.go +++ b/imgui/imgui.go @@ -381,6 +381,12 @@ func InvisibleButton(id string, size Vec2) bool { return C.iggInvisibleButton(idArg, sizeArg) != 0 } +func ArrowButton(id string, dir uint8) bool { + idArg, idFin := wrapString(id) + defer idFin() + return C.iggArrowButton(idArg, C.uchar(dir)) != 0 +} + func Bullet() { C.iggBullet() } diff --git a/imgui/imguiWrapper.cpp b/imgui/imguiWrapper.cpp index 89788556..3e2580d9 100644 --- a/imgui/imguiWrapper.cpp +++ b/imgui/imguiWrapper.cpp @@ -300,6 +300,11 @@ IggBool iggSmallButton(char const *label) return ImGui::SmallButton(label) ? 1 : 0; } +IggBool iggArrowButton(const char* id, unsigned char dir) +{ + return ImGui::ArrowButton(id, dir) ? 1 : 0; +} + IggBool iggInvisibleButton(char const *label, IggVec2 const *size) { Vec2Wrapper sizeArg(size); diff --git a/imgui/imguiWrapper.h b/imgui/imguiWrapper.h index c0915988..1d8a79a6 100644 --- a/imgui/imguiWrapper.h +++ b/imgui/imguiWrapper.h @@ -81,6 +81,7 @@ extern void iggLabelText(char const *label, char const *text); extern IggBool iggButton(char const *label, IggVec2 const *size); extern IggBool iggSmallButton(char const *label); +extern IggBool iggArrowButton(const char* id, unsigned char dir); extern IggBool iggInvisibleButton(char const *label, IggVec2 const *size); extern void iggImage(IggTextureID textureID, IggVec2 const *size, IggVec2 const *uv0, IggVec2 const *uv1, From b8ae5143738683e41a682e8b09510928950d7459 Mon Sep 17 00:00:00 2001 From: zlianon Date: Wed, 4 Nov 2020 15:58:34 +0100 Subject: [PATCH 5/6] Add PushAllowKeyboardFocus/PopAllowKeyboardFocus --- imgui/imgui.go | 8 ++++++++ imgui/imguiWrapper.cpp | 11 +++++++++++ imgui/imguiWrapper.h | 3 +++ 3 files changed, 22 insertions(+) diff --git a/imgui/imgui.go b/imgui/imgui.go index 721f8fdf..855b394e 100644 --- a/imgui/imgui.go +++ b/imgui/imgui.go @@ -1373,3 +1373,11 @@ func PushClipRect(clipRectMin, clipRectMax Vec2, intersectWithClipRect bool) { func PopClipRect() { C.iggPopClipRect() } + +func PushAllowKeyboardFocus(allowKeyboardFocus bool) { + C.iggPushAllowKeyboardFocus(castBool(allowKeyboardFocus)) +} + +func PopAllowKeyboardFocus() { + C.iggPopAllowKeyboardFocus() +} diff --git a/imgui/imguiWrapper.cpp b/imgui/imguiWrapper.cpp index 3e2580d9..efed06ad 100644 --- a/imgui/imguiWrapper.cpp +++ b/imgui/imguiWrapper.cpp @@ -270,10 +270,21 @@ void iggPopTextWrapPos(void) ImGui::PopTextWrapPos(); } +void iggPushAllowKeyboardFocus(IggBool allow_keyboard_focus) +{ + ImGui::PushAllowKeyboardFocus(allow_keyboard_focus); +} + +void iggPopAllowKeyboardFocus(void) +{ + ImGui::PopAllowKeyboardFocus(); +} + void iggPushID(char const *id) { ImGui::PushID(id); } + void iggPopID(void) { ImGui::PopID(); diff --git a/imgui/imguiWrapper.h b/imgui/imguiWrapper.h index 1d8a79a6..671eb902 100644 --- a/imgui/imguiWrapper.h +++ b/imgui/imguiWrapper.h @@ -73,6 +73,9 @@ extern float iggCalcItemWidth(void); extern void iggPushTextWrapPos(float wrapPosX); extern void iggPopTextWrapPos(void); +extern void iggPushAllowKeyboardFocus(IggBool allow_keyboard_focus); +extern void iggPopAllowKeyboardFocus(void); + extern void iggPushID(char const *id); extern void iggPopID(void); From 8d77041d4c65b8bbec0f4771628cac69d7ae9a8c Mon Sep 17 00:00:00 2001 From: zlianon Date: Wed, 4 Nov 2020 16:07:04 +0100 Subject: [PATCH 6/6] Add Bullet and ArrowButtons to widgets example --- examples/widgets/widgets.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/examples/widgets/widgets.go b/examples/widgets/widgets.go index c35499de..b2a23dea 100644 --- a/examples/widgets/widgets.go +++ b/examples/widgets/widgets.go @@ -92,6 +92,19 @@ func loop() { g.SmallButton("SmallButton", nil), ), + g.BulletText("Bullet1"), + g.BulletText("Bullet2"), + g.BulletText("Bullet3"), + + g.Line( + g.Label("Arrow buttons: "), + + g.ArrowButton("arrow left", g.DirectionLeft, nil), + g.ArrowButton("arrow right", g.DirectionRight, nil), + g.ArrowButton("arrow up", g.DirectionUp, nil), + g.ArrowButton("arrow down", g.DirectionDown, nil), + ), + g.Line( g.Button("Popup Modal", btnPopupCLicked), g.PopupModal("Confirm", g.Layout{