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

Commit

Permalink
Merge pull request #178 from inkyblackness/combo
Browse files Browse the repository at this point in the history
Combo
  • Loading branch information
dertseha authored Jun 4, 2022
2 parents b85dc63 + 7dbda0b commit 2c52d62
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Widgets.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "C"
import (
"fmt"
"math"
"strings"
)

// Text adds formatted text. See PushTextWrapPosV() or PushStyleColorV() for modifying the output.
Expand Down Expand Up @@ -210,6 +211,24 @@ func EndCombo() {
C.iggEndCombo()
}

// Combo calls ComboV(id, value, list, -1).
func Combo(id string, value *int32, list []string) bool {
return ComboV(id, value, list, -1)
}

// ComboV is a helper over BeginCombo()/EndCombo() which are kept available for convenience purpose.
// This is analogous to how ListBox are created.
func ComboV(id string, value *int32, list []string, heightInItems int) bool {
valueArg, valueFin := wrapInt32(value)
defer valueFin()
return C.iggCombo(
C.CString(id),
valueArg,
C.CString(strings.Join(list, string(byte(0)))+string(byte(0))),
(C.int)(heightInItems),
) != 0
}

// SliderFlags for DragFloat(), DragInt(), SliderFloat(), SliderInt() etc.
// We use the same sets of flags for DragXXX() and SliderXXX() functions as the features are the same and it makes it easier to swap them.
type SliderFlags int
Expand Down
5 changes: 5 additions & 0 deletions wrapper/Widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ void iggEndCombo(void)
ImGui::EndCombo();
}

IggBool iggCombo(char const *label, int *currentItem, char const *itemsSeparatedByZeros, int heightInItems)
{
return ImGui::Combo(label, currentItem, itemsSeparatedByZeros, heightInItems);
}

IggBool iggDragFloat(char const *label, float *value, float speed, float min, float max, char const *format, int flags)
{
return ImGui::DragFloat(label, value, speed, min, max, format, flags) ? 1 : 0;
Expand Down
1 change: 1 addition & 0 deletions wrapper/Widgets.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ extern void iggProgressBar(float fraction, IggVec2 const *size, char const *over

extern IggBool iggBeginCombo(char const *label, char const *previewValue, int flags);
extern void iggEndCombo(void);
extern IggBool iggCombo(char const *label, int *currentItem, char const *itemsSeparatedByZeros, int heightInItems);

extern IggBool iggDragFloat(char const *label, float *value, float speed, float min, float max, char const *format, int flags);
extern IggBool iggDragFloatN(char const *label, float *value, int n, float speed, float min, float max, char const *format, int flags);
Expand Down

0 comments on commit 2c52d62

Please sign in to comment.