Skip to content

Commit

Permalink
Merge pull request #82 from zlianon/master
Browse files Browse the repository at this point in the history
More Widgets!
  • Loading branch information
AllenDang authored Nov 5, 2020
2 parents 23f3cca + 8d77041 commit 05769b4
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 4 deletions.
10 changes: 10 additions & 0 deletions Direction.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package giu

type Direction uint8

const (
DirectionLeft = iota
DirectionRight = iota
DirectionUp = iota
DirectionDown = iota
)
8 changes: 4 additions & 4 deletions SplitLayout.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package giu

import "fmt"

type Direction uint8
type SplitDirection uint8

const (
DirectionHorizontal Direction = 1 << iota
DirectionHorizontal SplitDirection = 1 << iota
DirectionVertical
)

Expand All @@ -20,7 +20,7 @@ func (s *SplitLayoutState) Dispose() {

type SplitLayoutWidget struct {
id string
direction Direction
direction SplitDirection
layout1 Widget
layout2 Widget
originItemSpacingX float32
Expand All @@ -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,
Expand Down
62 changes: 62 additions & 0 deletions Widgets.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,68 @@ 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 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()
}

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
Expand Down
18 changes: 18 additions & 0 deletions examples/widgets/widgets.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,24 @@ func loop() {

g.Combo("Combo", items[itemSelected], items, &itemSelected, 0, 0, comboChanged),

g.Line(
g.Button("Button", nil),
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{
Expand Down
32 changes: 32 additions & 0 deletions imgui/imgui.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,13 +368,37 @@ 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()
sizeArg, _ := size.wrapped()
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()
}

// 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) {
Expand Down Expand Up @@ -1349,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()
}
31 changes: 31 additions & 0 deletions imgui/imguiWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -295,6 +306,16 @@ 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 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);
Expand Down Expand Up @@ -343,6 +364,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;
Expand Down
8 changes: 8 additions & 0 deletions imgui/imguiWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,18 @@ 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);

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 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,
Expand All @@ -93,6 +98,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);
Expand Down

0 comments on commit 05769b4

Please sign in to comment.