├── .github └── workflows │ ├── golangci-lint.yaml │ └── tests.yml ├── .gitignore ├── .golangci.yml ├── AllocatedGlyphRanges.go ├── AllocatedGlyphRanges_test.go ├── Assert.go ├── CONTRIBUTING.md ├── Color.go ├── Condition.go ├── Context.go ├── Context_test.go ├── DragDrop.go ├── DrawCommand.go ├── DrawData.go ├── DrawData_test.go ├── DrawList.go ├── Focus.go ├── Font.go ├── FontAtlas.go ├── FontConfig.go ├── FreeType.go ├── GlyphRanges.go ├── IO.go ├── InputTextCallbackData.go ├── LICENSE ├── Layout.go ├── ListClipper.go ├── Main.go ├── Main_test.go ├── PackedColor.go ├── Popup.go ├── README.md ├── Scroll.go ├── Settings.go ├── State.go ├── Style.go ├── Tables.go ├── TextureID.go ├── Vectors.go ├── Vectors_test.go ├── Widgets.go ├── Window.go ├── WrapperConverter.go ├── WrapperConverter_test.go ├── _licenses └── imgui-LICENSE.txt ├── assets └── screenshot.png ├── doc.go ├── go.mod ├── go.sum ├── imgui ├── govendorkeep.go ├── imconfig.h ├── imgui.cpp ├── imgui.h ├── imgui_demo.cpp ├── imgui_draw.cpp ├── imgui_internal.h ├── imgui_tables.cpp ├── imgui_widgets.cpp ├── imstb_rectpack.h ├── imstb_textedit.h ├── imstb_truetype.h └── misc │ └── freetype │ ├── govendorkeep.go │ ├── imgui_freetype.cpp │ └── imgui_freetype.h ├── scripts └── download-clang-format.sh ├── update_imgui.sh ├── wrapper.cpp ├── wrapper.go ├── wrapper ├── .clang-format ├── Color.cpp ├── Color.h ├── ConfigOverride.h ├── ConfiguredImGui.h ├── Context.cpp ├── Context.h ├── DragDrop.cpp ├── DragDrop.h ├── DrawCommand.cpp ├── DrawCommand.h ├── DrawData.cpp ├── DrawData.h ├── DrawList.cpp ├── DrawList.h ├── Focus.cpp ├── Focus.h ├── Font.cpp ├── Font.h ├── FontAtlas.cpp ├── FontAtlas.h ├── FontConfig.cpp ├── FontConfig.h ├── IO.cpp ├── IO.h ├── InputTextCallbackData.cpp ├── InputTextCallbackData.h ├── Layout.cpp ├── Layout.h ├── ListClipper.cpp ├── ListClipper.h ├── Main.cpp ├── Main.h ├── Popup.cpp ├── Popup.h ├── Scroll.cpp ├── Scroll.h ├── Settings.cpp ├── Settings.h ├── State.cpp ├── State.h ├── Style.cpp ├── Style.h ├── Tables.cpp ├── Tables.h ├── Types.h ├── Widgets.cpp ├── Widgets.h ├── Window.cpp ├── Window.h ├── WrapperConverter.cpp ├── WrapperConverter.h └── govendorkeep.go └── wrapper_cgo_hack.go /.github/workflows/golangci-lint.yaml: -------------------------------------------------------------------------------- 1 | name: golangci-lint 2 | on: [push, pull_request] 3 | jobs: 4 | golangci: 5 | name: lint 6 | runs-on: ubuntu-latest 7 | steps: 8 | - name: Set up Go 9 | uses: actions/setup-go@v3 10 | with: 11 | go-version: '1.17.8' 12 | check-latest: false 13 | - uses: actions/checkout@v2 14 | - name: golangci-lint 15 | uses: golangci/golangci-lint-action@v3 16 | with: 17 | version: v1.44.2 18 | -------------------------------------------------------------------------------- /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | on: [ push, pull_request ] 3 | jobs: 4 | 5 | tests: 6 | name: ${{matrix.go-version}} ${{matrix.os}} 7 | runs-on: ${{ matrix.os }} 8 | strategy: 9 | matrix: 10 | go-version: [ 1.12, 1.18 ] 11 | os: [ macos-latest, ubuntu-latest ] 12 | steps: 13 | - name: Set up Go 14 | uses: actions/setup-go@v1 15 | with: 16 | go-version: ${{matrix.go-version}} 17 | - name: Print go version 18 | run: go version 19 | - name: Check out module 20 | uses: actions/checkout@v1 21 | with: 22 | fetch-depth: 1 23 | - name: Download modules 24 | run: go mod tidy -v 25 | - name: Run tests 26 | run: go test -race $(go list -e ./... | grep -v v4/imgui | grep -v v4/wrapper) 27 | 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | 3 | imgui.ini 4 | 5 | -------------------------------------------------------------------------------- /.golangci.yml: -------------------------------------------------------------------------------- 1 | run: 2 | deadline: 5m 3 | skip-dirs: 4 | - imgui 5 | - wrapper 6 | 7 | linters: 8 | enable-all: true 9 | 10 | # linters are disabled if their majority of issues is considered false-positive (intended code) 11 | # and the remaining issues (if existing) aren't worth it. 12 | disable: 13 | - gochecknoglobals 14 | - goimports # disabled because of so many false-positives with "imgui-go" 15 | - gofumpt # disabled because no extra need 16 | - wsl # this one has become too pedantic 17 | - ifshort # was not available in v.1.28.3 and will be skipped for now 18 | - exhaustivestruct # was not available in v.1.28.3 and will be skipped for now 19 | - nlreturn # was not available in v.1.28.3 and will be skipped for now 20 | - paralleltest # was not available in v.1.28.3 and will be skipped for now 21 | - varnamelen # was not available in v.1.28.3 and will be skipped for now 22 | - gci # was not available in v.1.28.3 and will be skipped for now 23 | - forcetypeassert # was not available in v.1.28.3 and will be skipped for now 24 | - gomnd # was not available in v.1.28.3 and will be skipped for now 25 | 26 | issues: 27 | exclude-use-default: false # disable filtering of defaults for better zero-issue policy 28 | exclude: 29 | # There is a lot of pointer-mangling happening here, so disable this govet warning 30 | - possible misuse of unsafe.Pointer 31 | max-per-linter: 0 # disable limit; report all issues of a linter 32 | max-same-issues: 0 # disable limit; report all issues of the same issue 33 | 34 | linters-settings: 35 | lll: 36 | line-length: 160 37 | gocritic: 38 | disabled-checks: 39 | - dupSubExpr 40 | - commentFormatting 41 | - deprecatedComment 42 | -------------------------------------------------------------------------------- /AllocatedGlyphRanges.go: -------------------------------------------------------------------------------- 1 | package imgui 2 | 3 | // #include 4 | import "C" 5 | import ( 6 | "unsafe" 7 | ) 8 | 9 | // AllocatedGlyphRanges are GlyphRanges dynamically allocated by the application. 10 | // Such ranges need to be freed when they are no longer in use to avoid resource leak. 11 | type AllocatedGlyphRanges struct { 12 | GlyphRanges 13 | } 14 | 15 | // Free releases the underlying memory of the ranges. 16 | // Call this method when the ranges are no longer in use. 17 | func (ranges *AllocatedGlyphRanges) Free() { 18 | C.free(unsafe.Pointer(ranges.GlyphRanges.handle())) 19 | ranges.GlyphRanges = 0 20 | } 21 | 22 | // GlyphRangesBuilder can be used to create a new, combined, set of ranges. 23 | type GlyphRangesBuilder struct { 24 | ranges []glyphRange 25 | } 26 | 27 | // Build combines all the currently registered ranges and creates a new instance. 28 | // The returned ranges object needs to be explicitly freed in order to release resources. 29 | func (builder *GlyphRangesBuilder) Build() AllocatedGlyphRanges { 30 | const bytesPerUint16 = 2 31 | const uint16PerRangeEntry = 2 32 | ranges := builder.mergedRanges() 33 | raw := C.malloc(C.size_t(bytesPerUint16 * ((len(ranges) * uint16PerRangeEntry) + 1))) 34 | rawSlice := ptrToUint16Slice(raw) 35 | outIndex := 0 36 | for _, r := range ranges { 37 | rawSlice[outIndex+0] = r.from 38 | rawSlice[outIndex+1] = r.to 39 | outIndex += 2 40 | } 41 | rawSlice[outIndex] = 0 42 | return AllocatedGlyphRanges{GlyphRanges: GlyphRanges(raw)} 43 | } 44 | 45 | // AddExisting adds the given set of ranges to the builder. 46 | // The provided ranges are immediately extracted. 47 | func (builder *GlyphRangesBuilder) AddExisting(ranges ...GlyphRanges) { 48 | for _, rawRange := range ranges { 49 | builder.ranges = append(builder.ranges, rawRange.extract()...) 50 | } 51 | } 52 | 53 | // Add extends the builder with the given range (inclusive). 54 | // from must be smaller, or equal to, to - otherwise the range is ignored. 55 | func (builder *GlyphRangesBuilder) Add(from, to rune) { 56 | if from > to { 57 | return 58 | } 59 | builder.ranges = append(builder.ranges, glyphRange{from: uint16(from), to: uint16(to)}) 60 | } 61 | 62 | func (builder *GlyphRangesBuilder) mergedRanges() []glyphRange { 63 | result := make([]glyphRange, 0, len(builder.ranges)) 64 | add := func(candidate glyphRange) { 65 | merged := false 66 | for index := 0; !merged && (index < len(result)); index++ { 67 | existing := &result[index] 68 | if (existing.from <= candidate.to) && (existing.to >= candidate.from) { 69 | if existing.from > candidate.from { 70 | existing.from = candidate.from 71 | } 72 | if existing.to < candidate.to { 73 | existing.to = candidate.to 74 | } 75 | merged = true 76 | } 77 | } 78 | if !merged { 79 | result = append(result, candidate) 80 | } 81 | } 82 | for _, candidate := range builder.ranges { 83 | add(candidate) 84 | } 85 | return result 86 | } 87 | -------------------------------------------------------------------------------- /AllocatedGlyphRanges_test.go: -------------------------------------------------------------------------------- 1 | package imgui_test 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | "unsafe" 7 | 8 | "github.com/inkyblackness/imgui-go/v4" 9 | 10 | "github.com/stretchr/testify/assert" 11 | "github.com/stretchr/testify/require" 12 | ) 13 | 14 | func TestAllocatedGlyphRangesFreeSetsToZero(t *testing.T) { 15 | var builder imgui.GlyphRangesBuilder 16 | ranges := builder.Build() 17 | require.NotEqual(t, uintptr(0), uintptr(ranges.GlyphRanges), "Should have allocated") 18 | ranges.Free() 19 | assert.Equal(t, uintptr(0), uintptr(ranges.GlyphRanges), "Should have reset") 20 | } 21 | 22 | func TestGlyphRangesBuilderAdd(t *testing.T) { 23 | type singleRange struct { 24 | from rune 25 | to rune 26 | } 27 | tt := []struct { 28 | name string 29 | input []singleRange 30 | expected []uint16 31 | }{ 32 | {name: "No input should contain terminator only", input: nil, expected: []uint16{0}}, 33 | {name: "adding of single rune range", input: []singleRange{{from: 'A', to: 'A'}}, expected: []uint16{65, 65, 0}}, 34 | {name: "adding of larger range", input: []singleRange{{from: 'A', to: 'C'}}, expected: []uint16{65, 67, 0}}, 35 | {name: "adding two ranges", input: []singleRange{{from: 'A', to: 'C'}, {from: 'E', to: 'F'}}, expected: []uint16{65, 67, 69, 70, 0}}, 36 | {name: "wrong order is ignored", input: []singleRange{{from: 'B', to: 'A'}}, expected: []uint16{0}}, 37 | } 38 | 39 | for _, tc := range tt { 40 | var builder imgui.GlyphRangesBuilder 41 | for _, add := range tc.input { 42 | builder.Add(add.from, add.to) 43 | } 44 | result := builder.Build() 45 | require.NotEqual(t, uintptr(0), uintptr(result.GlyphRanges)) 46 | for index, expected := range tc.expected { 47 | resultPtr := unsafe.Pointer(uintptr(result.GlyphRanges) + uintptr(2*index)) // nolint: gosec 48 | resultShort := (*uint16)(resultPtr) 49 | assert.Equal(t, expected, *resultShort, fmt.Sprintf("%s: Index %d mismatch", tc.name, index)) 50 | } 51 | result.Free() 52 | } 53 | } 54 | 55 | func TestGlyphRangesBuilderAddExisting(t *testing.T) { 56 | aRange := func(from, to rune) imgui.AllocatedGlyphRanges { 57 | var builder imgui.GlyphRangesBuilder 58 | builder.Add(from, to) 59 | return builder.Build() 60 | } 61 | baseRangeAA := aRange('A', 'A') 62 | defer baseRangeAA.Free() 63 | baseRangeEF := aRange('E', 'F') 64 | defer baseRangeEF.Free() 65 | 66 | tt := []struct { 67 | name string 68 | input []imgui.GlyphRanges 69 | expected []uint16 70 | }{ 71 | {name: "adding of single range", input: []imgui.GlyphRanges{baseRangeAA.GlyphRanges}, expected: []uint16{65, 65, 0}}, 72 | {name: "adding of two single ranges", input: []imgui.GlyphRanges{baseRangeAA.GlyphRanges, baseRangeEF.GlyphRanges}, expected: []uint16{65, 65, 69, 70, 0}}, 73 | } 74 | 75 | for _, tc := range tt { 76 | var builder imgui.GlyphRangesBuilder 77 | for _, add := range tc.input { 78 | builder.AddExisting(add) 79 | } 80 | result := builder.Build() 81 | require.NotEqual(t, uintptr(0), uintptr(result.GlyphRanges)) 82 | for index, expected := range tc.expected { 83 | resultPtr := unsafe.Pointer(uintptr(result.GlyphRanges) + uintptr(2*index)) // nolint: gosec 84 | resultShort := (*uint16)(resultPtr) 85 | assert.Equal(t, expected, *resultShort, fmt.Sprintf("%s: Index %d mismatch", tc.name, index)) 86 | } 87 | result.Free() 88 | } 89 | } 90 | 91 | func TestGlyphRangesBuilderCompactsRanges(t *testing.T) { 92 | type singleRange struct { 93 | from rune 94 | to rune 95 | } 96 | tt := []struct { 97 | name string 98 | input []singleRange 99 | expected []uint16 100 | }{ 101 | {name: "Removing duplications", input: []singleRange{{from: 'A', to: 'B'}, {from: 'A', to: 'B'}}, expected: []uint16{65, 66}}, 102 | {name: "combining ranges A", input: []singleRange{{from: 'A', to: 'D'}, {from: 'B', to: 'E'}}, expected: []uint16{65, 69, 0}}, 103 | {name: "combining ranges B", input: []singleRange{{from: 'C', to: 'E'}, {from: 'A', to: 'D'}}, expected: []uint16{65, 69, 0}}, 104 | {name: "combining ranges C", input: []singleRange{{from: 'A', to: 'E'}, {from: 'B', to: 'C'}}, expected: []uint16{65, 69, 0}}, 105 | {name: "combining ranges of whole set", input: []singleRange{ 106 | {from: 'A', to: 'B'}, {from: 'E', to: 'F'}, {from: 'A', to: 'C'}}, expected: []uint16{65, 67, 69, 70, 0}}, 107 | } 108 | 109 | for _, tc := range tt { 110 | var builder imgui.GlyphRangesBuilder 111 | for _, add := range tc.input { 112 | builder.Add(add.from, add.to) 113 | } 114 | result := builder.Build() 115 | require.NotEqual(t, uintptr(0), uintptr(result.GlyphRanges)) 116 | for index, expected := range tc.expected { 117 | resultPtr := unsafe.Pointer(uintptr(result.GlyphRanges) + uintptr(2*index)) // nolint: gosec 118 | resultShort := (*uint16)(resultPtr) 119 | assert.Equal(t, expected, *resultShort, fmt.Sprintf("%s: Index %d mismatch", tc.name, index)) 120 | } 121 | result.Free() 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /Assert.go: -------------------------------------------------------------------------------- 1 | package imgui 2 | 3 | import "C" 4 | import ( 5 | "fmt" 6 | ) 7 | 8 | // AssertHandler is a handler for an assertion that happened in the native part of ImGui. 9 | type AssertHandler func(expression string, file string, line int) 10 | 11 | // AssertionError is the standard error being thrown by the default handler. 12 | type AssertionError struct { 13 | Expression string 14 | File string 15 | Line int 16 | } 17 | 18 | // Error returns the string representation. 19 | func (err AssertionError) Error() string { 20 | return fmt.Sprintf(`Assertion failed! 21 | File: %s, Line %d 22 | 23 | Expression: %s 24 | `, err.File, err.Line, err.Expression) 25 | } 26 | 27 | var assertHandler AssertHandler = func(expression string, file string, line int) { 28 | panic(AssertionError{ 29 | Expression: expression, 30 | File: file, 31 | Line: line, 32 | }) 33 | } 34 | 35 | // SetAssertHandler registers a handler function for all future assertions. 36 | // Setting nil will disable special handling. 37 | // The default handler panics. 38 | func SetAssertHandler(handler AssertHandler) { 39 | assertHandler = handler 40 | } 41 | 42 | //export iggAssert 43 | func iggAssert(expression *C.char, file *C.char, line C.int) { 44 | if assertHandler != nil { 45 | assertHandler(C.GoString(expression), C.GoString(file), int(line)) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing Guidelines 2 | 3 | Thank you for considering to contribute to this library! 4 | 5 | The following text lists guidelines for contributions. 6 | These guidelines don't have legal status, so use them as a reference and common sense - and feel free to update them as well! 7 | 8 | 9 | ### "I just want to know..." 10 | 11 | For questions, or general usage-information about **Dear ImGui**, please refer to the [homepage](https://github.com/ocornut/imgui), or look in the detailed documentation of the C++ source. 12 | This wrapper houses next to no functionality. As long as it is not a Go-specific issue, help will rather be there. 13 | 14 | ### Scope 15 | 16 | This wrapper exposes minimal functionality of **Dear ImGui**. Ideally, this functionality is that of the common minimum that someone would want. This wrapper does not strife for full configurability, like the original library. This is not even possible in some cases, as it requires compilation flags. 17 | 18 | ### Extensions 19 | If you can and want to make use of this library in your own projects, you are happy to do so. Pull-requests with extensions are happily accepted, provided that they uphold the following minimum requirements: 20 | * Code is properly formatted & linted (use [golangci-lint](https://github.com/golangci/golangci-lint) for a full check) 21 | * Public Go API is documented. Copied documentation from **Dear ImGui** is acceptable and recommended, assuming it is adapted regarding type names. If there is no documentation in the original, try to spend some time figuring it out. In any case, please make the comments readable as complete English sentences, as recommended by Go. 22 | * API and version philosophies are respected (see README.md) 23 | 24 | _Ideally_, please also extend the demo window(s) of [inkyblackness/imgui-go-examples](https://github.com/inkyblackness/imgui-go-examples) - see `internal/demo/Window.go`. 25 | This way we also grow a Go-based demonstrator. 26 | 27 | #### Clarification on API naming and signatures 28 | 29 | If a **Dear ImGui** function has the signature of 30 | 31 | ``` 32 | SomeControl(const char *label, int value, int optArg1 = 0, const char *optArg2 = "stuff"); 33 | ``` 34 | 35 | then the wrapper functions should be 36 | 37 | ``` 38 | // SomeControl calls SomeControlV(label, value, 0, "stuff"). 39 | SomeControl(label string, value int32) { 40 | SomeControlV(label, value, 0, "stuff") 41 | } 42 | 43 | // SomeControlV does things (text possibly copied from imgui.h). 44 | SomeControlV(label string, value int32, optArg1 int32, optArg2 string) { 45 | // ... 46 | } 47 | ``` 48 | 49 | The "idiomatic" function should have only the required parameters of the underlying function, and its comment specifies all the defaults, matching that of `imgui.h`. 50 | The "verbose" variant should require all the parameters of the underlying function. 51 | 52 | ### Code Style 53 | 54 | Please make sure Go code is formatted according to `go fmt`, and use the following linter: [golangci-lint](https://github.com/golangci/golangci-lint). 55 | 56 | > If there are linter errors that you didn't introduce, you don't have to clean them up - I might have missed them and will be handling them separately. 57 | 58 | For the C++ code under `/wrapper`, run `clang-format` (version 11 or newer) to adhere to the common formatting as specified by `/wrapper/.clang-format` file. 59 | 60 | ### Upgrade to newer Dear ImGui version 61 | 62 | To update the **Dear ImGui** sources, overwrite the files in the `imgui` subfolders. Please avoid any files not needed by the wrapper. 63 | 64 | An upgrade with _major_ changes in the API should be on purpose and with coordination. Such a change requires a bump of the major version of this wrapper. 65 | 66 | Otherwise, try to keep the API of this wrapper stable and keep compatible wrapper functions for changed/upgraded functions. 67 | 68 | On an upgrade of **Dear ImGui**, apart from updating the actual files, be sure to do the following steps: 69 | * In case `imconfig.h` is changed, be sure the intentional overrides in `wrapper/ConfigOverride.h` stay in effect. 70 | * Have a look at any extended enumerations. The Go variant will need extension/change as well, otherwise the constants will be wrong. 71 | * Check for any documentation changes of exported functions. The Go documentation should reflect such changes as well. 72 | * Run `go test ./...` . There is at least one test which is bound to the version and needs change as well. 73 | * Update the screenshots of the examples, they show the version number. Use `imgui-go-examples` to create it. 74 | * Update the `README.md` file, it indicates the version number. 75 | * Check if the license of **Dear ImGui** has changed and update the `_licenses/imgui-LICENSE.txt` file. This may happen every year (copyright year). 76 | 77 | #### Handling of removed functions 78 | 79 | In order to avoid needing a major version bump of the wrapper just for one removed function, use the following pattern: 80 | 81 | ``` 82 | // NewFunction does new stuff. 83 | func NewFunction() { 84 | } 85 | 86 | // OldFunction did something and is now delegating to NewFunction(). 87 | // Deprecated: Use NewFunction instead. 88 | func OldFunction() { 89 | NewFunction() 90 | } 91 | ``` 92 | 93 | The `OldFunction` is implemented using the new API, and is marked as `Deprecated: ` in the comment. 94 | IDEs tend to respect this and notify the user. 95 | 96 | If, however, a whole set of functionality is replaced, this then probably warrants a major version bump. 97 | -------------------------------------------------------------------------------- /Condition.go: -------------------------------------------------------------------------------- 1 | package imgui 2 | 3 | // Condition for SetWindow***(), SetNextWindow***(), SetNextTreeNode***() functions. 4 | // Important: Treat as a regular enum! Do NOT combine multiple values using binary operators! 5 | // All the functions above treat 0 as a shortcut to ConditionAlways. 6 | type Condition int 7 | 8 | const ( 9 | // ConditionNone sets no condition (always set the variable), same as ConditionAlways. 10 | ConditionNone Condition = 0 11 | // ConditionAlways sets the variable. 12 | ConditionAlways Condition = 1 << 0 13 | // ConditionOnce sets the variable once per runtime session (only the first call with succeed). 14 | ConditionOnce Condition = 1 << 1 15 | // ConditionFirstUseEver sets the variable if the object/window has no persistently saved data (no entry in .ini file). 16 | ConditionFirstUseEver Condition = 1 << 2 17 | // ConditionAppearing sets the variable if the object/window is appearing after being hidden/inactive (or the first time). 18 | ConditionAppearing Condition = 1 << 3 19 | ) 20 | -------------------------------------------------------------------------------- /Context.go: -------------------------------------------------------------------------------- 1 | package imgui 2 | 3 | import ( 4 | "errors" 5 | ) 6 | 7 | // #include "wrapper/Context.h" 8 | import "C" 9 | 10 | // Context specifies a scope of ImGui. 11 | // 12 | // All contexts share a same FontAtlas by default. 13 | // If you want different font atlas, you can create them and overwrite the CurrentIO.Fonts of an ImGui context. 14 | type Context struct { 15 | handle C.IggContext 16 | } 17 | 18 | // CreateContext produces a new internal state scope. 19 | // Passing nil for the fontAtlas creates a default font. 20 | // 21 | // Deprecated: Unmaintained wrapper. Use an alternative; see README of https://github.com/inkyblackness/imgui-go . 22 | func CreateContext(fontAtlas *FontAtlas) *Context { 23 | var fontAtlasPtr C.IggFontAtlas 24 | if fontAtlas != nil { 25 | fontAtlasPtr = fontAtlas.handle() 26 | } 27 | return &Context{handle: C.iggCreateContext(fontAtlasPtr)} 28 | } 29 | 30 | // ErrNoContext is used when no context is current. 31 | var ErrNoContext = errors.New("no current context") 32 | 33 | // CurrentContext returns the currently active state scope. 34 | // Returns ErrNoContext if no context is available. 35 | func CurrentContext() (*Context, error) { 36 | raw := C.iggGetCurrentContext() 37 | if raw == nil { 38 | return nil, ErrNoContext 39 | } 40 | return &Context{handle: raw}, nil 41 | } 42 | 43 | // Destroy removes the internal state scope. 44 | // Trying to destroy an already destroyed context does nothing. 45 | func (context *Context) Destroy() { 46 | if context.handle != nil { 47 | C.iggDestroyContext(context.handle) 48 | context.handle = nil 49 | } 50 | } 51 | 52 | // ErrContextDestroyed is returned when trying to use an already destroyed context. 53 | var ErrContextDestroyed = errors.New("context is destroyed") 54 | 55 | // SetCurrent activates this context as the currently active state scope. 56 | func (context Context) SetCurrent() error { 57 | if context.handle == nil { 58 | return ErrContextDestroyed 59 | } 60 | C.iggSetCurrentContext(context.handle) 61 | return nil 62 | } 63 | -------------------------------------------------------------------------------- /Context_test.go: -------------------------------------------------------------------------------- 1 | package imgui // nolint: testpackage 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/stretchr/testify/assert" 8 | "github.com/stretchr/testify/require" 9 | ) 10 | 11 | func TestCurrentContextReturnsErrorIfNoContextIsCurrent(t *testing.T) { 12 | context, err := CurrentContext() 13 | assert.Nil(t, context, "No context expected") 14 | assert.Equal(t, ErrNoContext, err, "Error expected") 15 | } 16 | 17 | func TestCreateContextReturnsNewInstance(t *testing.T) { 18 | context := CreateContext(nil) 19 | require.NotNil(t, context, "Context expected") 20 | context.Destroy() 21 | } 22 | 23 | func TestCurrentContextCanBeRetrieved(t *testing.T) { 24 | context := CreateContext(nil) 25 | require.NotNil(t, context, "Context expected") 26 | defer context.Destroy() 27 | 28 | current, _ := CurrentContext() 29 | assert.NotNil(t, current, "Current context expected") 30 | } 31 | 32 | func TestCurrentContextCanBeChanged(t *testing.T) { 33 | context1 := CreateContext(nil) 34 | require.NotNil(t, context1, "Context expected") 35 | defer context1.Destroy() 36 | 37 | first, _ := CurrentContext() 38 | assert.True(t, context1.handle == first.handle, "First context expected") 39 | 40 | context2 := CreateContext(nil) 41 | require.NotNil(t, context2, "Context expected") 42 | defer context2.Destroy() 43 | 44 | _ = context2.SetCurrent() 45 | 46 | second, _ := CurrentContext() 47 | assert.True(t, context2.handle == second.handle, fmt.Sprintf("Context should have changed to second 1=%v, 2=%v", context1, context2)) 48 | 49 | _ = context1.SetCurrent() 50 | 51 | third, _ := CurrentContext() 52 | assert.True(t, context1.handle == third.handle, fmt.Sprintf("Context should have changed to first 1=%v, 2=%v", context1, context2)) 53 | } 54 | 55 | func TestDestroyDoesNothingWhenCalledMultipleTimes(t *testing.T) { 56 | context := CreateContext(nil) 57 | require.NotNil(t, context, "Context expected") 58 | 59 | context.Destroy() 60 | context.Destroy() 61 | context.Destroy() 62 | } 63 | 64 | func TestSetCurrentReturnsErrorWhenContextDestroyed(t *testing.T) { 65 | context := CreateContext(nil) 66 | require.NotNil(t, context, "Context expected") 67 | context.Destroy() 68 | 69 | err := context.SetCurrent() 70 | assert.Equal(t, ErrContextDestroyed, err) 71 | } 72 | -------------------------------------------------------------------------------- /DragDrop.go: -------------------------------------------------------------------------------- 1 | package imgui 2 | 3 | // #include "wrapper/DragDrop.h" 4 | import "C" 5 | 6 | // DragDropFlags for BeginDragDropSource(), etc. 7 | type DragDropFlags int 8 | 9 | const ( 10 | // DragDropFlagsNone specifies the default behaviour. 11 | DragDropFlagsNone DragDropFlags = 0 12 | // DragDropFlagsSourceNoPreviewTooltip hides the tooltip that is open so you can display a preview or description of the source contents. 13 | DragDropFlagsSourceNoPreviewTooltip DragDropFlags = 1 << 0 14 | // DragDropFlagsSourceNoDisableHover preserves the behaviour of IsItemHovered. By default, when dragging we clear data so that IsItemHovered() will return true, to avoid subsequent user code submitting tooltips. 15 | DragDropFlagsSourceNoDisableHover DragDropFlags = 1 << 1 16 | // DragDropFlagsSourceNoHoldToOpenOthers disables the behavior that allows to open tree nodes and collapsing header by holding over them while dragging a source item. 17 | DragDropFlagsSourceNoHoldToOpenOthers DragDropFlags = 1 << 2 18 | // DragDropFlagsSourceAllowNullID allows items such as Text(), Image() that have no unique identifier to be used as drag source, by manufacturing a temporary identifier based on their window-relative position. This is extremely unusual within the dear ecosystem and so we made it explicit. 19 | DragDropFlagsSourceAllowNullID DragDropFlags = 1 << 3 20 | // DragDropFlagsSourceExtern specifies external source (from outside of), won't attempt to read current item/window info. Will always return true. Only one Extern source can be active simultaneously. 21 | DragDropFlagsSourceExtern DragDropFlags = 1 << 4 22 | 23 | // DragDropFlagsAcceptBeforeDelivery makes AcceptDragDropPayload() return true even before the mouse button is released. You can then call IsDelivery() to test if the payload needs to be delivered. 24 | DragDropFlagsAcceptBeforeDelivery DragDropFlags = 1 << 10 25 | // DragDropFlagsAcceptNoDrawDefaultRect does not draw the default highlight rectangle when hovering over target. 26 | DragDropFlagsAcceptNoDrawDefaultRect DragDropFlags = 1 << 11 27 | // DragDropFlagsAcceptPeekOnly is for peeking ahead and inspecting the payload before delivery. 28 | DragDropFlagsAcceptPeekOnly = DragDropFlagsAcceptBeforeDelivery | DragDropFlagsAcceptNoDrawDefaultRect 29 | ) 30 | 31 | const ( 32 | // DragDropPayloadTypeColor3F is payload type for 3 floats component color. 33 | DragDropPayloadTypeColor3F = "_COL3F" 34 | // DragDropPayloadTypeColor4F is payload type for 4 floats component color. 35 | DragDropPayloadTypeColor4F = "_COL4F" 36 | ) 37 | 38 | // BeginDragDropSource registers the currently active item as drag'n'drop source. 39 | // When this returns true you need to: 40 | // a) call SetDragDropPayload() exactly once, 41 | // b) you may render the payload visual/description, 42 | // c) call EndDragDropSource(). 43 | func BeginDragDropSource(flags DragDropFlags) bool { 44 | return C.iggBeginDragDropSource(C.int(flags)) != 0 45 | } 46 | 47 | // SetDragDropPayload sets the payload for current draw and drop source. 48 | // Strings starting with '_' are reserved for dear imgui internal types. 49 | // Data is copied and held by imgui. 50 | func SetDragDropPayload(dataType string, data []byte, cond Condition) bool { 51 | typeArg, typeFin := wrapString(dataType) 52 | defer typeFin() 53 | dataArg, dataFin := wrapBytes(data) 54 | defer dataFin() 55 | return C.iggSetDragDropPayload(typeArg, dataArg, C.int(len(data)), C.int(cond)) != 0 56 | } 57 | 58 | // EndDragDropSource closes the scope for current draw and drop source. 59 | // Only call EndDragDropSource() if BeginDragDropSource() returns true. 60 | func EndDragDropSource() { 61 | C.iggEndDragDropSource() 62 | } 63 | 64 | // BeginDragDropTarget must be called after submitting an item that may receive an item. 65 | // If this returns true, you can call AcceptDragDropPayload() and EndDragDropTarget(). 66 | func BeginDragDropTarget() bool { 67 | return C.iggBeginDragDropTarget() != 0 68 | } 69 | 70 | // AcceptDragDropPayload accepts contents of a given type. 71 | // If ImGuiDragDropFlags_AcceptBeforeDelivery is set you can peek into the payload before the mouse button is released. 72 | func AcceptDragDropPayload(dataType string, flags DragDropFlags) []byte { 73 | typeArg, typeFin := wrapString(dataType) 74 | defer typeFin() 75 | 76 | payload := C.iggAcceptDragDropPayload(typeArg, C.int(flags)) 77 | if payload == nil { 78 | return nil 79 | } 80 | 81 | data := C.iggPayloadData(payload) 82 | size := C.iggPayloadDataSize(payload) 83 | return C.GoBytes(data, size) 84 | } 85 | 86 | // EndDragDropTarget closed the scope for current drag and drop target. 87 | // Only call EndDragDropTarget() if BeginDragDropTarget() returns true. 88 | func EndDragDropTarget() { 89 | C.iggEndDragDropTarget() 90 | } 91 | -------------------------------------------------------------------------------- /DrawCommand.go: -------------------------------------------------------------------------------- 1 | package imgui 2 | 3 | // #include "wrapper/DrawCommand.h" 4 | import "C" 5 | 6 | // DrawCommand describes one GPU call (or a callback). 7 | type DrawCommand uintptr 8 | 9 | func (cmd DrawCommand) handle() C.IggDrawCmd { 10 | return C.IggDrawCmd(cmd) 11 | } 12 | 13 | // ElementCount is the number of indices (multiple of 3) to be rendered as triangles. 14 | // Vertices are stored in the callee DrawList's VertexBuffer, indices in IndexBuffer. 15 | func (cmd DrawCommand) ElementCount() int { 16 | var count C.uint 17 | C.iggDrawCommandGetElementCount(cmd.handle(), &count) 18 | return int(count) 19 | } 20 | 21 | // IndexOffset is the start offset in index buffer. 22 | // Always equal to sum of ElemCount drawn so far. 23 | func (cmd DrawCommand) IndexOffset() int { 24 | var count C.uint 25 | C.iggDrawCommandGetIndexOffset(cmd.handle(), &count) 26 | return int(count) 27 | } 28 | 29 | // VertexOffset is the start offset in vertex buffer. 30 | // ImGuiBackendFlags_RendererHasVtxOffset: false always 0, 31 | // otherwise may be >0 to support meshes larger than 64K vertices with 16-bit indices. 32 | func (cmd DrawCommand) VertexOffset() int { 33 | var count C.uint 34 | C.iggDrawCommandGetVertexOffset(cmd.handle(), &count) 35 | return int(count) 36 | } 37 | 38 | // ClipRect defines the clipping rectangle (x1, y1, x2, y2). 39 | func (cmd DrawCommand) ClipRect() (rect Vec4) { 40 | rectArg, rectFin := rect.wrapped() 41 | defer rectFin() 42 | C.iggDrawCommandGetClipRect(cmd.handle(), rectArg) 43 | return 44 | } 45 | 46 | // TextureID is the user-provided texture ID. 47 | // Set by user in FontAtlas.SetTextureID() for fonts or passed to Image*() functions. 48 | // Ignore if never using images or multiple fonts atlas. 49 | func (cmd DrawCommand) TextureID() TextureID { 50 | var id C.IggTextureID 51 | C.iggDrawCommandGetTextureID(cmd.handle(), &id) 52 | return TextureID(id) 53 | } 54 | 55 | // HasUserCallback returns true if this handle command should be deferred. 56 | func (cmd DrawCommand) HasUserCallback() bool { 57 | return C.iggDrawCommandHasUserCallback(cmd.handle()) != 0 58 | } 59 | 60 | // CallUserCallback calls the user callback instead of rendering the vertices. 61 | // ClipRect and TextureID will be set normally. 62 | func (cmd DrawCommand) CallUserCallback(list DrawList) { 63 | C.iggDrawCommandCallUserCallback(cmd.handle(), list.handle()) 64 | } 65 | -------------------------------------------------------------------------------- /DrawData.go: -------------------------------------------------------------------------------- 1 | package imgui 2 | 3 | // #include "wrapper/DrawData.h" 4 | import "C" 5 | import "unsafe" 6 | 7 | // RenderedDrawData returns the created draw commands, which are valid after Render() and 8 | // until the next call to NewFrame(). This is what you have to render. 9 | func RenderedDrawData() DrawData { 10 | return DrawData(C.iggGetDrawData()) 11 | } 12 | 13 | // DrawData contains all draw data to render an ImGui frame. 14 | type DrawData uintptr 15 | 16 | func (data DrawData) handle() C.IggDrawData { 17 | return C.IggDrawData(data) 18 | } 19 | 20 | // Valid indicates whether the structure is usable. 21 | // It is valid only after Render() is called and before the next NewFrame() is called. 22 | func (data DrawData) Valid() bool { 23 | return (data.handle() != nil) && (C.iggDrawDataValid(data.handle()) != 0) 24 | } 25 | 26 | // CommandLists is an array of DrawList to render. 27 | // The DrawList are owned by the context and only pointed to from here. 28 | func (data DrawData) CommandLists() []DrawList { 29 | var handles unsafe.Pointer 30 | var count C.int 31 | 32 | C.iggDrawDataGetCommandLists(data.handle(), &handles, &count) 33 | list := make([]DrawList, int(count)) 34 | for i := 0; i < int(count); i++ { 35 | list[i] = DrawList(*((*uintptr)(handles))) 36 | handles = unsafe.Pointer(uintptr(handles) + unsafe.Sizeof(handles)) // nolint: gas 37 | } 38 | 39 | return list 40 | } 41 | 42 | // DisplayPos returns the top-left position of the viewport to render. 43 | // Use this as the top-left of the orthogonal projection matrix. 44 | // For the main viewport this is equal to MainViewport().Pos(). 45 | // Usually {0, 0} in a single-viewport application. 46 | func (data DrawData) DisplayPos() Vec2 { 47 | var value Vec2 48 | valueArg, valueFin := value.wrapped() 49 | C.iggDrawDataDisplayPos(data.handle(), valueArg) 50 | valueFin() 51 | return value 52 | } 53 | 54 | // DisplaySize returns the size of the viewport to render. 55 | // For the main viewport this is equal to MainViewport().Size(). 56 | // Usually set by IO.SetDisplaySize(). 57 | func (data DrawData) DisplaySize() Vec2 { 58 | var value Vec2 59 | valueArg, valueFin := value.wrapped() 60 | C.iggDrawDataDisplaySize(data.handle(), valueArg) 61 | valueFin() 62 | return value 63 | } 64 | 65 | // FrameBufferScale returns the amount of pixels for each unit of DisplaySize(). 66 | // Generally (1,1) on normal display, (2,2) on OSX with Retina display. 67 | // See also IO.DisplayFrameBufferScale(). 68 | func (data DrawData) FrameBufferScale() Vec2 { 69 | var value Vec2 70 | valueArg, valueFin := value.wrapped() 71 | C.iggDrawDataFrameBufferScale(data.handle(), valueArg) 72 | valueFin() 73 | return value 74 | } 75 | 76 | // ScaleClipRects is a helper to scale the ClipRect field of each DrawCmd. 77 | // Use if your final output buffer is at a different scale than ImGui expects, 78 | // or if there is a difference between your window resolution and framebuffer resolution. 79 | func (data DrawData) ScaleClipRects(scale Vec2) { 80 | scaleArg, _ := scale.wrapped() 81 | C.iggDrawDataScaleClipRects(data.handle(), scaleArg) 82 | } 83 | -------------------------------------------------------------------------------- /DrawData_test.go: -------------------------------------------------------------------------------- 1 | package imgui_test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/inkyblackness/imgui-go/v4" 7 | 8 | "github.com/stretchr/testify/assert" 9 | ) 10 | 11 | func TestDrawData(t *testing.T) { 12 | context := imgui.CreateContext(nil) 13 | defer context.Destroy() 14 | 15 | io := imgui.CurrentIO() 16 | io.SetDisplaySize(imgui.Vec2{X: 800, Y: 600}) 17 | io.Fonts().TextureDataAlpha8() 18 | 19 | for i := 0; i < 2; i++ { 20 | imgui.NewFrame() 21 | imgui.ShowDemoWindow(nil) 22 | imgui.Render() 23 | } 24 | drawData := imgui.RenderedDrawData() 25 | 26 | assert.True(t, drawData.Valid(), "Draw data should be valid") 27 | list := drawData.CommandLists() 28 | assert.True(t, len(list) > 0, "At least one draw data list expected") 29 | } 30 | -------------------------------------------------------------------------------- /Focus.go: -------------------------------------------------------------------------------- 1 | package imgui 2 | 3 | // #include "wrapper/Focus.h" 4 | import "C" 5 | 6 | // SetItemDefaultFocus makes the last item the default focused item of a window. 7 | func SetItemDefaultFocus() { 8 | C.iggSetItemDefaultFocus() 9 | } 10 | 11 | // IsItemFocused returns true if the last item is focused. 12 | func IsItemFocused() bool { 13 | return C.iggIsItemFocused() != 0 14 | } 15 | 16 | // IsAnyItemFocused returns true if any item is focused. 17 | func IsAnyItemFocused() bool { 18 | return C.iggIsAnyItemFocused() != 0 19 | } 20 | 21 | // SetKeyboardFocusHere calls SetKeyboardFocusHereV(0). 22 | func SetKeyboardFocusHere() { 23 | C.iggSetKeyboardFocusHere(0) 24 | } 25 | 26 | // SetKeyboardFocusHereV gives keyboard focus to next item. 27 | func SetKeyboardFocusHereV(offset int) { 28 | C.iggSetKeyboardFocusHere(C.int(offset)) 29 | } 30 | -------------------------------------------------------------------------------- /Font.go: -------------------------------------------------------------------------------- 1 | package imgui 2 | 3 | // #include "wrapper/Font.h" 4 | // #include "wrapper/Types.h" 5 | import "C" 6 | 7 | // Font describes one loaded font in an atlas. 8 | type Font uintptr 9 | 10 | // FontGlyph represents a single font glyph from a font atlas. 11 | type FontGlyph uintptr 12 | 13 | // DefaultFont can be used to refer to the default font of the current font atlas without 14 | // having the actual font reference. 15 | const DefaultFont Font = 0 16 | 17 | // PushFont adds the given font on the stack. Use DefaultFont to refer to the default font. 18 | func PushFont(font Font) { 19 | C.iggPushFont(font.handle()) 20 | } 21 | 22 | // PopFont removes the previously pushed font from the stack. 23 | func PopFont() { 24 | C.iggPopFont() 25 | } 26 | 27 | // FontSize returns the current font size (= height in pixels) of the current font with the current scale applied. 28 | func FontSize() float32 { 29 | return float32(C.iggGetFontSize()) 30 | } 31 | 32 | // CalcTextSize calculates the size of the text. 33 | func CalcTextSize(text string, hideTextAfterDoubleHash bool, wrapWidth float32) Vec2 { 34 | CString := newStringBuffer(text) 35 | defer CString.free() 36 | 37 | var vec2 Vec2 38 | valueArg, returnFunc := vec2.wrapped() 39 | 40 | C.iggCalcTextSize((*C.char)(CString.ptr), C.int(CString.size)-1, castBool(hideTextAfterDoubleHash), C.float(wrapWidth), valueArg) 41 | returnFunc() 42 | 43 | return vec2 44 | } 45 | 46 | func (font Font) handle() C.IggFont { 47 | return C.IggFont(font) 48 | } 49 | 50 | // FontSize returns the height of the given font. 51 | func (font Font) FontSize() float32 { 52 | return float32(C.iggFontFontSize(font.handle())) 53 | } 54 | 55 | // FindGlyph returns the FontGlyph corresponding to the given rune. 56 | func (font Font) FindGlyph(ch rune) FontGlyph { 57 | return FontGlyph(C.iggFindGlyph(font.handle(), C.int(ch))) 58 | } 59 | 60 | func (glyph FontGlyph) handle() C.IggFontGlyph { 61 | return C.IggFontGlyph(glyph) 62 | } 63 | 64 | // Colored returns whether the glyph is colored. 65 | func (glyph FontGlyph) Colored() bool { 66 | return C.iggFontGlyphColored(glyph.handle()) != 0 67 | } 68 | 69 | // Visible indicates whether the glyph is visible; it will be false for a space character, for example. 70 | func (glyph FontGlyph) Visible() bool { 71 | return C.iggFontGlyphVisible(glyph.handle()) != 0 72 | } 73 | 74 | // Codepoint returns the codepoint associated with the glyph. 75 | func (glyph FontGlyph) Codepoint() int { 76 | return int(C.iggFontGlyphCodepoint(glyph.handle())) 77 | } 78 | 79 | // AdvanceX returns the horizontal difference to the next character after the glyph is drawn. 80 | func (glyph FontGlyph) AdvanceX() float32 { 81 | return float32(C.iggFontGlyphAdvanceX(glyph.handle())) 82 | } 83 | 84 | // X0 returns the lower x coordinate of the glyph. 85 | func (glyph FontGlyph) X0() float32 { 86 | return float32(C.iggFontGlyphX0(glyph.handle())) 87 | } 88 | 89 | // Y0 returns the lower y coordinate of the glyph. 90 | func (glyph FontGlyph) Y0() float32 { 91 | return float32(C.iggFontGlyphY0(glyph.handle())) 92 | } 93 | 94 | // X1 returns the upper x coordinate of the glyph. 95 | func (glyph FontGlyph) X1() float32 { 96 | return float32(C.iggFontGlyphX1(glyph.handle())) 97 | } 98 | 99 | // Y1 returns the upper y coordinate of the glyph. 100 | func (glyph FontGlyph) Y1() float32 { 101 | return float32(C.iggFontGlyphY1(glyph.handle())) 102 | } 103 | 104 | // U0 returns the u texture coordinate associated with the X0() vertex of the glyph. 105 | func (glyph FontGlyph) U0() float32 { 106 | return float32(C.iggFontGlyphU0(glyph.handle())) 107 | } 108 | 109 | // V0 returns the v texture coordinate associated with the Y0() vertex of the glyph. 110 | func (glyph FontGlyph) V0() float32 { 111 | return float32(C.iggFontGlyphV0(glyph.handle())) 112 | } 113 | 114 | // U1 returns the u texture coordinate associated with the X1() vertex of the glyph. 115 | func (glyph FontGlyph) U1() float32 { 116 | return float32(C.iggFontGlyphU1(glyph.handle())) 117 | } 118 | 119 | // V1 returns the v texture coordinate associated with the Y1() vertex of the glyph. 120 | func (glyph FontGlyph) V1() float32 { 121 | return float32(C.iggFontGlyphV1(glyph.handle())) 122 | } 123 | -------------------------------------------------------------------------------- /FontAtlas.go: -------------------------------------------------------------------------------- 1 | package imgui 2 | 3 | // #include "wrapper/FontAtlas.h" 4 | import "C" 5 | import "unsafe" 6 | 7 | // Alpha8Image represents a imgui backed 8-bit alpha value image. 8 | type Alpha8Image struct { 9 | Width, Height int 10 | Pixels unsafe.Pointer 11 | } 12 | 13 | // RGBA32Image represents a imgui backed 32-bit RGBA (8 bits per channel) value image. 14 | type RGBA32Image struct { 15 | Width, Height int 16 | Pixels unsafe.Pointer 17 | } 18 | 19 | // FontAtlas contains runtime data for multiple fonts, 20 | // bake multiple fonts into a single texture, TTF/OTF font loader. 21 | type FontAtlas uintptr 22 | 23 | func (atlas FontAtlas) handle() C.IggFontAtlas { 24 | return C.IggFontAtlas(atlas) 25 | } 26 | 27 | // GlyphRangesDefault describes Basic Latin, Extended Latin. 28 | func (atlas FontAtlas) GlyphRangesDefault() GlyphRanges { 29 | return GlyphRanges(C.iggGetGlyphRangesDefault(atlas.handle())) 30 | } 31 | 32 | // GlyphRangesKorean describes Default + Korean characters. 33 | func (atlas FontAtlas) GlyphRangesKorean() GlyphRanges { 34 | return GlyphRanges(C.iggGetGlyphRangesKorean(atlas.handle())) 35 | } 36 | 37 | // GlyphRangesJapanese describes Default + Hiragana, Katakana, Half-Width, Selection of 1946 Ideographs. 38 | func (atlas FontAtlas) GlyphRangesJapanese() GlyphRanges { 39 | return GlyphRanges(C.iggGetGlyphRangesJapanese(atlas.handle())) 40 | } 41 | 42 | // GlyphRangesChineseFull describes Default + Half-Width + Japanese Hiragana/Katakana + full set of about 21000 CJK 43 | // Unified Ideographs. 44 | func (atlas FontAtlas) GlyphRangesChineseFull() GlyphRanges { 45 | return GlyphRanges(C.iggGetGlyphRangesChineseFull(atlas.handle())) 46 | } 47 | 48 | // GlyphRangesChineseSimplifiedCommon describes Default + Half-Width + Japanese Hiragana/Katakana + set of 2500 CJK 49 | // Unified Ideographs for common simplified Chinese. 50 | func (atlas FontAtlas) GlyphRangesChineseSimplifiedCommon() GlyphRanges { 51 | return GlyphRanges(C.iggGetGlyphRangesChineseSimplifiedCommon(atlas.handle())) 52 | } 53 | 54 | // GlyphRangesCyrillic describes Default + about 400 Cyrillic characters. 55 | func (atlas FontAtlas) GlyphRangesCyrillic() GlyphRanges { 56 | return GlyphRanges(C.iggGetGlyphRangesCyrillic(atlas.handle())) 57 | } 58 | 59 | // GlyphRangesThai describes Default + Thai characters. 60 | func (atlas FontAtlas) GlyphRangesThai() GlyphRanges { 61 | return GlyphRanges(C.iggGetGlyphRangesThai(atlas.handle())) 62 | } 63 | 64 | // AddFontDefault adds the default font to the atlas. This is done by default if you do not call any 65 | // of the AddFont* methods before retrieving the texture data. 66 | func (atlas FontAtlas) AddFontDefault() Font { 67 | fontHandle := C.iggAddFontDefault(atlas.handle()) 68 | return Font(fontHandle) 69 | } 70 | 71 | // AddFontDefaultV adds the default font to the atlas using the specified FontConfig. 72 | func (atlas FontAtlas) AddFontDefaultV(cfg FontConfig) Font { 73 | fontHandle := C.iggAddFontDefaultV(atlas.handle(), cfg.handle()) 74 | return Font(fontHandle) 75 | } 76 | 77 | // AddFontFromFileTTFV attempts to load a font from given TTF file. 78 | func (atlas FontAtlas) AddFontFromFileTTFV(filename string, sizePixels float32, 79 | config FontConfig, glyphRange GlyphRanges) Font { 80 | filenameArg, filenameFin := wrapString(filename) 81 | defer filenameFin() 82 | fontHandle := C.iggAddFontFromFileTTF(atlas.handle(), filenameArg, C.float(sizePixels), 83 | config.handle(), glyphRange.handle()) 84 | return Font(fontHandle) 85 | } 86 | 87 | // AddFontFromFileTTF calls AddFontFromFileTTFV(filename, sizePixels, DefaultFontConfig, EmptyGlyphRanges). 88 | func (atlas FontAtlas) AddFontFromFileTTF(filename string, sizePixels float32) Font { 89 | return atlas.AddFontFromFileTTFV(filename, sizePixels, DefaultFontConfig, EmptyGlyphRanges) 90 | } 91 | 92 | // AddFontFromMemoryTTFV attempts to load a font from given TTF byte array. 93 | func (atlas FontAtlas) AddFontFromMemoryTTFV( 94 | fontData []byte, sizePixels float32, 95 | config FontConfig, 96 | glyphRange GlyphRanges, 97 | ) Font { 98 | // NOTE: We never free the fontDataC array because IMGUI's AddFontFromMemoryTTF takes ownership if 99 | // FontConfig.FontDataOwnedByAtlas == true (which it is by default). We do not expose this flag in Go 100 | // so we can assume in most cases it is true. 101 | if !config.getFontDataOwnedByAtlas() { 102 | panic("Only ImFontConfig.FontDataOwnedByAtlas == true is supported.") 103 | } 104 | 105 | fontDataC := C.malloc(C.size_t(len(fontData))) 106 | cBuf := ptrToByteSlice(fontDataC) 107 | 108 | copy(cBuf, fontData) 109 | 110 | fontHandle := C.iggAddFontFromMemoryTTF(atlas.handle(), (*C.char)(fontDataC), C.int(len(fontData)), C.float(sizePixels), 111 | config.handle(), glyphRange.handle()) 112 | 113 | return Font(fontHandle) 114 | } 115 | 116 | // AddFontFromMemoryTTF calls AddFontFromMemoryTTFV(fontData, sizePixels, DefaultFontConfig, EmptyGlyphRanges). 117 | func (atlas FontAtlas) AddFontFromMemoryTTF(fontData []byte, sizePixels float32) Font { 118 | return atlas.AddFontFromMemoryTTFV(fontData, sizePixels, DefaultFontConfig, EmptyGlyphRanges) 119 | } 120 | 121 | // SetTexDesiredWidth registers the width desired by user before building the image. Must be a power-of-two. 122 | // If have many glyphs your graphics API have texture size restrictions you may want to increase texture width to decrease height. 123 | // Set to 0 by default, causing auto-calculation. 124 | func (atlas FontAtlas) SetTexDesiredWidth(value int) { 125 | C.iggFontAtlasSetTexDesiredWidth(atlas.handle(), C.int(value)) 126 | } 127 | 128 | // TextureDataAlpha8 returns the image in 8-bit alpha values for the font atlas. 129 | // The returned image is valid as long as the font atlas is. 130 | func (atlas FontAtlas) TextureDataAlpha8() *Alpha8Image { 131 | var pixels *C.uchar 132 | var width C.int 133 | var height C.int 134 | var bytesPerPixel C.int 135 | C.iggFontAtlasGetTexDataAsAlpha8(atlas.handle(), &pixels, &width, &height, &bytesPerPixel) 136 | 137 | return &Alpha8Image{ 138 | Width: int(width), 139 | Height: int(height), 140 | Pixels: unsafe.Pointer(pixels), // nolint: gas 141 | } 142 | } 143 | 144 | // TextureDataRGBA32 returns the image in 32-bit RGBA values for the font atlas. 145 | // The returned image is valid as long as the font atlas is. 146 | func (atlas FontAtlas) TextureDataRGBA32() *RGBA32Image { 147 | var pixels *C.uchar 148 | var width C.int 149 | var height C.int 150 | var bytesPerPixel C.int 151 | C.iggFontAtlasGetTexDataAsRGBA32(atlas.handle(), &pixels, &width, &height, &bytesPerPixel) 152 | 153 | return &RGBA32Image{ 154 | Width: int(width), 155 | Height: int(height), 156 | Pixels: unsafe.Pointer(pixels), // nolint: gas 157 | } 158 | } 159 | 160 | // SetTextureID sets user data to refer to the texture once it has been uploaded to user's graphic systems. 161 | // It is passed back to you during rendering via the DrawCommand. 162 | func (atlas FontAtlas) SetTextureID(id TextureID) { 163 | C.iggFontAtlasSetTextureID(atlas.handle(), id.handle()) 164 | } 165 | 166 | // TextureID returns the renderer-specific texture identifier for the font atlas. 167 | func (atlas FontAtlas) TextureID() TextureID { 168 | return TextureID(C.iggFontAtlasGetTextureID(atlas.handle())) 169 | } 170 | 171 | // Build pixels data. This is called automatically for you by the TextureData*** functions. 172 | func (atlas FontAtlas) Build() bool { 173 | return C.iggFontAtlasBuild(atlas.handle()) != 0 174 | } 175 | 176 | // FontBuilderFlags returns shared flags (for all fonts) for custom font builder. 177 | func (atlas FontAtlas) FontBuilderFlags() uint { 178 | return uint(C.iggFontAtlasGetFontBuilderFlags(atlas.handle())) 179 | } 180 | 181 | // SetFontBuilderFlags sets shared flags (for all fonts) for custom font builder. 182 | // THIS IS BUILD IMPLEMENTATION DEPENDENT. Per-font override is also available in FontConfig. 183 | func (atlas FontAtlas) SetFontBuilderFlags(flags uint) { 184 | C.iggFontAtlasSetFontBuilderFlags(atlas.handle(), C.uint(flags)) 185 | } 186 | -------------------------------------------------------------------------------- /FontConfig.go: -------------------------------------------------------------------------------- 1 | package imgui 2 | 3 | // #include "wrapper/FontConfig.h" 4 | import "C" 5 | 6 | // FontConfig describes properties of a single font. 7 | type FontConfig uintptr 8 | 9 | // DefaultFontConfig lets ImGui take default properties as per implementation. 10 | // The properties of the default configuration cannot be changed using the SetXXX functions. 11 | const DefaultFontConfig FontConfig = 0 12 | 13 | func (config FontConfig) handle() C.IggFontConfig { 14 | return C.IggFontConfig(config) 15 | } 16 | 17 | // NewFontConfig creates a new font configuration. 18 | // Delete must be called on the returned config. 19 | func NewFontConfig() FontConfig { 20 | configHandle := C.iggNewFontConfig() 21 | return FontConfig(configHandle) 22 | } 23 | 24 | // Delete removes the font configuration and resets it to the DefaultFontConfig. 25 | func (config *FontConfig) Delete() { 26 | if *config != DefaultFontConfig { 27 | C.iggFontConfigDelete(config.handle()) 28 | *config = DefaultFontConfig 29 | } 30 | } 31 | 32 | // SetSize sets the size in pixels for rasterizer (more or less maps to the 33 | // resulting font height). 34 | func (config FontConfig) SetSize(sizePixels float32) { 35 | if config != DefaultFontConfig { 36 | C.iggFontConfigSetSize(config.handle(), C.float(sizePixels)) 37 | } 38 | } 39 | 40 | // SetOversampleH sets the oversampling amount for the X axis. 41 | // Rasterize at higher quality for sub-pixel positioning. 42 | // We don't use sub-pixel positions on the Y axis. 43 | func (config FontConfig) SetOversampleH(value int) { 44 | if config != DefaultFontConfig { 45 | C.iggFontConfigSetOversampleH(config.handle(), C.int(value)) 46 | } 47 | } 48 | 49 | // SetOversampleV sets the oversampling amount for the Y axis. 50 | // Rasterize at higher quality for sub-pixel positioning. 51 | // We don't use sub-pixel positions on the Y axis. 52 | func (config FontConfig) SetOversampleV(value int) { 53 | if config != DefaultFontConfig { 54 | C.iggFontConfigSetOversampleV(config.handle(), C.int(value)) 55 | } 56 | } 57 | 58 | // SetPixelSnapH aligns every glyph to pixel boundary if enabled. Useful e.g. if 59 | // you are merging a non-pixel aligned font with the default font. If enabled, 60 | // you can set OversampleH/V to 1. 61 | func (config FontConfig) SetPixelSnapH(value bool) { 62 | if config != DefaultFontConfig { 63 | C.iggFontConfigSetPixelSnapH(config.handle(), castBool(value)) 64 | } 65 | } 66 | 67 | // SetGlyphMinAdvanceX sets the minimum AdvanceX for glyphs. 68 | // Set Min to align font icons, set both Min/Max to enforce mono-space font. 69 | func (config FontConfig) SetGlyphMinAdvanceX(value float32) { 70 | if config != DefaultFontConfig { 71 | C.iggFontConfigSetGlyphMinAdvanceX(config.handle(), C.float(value)) 72 | } 73 | } 74 | 75 | // SetGlyphMaxAdvanceX sets the maximum AdvanceX for glyphs. 76 | // Set both Min/Max to enforce mono-space font. 77 | func (config FontConfig) SetGlyphMaxAdvanceX(value float32) { 78 | if config != DefaultFontConfig { 79 | C.iggFontConfigSetGlyphMaxAdvanceX(config.handle(), C.float(value)) 80 | } 81 | } 82 | 83 | // SetGlyphOffsetX sets the horizontal offset for all glyphs. Positive values 84 | // adjust the glyph to the right and negative values adjust the glyph to the 85 | // left. 86 | func (config FontConfig) SetGlyphOffsetX(value float32) { 87 | if config != DefaultFontConfig { 88 | C.iggFontConfigSetGlyphOffsetX(config.handle(), C.float(value)) 89 | } 90 | } 91 | 92 | // SetGlyphOffsetY sets the vertical offset for all glyphs. Positive values 93 | // adjust the glyph downward and negative value adjust the glyph upward. 94 | func (config FontConfig) SetGlyphOffsetY(value float32) { 95 | if config != DefaultFontConfig { 96 | C.iggFontConfigSetGlyphOffsetY(config.handle(), C.float(value)) 97 | } 98 | } 99 | 100 | // SetMergeMode merges the new fonts into the previous font if enabled. This way 101 | // you can combine multiple input fonts into one (e.g. ASCII font + icons + 102 | // Japanese glyphs). You may want to use GlyphOffset.y when merge font of 103 | // different heights. 104 | func (config FontConfig) SetMergeMode(value bool) { 105 | if config != DefaultFontConfig { 106 | C.iggFontConfigSetMergeMode(config.handle(), castBool(value)) 107 | } 108 | } 109 | 110 | // SetName sets a short display name for a font, for diagnostic purposes. 111 | // If the FontConfig does not provide a name, one will be synthesized for 112 | // fonts which are added from files. When adding fonts from memory, this 113 | // method can be used to provide a name. 114 | // The name will be truncated if it is longer than the limit supported by imgui. 115 | func (config FontConfig) SetName(name string) { 116 | if config != DefaultFontConfig { 117 | nameArg, nameFin := wrapString(name) 118 | defer nameFin() 119 | C.iggFontConfigSetName(config.handle(), nameArg) 120 | } 121 | } 122 | 123 | // getFontDataOwnedByAtlas gets the current ownership status of the font data. 124 | func (config FontConfig) getFontDataOwnedByAtlas() bool { 125 | if config != DefaultFontConfig { 126 | return C.iggFontConfigGetFontDataOwnedByAtlas(config.handle()) != 0 127 | } 128 | 129 | return true 130 | } 131 | 132 | // FontBuilderFlags returns settings for custom font builder. 133 | func (config FontConfig) FontBuilderFlags() uint { 134 | return uint(C.iggFontConfigGetFontBuilderFlags(config.handle())) 135 | } 136 | 137 | // SetFontBuilderFlags sets settings for custom font builder. THIS IS BUILDER IMPLEMENTATION DEPENDENT. Leave as zero if unsure. 138 | func (config FontConfig) SetFontBuilderFlags(flags uint) { 139 | C.iggFontConfigSetFontBuilderFlags(config.handle(), C.uint(flags)) 140 | } 141 | -------------------------------------------------------------------------------- /FreeType.go: -------------------------------------------------------------------------------- 1 | // +build imguifreetype 2 | 3 | package imgui 4 | 5 | // #cgo pkg-config: freetype2 6 | // #cgo CXXFLAGS: -DIMGUI_ENABLE_FREETYPE 7 | // #cgo CFLAGS: -DIMGUI_ENABLE_FREETYPE 8 | // #cgo CPPFLAGS: -DIMGUI_ENABLE_FREETYPE 9 | import "C" 10 | 11 | // Hinting greatly impacts visuals (and glyph sizes). 12 | // - By default, hinting is enabled and the font's native hinter is preferred over the auto-hinter. 13 | // - When disabled, FreeType generates blurrier glyphs, more or less matches the stb_truetype.h 14 | // - The Default hinting mode usually looks good, but may distort glyphs in an unusual way. 15 | // - The Light hinting mode generates fuzzier glyphs but better matches Microsoft's rasterizer. 16 | // You can set those flags globaly in FontAtlas.SetFontBuilderFlags(flags) 17 | // You can set those flags on a per font basis in FontConfig.SetFontBuilderFlags(flags). 18 | const ( 19 | // FreeTypeBuilderFlagsNoHinting disables hinting. 20 | // This generally generates 'blurrier' bitmap glyphs when the glyph are rendered in any of the anti-aliased modes. 21 | FreeTypeBuilderFlagsNoHinting = 1 << 0 22 | // FreeTypeBuilderFlagsNoAutoHint disables auto-hinter. 23 | FreeTypeBuilderFlagsNoAutoHint = 1 << 1 24 | // FreeTypeBuilderFlagsForceAutoHint indicates that the auto-hinter is preferred over the font's native hinter. 25 | FreeTypeBuilderFlagsForceAutoHint = 1 << 2 26 | // FreeTypeBuilderFlagsLightHinting is a lighter hinting algorithm for gray-level modes. 27 | // Many generated glyphs are fuzzier but better resemble their original shape. 28 | // This is achieved by snapping glyphs to the pixel grid only vertically (Y-axis), 29 | // as is done by Microsoft's ClearType and Adobe's proprietary font renderer. 30 | // This preserves inter-glyph spacing in horizontal text. 31 | FreeTypeBuilderFlagsLightHinting = 1 << 3 32 | // FreeTypeBuilderFlagsMonoHinting is a strong hinting algorithm that should only be used for monochrome output. 33 | FreeTypeBuilderFlagsMonoHinting = 1 << 4 34 | // FreeTypeBuilderFlagsBold is for styling: Should we artificially embolden the font? 35 | FreeTypeBuilderFlagsBold = 1 << 5 36 | // FreeTypeBuilderFlagsOblique is for styling: Should we slant the font, emulating italic style? 37 | FreeTypeBuilderFlagsOblique = 1 << 6 38 | // FreeTypeBuilderFlagsMonochrome disables anti-aliasing. Combine this with MonoHinting for best results! 39 | FreeTypeBuilderFlagsMonochrome = 1 << 7 40 | // FreeTypeBuilderFlagsLoadColor enables FreeType color-layered glyphs. 41 | FreeTypeBuilderFlagsLoadColor = 1 << 8 42 | // FreeTypeBuilderFlagsBitmap enables FreeType bitmap glyphs 43 | FreeTypeBuilderFlagsBitmap = 1 << 9 44 | ) 45 | -------------------------------------------------------------------------------- /GlyphRanges.go: -------------------------------------------------------------------------------- 1 | package imgui 2 | 3 | // #include "wrapper/Types.h" 4 | import "C" 5 | import "unsafe" 6 | 7 | // GlyphRanges describes a list of Unicode ranges; 2 value per range, values are inclusive. 8 | // Standard ranges can be queried from FontAtlas.GlyphRanges*() functions. 9 | type GlyphRanges uintptr 10 | 11 | // EmptyGlyphRanges is one that does not contain any ranges. 12 | const EmptyGlyphRanges GlyphRanges = 0 13 | 14 | func (glyphs GlyphRanges) handle() C.IggGlyphRanges { 15 | return C.IggGlyphRanges(glyphs) 16 | } 17 | 18 | type glyphRange struct{ from, to uint16 } 19 | 20 | func (glyphs GlyphRanges) extract() (result []glyphRange) { 21 | if glyphs == 0 { 22 | return 23 | } 24 | rawSlice := ptrToUint16Slice(unsafe.Pointer(glyphs.handle())) 25 | index := 0 26 | // iterate until end of list or an arbitrary paranoia limit, should the list not be proper. 27 | for (rawSlice[index] != 0) && (index < 1000) { 28 | result = append(result, glyphRange{from: rawSlice[index+0], to: rawSlice[index+1]}) 29 | index += 2 30 | } 31 | return 32 | } 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | New BSD License 2 | 3 | © 2018, Christian Haas 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | * Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | * Neither the name of "InkyBlackness" nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE LISTED COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /Layout.go: -------------------------------------------------------------------------------- 1 | package imgui 2 | 3 | // #include "wrapper/Layout.h" 4 | import "C" 5 | 6 | // PushID pushes the given identifier into the ID stack. IDs are hash of the entire stack! 7 | func PushID(id string) { 8 | idArg, idFin := wrapString(id) 9 | defer idFin() 10 | C.iggPushID(idArg) 11 | } 12 | 13 | // PushIDInt pushes the given identifier into the ID stack. IDs are hash of the entire stack! 14 | func PushIDInt(id int) { 15 | C.iggPushIDInt(C.int(id)) 16 | } 17 | 18 | // PopID removes the last pushed identifier from the ID stack. 19 | func PopID() { 20 | C.iggPopID() 21 | } 22 | 23 | // Separator is generally horizontal. Inside a menu bar or in horizontal layout mode, this becomes a vertical separator. 24 | func Separator() { 25 | C.iggSeparator() 26 | } 27 | 28 | // SameLineV is between widgets or groups to layout them horizontally. 29 | func SameLineV(posX float32, spacingW float32) { 30 | C.iggSameLine(C.float(posX), C.float(spacingW)) 31 | } 32 | 33 | // SameLine calls SameLineV(0, -1). 34 | func SameLine() { 35 | SameLineV(0, -1) 36 | } 37 | 38 | // Spacing adds vertical spacing. 39 | func Spacing() { 40 | C.iggSpacing() 41 | } 42 | 43 | // Dummy adds a dummy item of given size. 44 | func Dummy(size Vec2) { 45 | sizeArg, _ := size.wrapped() 46 | C.iggDummy(sizeArg) 47 | } 48 | 49 | // Indent moves content position toward the right by style.IndentSpacing. 50 | func Indent() { 51 | C.iggIndent(0) 52 | } 53 | 54 | // Unindent moves content position back to the left by style.IndentSpacing. 55 | func Unindent() { 56 | C.iggUnindent(0) 57 | } 58 | 59 | // IndentV moves content position toward the right, by style.IndentSpacing or indentW if not zero. 60 | func IndentV(indentW float32) { 61 | C.iggIndent(C.float(indentW)) 62 | } 63 | 64 | // UnindentV moves content position back to the left, by style.IndentSpacing or indentW if not zero. 65 | func UnindentV(indentW float32) { 66 | C.iggUnindent(C.float(indentW)) 67 | } 68 | 69 | // BeginGroup locks horizontal starting position + capture group bounding box into one "item"; 70 | // So you can use IsItemHovered() or layout primitives such as SameLine() on whole group, etc. 71 | func BeginGroup() { 72 | C.iggBeginGroup() 73 | } 74 | 75 | // EndGroup must be called for each call to BeginGroup(). 76 | func EndGroup() { 77 | C.iggEndGroup() 78 | } 79 | 80 | /* 81 | // Disabled API is beta as v1.84; they can change in such a way that require a 82 | // major version. So, it's better to leave them out until out of beta. 83 | 84 | // BeginDisabled starts a disabled group. 85 | func BeginDisabled() { 86 | BeginDisabledV(true) 87 | } 88 | 89 | // BeginDisabledV starts a disabled group only if parameter is true. 90 | func BeginDisabledV(disabled bool) { 91 | C.iggBeginDisabled(castBool(disabled)) 92 | } 93 | 94 | // EndDisabled must be called for each call to BeginDisabled(). 95 | func EndDisabled() { 96 | C.iggEndDisabled() 97 | } 98 | */ 99 | 100 | // CursorPos returns the cursor position in window coordinates (relative to window position). 101 | func CursorPos() Vec2 { 102 | var value Vec2 103 | valueArg, valueFin := value.wrapped() 104 | C.iggCursorPos(valueArg) 105 | valueFin() 106 | return value 107 | } 108 | 109 | // CursorPosX returns the x-coordinate of the cursor position in window coordinates. 110 | func CursorPosX() float32 { 111 | return float32(C.iggCursorPosX()) 112 | } 113 | 114 | // CursorPosY returns the y-coordinate of the cursor position in window coordinates. 115 | func CursorPosY() float32 { 116 | return float32(C.iggCursorPosY()) 117 | } 118 | 119 | // CursorStartPos returns the initial cursor position in window coordinates. 120 | func CursorStartPos() Vec2 { 121 | var value Vec2 122 | valueArg, valueFin := value.wrapped() 123 | C.iggCursorStartPos(valueArg) 124 | valueFin() 125 | return value 126 | } 127 | 128 | // CursorScreenPos returns cursor position in absolute coordinates (useful to work with DrawList API). 129 | // Generally top-left == MainViewport().Pos() == (0,0) in single viewport mode, 130 | // and bottom-right == MainViewport().Pos()+Size == io.DisplaySize in single-viewport mode. 131 | func CursorScreenPos() Vec2 { 132 | var value Vec2 133 | valueArg, valueFin := value.wrapped() 134 | C.iggCursorScreenPos(valueArg) 135 | valueFin() 136 | return value 137 | } 138 | 139 | // SetCursorPos sets the cursor relative to the current window. 140 | func SetCursorPos(localPos Vec2) { 141 | localPosArg, _ := localPos.wrapped() 142 | C.iggSetCursorPos(localPosArg) 143 | } 144 | 145 | // SetCursorScreenPos sets cursor position in absolute coordinates. 146 | func SetCursorScreenPos(absPos Vec2) { 147 | absPosArg, _ := absPos.wrapped() 148 | C.iggSetCursorScreenPos(absPosArg) 149 | } 150 | 151 | // AlignTextToFramePadding vertically aligns upcoming text baseline to 152 | // FramePadding.y so that it will align properly to regularly framed 153 | // items. Call if you have text on a line before a framed item. 154 | func AlignTextToFramePadding() { 155 | C.iggAlignTextToFramePadding() 156 | } 157 | 158 | // TextLineHeight returns ~ FontSize. 159 | func TextLineHeight() float32 { 160 | return float32(C.iggGetTextLineHeight()) 161 | } 162 | 163 | // TextLineHeightWithSpacing returns ~ FontSize + style.ItemSpacing.y (distance in pixels between 2 consecutive lines of text). 164 | func TextLineHeightWithSpacing() float32 { 165 | return float32(C.iggGetTextLineHeightWithSpacing()) 166 | } 167 | 168 | // FrameHeight returns the height of the current frame. This is equal to the 169 | // font size plus the padding at the top and bottom. 170 | func FrameHeight() float32 { 171 | return float32(C.iggGetFrameHeight()) 172 | } 173 | 174 | // FrameHeightWithSpacing returns the height of the current frame with the item 175 | // spacing added. This is equal to the font size plus the padding at the top 176 | // and bottom, plus the value of style.ItemSpacing.y. 177 | func FrameHeightWithSpacing() float32 { 178 | return float32(C.iggGetFrameHeightWithSpacing()) 179 | } 180 | -------------------------------------------------------------------------------- /ListClipper.go: -------------------------------------------------------------------------------- 1 | package imgui 2 | 3 | // #include "wrapper/ListClipper.h" 4 | import "C" 5 | 6 | // ListClipper is a helper to manually clip large list of items. 7 | // If you are submitting lots of evenly spaced items and you have a random access to the list, you can perform coarse 8 | // clipping based on visibility to save yourself from processing those items at all. 9 | // The clipper calculates the range of visible items and advance the cursor to compensate for the non-visible items we have skipped. 10 | // (Dear ImGui already clip items based on their bounds but it needs to measure text size to do so, whereas manual coarse clipping before submission makes this cost and your own data fetching/submission cost almost null) 11 | // Usage: 12 | // var clipper imgui.ListClipper 13 | // clipper.Begin(1000) // We have 1000 elements, evenly spaced. 14 | // for clipper.Step() { 15 | // for i := clipper.DisplayStart; i < clipper.DisplayEnd; i += 1 { 16 | // imgui.Text(fmt.Sprintf("line number %d", i)) 17 | // } 18 | // } 19 | // Generally what happens is: 20 | // - Clipper lets you process the first element (DisplayStart = 0, DisplayEnd = 1) regardless of it being visible or not. 21 | // - User code submit one element. 22 | // - Clipper can measure the height of the first element 23 | // - Clipper calculate the actual range of elements to display based on the current clipping rectangle, position the cursor before the first visible element. 24 | // - User code submit visible elements. 25 | type ListClipper struct { 26 | DisplayStart int 27 | DisplayEnd int 28 | 29 | // [Internal] 30 | ItemsCount int 31 | StepNo int 32 | ItemsFrozen int 33 | ItemsHeight float32 34 | StartPosY float32 35 | } 36 | 37 | // wrapped returns C struct and func for setting the values when done. 38 | func (clipper *ListClipper) wrapped() (out *C.IggListClipper, finisher func()) { 39 | if clipper == nil { 40 | return nil, func() {} 41 | } 42 | out = &C.IggListClipper{ 43 | DisplayStart: C.int(clipper.DisplayStart), 44 | DisplayEnd: C.int(clipper.DisplayEnd), 45 | 46 | ItemsCount: C.int(clipper.ItemsCount), 47 | StepNo: C.int(clipper.StepNo), 48 | ItemsFrozen: C.int(clipper.ItemsFrozen), 49 | ItemsHeight: C.float(clipper.ItemsHeight), 50 | StartPosY: C.float(clipper.StartPosY), 51 | } 52 | finisher = func() { 53 | clipper.DisplayStart = int(out.DisplayStart) 54 | clipper.DisplayEnd = int(out.DisplayEnd) 55 | 56 | clipper.ItemsCount = int(out.ItemsCount) 57 | clipper.StepNo = int(out.StepNo) 58 | clipper.ItemsFrozen = int(out.ItemsFrozen) 59 | clipper.ItemsHeight = float32(out.ItemsHeight) 60 | clipper.StartPosY = float32(out.StartPosY) 61 | } 62 | return 63 | } 64 | 65 | // Step must be called in a loop until it returns false. 66 | // The DisplayStart/DisplayEnd fields will be set and you can process/draw those items. 67 | func (clipper *ListClipper) Step() bool { 68 | arg, finishFunc := clipper.wrapped() 69 | defer finishFunc() 70 | return C.iggListClipperStep(arg) != 0 71 | } 72 | 73 | // Begin calls BeginV(itemsCount, -1.0) . 74 | func (clipper *ListClipper) Begin(itemsCount int) { 75 | clipper.BeginV(itemsCount, -1.0) 76 | } 77 | 78 | // BeginV must be called before stepping. 79 | // Use an itemCount of math.MaxInt if you don't know how many items you have. 80 | // In this case the cursor won't be advanced in the final step. 81 | // 82 | // For itemsHeight, use -1.0 to be calculated automatically on first step. 83 | // Otherwise pass in the distance between your items, typically 84 | // GetTextLineHeightWithSpacing() or GetFrameHeightWithSpacing(). 85 | func (clipper *ListClipper) BeginV(itemsCount int, itemsHeight float32) { 86 | arg, finishFunc := clipper.wrapped() 87 | defer finishFunc() 88 | C.iggListClipperBegin(arg, C.int(itemsCount), C.float(itemsHeight)) 89 | } 90 | 91 | // End resets the clipper. This function is automatically called on the last call of Step() that returns false. 92 | func (clipper *ListClipper) End() { 93 | arg, finishFunc := clipper.wrapped() 94 | defer finishFunc() 95 | C.iggListClipperEnd(arg) 96 | } 97 | -------------------------------------------------------------------------------- /Main.go: -------------------------------------------------------------------------------- 1 | package imgui 2 | 3 | // #include "wrapper/Main.h" 4 | import "C" 5 | 6 | // Version returns a version string e.g. "1.23". 7 | func Version() string { 8 | return C.GoString(C.iggGetVersion()) 9 | } 10 | 11 | // Time returns global imgui time. Incremented by io.DeltaTime every frame. 12 | func Time() float64 { 13 | return float64(C.iggGetTime()) 14 | } 15 | 16 | // NewFrame starts a new ImGui frame, you can submit any command from this point until Render()/EndFrame(). 17 | func NewFrame() { 18 | C.iggNewFrame() 19 | } 20 | 21 | // Render ends the ImGui frame, finalize the draw data. 22 | // After this method, call RenderedDrawData to retrieve the draw commands and execute them. 23 | func Render() { 24 | C.iggRender() 25 | } 26 | 27 | // EndFrame ends the ImGui frame. Automatically called by Render(), so most likely don't need to ever 28 | // call that yourself directly. If you don't need to render you may call EndFrame() but you'll have 29 | // wasted CPU already. If you don't need to render, better to not create any imgui windows instead! 30 | func EndFrame() { 31 | C.iggEndFrame() 32 | } 33 | -------------------------------------------------------------------------------- /Main_test.go: -------------------------------------------------------------------------------- 1 | package imgui_test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/inkyblackness/imgui-go/v4" 7 | 8 | "github.com/stretchr/testify/assert" 9 | ) 10 | 11 | func TestVersion(t *testing.T) { 12 | version := imgui.Version() 13 | assert.Equal(t, "1.85", version) 14 | } 15 | -------------------------------------------------------------------------------- /PackedColor.go: -------------------------------------------------------------------------------- 1 | package imgui 2 | 3 | import ( 4 | "image/color" 5 | "math" 6 | ) 7 | 8 | // PackedColor is a 32-bit RGBA color value, with 8 bits per color channel. 9 | // The bytes are assigned as 0xAABBGGRR. 10 | type PackedColor uint32 11 | 12 | const ( 13 | packedRedShift = 0 14 | packedGreenShift = 8 15 | packedBlueShift = 16 16 | packedAlphaShift = 24 17 | ) 18 | 19 | // RGBA implements the color.Color interface. 20 | func (clr PackedColor) RGBA() (r, g, b, a uint32) { 21 | return color.NRGBA{ 22 | R: uint8(uint32(clr) >> packedRedShift), 23 | G: uint8(uint32(clr) >> packedGreenShift), 24 | B: uint8(uint32(clr) >> packedBlueShift), 25 | A: uint8(uint32(clr) >> packedAlphaShift), 26 | }.RGBA() 27 | } 28 | 29 | // PackedColorModel converts colors to PackedColor instances. 30 | var PackedColorModel = color.ModelFunc(func(in color.Color) color.Color { return Packed(in) }) 31 | 32 | // Packed converts the given color to a PackedColor instance. 33 | func Packed(c color.Color) PackedColor { 34 | nrgba := color.NRGBAModel.Convert(c).(color.NRGBA) 35 | return PackedColor(0 | 36 | uint32(nrgba.R)<= math.MaxUint8: 50 | return math.MaxUint8 51 | default: 52 | return uint32(scaled) 53 | } 54 | } 55 | return PackedColor(0 | 56 | convert(vec.X)< If you are trying to do this on MS Windows with MinGW and receive an error like 80 | > `pkg-config: exec: "pkg-config": executable file not found in %PATH%`, 81 | > refer to [online guides](https://stackoverflow.com/questions/1710922/how-to-install-pkg-config-in-windows) on how to add this to your installation. 82 | 83 | ## Alternatives 84 | 85 | Since 2022-08, there is https://github.com/AllenDang/cimgui-go , which is an auto-generated wrapper that 86 | makes it easier to be at the latest version of **Dear ImGui**. It is recommended to use that one instead. 87 | 88 | Before inkyblackness/imgui-go was created, the following alternatives were considered - and ignored: 89 | * `kdrag0n/go-imgui` (no longer available). Reasons for dismissal at time of decision: 90 | * Auto-generated bloat, which doesn't help 91 | * Was using old API (1.5x) 92 | * Did not compile 93 | * Project appeared to be abandoned 94 | * [Extrawurst/cimgui](https://github.com/Extrawurst/cimgui). Reasons for dismissal at time of decision: 95 | * Was using old API (1.5x), 1.6x was attempted 96 | * Apparently semi-exposed the C++ API, especially through the structures 97 | * Adding this adds another dependency 98 | * Note: `cimgui` has since switched to an auto-generated method. You can use that instead of this manually curated wrapper here. 99 | 100 | 101 | ## License 102 | 103 | The project is available under the terms of the **New BSD License** (see LICENSE file). 104 | The licenses of included sources are stored in the **_licenses** folder. 105 | -------------------------------------------------------------------------------- /Scroll.go: -------------------------------------------------------------------------------- 1 | package imgui 2 | 3 | // #include "wrapper/Scroll.h" 4 | import "C" 5 | 6 | // ScrollX returns the horizontal scrolling amount [0..GetScrollMaxX()]. 7 | func ScrollX() float32 { 8 | return float32(C.iggGetScrollX()) 9 | } 10 | 11 | // ScrollY returns the vertical scrolling amount [0..GetScrollMaxY()]. 12 | func ScrollY() float32 { 13 | return float32(C.iggGetScrollY()) 14 | } 15 | 16 | // ScrollMaxX returns the maximum horizontal scrolling amount: ContentSize.X - WindowSize.X . 17 | func ScrollMaxX() float32 { 18 | return float32(C.iggGetScrollMaxX()) 19 | } 20 | 21 | // ScrollMaxY returns the maximum vertical scrolling amount: ContentSize.Y - WindowSize.Y . 22 | func ScrollMaxY() float32 { 23 | return float32(C.iggGetScrollMaxY()) 24 | } 25 | 26 | // SetScrollHereX adjusts horizontal scrolling amount to make current cursor 27 | // position visible. ratio=0.0: left, 0.5: center, 1.0: right. When using to 28 | // make a "default/current item" visible, consider using SetItemDefaultFocus() 29 | // instead. 30 | func SetScrollHereX(ratio float32) { 31 | C.iggSetScrollHereX(C.float(ratio)) 32 | } 33 | 34 | // SetScrollHereY adjusts vertical scrolling amount to make current cursor 35 | // position visible. ratio=0.0: top, 0.5: center, 1.0: bottom. When using to 36 | // make a "default/current item" visible, consider using SetItemDefaultFocus() 37 | // instead. 38 | func SetScrollHereY(ratio float32) { 39 | C.iggSetScrollHereY(C.float(ratio)) 40 | } 41 | 42 | // SetScrollX sets horizontal scrolling amount [0 .. ScrollMaxX()]. 43 | func SetScrollX(scrollX float32) { 44 | C.iggSetScrollX(C.float(scrollX)) 45 | } 46 | 47 | // SetScrollY sets vertical scrolling amount [0 .. ScrollMaxY()]. 48 | func SetScrollY(scrollY float32) { 49 | C.iggSetScrollY(C.float(scrollY)) 50 | } 51 | -------------------------------------------------------------------------------- /Settings.go: -------------------------------------------------------------------------------- 1 | package imgui 2 | 3 | // #include "wrapper/Settings.h" 4 | import "C" 5 | 6 | // LoadIniSettingsFromDisk loads ini settings from disk. 7 | func LoadIniSettingsFromDisk(fileName string) { 8 | fileNameArg, fileNameFin := wrapString(fileName) 9 | defer fileNameFin() 10 | C.iggLoadIniSettingsFromDisk(fileNameArg) 11 | } 12 | 13 | // LoadIniSettingsFromMemory loads ini settings from memory. 14 | func LoadIniSettingsFromMemory(data string) { 15 | dataArg, dataFin := wrapString(data) 16 | defer dataFin() 17 | C.iggLoadIniSettingsFromMemory(dataArg) 18 | } 19 | 20 | // SaveIniSettingsToDisk saves ini settings to disk. 21 | func SaveIniSettingsToDisk(fileName string) { 22 | fileNameArg, fileNameFin := wrapString(fileName) 23 | defer fileNameFin() 24 | C.iggSaveIniSettingsToDisk(fileNameArg) 25 | } 26 | 27 | // SaveIniSettingsToMemory saves ini settings to memory. 28 | func SaveIniSettingsToMemory() string { 29 | return C.GoString(C.iggSaveIniSettingsToMemory()) 30 | } 31 | -------------------------------------------------------------------------------- /TextureID.go: -------------------------------------------------------------------------------- 1 | package imgui 2 | 3 | // #include "wrapper/Types.h" 4 | import "C" 5 | 6 | // TextureID is a user data to identify a texture. 7 | // 8 | // TextureID is a uintptr used to pass renderer-agnostic texture references around until it hits your render function. 9 | // imgui knows nothing about what those bits represent, it just passes them around. It is up to you to decide what you want the value to carry! 10 | // 11 | // It could be an identifier to your OpenGL texture (cast as uint32), a key to your custom engine material, etc. 12 | // At the end of the chain, your renderer takes this value to cast it back into whatever it needs to select a current texture to render. 13 | // 14 | // To display a custom image/texture within an imgui window, you may use functions such as imgui.Image(). 15 | // imgui will generate the geometry and draw calls using the TextureID that you passed and which your renderer can use. 16 | // It is your responsibility to get textures uploaded to your GPU. 17 | // 18 | // Note: Internally, the value is based on a pointer type, so its size is dependent on your architecture. 19 | // For the most part, this will be 64bits on current systems (in 2018). 20 | // Beware: This value must never be a Go pointer, because the value escapes the runtime! 21 | type TextureID uintptr 22 | 23 | func (id TextureID) handle() C.IggTextureID { 24 | return C.IggTextureID(id) 25 | } 26 | -------------------------------------------------------------------------------- /Vectors.go: -------------------------------------------------------------------------------- 1 | package imgui 2 | 3 | // #include "wrapper/Types.h" 4 | import "C" 5 | 6 | // Vec2 represents a two-dimensional vector. 7 | type Vec2 struct { 8 | X float32 9 | Y float32 10 | } 11 | 12 | func (vec *Vec2) wrapped() (out *C.IggVec2, finisher func()) { 13 | if vec != nil { 14 | out = &C.IggVec2{ 15 | x: C.float(vec.X), 16 | y: C.float(vec.Y), 17 | } 18 | finisher = func() { 19 | vec.X = float32(out.x) // nolint: gotype 20 | vec.Y = float32(out.y) // nolint: gotype 21 | } 22 | } else { 23 | finisher = func() {} 24 | } 25 | return 26 | } 27 | 28 | // Plus returns vec + other. 29 | func (vec Vec2) Plus(other Vec2) Vec2 { 30 | return Vec2{ 31 | X: vec.X + other.X, 32 | Y: vec.Y + other.Y, 33 | } 34 | } 35 | 36 | // Minus returns vec - other. 37 | func (vec Vec2) Minus(other Vec2) Vec2 { 38 | return Vec2{ 39 | X: vec.X - other.X, 40 | Y: vec.Y - other.Y, 41 | } 42 | } 43 | 44 | // Times returns vec * value. 45 | func (vec Vec2) Times(value float32) Vec2 { 46 | return Vec2{ 47 | X: vec.X * value, 48 | Y: vec.Y * value, 49 | } 50 | } 51 | 52 | // Vec4 represents a four-dimensional vector. 53 | type Vec4 struct { 54 | X float32 55 | Y float32 56 | Z float32 57 | W float32 58 | } 59 | 60 | func (vec *Vec4) wrapped() (out *C.IggVec4, finisher func()) { 61 | if vec != nil { 62 | out = &C.IggVec4{ 63 | x: C.float(vec.X), 64 | y: C.float(vec.Y), 65 | z: C.float(vec.Z), 66 | w: C.float(vec.W), 67 | } 68 | finisher = func() { 69 | vec.X = float32(out.x) // nolint: gotype 70 | vec.Y = float32(out.y) // nolint: gotype 71 | vec.Z = float32(out.z) // nolint: gotype 72 | vec.W = float32(out.w) // nolint: gotype 73 | } 74 | } else { 75 | finisher = func() {} 76 | } 77 | return 78 | } 79 | 80 | // Plus returns vec + other. 81 | func (vec Vec4) Plus(other Vec4) Vec4 { 82 | return Vec4{ 83 | X: vec.X + other.X, 84 | Y: vec.Y + other.Y, 85 | Z: vec.Z + other.Z, 86 | W: vec.W + other.W, 87 | } 88 | } 89 | 90 | // Minus returns vec - other. 91 | func (vec Vec4) Minus(other Vec4) Vec4 { 92 | return Vec4{ 93 | X: vec.X - other.X, 94 | Y: vec.Y - other.Y, 95 | Z: vec.Z - other.Z, 96 | W: vec.W - other.W, 97 | } 98 | } 99 | 100 | // Times returns vec * value. 101 | func (vec Vec4) Times(value float32) Vec4 { 102 | return Vec4{ 103 | X: vec.X * value, 104 | Y: vec.Y * value, 105 | Z: vec.Z * value, 106 | W: vec.W * value, 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /Vectors_test.go: -------------------------------------------------------------------------------- 1 | package imgui_test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/assert" 7 | 8 | "github.com/inkyblackness/imgui-go/v4" 9 | ) 10 | 11 | func TestVec2Addition(t *testing.T) { 12 | tt := []struct { 13 | first imgui.Vec2 14 | second imgui.Vec2 15 | expected imgui.Vec2 16 | }{ 17 | {first: imgui.Vec2{X: 0, Y: 0}, second: imgui.Vec2{X: 10, Y: 10}, expected: imgui.Vec2{X: 10, Y: 10}}, 18 | {first: imgui.Vec2{X: 10, Y: 10}, second: imgui.Vec2{X: -20, Y: 100.5}, expected: imgui.Vec2{X: -10, Y: 110.5}}, 19 | {first: imgui.Vec2{X: 2, Y: 4}, second: imgui.Vec2{X: -2, Y: -4}, expected: imgui.Vec2{X: 0, Y: 0}}, 20 | } 21 | 22 | for _, tc := range tt { 23 | assert.Equal(t, tc.expected, tc.first.Plus(tc.second), "Failed for %v + %v", tc.first, tc.second) 24 | } 25 | } 26 | 27 | func TestVec2Subtraction(t *testing.T) { 28 | tt := []struct { 29 | first imgui.Vec2 30 | second imgui.Vec2 31 | expected imgui.Vec2 32 | }{ 33 | {first: imgui.Vec2{X: 0, Y: 0}, second: imgui.Vec2{X: 10, Y: 10}, expected: imgui.Vec2{X: -10, Y: -10}}, 34 | {first: imgui.Vec2{X: 10, Y: 10}, second: imgui.Vec2{X: -20, Y: 100.5}, expected: imgui.Vec2{X: 30, Y: -90.5}}, 35 | {first: imgui.Vec2{X: 2, Y: 4}, second: imgui.Vec2{X: -2, Y: -4}, expected: imgui.Vec2{X: 4, Y: 8}}, 36 | } 37 | 38 | for _, tc := range tt { 39 | assert.Equal(t, tc.expected, tc.first.Minus(tc.second), "Failed for %v - %v", tc.first, tc.second) 40 | } 41 | } 42 | 43 | func TestVec2Scaling(t *testing.T) { 44 | tt := []struct { 45 | first imgui.Vec2 46 | scale float32 47 | expected imgui.Vec2 48 | }{ 49 | {first: imgui.Vec2{X: 1, Y: 2}, scale: 1.0, expected: imgui.Vec2{X: 1, Y: 2}}, 50 | {first: imgui.Vec2{X: 10, Y: 10}, scale: 0.0, expected: imgui.Vec2{X: 0, Y: 0}}, 51 | {first: imgui.Vec2{X: 2, Y: 4}, scale: -2.0, expected: imgui.Vec2{X: -4, Y: -8}}, 52 | } 53 | 54 | for _, tc := range tt { 55 | assert.Equal(t, tc.expected, tc.first.Times(tc.scale), "Failed for %v * %v", tc.first, tc.scale) 56 | } 57 | } 58 | 59 | func TestVec4Addition(t *testing.T) { 60 | vec := func(x, y, z, w float32) imgui.Vec4 { 61 | return imgui.Vec4{X: x, Y: y, Z: z, W: w} 62 | } 63 | tt := []struct { 64 | first imgui.Vec4 65 | second imgui.Vec4 66 | expected imgui.Vec4 67 | }{ 68 | {first: vec(0, 0, 0, 0), second: vec(10, 20, 30, 40), expected: vec(10, 20, 30, 40)}, 69 | {first: vec(10, 20, 30, 40), second: vec(-5, -5, -5, -5), expected: vec(5, 15, 25, 35)}, 70 | {first: vec(1, 2, 3, 4), second: vec(-10, -10, -10, -10), expected: vec(-9, -8, -7, -6)}, 71 | } 72 | 73 | for _, tc := range tt { 74 | assert.Equal(t, tc.expected, tc.first.Plus(tc.second), "Failed for %v + %v", tc.first, tc.second) 75 | } 76 | } 77 | 78 | func TestVec4Subtraction(t *testing.T) { 79 | vec := func(x, y, z, w float32) imgui.Vec4 { 80 | return imgui.Vec4{X: x, Y: y, Z: z, W: w} 81 | } 82 | tt := []struct { 83 | first imgui.Vec4 84 | second imgui.Vec4 85 | expected imgui.Vec4 86 | }{ 87 | {first: vec(0, 0, 0, 0), second: vec(10, 20, 30, 40), expected: vec(-10, -20, -30, -40)}, 88 | {first: vec(10, 20, 30, 40), second: vec(-5, -5, -5, -5), expected: vec(15, 25, 35, 45)}, 89 | {first: vec(1, 2, 3, 4), second: vec(-10, -10, -10, -10), expected: vec(11, 12, 13, 14)}, 90 | } 91 | 92 | for _, tc := range tt { 93 | assert.Equal(t, tc.expected, tc.first.Minus(tc.second), "Failed for %v - %v", tc.first, tc.second) 94 | } 95 | } 96 | 97 | func TestVec4Scaling(t *testing.T) { 98 | vec := func(x, y, z, w float32) imgui.Vec4 { 99 | return imgui.Vec4{X: x, Y: y, Z: z, W: w} 100 | } 101 | tt := []struct { 102 | first imgui.Vec4 103 | scale float32 104 | expected imgui.Vec4 105 | }{ 106 | {first: vec(10, 20, 30, 40), scale: 1.0, expected: vec(10, 20, 30, 40)}, 107 | {first: vec(10, 20, 30, 40), scale: -0.5, expected: vec(-5, -10, -15, -20)}, 108 | {first: vec(1, 2, 3, 4), scale: 2.0, expected: vec(2, 4, 6, 8)}, 109 | } 110 | 111 | for _, tc := range tt { 112 | assert.Equal(t, tc.expected, tc.first.Times(tc.scale), "Failed for %v * %v", tc.first, tc.scale) 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /WrapperConverter.go: -------------------------------------------------------------------------------- 1 | package imgui 2 | 3 | // #include "wrapper/Types.h" 4 | // #include 5 | // #include 6 | import "C" 7 | import "unsafe" 8 | 9 | func castBool(value bool) (cast C.IggBool) { 10 | if value { 11 | cast = 1 12 | } 13 | return 14 | } 15 | 16 | func wrapBool(goValue *bool) (wrapped *C.IggBool, finisher func()) { 17 | if goValue != nil { 18 | var cValue C.IggBool 19 | if *goValue { 20 | cValue = 1 21 | } 22 | wrapped = &cValue 23 | finisher = func() { 24 | *goValue = cValue != 0 25 | } 26 | } else { 27 | finisher = func() {} 28 | } 29 | return 30 | } 31 | 32 | func wrapInt32(goValue *int32) (wrapped *C.int, finisher func()) { 33 | if goValue != nil { 34 | cValue := C.int(*goValue) 35 | wrapped = &cValue 36 | finisher = func() { 37 | *goValue = int32(cValue) 38 | } 39 | } else { 40 | finisher = func() {} 41 | } 42 | return 43 | } 44 | 45 | func wrapFloat(goValue *float32) (wrapped *C.float, finisher func()) { 46 | if goValue != nil { 47 | cValue := C.float(*goValue) 48 | wrapped = &cValue 49 | finisher = func() { 50 | *goValue = float32(cValue) 51 | } 52 | } else { 53 | finisher = func() {} 54 | } 55 | return 56 | } 57 | 58 | func wrapString(value string) (wrapped *C.char, finisher func()) { 59 | wrapped = C.CString(value) 60 | finisher = func() { C.free(unsafe.Pointer(wrapped)) } // nolint: gas 61 | return 62 | } 63 | 64 | func wrapBytes(value []byte) (wrapped unsafe.Pointer, finisher func()) { 65 | wrapped = C.CBytes(value) 66 | finisher = func() { C.free(wrapped) } // nolint: gas 67 | return 68 | } 69 | 70 | type stringBuffer struct { 71 | ptr unsafe.Pointer 72 | size int 73 | } 74 | 75 | func newStringBuffer(initialValue string) *stringBuffer { 76 | rawText := []byte(initialValue) 77 | bufSize := len(rawText) + 1 78 | newPtr := C.malloc(C.size_t(bufSize)) 79 | zeroOffset := bufSize - 1 80 | buf := ptrToByteSlice(newPtr) 81 | copy(buf[:zeroOffset], rawText) 82 | buf[zeroOffset] = 0 83 | 84 | return &stringBuffer{ptr: newPtr, size: bufSize} 85 | } 86 | 87 | func (buf *stringBuffer) free() { 88 | C.free(buf.ptr) 89 | buf.size = 0 90 | } 91 | 92 | func (buf *stringBuffer) resizeTo(requestedSize int) { 93 | bufSize := requestedSize 94 | if bufSize < 1 { 95 | bufSize = 1 96 | } 97 | newPtr := C.malloc(C.size_t(bufSize)) 98 | copySize := bufSize 99 | if copySize > buf.size { 100 | copySize = buf.size 101 | } 102 | if copySize > 0 { 103 | C.memcpy(newPtr, buf.ptr, C.size_t(copySize)) 104 | } 105 | ptrToByteSlice(newPtr)[bufSize-1] = 0 106 | C.free(buf.ptr) 107 | buf.ptr = newPtr 108 | buf.size = bufSize 109 | } 110 | 111 | func (buf stringBuffer) toGo() string { 112 | if (buf.ptr == nil) || (buf.size < 1) { 113 | return "" 114 | } 115 | ptrToByteSlice(buf.ptr)[buf.size-1] = 0 116 | return C.GoString((*C.char)(buf.ptr)) 117 | } 118 | 119 | // unrealisticLargePointer is used to cast an arbitrary native pointer to a slice. 120 | // Its value is chosen to fit into a 32bit architecture, and still be large 121 | // enough to cover "any" data blob. Note that this value is in bytes. 122 | // Should an array of larger primitives be addressed, be sure to divide the value 123 | // by the size of the elements. 124 | const unrealisticLargePointer = 1 << 30 125 | 126 | func ptrToByteSlice(p unsafe.Pointer) []byte { 127 | return (*[unrealisticLargePointer]byte)(p)[:] 128 | } 129 | 130 | func ptrToUint16Slice(p unsafe.Pointer) []uint16 { 131 | return (*[unrealisticLargePointer / 2]uint16)(p)[:] 132 | } 133 | -------------------------------------------------------------------------------- /WrapperConverter_test.go: -------------------------------------------------------------------------------- 1 | package imgui // nolint: testpackage 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/stretchr/testify/assert" 8 | "github.com/stretchr/testify/require" 9 | ) 10 | 11 | func TestStringBufferAllocation(t *testing.T) { 12 | tt := []struct { 13 | initialValue string 14 | expectedSize int 15 | }{ 16 | {initialValue: "", expectedSize: 1}, 17 | {initialValue: "a", expectedSize: 2}, 18 | {initialValue: "123456789", expectedSize: 10}, 19 | } 20 | for _, tc := range tt { 21 | td := tc 22 | t.Run(fmt.Sprintf("<%s>", td.initialValue), func(t *testing.T) { 23 | buf := newStringBuffer(td.initialValue) 24 | defer buf.free() 25 | assert.Equal(t, td.expectedSize, buf.size) 26 | }) 27 | } 28 | } 29 | 30 | func TestStringBufferStorage(t *testing.T) { 31 | tt := []string{"", "a", "ab", "SomeLongerText"} 32 | 33 | for _, tc := range tt { 34 | td := tc 35 | t.Run("Value <"+td+">", func(t *testing.T) { 36 | buf := newStringBuffer(td) 37 | require.NotNil(t, buf, "buffer expected") 38 | defer buf.free() 39 | result := buf.toGo() 40 | assert.Equal(t, td, result) 41 | }) 42 | } 43 | } 44 | 45 | func TestStringBufferResize(t *testing.T) { 46 | tt := []struct { 47 | initialValue string 48 | newSize int 49 | expectedValue string 50 | }{ 51 | {initialValue: "", newSize: 10, expectedValue: ""}, 52 | {initialValue: "abcd", newSize: 10, expectedValue: "abcd"}, 53 | {initialValue: "abcd", newSize: 3, expectedValue: "ab"}, 54 | {initialValue: "efgh", newSize: 0, expectedValue: ""}, 55 | } 56 | for _, tc := range tt { 57 | td := tc 58 | t.Run(fmt.Sprintf("<%s> -> %d", td.initialValue, tc.newSize), func(t *testing.T) { 59 | buf := newStringBuffer(td.initialValue) 60 | defer buf.free() 61 | buf.resizeTo(td.newSize) 62 | assert.Equal(t, td.expectedValue, buf.toGo()) 63 | }) 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /_licenses/imgui-LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2021 Omar Cornut 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /assets/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eliasdaler/imgui-go/9b3efd2f9530fba52fbfe51648e58f4701d07e2a/assets/screenshot.png -------------------------------------------------------------------------------- /doc.go: -------------------------------------------------------------------------------- 1 | // Package imgui contains all the functions to create an immediate mode graphical user interface based on Dear ImGui. 2 | // 3 | // Setup 4 | // 5 | // For integration, please refer to the dedicated repository 6 | // https://github.com/inkyblackness/imgui-go-examples , 7 | // which contains ported examples of the C++ version, available to Go. 8 | // 9 | // Conventions 10 | // 11 | // The exported functions and constants are named closely to that of the wrapped library. 12 | // If a function has optional parameters, it will be available in two versions: 13 | // A verbose one, which has all optional parameters listed, and a terse one, with only the mandatory parameters in its signature. 14 | // The verbose variant will have the suffix V in its name. For example, there are 15 | // func Button(id string) bool 16 | // and 17 | // func ButtonV(id string, size Vec2) bool 18 | // The terse variant will list the default parameters it uses to call the verbose variant. 19 | // 20 | // There are several types which are based on uintptr. These are references to the wrapped instances in C++. 21 | // You will always get to such a reference via some function - you never "instantiate" such an instance on your own. 22 | package imgui 23 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/inkyblackness/imgui-go/v4 2 | 3 | require github.com/stretchr/testify v1.3.0 4 | 5 | go 1.13 6 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= 2 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 3 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 4 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 5 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 6 | github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= 7 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 8 | -------------------------------------------------------------------------------- /imgui/govendorkeep.go: -------------------------------------------------------------------------------- 1 | package cgoimgui 2 | -------------------------------------------------------------------------------- /imgui/misc/freetype/govendorkeep.go: -------------------------------------------------------------------------------- 1 | package cgofreetype 2 | -------------------------------------------------------------------------------- /imgui/misc/freetype/imgui_freetype.h: -------------------------------------------------------------------------------- 1 | // dear imgui: FreeType font builder (used as a replacement for the stb_truetype builder) 2 | // (headers) 3 | 4 | #pragma once 5 | 6 | #include "imgui.h" // IMGUI_API 7 | 8 | // Forward declarations 9 | struct ImFontAtlas; 10 | struct ImFontBuilderIO; 11 | 12 | // Hinting greatly impacts visuals (and glyph sizes). 13 | // - By default, hinting is enabled and the font's native hinter is preferred over the auto-hinter. 14 | // - When disabled, FreeType generates blurrier glyphs, more or less matches the stb_truetype.h 15 | // - The Default hinting mode usually looks good, but may distort glyphs in an unusual way. 16 | // - The Light hinting mode generates fuzzier glyphs but better matches Microsoft's rasterizer. 17 | // You can set those flags globaly in ImFontAtlas::FontBuilderFlags 18 | // You can set those flags on a per font basis in ImFontConfig::FontBuilderFlags 19 | enum ImGuiFreeTypeBuilderFlags 20 | { 21 | ImGuiFreeTypeBuilderFlags_NoHinting = 1 << 0, // Disable hinting. This generally generates 'blurrier' bitmap glyphs when the glyph are rendered in any of the anti-aliased modes. 22 | ImGuiFreeTypeBuilderFlags_NoAutoHint = 1 << 1, // Disable auto-hinter. 23 | ImGuiFreeTypeBuilderFlags_ForceAutoHint = 1 << 2, // Indicates that the auto-hinter is preferred over the font's native hinter. 24 | ImGuiFreeTypeBuilderFlags_LightHinting = 1 << 3, // A lighter hinting algorithm for gray-level modes. Many generated glyphs are fuzzier but better resemble their original shape. This is achieved by snapping glyphs to the pixel grid only vertically (Y-axis), as is done by Microsoft's ClearType and Adobe's proprietary font renderer. This preserves inter-glyph spacing in horizontal text. 25 | ImGuiFreeTypeBuilderFlags_MonoHinting = 1 << 4, // Strong hinting algorithm that should only be used for monochrome output. 26 | ImGuiFreeTypeBuilderFlags_Bold = 1 << 5, // Styling: Should we artificially embolden the font? 27 | ImGuiFreeTypeBuilderFlags_Oblique = 1 << 6, // Styling: Should we slant the font, emulating italic style? 28 | ImGuiFreeTypeBuilderFlags_Monochrome = 1 << 7, // Disable anti-aliasing. Combine this with MonoHinting for best results! 29 | ImGuiFreeTypeBuilderFlags_LoadColor = 1 << 8, // Enable FreeType color-layered glyphs 30 | ImGuiFreeTypeBuilderFlags_Bitmap = 1 << 9 // Enable FreeType bitmap glyphs 31 | }; 32 | 33 | namespace ImGuiFreeType 34 | { 35 | // This is automatically assigned when using '#define IMGUI_ENABLE_FREETYPE'. 36 | // If you need to dynamically select between multiple builders: 37 | // - you can manually assign this builder with 'atlas->FontBuilderIO = ImGuiFreeType::GetBuilderForFreeType()' 38 | // - prefer deep-copying this into your own ImFontBuilderIO instance if you use hot-reloading that messes up static data. 39 | IMGUI_API const ImFontBuilderIO* GetBuilderForFreeType(); 40 | 41 | // Override allocators. By default ImGuiFreeType will use IM_ALLOC()/IM_FREE() 42 | // However, as FreeType does lots of allocations we provide a way for the user to redirect it to a separate memory heap if desired. 43 | IMGUI_API void SetAllocatorFunctions(void* (*alloc_func)(size_t sz, void* user_data), void (*free_func)(void* ptr, void* user_data), void* user_data = NULL); 44 | 45 | // Obsolete names (will be removed soon) 46 | // Prefer using '#define IMGUI_ENABLE_FREETYPE' 47 | #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS 48 | static inline bool BuildFontAtlas(ImFontAtlas* atlas, unsigned int flags = 0) { atlas->FontBuilderIO = GetBuilderForFreeType(); atlas->FontBuilderFlags = flags; return atlas->Build(); } 49 | #endif 50 | } 51 | -------------------------------------------------------------------------------- /scripts/download-clang-format.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This script downloads clang-format as a utility. 4 | # The referenced package is actually an NPM package, 5 | # but why install npm and all that comes with it, when a direct download works as fine. 6 | # Read more about clang-format here: https://clang.llvm.org/docs/ClangFormat.html 7 | 8 | PACKAGE_VERSION=1.4.0 9 | 10 | wget https://github.com/angular/clang-format/archive/v${PACKAGE_VERSION}.tar.gz 11 | tar -zxvf v${PACKAGE_VERSION}.tar.gz clang-format-${PACKAGE_VERSION}/bin/linux_x64/clang-format --strip-components=3 12 | -------------------------------------------------------------------------------- /update_imgui.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | # This is a small script to fetch the imgui source 6 | 7 | TMP_IMGUI=.tmp_imgui 8 | DEST=imgui 9 | UPSTREAM_GIT_URI=https://github.com/ocornut/imgui.git 10 | 11 | if [ $# -ne 1 ]; then 12 | echo "Usage: $0 " 13 | exit 1 14 | fi 15 | 16 | GIT_REV=$1 17 | 18 | mkdir -p $DEST 19 | echo "Cloning imgui to $TMP_IMGUI" 20 | git clone --depth=1 --branch $GIT_REV $UPSTREAM_GIT_URI $TMP_IMGUI 21 | 22 | mkdir -p $DEST 23 | rm -rf $DEST/* 24 | 25 | echo "Copying files" 26 | # Copy core files 27 | cp $TMP_IMGUI/*.{h,cpp} $DEST/ 28 | echo "package cgo${DEST}" > $DEST/govendorkeep.go 29 | 30 | # Copy freetype 31 | mkdir -p $DEST/misc/freetype 32 | cp $TMP_IMGUI/misc/freetype/*.{h,cpp} $DEST/misc/freetype 33 | echo "package cgofreetype" > $DEST/misc/freetype/govendorkeep.go 34 | 35 | # Copy license 36 | cp $TMP_IMGUI/LICENSE.txt _licenses/imgui-LICENSE.txt 37 | 38 | # Clean up 39 | echo "Removing $TMP_IMGUI" 40 | rm -fr $TMP_IMGUI 41 | -------------------------------------------------------------------------------- /wrapper.cpp: -------------------------------------------------------------------------------- 1 | #include "wrapper/ConfiguredImGui.h" 2 | 3 | // imgui code 4 | // imgui/ is added to include path in wrapper.go 5 | #include "imgui.cpp" 6 | #include "imgui_demo.cpp" 7 | #include "imgui_draw.cpp" 8 | #include "imgui_tables.cpp" 9 | #include "imgui_widgets.cpp" 10 | #ifdef IMGUI_ENABLE_FREETYPE 11 | #include "misc/freetype/imgui_freetype.cpp" 12 | #endif 13 | 14 | // imgui-go code 15 | #include "wrapper/Color.cpp" 16 | #include "wrapper/Context.cpp" 17 | #include "wrapper/Focus.cpp" 18 | #include "wrapper/DragDrop.cpp" 19 | #include "wrapper/DrawCommand.cpp" 20 | #include "wrapper/DrawData.cpp" 21 | #include "wrapper/DrawList.cpp" 22 | #include "wrapper/Font.cpp" 23 | #include "wrapper/FontAtlas.cpp" 24 | #include "wrapper/FontConfig.cpp" 25 | #include "wrapper/InputTextCallbackData.cpp" 26 | #include "wrapper/IO.cpp" 27 | #include "wrapper/Layout.cpp" 28 | #include "wrapper/ListClipper.cpp" 29 | #include "wrapper/Main.cpp" 30 | #include "wrapper/Popup.cpp" 31 | #include "wrapper/Scroll.cpp" 32 | #include "wrapper/State.cpp" 33 | #include "wrapper/Style.cpp" 34 | #include "wrapper/Tables.cpp" 35 | #include "wrapper/Widgets.cpp" 36 | #include "wrapper/Window.cpp" 37 | #include "wrapper/WrapperConverter.cpp" 38 | #include "wrapper/Settings.cpp" 39 | -------------------------------------------------------------------------------- /wrapper.go: -------------------------------------------------------------------------------- 1 | package imgui 2 | 3 | // #cgo CPPFLAGS: -I./imgui -DIMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS 4 | // #cgo CXXFLAGS: -std=c++11 5 | // #cgo CXXFLAGS: -Wno-subobject-linkage 6 | import "C" 7 | 8 | // Note: imgui_freetype.cpp compilation gives these warnings, hence it's disabled in CXXFLAGS 9 | // 10 | // In file included from wrapper.cpp:10: 11 | // .\imgui/misc/freetype/imgui_freetype.cpp:294:8: warning: 'ImFontBuildSrcGlyphFT' has a field 'ImFontBuildSrcGlyphFT::Info' whose type uses the anonymous namespace [-Wsubobject-linkage] 12 | // 294 | struct ImFontBuildSrcGlyphFT 13 | // | ^~~~~~~~~~~~~~~~~~~~~ 14 | // .\imgui/misc/freetype/imgui_freetype.cpp:301:8: warning: 'ImFontBuildSrcDataFT' has a field 'ImFontBuildSrcDataFT::Font' whose type uses the anonymous namespace [-Wsubobject-linkage] 15 | // 301 | struct ImFontBuildSrcDataFT 16 | // | ^~~~~~~~~~~~~~~~~~~~ 17 | -------------------------------------------------------------------------------- /wrapper/.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | AccessModifierOffset: -3 4 | AlignAfterOpenBracket: DontAlign 5 | AlignConsecutiveMacros: false 6 | AlignConsecutiveAssignments: false 7 | AlignConsecutiveDeclarations: false 8 | AlignEscapedNewlines: Right 9 | AlignOperands: false 10 | AlignTrailingComments: false 11 | AllowAllArgumentsOnNextLine: true 12 | AllowAllConstructorInitializersOnNextLine: true 13 | AllowAllParametersOfDeclarationOnNextLine: true 14 | AllowShortBlocksOnASingleLine: Never 15 | AllowShortCaseLabelsOnASingleLine: false 16 | AllowShortFunctionsOnASingleLine: None 17 | AllowShortLambdasOnASingleLine: All 18 | AllowShortIfStatementsOnASingleLine: Never 19 | AllowShortLoopsOnASingleLine: false 20 | AlwaysBreakAfterDefinitionReturnType: None 21 | AlwaysBreakAfterReturnType: None 22 | AlwaysBreakBeforeMultilineStrings: false 23 | AlwaysBreakTemplateDeclarations: MultiLine 24 | BinPackArguments: true 25 | BinPackParameters: true 26 | BraceWrapping: 27 | AfterCaseLabel: true 28 | AfterClass: true 29 | AfterControlStatement: true 30 | AfterEnum: true 31 | AfterFunction: true 32 | AfterNamespace: true 33 | AfterObjCDeclaration: true 34 | AfterStruct: true 35 | AfterUnion: true 36 | AfterExternBlock: false 37 | BeforeCatch: true 38 | BeforeElse: true 39 | IndentBraces: false 40 | SplitEmptyFunction: true 41 | SplitEmptyRecord: true 42 | SplitEmptyNamespace: true 43 | BreakBeforeBinaryOperators: All 44 | BreakBeforeBraces: Custom 45 | BreakBeforeInheritanceComma: false 46 | BreakInheritanceList: BeforeColon 47 | BreakBeforeTernaryOperators: true 48 | BreakConstructorInitializersBeforeComma: false 49 | BreakConstructorInitializers: BeforeComma 50 | BreakAfterJavaFieldAnnotations: false 51 | BreakStringLiterals: true 52 | ColumnLimit: 0 53 | CommentPragmas: '^ IWYU pragma:' 54 | CompactNamespaces: false 55 | ConstructorInitializerAllOnOneLineOrOnePerLine: false 56 | ConstructorInitializerIndentWidth: 3 57 | ContinuationIndentWidth: 3 58 | Cpp11BracedListStyle: false 59 | DeriveLineEnding: true 60 | DerivePointerAlignment: false 61 | DisableFormat: false 62 | ExperimentalAutoDetectBinPacking: false 63 | FixNamespaceComments: false 64 | ForEachMacros: 65 | - foreach 66 | - Q_FOREACH 67 | - BOOST_FOREACH 68 | IncludeBlocks: Preserve 69 | IncludeCategories: 70 | - Regex: '^"(llvm|llvm-c|clang|clang-c)/' 71 | Priority: 2 72 | SortPriority: 0 73 | - Regex: '^(<|"(gtest|gmock|isl|json)/)' 74 | Priority: 3 75 | SortPriority: 0 76 | - Regex: '.*' 77 | Priority: 1 78 | SortPriority: 0 79 | IncludeIsMainRegex: '(Test)?$' 80 | IncludeIsMainSourceRegex: '' 81 | IndentCaseLabels: false 82 | IndentCaseBlocks: false 83 | IndentGotoLabels: true 84 | IndentPPDirectives: None 85 | IndentWidth: 3 86 | IndentWrappedFunctionNames: false 87 | JavaScriptQuotes: Leave 88 | JavaScriptWrapImports: true 89 | KeepEmptyLinesAtTheStartOfBlocks: true 90 | MacroBlockBegin: '' 91 | MacroBlockEnd: '' 92 | MaxEmptyLinesToKeep: 1 93 | NamespaceIndentation: None 94 | ObjCBinPackProtocolList: Auto 95 | ObjCBlockIndentWidth: 3 96 | ObjCSpaceAfterProperty: true 97 | ObjCSpaceBeforeProtocolList: true 98 | PenaltyBreakAssignment: 2 99 | PenaltyBreakBeforeFirstCallParameter: 19 100 | PenaltyBreakComment: 300 101 | PenaltyBreakFirstLessLess: 120 102 | PenaltyBreakString: 1000 103 | PenaltyBreakTemplateDeclaration: 10 104 | PenaltyExcessCharacter: 1000000 105 | PenaltyReturnTypeOnItsOwnLine: 60 106 | PointerAlignment: Right 107 | ReflowComments: true 108 | SortIncludes: true 109 | SortUsingDeclarations: true 110 | SpaceAfterCStyleCast: false 111 | SpaceAfterLogicalNot: false 112 | SpaceAfterTemplateKeyword: true 113 | SpaceBeforeAssignmentOperators: true 114 | SpaceBeforeCpp11BracedList: true 115 | SpaceBeforeCtorInitializerColon: true 116 | SpaceBeforeInheritanceColon: true 117 | SpaceBeforeParens: ControlStatements 118 | SpaceBeforeRangeBasedForLoopColon: true 119 | SpaceInEmptyBlock: true 120 | SpaceInEmptyParentheses: false 121 | SpacesBeforeTrailingComments: 1 122 | SpacesInAngles: false 123 | SpacesInConditionalStatement: false 124 | SpacesInContainerLiterals: true 125 | SpacesInCStyleCastParentheses: false 126 | SpacesInParentheses: false 127 | SpacesInSquareBrackets: false 128 | SpaceBeforeSquareBrackets: false 129 | Standard: Latest 130 | StatementMacros: 131 | - Q_UNUSED 132 | - QT_REQUIRE_VERSION 133 | TabWidth: 8 134 | UseCRLF: false 135 | UseTab: Never 136 | ... 137 | 138 | -------------------------------------------------------------------------------- /wrapper/Color.cpp: -------------------------------------------------------------------------------- 1 | #include "ConfiguredImGui.h" 2 | 3 | #include "Color.h" 4 | #include "WrapperConverter.h" 5 | 6 | IggBool iggColorEdit3(char const *label, float *col, int flags) 7 | { 8 | return ImGui::ColorEdit3(label, col, flags) ? 1 : 0; 9 | } 10 | 11 | IggBool iggColorEdit4(char const *label, float *col, int flags) 12 | { 13 | return ImGui::ColorEdit4(label, col, flags) ? 1 : 0; 14 | } 15 | 16 | IggBool iggColorButton(char const *label, IggVec4 const *col, int flags, IggVec2 const *size) 17 | { 18 | Vec2Wrapper sizeArg(size); 19 | Vec4Wrapper colArg(col); 20 | bool ret = ImGui::ColorButton(label, *colArg, flags, *sizeArg) ? 1 : 0; 21 | return ret; 22 | } 23 | 24 | IggBool iggColorPicker3(char const *label, float *col, int flags) 25 | { 26 | return ImGui::ColorPicker3(label, col, flags) ? 1 : 0; 27 | } 28 | 29 | IggBool iggColorPicker4(char const *label, float *col, int flags) 30 | { 31 | return ImGui::ColorPicker4(label, col, flags) ? 1 : 0; 32 | } -------------------------------------------------------------------------------- /wrapper/Color.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | extern IggBool iggColorEdit3(char const *label, float *col, int flags); 10 | extern IggBool iggColorEdit4(char const *label, float *col, int flags); 11 | extern IggBool iggColorButton(char const *label, IggVec4 const *col, int flags, IggVec2 const *size); 12 | extern IggBool iggColorPicker3(char const *label, float *col, int flags); 13 | extern IggBool iggColorPicker4(char const *label, float *col, int flags); 14 | 15 | #ifdef __cplusplus 16 | } 17 | #endif 18 | -------------------------------------------------------------------------------- /wrapper/ConfigOverride.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Overrides as per standard imconfig.h 4 | 5 | extern "C" void iggAssert(char const *expression, char const *file, int line); 6 | #define IM_ASSERT(_EXPR) \ 7 | do \ 8 | { \ 9 | if ((_EXPR) == 0) \ 10 | { \ 11 | iggAssert(#_EXPR, __FILE__, __LINE__); \ 12 | } \ 13 | } while (false) 14 | 15 | #define IMGUI_DISABLE_OBSOLETE_FUNCTIONS 16 | -------------------------------------------------------------------------------- /wrapper/ConfiguredImGui.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // As recommended in imgui/imconfig.h, the IMGUI_USER_CONFIG must be specified 4 | // whenever imgui is used. As such, the wrapper code should never include imgui.h directly. 5 | 6 | #define IMGUI_USER_CONFIG "wrapper/ConfigOverride.h" 7 | #include "imgui.h" 8 | -------------------------------------------------------------------------------- /wrapper/Context.cpp: -------------------------------------------------------------------------------- 1 | #include "ConfiguredImGui.h" 2 | 3 | #include "Context.h" 4 | 5 | IggContext iggCreateContext(IggFontAtlas sharedFontAtlas) 6 | { 7 | ImGuiContext *context = ImGui::CreateContext(reinterpret_cast(sharedFontAtlas)); 8 | return reinterpret_cast(context); 9 | } 10 | 11 | void iggDestroyContext(IggContext context) 12 | { 13 | ImGui::DestroyContext(reinterpret_cast(context)); 14 | } 15 | 16 | IggContext iggGetCurrentContext() 17 | { 18 | return reinterpret_cast(ImGui::GetCurrentContext()); 19 | } 20 | 21 | void iggSetCurrentContext(IggContext context) 22 | { 23 | ImGui::SetCurrentContext(reinterpret_cast(context)); 24 | } 25 | -------------------------------------------------------------------------------- /wrapper/Context.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | extern IggContext iggCreateContext(IggFontAtlas sharedFontAtlas); 10 | extern void iggDestroyContext(IggContext context); 11 | extern IggContext iggGetCurrentContext(); 12 | extern void iggSetCurrentContext(IggContext context); 13 | 14 | #ifdef __cplusplus 15 | } 16 | #endif -------------------------------------------------------------------------------- /wrapper/DragDrop.cpp: -------------------------------------------------------------------------------- 1 | #include "ConfiguredImGui.h" 2 | 3 | #include "DragDrop.h" 4 | 5 | IggBool iggBeginDragDropSource(int flags) 6 | { 7 | return ImGui::BeginDragDropSource(flags) ? 1 : 0; 8 | } 9 | 10 | IggBool iggSetDragDropPayload(const char *type, const void *data, int size, int cond) 11 | { 12 | return ImGui::SetDragDropPayload(type, data, size, cond) ? 1 : 0; 13 | } 14 | 15 | void iggEndDragDropSource() 16 | { 17 | ImGui::EndDragDropSource(); 18 | } 19 | 20 | IggBool iggBeginDragDropTarget() 21 | { 22 | return ImGui::BeginDragDropTarget() ? 1 : 0; 23 | } 24 | 25 | void *iggPayloadData(IggPayload payload) 26 | { 27 | const ImGuiPayload *p = reinterpret_cast(payload); 28 | return p->Data; 29 | } 30 | 31 | int iggPayloadDataSize(const IggPayload payload) 32 | { 33 | const ImGuiPayload *p = reinterpret_cast(payload); 34 | return p->DataSize; 35 | } 36 | 37 | const IggPayload iggAcceptDragDropPayload(const char *type, int flags) 38 | { 39 | const ImGuiPayload *payload = ImGui::AcceptDragDropPayload(type, flags); 40 | const IggPayload res = reinterpret_cast(const_cast(payload)); 41 | return res; 42 | } 43 | 44 | void iggEndDragDropTarget() 45 | { 46 | ImGui::EndDragDropTarget(); 47 | } -------------------------------------------------------------------------------- /wrapper/DragDrop.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | extern IggBool iggBeginDragDropSource(int flags); 10 | extern IggBool iggSetDragDropPayload(const char *type, const void *data, int size, int cond); 11 | extern void iggEndDragDropSource(); 12 | extern IggBool iggBeginDragDropTarget(); 13 | extern const IggPayload iggAcceptDragDropPayload(const char *type, int flags); 14 | extern void iggEndDragDropTarget(); 15 | 16 | extern void *iggPayloadData(const IggPayload payload); 17 | extern int iggPayloadDataSize(const IggPayload payload); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | -------------------------------------------------------------------------------- /wrapper/DrawCommand.cpp: -------------------------------------------------------------------------------- 1 | #include "ConfiguredImGui.h" 2 | 3 | #include "DrawCommand.h" 4 | #include "WrapperConverter.h" 5 | 6 | void iggDrawCommandGetElementCount(IggDrawCmd handle, unsigned int *count) 7 | { 8 | ImDrawCmd *cmd = reinterpret_cast(handle); 9 | *count = cmd->ElemCount; 10 | } 11 | 12 | void iggDrawCommandGetIndexOffset(IggDrawCmd handle, unsigned int *count) 13 | { 14 | ImDrawCmd *cmd = reinterpret_cast(handle); 15 | *count = cmd->IdxOffset; 16 | } 17 | 18 | void iggDrawCommandGetVertexOffset(IggDrawCmd handle, unsigned int *count) 19 | { 20 | ImDrawCmd *cmd = reinterpret_cast(handle); 21 | *count = cmd->VtxOffset; 22 | } 23 | 24 | void iggDrawCommandGetClipRect(IggDrawCmd handle, IggVec4 *rect) 25 | { 26 | ImDrawCmd *cmd = reinterpret_cast(handle); 27 | exportValue(*rect, cmd->ClipRect); 28 | } 29 | 30 | void iggDrawCommandGetTextureID(IggDrawCmd handle, IggTextureID *id) 31 | { 32 | ImDrawCmd *cmd = reinterpret_cast(handle); 33 | *id = reinterpret_cast(cmd->TextureId); 34 | } 35 | 36 | IggBool iggDrawCommandHasUserCallback(IggDrawCmd handle) 37 | { 38 | ImDrawCmd *cmd = reinterpret_cast(handle); 39 | return (cmd->UserCallback != 0) ? 1 : 0; 40 | } 41 | 42 | void iggDrawCommandCallUserCallback(IggDrawCmd handle, IggDrawList listHandle) 43 | { 44 | ImDrawCmd *cmd = reinterpret_cast(handle); 45 | ImDrawList *list = reinterpret_cast(listHandle); 46 | cmd->UserCallback(list, cmd); 47 | } 48 | -------------------------------------------------------------------------------- /wrapper/DrawCommand.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | extern void iggDrawCommandGetElementCount(IggDrawCmd handle, unsigned int *count); 10 | extern void iggDrawCommandGetIndexOffset(IggDrawCmd handle, unsigned int *count); 11 | extern void iggDrawCommandGetVertexOffset(IggDrawCmd handle, unsigned int *count); 12 | extern void iggDrawCommandGetClipRect(IggDrawCmd handle, IggVec4 *rect); 13 | extern void iggDrawCommandGetTextureID(IggDrawCmd handle, IggTextureID *id); 14 | extern IggBool iggDrawCommandHasUserCallback(IggDrawCmd handle); 15 | extern void iggDrawCommandCallUserCallback(IggDrawCmd handle, IggDrawList listHandle); 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | -------------------------------------------------------------------------------- /wrapper/DrawData.cpp: -------------------------------------------------------------------------------- 1 | #include "ConfiguredImGui.h" 2 | 3 | #include "DrawData.h" 4 | #include "WrapperConverter.h" 5 | 6 | IggDrawData iggGetDrawData() 7 | { 8 | return reinterpret_cast(ImGui::GetDrawData()); 9 | } 10 | 11 | IggBool iggDrawDataValid(IggDrawData handle) 12 | { 13 | ImDrawData *drawData = reinterpret_cast(handle); 14 | IggBool result = 0; 15 | exportValue(result, drawData->Valid); 16 | return result; 17 | } 18 | 19 | void iggDrawDataGetCommandLists(IggDrawData handle, void **handles, int *count) 20 | { 21 | ImDrawData *drawData = reinterpret_cast(handle); 22 | *handles = reinterpret_cast(drawData->CmdLists); 23 | *count = drawData->CmdListsCount; 24 | } 25 | 26 | void iggDrawDataDisplayPos(IggDrawData handle, IggVec2 *value) 27 | { 28 | ImDrawData *drawData = reinterpret_cast(handle); 29 | exportValue(*value, drawData->DisplayPos); 30 | } 31 | 32 | void iggDrawDataDisplaySize(IggDrawData handle, IggVec2 *value) 33 | { 34 | ImDrawData *drawData = reinterpret_cast(handle); 35 | exportValue(*value, drawData->DisplaySize); 36 | } 37 | 38 | void iggDrawDataFrameBufferScale(IggDrawData handle, IggVec2 *value) 39 | { 40 | ImDrawData *drawData = reinterpret_cast(handle); 41 | exportValue(*value, drawData->FramebufferScale); 42 | } 43 | 44 | void iggDrawDataScaleClipRects(IggDrawData handle, IggVec2 const *scale) 45 | { 46 | ImDrawData *drawData = reinterpret_cast(handle); 47 | Vec2Wrapper wrappedScale(scale); 48 | drawData->ScaleClipRects(*wrappedScale); 49 | } 50 | -------------------------------------------------------------------------------- /wrapper/DrawData.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | extern IggDrawData iggGetDrawData(void); 10 | extern IggBool iggDrawDataValid(IggDrawData handle); 11 | extern void iggDrawDataGetCommandLists(IggDrawData handle, void **handles, int *count); 12 | extern void iggDrawDataDisplayPos(IggDrawData handle, IggVec2 *value); 13 | extern void iggDrawDataDisplaySize(IggDrawData handle, IggVec2 *value); 14 | extern void iggDrawDataFrameBufferScale(IggDrawData handle, IggVec2 *value); 15 | extern void iggDrawDataScaleClipRects(IggDrawData handle, IggVec2 const *scale); 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | -------------------------------------------------------------------------------- /wrapper/DrawList.cpp: -------------------------------------------------------------------------------- 1 | #include "ConfiguredImGui.h" 2 | 3 | #include "DrawList.h" 4 | #include "WrapperConverter.h" 5 | 6 | int iggDrawListGetCommandCount(IggDrawList handle) 7 | { 8 | ImDrawList *list = reinterpret_cast(handle); 9 | return list->CmdBuffer.Size; 10 | } 11 | 12 | IggDrawCmd iggDrawListGetCommand(IggDrawList handle, int index) 13 | { 14 | ImDrawList *list = reinterpret_cast(handle); 15 | return reinterpret_cast(&list->CmdBuffer.Data[index]); 16 | } 17 | 18 | void iggDrawListGetRawIndexBuffer(IggDrawList handle, void **data, int *byteSize) 19 | { 20 | ImDrawList *list = reinterpret_cast(handle); 21 | *data = list->IdxBuffer.Data; 22 | *byteSize = static_cast(sizeof(ImDrawIdx)) * list->IdxBuffer.Size; 23 | } 24 | 25 | void iggDrawListGetRawVertexBuffer(IggDrawList handle, void **data, int *byteSize) 26 | { 27 | ImDrawList *list = reinterpret_cast(handle); 28 | *data = list->VtxBuffer.Data; 29 | *byteSize = static_cast(sizeof(ImDrawVert)) * list->VtxBuffer.Size; 30 | } 31 | 32 | void iggGetIndexBufferLayout(size_t *entrySize) 33 | { 34 | *entrySize = sizeof(ImDrawIdx); 35 | } 36 | 37 | void iggGetVertexBufferLayout(size_t *entrySize, size_t *posOffset, size_t *uvOffset, size_t *colOffset) 38 | { 39 | *entrySize = sizeof(ImDrawVert); 40 | *posOffset = IM_OFFSETOF(ImDrawVert, pos); 41 | *uvOffset = IM_OFFSETOF(ImDrawVert, uv); 42 | *colOffset = IM_OFFSETOF(ImDrawVert, col); 43 | } 44 | 45 | void iggAddLine(IggDrawList handle, IggVec2 const *p1, IggVec2 const *p2, IggPackedColor col, float thickness) 46 | { 47 | Vec2Wrapper p1Arg(p1); 48 | Vec2Wrapper p2Arg(p2); 49 | 50 | ImDrawList *list = reinterpret_cast(handle); 51 | list->AddLine(*p1Arg, *p2Arg, col, thickness); 52 | } 53 | 54 | void iggAddRect(IggDrawList handle, IggVec2 const *min, IggVec2 const *max, IggPackedColor col, float rounding, int flags, float thickness) 55 | { 56 | Vec2Wrapper minArg(min); 57 | Vec2Wrapper maxArg(max); 58 | 59 | ImDrawList *list = reinterpret_cast(handle); 60 | list->AddRect(*minArg, *maxArg, col, rounding, flags, thickness); 61 | } 62 | 63 | void iggAddRectFilled(IggDrawList handle, IggVec2 const *min, IggVec2 const *max, IggPackedColor col, float rounding, int flags) 64 | { 65 | Vec2Wrapper minArg(min); 66 | Vec2Wrapper maxArg(max); 67 | 68 | ImDrawList *list = reinterpret_cast(handle); 69 | list->AddRectFilled(*minArg, *maxArg, col, rounding, flags); 70 | } 71 | 72 | void iggAddRectFilledMultiColor(IggDrawList handle, IggVec2 const *min, IggVec2 const *max, IggPackedColor col_upper_left, IggPackedColor col_upper_right, IggPackedColor col_bottom_right, IggPackedColor col_bottom_left) 73 | { 74 | Vec2Wrapper minArg(min); 75 | Vec2Wrapper maxArg(max); 76 | 77 | ImDrawList *list = reinterpret_cast(handle); 78 | list->AddRectFilledMultiColor(*minArg, *maxArg, col_upper_left, col_upper_right, col_bottom_right, col_bottom_left); 79 | } 80 | 81 | void iggAddCircle(IggDrawList handle, IggVec2 const *center, float radius, IggPackedColor col, int numSegments, float thickness) 82 | { 83 | Vec2Wrapper centerArg(center); 84 | 85 | ImDrawList *list = reinterpret_cast(handle); 86 | list->AddCircle(*centerArg, radius, col, numSegments, thickness); 87 | } 88 | 89 | void iggAddCircleFilled(IggDrawList handle, IggVec2 const *center, float radius, IggPackedColor col, int numSegments) 90 | { 91 | Vec2Wrapper centerArg(center); 92 | 93 | ImDrawList *list = reinterpret_cast(handle); 94 | list->AddCircleFilled(*centerArg, radius, col, numSegments); 95 | } 96 | 97 | void iggAddTriangle(IggDrawList handle, IggVec2 *p1, IggVec2 *p2, IggVec2 *p3, IggPackedColor col, float thickness) 98 | { 99 | Vec2Wrapper p1Arg(p1); 100 | Vec2Wrapper p2Arg(p2); 101 | Vec2Wrapper p3Arg(p3); 102 | 103 | ImDrawList *list = reinterpret_cast(handle); 104 | list->AddTriangle(*p1Arg, *p2Arg, *p3Arg, col, thickness); 105 | } 106 | 107 | void iggAddTriangleFilled(IggDrawList handle, IggVec2 *p1, IggVec2 *p2, IggVec2 *p3, IggPackedColor col) 108 | { 109 | Vec2Wrapper p1Arg(p1); 110 | Vec2Wrapper p2Arg(p2); 111 | Vec2Wrapper p3Arg(p3); 112 | 113 | ImDrawList *list = reinterpret_cast(handle); 114 | list->AddTriangleFilled(*p1Arg, *p2Arg, *p3Arg, col); 115 | } 116 | 117 | void iggAddText(IggDrawList handle, IggVec2 const *pos, IggPackedColor col, const char *text, int length) 118 | { 119 | Vec2Wrapper posArg(pos); 120 | ImDrawList *list = reinterpret_cast(handle); 121 | list->AddText(*posArg, col, text, text + length); 122 | } 123 | 124 | void iggAddImage(IggDrawList handle, IggTextureID textureID, IggVec2* pMin, IggVec2* pMax, IggVec2* uvMin, IggVec2* uvMax, IggPackedColor col) { 125 | Vec2Wrapper pMinArg(pMin); 126 | Vec2Wrapper pMaxArg(pMax); 127 | Vec2Wrapper uvMinArg(uvMin); 128 | Vec2Wrapper uvMaxArg(uvMax); 129 | 130 | ImDrawList* list = reinterpret_cast(handle); 131 | list->AddImage(reinterpret_cast(textureID), *pMinArg, *pMaxArg, *uvMinArg, *uvMaxArg, col); 132 | } 133 | 134 | void iggAddImageQuad(IggDrawList handle, IggTextureID textureID, IggVec2* p1, IggVec2* p2, IggVec2* p3, IggVec2* p4, IggVec2* uv1, IggVec2* uv2, IggVec2* uv3, IggVec2* uv4, IggPackedColor col) { 135 | Vec2Wrapper p1Arg(p1); 136 | Vec2Wrapper p2Arg(p2); 137 | Vec2Wrapper p3Arg(p3); 138 | Vec2Wrapper p4Arg(p4); 139 | Vec2Wrapper uv1Arg(uv1); 140 | Vec2Wrapper uv2Arg(uv2); 141 | Vec2Wrapper uv3Arg(uv3); 142 | Vec2Wrapper uv4Arg(uv4); 143 | 144 | ImDrawList *list = reinterpret_cast(handle); 145 | list->AddImageQuad(reinterpret_cast(textureID), *p1Arg, *p2Arg, *p3Arg, *p4Arg, *uv1Arg, *uv2Arg, *uv3Arg, *uv4Arg, col); 146 | } 147 | 148 | void iggPushClipRect(IggDrawList handle, IggVec2 const *min, IggVec2 const *max, IggBool intersectWithCurrentClipRect) 149 | { 150 | ImDrawList *list = reinterpret_cast(handle); 151 | Vec2Wrapper minArg(min); 152 | Vec2Wrapper maxArg(max); 153 | list->PushClipRect(*minArg, *maxArg, intersectWithCurrentClipRect != 0); 154 | } 155 | 156 | void iggPopClipRect(IggDrawList handle) 157 | { 158 | ImDrawList *list = reinterpret_cast(handle); 159 | list->PopClipRect(); 160 | } 161 | 162 | IggDrawList iggGetWindowDrawList() 163 | { 164 | return static_cast(const_cast(ImGui::GetWindowDrawList())); 165 | } 166 | 167 | IggDrawList iggGetForegroundDrawList() 168 | { 169 | return static_cast(const_cast(ImGui::GetForegroundDrawList())); 170 | } 171 | 172 | IggDrawList iggGetBackgroundDrawList() 173 | { 174 | return static_cast(const_cast(ImGui::GetBackgroundDrawList())); 175 | } 176 | -------------------------------------------------------------------------------- /wrapper/DrawList.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | extern int iggDrawListGetCommandCount(IggDrawList handle); 10 | extern IggDrawCmd iggDrawListGetCommand(IggDrawList handle, int index); 11 | extern void iggDrawListGetRawIndexBuffer(IggDrawList handle, void **data, int *byteSize); 12 | extern void iggDrawListGetRawVertexBuffer(IggDrawList handle, void **data, int *byteSize); 13 | 14 | extern void iggGetIndexBufferLayout(size_t *entrySize); 15 | extern void iggGetVertexBufferLayout(size_t *entrySize, size_t *posOffset, size_t *uvOffset, size_t *colOffset); 16 | 17 | extern void iggAddLine(IggDrawList handle, IggVec2 const *p1, IggVec2 const *p2, IggPackedColor col, float thickness); 18 | extern void iggAddRect(IggDrawList handle, IggVec2 const *min, IggVec2 const *max, IggPackedColor col, float rounding, int flags, float thickness); 19 | extern void iggAddRectFilled(IggDrawList handle, IggVec2 const *min, IggVec2 const *max, IggPackedColor col, float rounding, int flags); 20 | extern void iggAddRectFilledMultiColor(IggDrawList handle, IggVec2 const *min, IggVec2 const *max, IggPackedColor col_upper_left, IggPackedColor col_upper_right, IggPackedColor col_bottom_right, IggPackedColor col_bottom_left); 21 | extern void iggAddCircle(IggDrawList handle, IggVec2 const *center, float radius, IggPackedColor col, int numSegments, float thickness); 22 | extern void iggAddCircleFilled(IggDrawList handle, IggVec2 const *center, float radius, IggPackedColor col, int numSegments); 23 | extern void iggAddTriangle(IggDrawList handle, IggVec2 *p1, IggVec2 *p2, IggVec2 *p3, IggPackedColor col, float thickness); 24 | extern void iggAddTriangleFilled(IggDrawList handle, IggVec2 *p1, IggVec2 *p2, IggVec2 *p3, IggPackedColor col); 25 | extern void iggAddText(IggDrawList handle, IggVec2 const *pos, IggPackedColor col, const char *text, int length); 26 | extern void iggAddImage(IggDrawList handle, IggTextureID textureID, IggVec2* pMin, IggVec2* pMax, IggVec2* uvMin, IggVec2* uvMax, IggPackedColor col); 27 | extern void iggAddImageQuad(IggDrawList handle, IggTextureID textureID, IggVec2* p1, IggVec2* p2, IggVec2* p3, IggVec2* p4, IggVec2* uv1, IggVec2* uv2, IggVec2* uv3, IggVec2* uv4, IggPackedColor col); 28 | 29 | extern void iggPushClipRect(IggDrawList handle, IggVec2 const *min, IggVec2 const *max, IggBool intersectWithCurrentClipRect); 30 | extern void iggPopClipRect(IggDrawList handle); 31 | 32 | extern IggDrawList iggGetWindowDrawList(); 33 | extern IggDrawList iggGetForegroundDrawList(); 34 | extern IggDrawList iggGetBackgroundDrawList(); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | -------------------------------------------------------------------------------- /wrapper/Focus.cpp: -------------------------------------------------------------------------------- 1 | #include "ConfiguredImGui.h" 2 | 3 | #include "Focus.h" 4 | 5 | void iggSetItemDefaultFocus() 6 | { 7 | ImGui::SetItemDefaultFocus(); 8 | } 9 | 10 | IggBool iggIsItemFocused() 11 | { 12 | return ImGui::IsItemFocused(); 13 | } 14 | 15 | IggBool iggIsAnyItemFocused() 16 | { 17 | return ImGui::IsAnyItemFocused(); 18 | } 19 | 20 | void iggSetKeyboardFocusHere(int offset) 21 | { 22 | ImGui::SetKeyboardFocusHere(offset); 23 | } 24 | -------------------------------------------------------------------------------- /wrapper/Focus.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | extern void iggSetItemDefaultFocus(); 10 | extern IggBool iggIsItemFocused(); 11 | extern IggBool iggIsAnyItemFocused(); 12 | extern void iggSetKeyboardFocusHere(int offset); 13 | 14 | #ifdef __cplusplus 15 | } 16 | #endif 17 | -------------------------------------------------------------------------------- /wrapper/Font.cpp: -------------------------------------------------------------------------------- 1 | #include "ConfiguredImGui.h" 2 | 3 | #include "Font.h" 4 | 5 | void iggPushFont(IggFont handle) 6 | { 7 | ImFont *font = reinterpret_cast(handle); 8 | ImGui::PushFont(font); 9 | } 10 | 11 | void iggPopFont(void) 12 | { 13 | ImGui::PopFont(); 14 | } 15 | 16 | float iggGetFontSize() 17 | { 18 | return ImGui::GetFontSize(); 19 | } 20 | 21 | void iggCalcTextSize(const char *text, int length, IggBool hide_text_after_double_hash, float wrap_width, IggVec2 *value) 22 | { 23 | exportValue(*value, ImGui::CalcTextSize(text, text + length, hide_text_after_double_hash, wrap_width)); 24 | } 25 | 26 | float iggFontFontSize(IggFont handle) 27 | { 28 | ImFont *font = reinterpret_cast(handle); 29 | return font->FontSize; 30 | } 31 | 32 | IggFontGlyph iggFindGlyph(IggFont handle, int ch) 33 | { 34 | ImFont *font = reinterpret_cast(handle); 35 | return (IggFontGlyph)font->FindGlyph(ch); 36 | } 37 | 38 | int iggFontGlyphColored(IggFontGlyph handle) 39 | { 40 | ImFontGlyph *glyph = reinterpret_cast(handle); 41 | return glyph->Colored; 42 | } 43 | 44 | int iggFontGlyphVisible(IggFontGlyph handle) 45 | { 46 | ImFontGlyph *glyph = reinterpret_cast(handle); 47 | return glyph->Visible; 48 | } 49 | 50 | int iggFontGlyphCodepoint(IggFontGlyph handle) 51 | { 52 | ImFontGlyph *glyph = reinterpret_cast(handle); 53 | return glyph->Codepoint; 54 | } 55 | 56 | float iggFontGlyphAdvanceX(IggFontGlyph handle) 57 | { 58 | ImFontGlyph *glyph = reinterpret_cast(handle); 59 | return glyph->AdvanceX; 60 | } 61 | 62 | float iggFontGlyphX0(IggFontGlyph handle) 63 | { 64 | ImFontGlyph *glyph = reinterpret_cast(handle); 65 | return glyph->X0; 66 | } 67 | 68 | float iggFontGlyphY0(IggFontGlyph handle) 69 | { 70 | ImFontGlyph *glyph = reinterpret_cast(handle); 71 | return glyph->Y0; 72 | } 73 | 74 | float iggFontGlyphX1(IggFontGlyph handle) 75 | { 76 | ImFontGlyph *glyph = reinterpret_cast(handle); 77 | return glyph->X1; 78 | } 79 | 80 | float iggFontGlyphY1(IggFontGlyph handle) 81 | { 82 | ImFontGlyph *glyph = reinterpret_cast(handle); 83 | return glyph->Y1; 84 | } 85 | 86 | float iggFontGlyphU0(IggFontGlyph handle) 87 | { 88 | ImFontGlyph *glyph = reinterpret_cast(handle); 89 | return glyph->U0; 90 | } 91 | 92 | float iggFontGlyphV0(IggFontGlyph handle) 93 | { 94 | ImFontGlyph *glyph = reinterpret_cast(handle); 95 | return glyph->V0; 96 | } 97 | 98 | float iggFontGlyphU1(IggFontGlyph handle) 99 | { 100 | ImFontGlyph *glyph = reinterpret_cast(handle); 101 | return glyph->U1; 102 | } 103 | 104 | float iggFontGlyphV1(IggFontGlyph handle) 105 | { 106 | ImFontGlyph *glyph = reinterpret_cast(handle); 107 | return glyph->V1; 108 | } 109 | -------------------------------------------------------------------------------- /wrapper/Font.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | extern void iggPushFont(IggFont handle); 10 | extern void iggPopFont(void); 11 | extern void iggCalcTextSize(const char *text, int length, IggBool hide_text_after_double_hash, float wrap_width, IggVec2 *value); 12 | extern float iggGetFontSize(); 13 | extern float iggFontFontSize(IggFont handle); 14 | extern IggFontGlyph iggFindGlyph(IggFont font, int ch); 15 | extern int iggFontGlyphColored(IggFontGlyph glyph); 16 | extern int iggFontGlyphVisible(IggFontGlyph glyph); 17 | extern int iggFontGlyphCodepoint(IggFontGlyph glyph); 18 | extern float iggFontGlyphAdvanceX(IggFontGlyph glyph); 19 | extern float iggFontGlyphX0(IggFontGlyph glyph); 20 | extern float iggFontGlyphY0(IggFontGlyph glyph); 21 | extern float iggFontGlyphX1(IggFontGlyph glyph); 22 | extern float iggFontGlyphY1(IggFontGlyph glyph); 23 | extern float iggFontGlyphU0(IggFontGlyph glyph); 24 | extern float iggFontGlyphV0(IggFontGlyph glyph); 25 | extern float iggFontGlyphU1(IggFontGlyph glyph); 26 | extern float iggFontGlyphV1(IggFontGlyph glyph); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | -------------------------------------------------------------------------------- /wrapper/FontAtlas.cpp: -------------------------------------------------------------------------------- 1 | #include "ConfiguredImGui.h" 2 | 3 | #include "FontAtlas.h" 4 | #include "WrapperConverter.h" 5 | 6 | IggGlyphRanges iggGetGlyphRangesDefault(IggFontAtlas handle) 7 | { 8 | ImFontAtlas *fontAtlas = reinterpret_cast(handle); 9 | return static_cast(const_cast(fontAtlas->GetGlyphRangesDefault())); 10 | } 11 | 12 | IggGlyphRanges iggGetGlyphRangesKorean(IggFontAtlas handle) 13 | { 14 | ImFontAtlas *fontAtlas = reinterpret_cast(handle); 15 | return static_cast(const_cast(fontAtlas->GetGlyphRangesKorean())); 16 | } 17 | 18 | IggGlyphRanges iggGetGlyphRangesJapanese(IggFontAtlas handle) 19 | { 20 | ImFontAtlas *fontAtlas = reinterpret_cast(handle); 21 | return static_cast(const_cast(fontAtlas->GetGlyphRangesJapanese())); 22 | } 23 | 24 | IggGlyphRanges iggGetGlyphRangesChineseFull(IggFontAtlas handle) 25 | { 26 | ImFontAtlas *fontAtlas = reinterpret_cast(handle); 27 | return static_cast(const_cast(fontAtlas->GetGlyphRangesChineseFull())); 28 | } 29 | 30 | IggGlyphRanges iggGetGlyphRangesChineseSimplifiedCommon(IggFontAtlas handle) 31 | { 32 | ImFontAtlas *fontAtlas = reinterpret_cast(handle); 33 | return static_cast(const_cast(fontAtlas->GetGlyphRangesChineseSimplifiedCommon())); 34 | } 35 | 36 | IggGlyphRanges iggGetGlyphRangesCyrillic(IggFontAtlas handle) 37 | { 38 | ImFontAtlas *fontAtlas = reinterpret_cast(handle); 39 | return static_cast(const_cast(fontAtlas->GetGlyphRangesCyrillic())); 40 | } 41 | 42 | IggGlyphRanges iggGetGlyphRangesThai(IggFontAtlas handle) 43 | { 44 | ImFontAtlas *fontAtlas = reinterpret_cast(handle); 45 | return static_cast(const_cast(fontAtlas->GetGlyphRangesThai())); 46 | } 47 | 48 | IggFont iggAddFontDefault(IggFontAtlas handle) 49 | { 50 | ImFontAtlas *fontAtlas = reinterpret_cast(handle); 51 | ImFont *font = fontAtlas->AddFontDefault(); 52 | return static_cast(font); 53 | } 54 | 55 | IggFont iggAddFontDefaultV(IggFontAtlas handle, IggFontConfig config) 56 | { 57 | ImFontAtlas *fontAtlas = reinterpret_cast(handle); 58 | ImFontConfig *fontConfig = reinterpret_cast(config); 59 | ImFont *font = fontAtlas->AddFontDefault(fontConfig); 60 | return static_cast(font); 61 | } 62 | 63 | IggFont iggAddFontFromFileTTF(IggFontAtlas handle, char const *filename, float sizePixels, 64 | IggFontConfig config, IggGlyphRanges glyphRanges) 65 | { 66 | ImFontAtlas *fontAtlas = reinterpret_cast(handle); 67 | ImFontConfig *fontConfig = reinterpret_cast(config); 68 | ImWchar *glyphChars = reinterpret_cast(glyphRanges); 69 | ImFont *font = fontAtlas->AddFontFromFileTTF(filename, sizePixels, fontConfig, glyphChars); 70 | return static_cast(font); 71 | } 72 | 73 | IggFont iggAddFontFromMemoryTTF(IggFontAtlas handle, char *font_data, int font_size, float sizePixels, 74 | IggFontConfig config, IggGlyphRanges glyphRanges) 75 | { 76 | ImFontAtlas *fontAtlas = reinterpret_cast(handle); 77 | ImFontConfig *fontConfig = reinterpret_cast(config); 78 | ImWchar *glyphChars = reinterpret_cast(glyphRanges); 79 | ImFont *font = fontAtlas->AddFontFromMemoryTTF(font_data, font_size, sizePixels, fontConfig, glyphChars); 80 | return static_cast(font); 81 | } 82 | 83 | void iggFontAtlasSetTexDesiredWidth(IggFontAtlas handle, int value) 84 | { 85 | ImFontAtlas *fontAtlas = reinterpret_cast(handle); 86 | fontAtlas->TexDesiredWidth = value; 87 | } 88 | 89 | void iggFontAtlasGetTexDataAsAlpha8(IggFontAtlas handle, unsigned char **pixels, 90 | int *width, int *height, int *bytesPerPixel) 91 | { 92 | ImFontAtlas *fontAtlas = reinterpret_cast(handle); 93 | fontAtlas->GetTexDataAsAlpha8(pixels, width, height, bytesPerPixel); 94 | } 95 | 96 | void iggFontAtlasGetTexDataAsRGBA32(IggFontAtlas handle, unsigned char **pixels, 97 | int *width, int *height, int *bytesPerPixel) 98 | { 99 | ImFontAtlas *fontAtlas = reinterpret_cast(handle); 100 | fontAtlas->GetTexDataAsRGBA32(pixels, width, height, bytesPerPixel); 101 | } 102 | 103 | void iggFontAtlasSetTextureID(IggFontAtlas handle, IggTextureID id) 104 | { 105 | ImFontAtlas *fontAtlas = reinterpret_cast(handle); 106 | fontAtlas->SetTexID(reinterpret_cast(id)); 107 | } 108 | 109 | IggTextureID iggFontAtlasGetTextureID(IggFontAtlas handle) 110 | { 111 | ImFontAtlas *fontAtlas = reinterpret_cast(handle); 112 | return IggTextureID(fontAtlas->TexID); 113 | } 114 | 115 | IggBool iggFontAtlasBuild(IggFontAtlas handle) 116 | { 117 | ImFontAtlas *fontAtlas = reinterpret_cast(handle); 118 | return fontAtlas->Build() ? 1 : 0; 119 | } 120 | 121 | unsigned int iggFontAtlasGetFontBuilderFlags(IggFontAtlas handle) 122 | { 123 | ImFontAtlas *fontAtlas = reinterpret_cast(handle); 124 | return fontAtlas->FontBuilderFlags; 125 | } 126 | 127 | void iggFontAtlasSetFontBuilderFlags(IggFontAtlas handle, unsigned int flags) 128 | { 129 | ImFontAtlas *fontAtlas = reinterpret_cast(handle); 130 | fontAtlas->FontBuilderFlags = flags; 131 | } 132 | 133 | -------------------------------------------------------------------------------- /wrapper/FontAtlas.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | extern IggGlyphRanges iggGetGlyphRangesDefault(IggFontAtlas handle); 10 | extern IggGlyphRanges iggGetGlyphRangesKorean(IggFontAtlas handle); 11 | extern IggGlyphRanges iggGetGlyphRangesJapanese(IggFontAtlas handle); 12 | extern IggGlyphRanges iggGetGlyphRangesChineseFull(IggFontAtlas handle); 13 | extern IggGlyphRanges iggGetGlyphRangesChineseSimplifiedCommon(IggFontAtlas handle); 14 | extern IggGlyphRanges iggGetGlyphRangesCyrillic(IggFontAtlas handle); 15 | extern IggGlyphRanges iggGetGlyphRangesThai(IggFontAtlas handle); 16 | 17 | extern IggFont iggAddFontDefault(IggFontAtlas handle); 18 | extern IggFont iggAddFontDefaultV(IggFontAtlas handle, IggFontConfig config); 19 | extern IggFont iggAddFontFromFileTTF(IggFontAtlas handle, char const *filename, float sizePixels, 20 | IggFontConfig config, IggGlyphRanges glyphRanges); 21 | extern IggFont iggAddFontFromMemoryTTF(IggFontAtlas handle, char *font_data, int font_size, float sizePixels, 22 | IggFontConfig config, IggGlyphRanges glyphRanges); 23 | 24 | extern void iggFontAtlasSetTexDesiredWidth(IggFontAtlas handle, int value); 25 | 26 | extern void iggFontAtlasGetTexDataAsAlpha8(IggFontAtlas handle, unsigned char **pixels, 27 | int *width, int *height, int *bytesPerPixel); 28 | extern void iggFontAtlasGetTexDataAsRGBA32(IggFontAtlas handle, unsigned char **pixels, 29 | int *width, int *height, int *bytesPerPixel); 30 | extern void iggFontAtlasSetTextureID(IggFontAtlas handle, IggTextureID id); 31 | extern IggTextureID iggFontAtlasGetTextureID(IggFontAtlas handle); 32 | extern IggBool iggFontAtlasBuild(IggFontAtlas handle); 33 | 34 | extern unsigned int iggFontAtlasGetFontBuilderFlags(IggFontAtlas handle); 35 | extern void iggFontAtlasSetFontBuilderFlags(IggFontAtlas handle, unsigned int flags); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | -------------------------------------------------------------------------------- /wrapper/FontConfig.cpp: -------------------------------------------------------------------------------- 1 | #include "ConfiguredImGui.h" 2 | 3 | #include "FontConfig.h" 4 | 5 | IggFontConfig iggNewFontConfig() 6 | { 7 | ImFontConfig *fontConfig = new ImFontConfig(); 8 | return static_cast(fontConfig); 9 | } 10 | 11 | void iggFontConfigDelete(IggFontConfig handle) 12 | { 13 | ImFontConfig *fontConfig = reinterpret_cast(handle); 14 | delete fontConfig; 15 | } 16 | 17 | void iggFontConfigSetSize(IggFontConfig handle, float sizePixels) 18 | { 19 | ImFontConfig *fontConfig = reinterpret_cast(handle); 20 | fontConfig->SizePixels = sizePixels; 21 | } 22 | 23 | void iggFontConfigSetOversampleH(IggFontConfig handle, int value) 24 | { 25 | ImFontConfig *fontConfig = reinterpret_cast(handle); 26 | fontConfig->OversampleH = value; 27 | } 28 | 29 | void iggFontConfigSetOversampleV(IggFontConfig handle, int value) 30 | { 31 | ImFontConfig *fontConfig = reinterpret_cast(handle); 32 | fontConfig->OversampleV = value; 33 | } 34 | 35 | void iggFontConfigSetPixelSnapH(IggFontConfig handle, IggBool value) 36 | { 37 | ImFontConfig *fontConfig = reinterpret_cast(handle); 38 | fontConfig->PixelSnapH = value; 39 | } 40 | 41 | void iggFontConfigSetGlyphMinAdvanceX(IggFontConfig handle, float value) 42 | { 43 | ImFontConfig *fontConfig = reinterpret_cast(handle); 44 | fontConfig->GlyphMinAdvanceX = value; 45 | } 46 | 47 | void iggFontConfigSetGlyphMaxAdvanceX(IggFontConfig handle, float value) 48 | { 49 | ImFontConfig *fontConfig = reinterpret_cast(handle); 50 | fontConfig->GlyphMaxAdvanceX = value; 51 | } 52 | 53 | void iggFontConfigSetGlyphOffsetX(IggFontConfig handle, float value) 54 | { 55 | ImFontConfig *fontConfig = reinterpret_cast(handle); 56 | fontConfig->GlyphOffset.x = value; 57 | } 58 | 59 | void iggFontConfigSetGlyphOffsetY(IggFontConfig handle, float value) 60 | { 61 | ImFontConfig *fontConfig = reinterpret_cast(handle); 62 | fontConfig->GlyphOffset.y = value; 63 | } 64 | 65 | void iggFontConfigSetMergeMode(IggFontConfig handle, IggBool value) 66 | { 67 | ImFontConfig *fontConfig = reinterpret_cast(handle); 68 | fontConfig->MergeMode = value; 69 | } 70 | 71 | void iggFontConfigSetName(IggFontConfig handle, char const *value) 72 | { 73 | ImFontConfig *fontConfig = reinterpret_cast(handle); 74 | const size_t bufSize = sizeof(fontConfig->Name); 75 | strncpy(fontConfig->Name, value, bufSize - 1); 76 | fontConfig->Name[bufSize - 1] = '\0'; 77 | } 78 | 79 | int iggFontConfigGetFontDataOwnedByAtlas(IggFontConfig handle) 80 | { 81 | ImFontConfig *fontConfig = reinterpret_cast(handle); 82 | return fontConfig->FontDataOwnedByAtlas; 83 | } 84 | 85 | unsigned int iggFontConfigGetFontBuilderFlags(IggFontConfig handle) 86 | { 87 | ImFontConfig *fontConfig = reinterpret_cast(handle); 88 | return fontConfig->FontBuilderFlags; 89 | } 90 | 91 | void iggFontConfigSetFontBuilderFlags(IggFontConfig handle, unsigned int flags) 92 | { 93 | ImFontConfig *fontConfig = reinterpret_cast(handle); 94 | fontConfig->FontBuilderFlags = flags; 95 | } 96 | -------------------------------------------------------------------------------- /wrapper/FontConfig.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | extern IggFontConfig iggNewFontConfig(); 10 | extern void iggFontConfigDelete(IggFontConfig handle); 11 | 12 | extern void iggFontConfigSetSize(IggFontConfig handle, float sizePixels); 13 | extern void iggFontConfigSetOversampleH(IggFontConfig handle, int value); 14 | extern void iggFontConfigSetOversampleV(IggFontConfig handle, int value); 15 | extern void iggFontConfigSetPixelSnapH(IggFontConfig handle, IggBool value); 16 | extern void iggFontConfigSetGlyphMinAdvanceX(IggFontConfig handle, float value); 17 | extern void iggFontConfigSetGlyphMaxAdvanceX(IggFontConfig handle, float value); 18 | extern void iggFontConfigSetGlyphOffsetX(IggFontConfig handle, float value); 19 | extern void iggFontConfigSetGlyphOffsetY(IggFontConfig handle, float value); 20 | extern void iggFontConfigSetMergeMode(IggFontConfig handle, IggBool value); 21 | extern void iggFontConfigSetName(IggFontConfig handle, char const *value); 22 | extern int iggFontConfigGetFontDataOwnedByAtlas(IggFontConfig handle); 23 | 24 | extern unsigned int iggFontConfigGetFontBuilderFlags(IggFontConfig handle); 25 | extern void iggFontConfigSetFontBuilderFlags(IggFontConfig handle, unsigned int flags); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | -------------------------------------------------------------------------------- /wrapper/IO.cpp: -------------------------------------------------------------------------------- 1 | #include "ConfiguredImGui.h" 2 | 3 | #include "IO.h" 4 | #include "WrapperConverter.h" 5 | 6 | #include 7 | 8 | IggIO iggGetCurrentIO() 9 | { 10 | return reinterpret_cast(&ImGui::GetIO()); 11 | } 12 | 13 | IggBool iggWantCaptureMouse(IggIO handle) 14 | { 15 | ImGuiIO *io = reinterpret_cast(handle); 16 | return io->WantCaptureMouse ? 1 : 0; 17 | } 18 | 19 | IggBool iggWantCaptureMouseUnlessPopupClose(IggIO handle) 20 | { 21 | ImGuiIO *io = reinterpret_cast(handle); 22 | return io->WantCaptureMouseUnlessPopupClose ? 1 : 0; 23 | } 24 | 25 | IggBool iggWantCaptureKeyboard(IggIO handle) 26 | { 27 | ImGuiIO *io = reinterpret_cast(handle); 28 | return io->WantCaptureKeyboard ? 1 : 0; 29 | } 30 | 31 | IggBool iggWantTextInput(IggIO handle) 32 | { 33 | ImGuiIO *io = reinterpret_cast(handle); 34 | return io->WantTextInput ? 1 : 0; 35 | } 36 | 37 | extern float iggFramerate(IggIO handle) 38 | { 39 | ImGuiIO *io = reinterpret_cast(handle); 40 | return io->Framerate; 41 | } 42 | 43 | extern int iggMetricsRenderVertices(IggIO handle) 44 | { 45 | ImGuiIO *io = reinterpret_cast(handle); 46 | return io->MetricsRenderVertices; 47 | } 48 | 49 | extern int iggMetricsRenderIndices(IggIO handle) 50 | { 51 | ImGuiIO *io = reinterpret_cast(handle); 52 | return io->MetricsRenderIndices; 53 | } 54 | 55 | extern int iggMetricsRenderWindows(IggIO handle) 56 | { 57 | ImGuiIO *io = reinterpret_cast(handle); 58 | return io->MetricsRenderWindows; 59 | } 60 | 61 | extern int iggMetricsActiveWindows(IggIO handle) 62 | { 63 | ImGuiIO *io = reinterpret_cast(handle); 64 | return io->MetricsActiveWindows; 65 | } 66 | 67 | extern int iggMetricsActiveAllocations(IggIO handle) 68 | { 69 | ImGuiIO *io = reinterpret_cast(handle); 70 | return io->MetricsActiveAllocations; 71 | } 72 | 73 | extern void iggMouseDelta(IggIO handle, IggVec2 *value) 74 | { 75 | ImGuiIO *io = reinterpret_cast(handle); 76 | exportValue(*value, io->MouseDelta); 77 | } 78 | 79 | extern void iggMouseWheel(IggIO handle, float *mouseWheelH, float *mouseWheel) 80 | { 81 | ImGuiIO *io = reinterpret_cast(handle); 82 | *mouseWheelH = io->MouseWheelH; 83 | *mouseWheel = io->MouseWheel; 84 | } 85 | 86 | extern void iggDisplayFrameBufferScale(IggIO handle, IggVec2 *value) 87 | { 88 | ImGuiIO *io = reinterpret_cast(handle); 89 | exportValue(*value, io->DisplayFramebufferScale); 90 | } 91 | 92 | IggFontAtlas iggIoGetFonts(IggIO handle) 93 | { 94 | ImGuiIO *io = reinterpret_cast(handle); 95 | return reinterpret_cast(io->Fonts); 96 | } 97 | 98 | void iggIoSetDisplaySize(IggIO handle, IggVec2 const *value) 99 | { 100 | ImGuiIO *io = reinterpret_cast(handle); 101 | importValue(io->DisplaySize, *value); 102 | } 103 | 104 | void iggIoSetDisplayFrameBufferScale(IggIO handle, IggVec2 const *value) 105 | { 106 | ImGuiIO *io = reinterpret_cast(handle); 107 | importValue(io->DisplayFramebufferScale, *value); 108 | } 109 | 110 | void iggIoGetMousePosition(IggIO handle, IggVec2 *value) 111 | { 112 | ImGuiIO *io = reinterpret_cast(handle); 113 | exportValue(*value, io->MousePos); 114 | } 115 | 116 | void iggIoSetMousePosition(IggIO handle, IggVec2 const *value) 117 | { 118 | ImGuiIO *io = reinterpret_cast(handle); 119 | importValue(io->MousePos, *value); 120 | } 121 | 122 | void iggIoSetMouseButtonDown(IggIO handle, int index, IggBool value) 123 | { 124 | ImGuiIO *io = reinterpret_cast(handle); 125 | io->MouseDown[index] = value != 0; 126 | } 127 | 128 | void iggIoAddMouseWheelDelta(IggIO handle, float horizontal, float vertical) 129 | { 130 | ImGuiIO *io = reinterpret_cast(handle); 131 | io->MouseWheelH += horizontal; 132 | io->MouseWheel += vertical; 133 | } 134 | 135 | void iggIoSetDeltaTime(IggIO handle, float value) 136 | { 137 | ImGuiIO *io = reinterpret_cast(handle); 138 | io->DeltaTime = value; 139 | } 140 | 141 | void iggIoSetFontGlobalScale(IggIO handle, float value) 142 | { 143 | ImGuiIO *io = reinterpret_cast(handle); 144 | io->FontGlobalScale = value; 145 | } 146 | 147 | void iggIoKeyPress(IggIO handle, int key) 148 | { 149 | ImGuiIO &io = *reinterpret_cast(handle); 150 | io.KeysDown[key] = true; 151 | } 152 | 153 | void iggIoKeyRelease(IggIO handle, int key) 154 | { 155 | ImGuiIO &io = *reinterpret_cast(handle); 156 | io.KeysDown[key] = false; 157 | } 158 | 159 | void iggIoKeyMap(IggIO handle, int imguiKey, int nativeKey) 160 | { 161 | ImGuiIO &io = *reinterpret_cast(handle); 162 | io.KeyMap[imguiKey] = nativeKey; 163 | } 164 | 165 | void iggIoKeyCtrl(IggIO handle, int leftCtrl, int rightCtrl) 166 | { 167 | ImGuiIO &io = *reinterpret_cast(handle); 168 | io.KeyCtrl = io.KeysDown[leftCtrl] || io.KeysDown[rightCtrl]; 169 | } 170 | 171 | IggBool iggIoKeyCtrlPressed(IggIO handle) 172 | { 173 | ImGuiIO &io = *reinterpret_cast(handle); 174 | return io.KeyCtrl ? 1 : 0; 175 | } 176 | 177 | void iggIoKeyShift(IggIO handle, int leftShift, int rightShift) 178 | { 179 | ImGuiIO &io = *reinterpret_cast(handle); 180 | io.KeyShift = io.KeysDown[leftShift] || io.KeysDown[rightShift]; 181 | } 182 | 183 | IggBool iggIoKeyShiftPressed(IggIO handle) 184 | { 185 | ImGuiIO &io = *reinterpret_cast(handle); 186 | return io.KeyShift ? 1 : 0; 187 | } 188 | 189 | void iggIoKeyAlt(IggIO handle, int leftAlt, int rightAlt) 190 | { 191 | ImGuiIO &io = *reinterpret_cast(handle); 192 | io.KeyAlt = io.KeysDown[leftAlt] || io.KeysDown[rightAlt]; 193 | } 194 | 195 | IggBool iggIoKeyAltPressed(IggIO handle) 196 | { 197 | ImGuiIO &io = *reinterpret_cast(handle); 198 | return io.KeyAlt ? 1 : 0; 199 | } 200 | 201 | void iggIoKeySuper(IggIO handle, int leftSuper, int rightSuper) 202 | { 203 | ImGuiIO &io = *reinterpret_cast(handle); 204 | io.KeySuper = io.KeysDown[leftSuper] || io.KeysDown[rightSuper]; 205 | } 206 | 207 | IggBool iggIoKeySuperPressed(IggIO handle) 208 | { 209 | ImGuiIO &io = *reinterpret_cast(handle); 210 | return io.KeySuper? 1 : 0; 211 | } 212 | 213 | void iggIoAddInputCharactersUTF8(IggIO handle, char const *utf8Chars) 214 | { 215 | ImGuiIO &io = *reinterpret_cast(handle); 216 | io.AddInputCharactersUTF8(utf8Chars); 217 | } 218 | 219 | void iggIoSetIniFilename(IggIO handle, char const *value) 220 | { 221 | static std::string bufferValue; 222 | ImGuiIO &io = *reinterpret_cast(handle); 223 | bufferValue = (value != nullptr) ? value : ""; 224 | io.IniFilename = bufferValue.empty() ? nullptr : bufferValue.c_str(); 225 | } 226 | 227 | void iggIoSetConfigFlags(IggIO handle, int flags) 228 | { 229 | ImGuiIO &io = *reinterpret_cast(handle); 230 | io.ConfigFlags = flags; 231 | } 232 | 233 | void iggIoSetBackendFlags(IggIO handle, int flags) 234 | { 235 | ImGuiIO &io = *reinterpret_cast(handle); 236 | io.BackendFlags = flags; 237 | } 238 | 239 | int iggIoGetBackendFlags(IggIO handle) 240 | { 241 | ImGuiIO &io = *reinterpret_cast(handle); 242 | return io.BackendFlags; 243 | } 244 | 245 | 246 | void iggIoSetMouseDrawCursor(IggIO handle, IggBool show) 247 | { 248 | ImGuiIO &io = *reinterpret_cast(handle); 249 | io.MouseDrawCursor = show != 0; 250 | } 251 | 252 | extern "C" void iggIoSetClipboardText(IggIO handle, char *text); 253 | extern "C" char *iggIoGetClipboardText(IggIO handle); 254 | 255 | static void iggIoSetClipboardTextWrapper(void *userData, char const *text) 256 | { 257 | iggIoSetClipboardText(userData, const_cast(text)); 258 | } 259 | 260 | static char const *iggIoGetClipboardTextWrapper(void *userData) 261 | { 262 | return iggIoGetClipboardText(userData); 263 | } 264 | 265 | void iggIoRegisterClipboardFunctions(IggIO handle) 266 | { 267 | ImGuiIO &io = *reinterpret_cast(handle); 268 | io.ClipboardUserData = handle; 269 | io.GetClipboardTextFn = iggIoGetClipboardTextWrapper; 270 | io.SetClipboardTextFn = iggIoSetClipboardTextWrapper; 271 | } 272 | 273 | void iggIoClearClipboardFunctions(IggIO handle) 274 | { 275 | ImGuiIO &io = *reinterpret_cast(handle); 276 | io.GetClipboardTextFn = nullptr; 277 | io.SetClipboardTextFn = nullptr; 278 | io.ClipboardUserData = nullptr; 279 | } 280 | -------------------------------------------------------------------------------- /wrapper/IO.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | extern IggIO iggGetCurrentIO(void); 10 | 11 | extern IggBool iggWantCaptureMouse(IggIO handle); 12 | extern IggBool iggWantCaptureMouseUnlessPopupClose(IggIO handle); 13 | extern IggBool iggWantCaptureKeyboard(IggIO handle); 14 | extern IggBool iggWantTextInput(IggIO handle); 15 | extern float iggFramerate(IggIO handle); 16 | extern int iggMetricsRenderVertices(IggIO handle); 17 | extern int iggMetricsRenderIndices(IggIO handle); 18 | extern int iggMetricsRenderWindows(IggIO handle); 19 | extern int iggMetricsActiveWindows(IggIO handle); 20 | extern int iggMetricsActiveAllocations(IggIO handle); 21 | extern void iggMouseDelta(IggIO handle, IggVec2 *value); 22 | extern void iggMouseWheel(IggIO handle, float *mouseWheelH, float *mouseWheel); 23 | extern void iggDisplayFrameBufferScale(IggIO handle, IggVec2 *value); 24 | extern IggFontAtlas iggIoGetFonts(IggIO handle); 25 | 26 | extern void iggIoSetDisplaySize(IggIO handle, IggVec2 const *value); 27 | extern void iggIoSetDisplayFrameBufferScale(IggIO handle, IggVec2 const *value); 28 | extern void iggIoGetMousePosition(IggIO handle, IggVec2 *value); 29 | extern void iggIoSetMousePosition(IggIO handle, IggVec2 const *value); 30 | extern void iggIoSetMouseButtonDown(IggIO handle, int index, IggBool value); 31 | extern void iggIoAddMouseWheelDelta(IggIO handle, float x, float y); 32 | extern void iggIoSetDeltaTime(IggIO handle, float value); 33 | extern void iggIoSetFontGlobalScale(IggIO handle, float value); 34 | 35 | extern void iggIoKeyPress(IggIO handle, int key); 36 | extern void iggIoKeyRelease(IggIO handle, int key); 37 | extern void iggIoKeyMap(IggIO handle, int imguiKey, int nativeKey); 38 | extern void iggIoKeyCtrl(IggIO handle, int leftCtrl, int rightCtrl); 39 | extern IggBool iggIoKeyCtrlPressed(IggIO handle); 40 | extern void iggIoKeyShift(IggIO handle, int leftShift, int rightShift); 41 | extern IggBool iggIoKeyShiftPressed(IggIO handle); 42 | extern void iggIoKeyAlt(IggIO handle, int leftAlt, int rightAlt); 43 | extern IggBool iggIoKeyAltPressed(IggIO handle); 44 | extern void iggIoKeySuper(IggIO handle, int leftSuper, int rightSuper); 45 | extern IggBool iggIoKeySuperPressed(IggIO handle); 46 | extern void iggIoAddInputCharactersUTF8(IggIO handle, char const *utf8Chars); 47 | extern void iggIoSetIniFilename(IggIO handle, char const *value); 48 | extern void iggIoSetConfigFlags(IggIO handle, int flags); 49 | extern void iggIoSetBackendFlags(IggIO handle, int flags); 50 | extern int iggIoGetBackendFlags(IggIO handle); 51 | extern void iggIoSetMouseDrawCursor(IggIO handle, IggBool show); 52 | 53 | extern void iggIoRegisterClipboardFunctions(IggIO handle); 54 | extern void iggIoClearClipboardFunctions(IggIO handle); 55 | 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | -------------------------------------------------------------------------------- /wrapper/InputTextCallbackData.cpp: -------------------------------------------------------------------------------- 1 | #include "ConfiguredImGui.h" 2 | 3 | #include "InputTextCallbackData.h" 4 | 5 | int iggInputTextCallbackDataGetEventFlag(IggInputTextCallbackData handle) 6 | { 7 | ImGuiInputTextCallbackData *data = reinterpret_cast(handle); 8 | return data->EventFlag; 9 | } 10 | 11 | int iggInputTextCallbackDataGetFlags(IggInputTextCallbackData handle) 12 | { 13 | ImGuiInputTextCallbackData *data = reinterpret_cast(handle); 14 | return data->Flags; 15 | } 16 | 17 | unsigned short iggInputTextCallbackDataGetEventChar(IggInputTextCallbackData handle) 18 | { 19 | ImGuiInputTextCallbackData *data = reinterpret_cast(handle); 20 | return data->EventChar; 21 | } 22 | 23 | void iggInputTextCallbackDataSetEventChar(IggInputTextCallbackData handle, unsigned short value) 24 | { 25 | ImGuiInputTextCallbackData *data = reinterpret_cast(handle); 26 | data->EventChar = value; 27 | } 28 | 29 | int iggInputTextCallbackDataGetEventKey(IggInputTextCallbackData handle) 30 | { 31 | ImGuiInputTextCallbackData *data = reinterpret_cast(handle); 32 | return data->EventKey; 33 | } 34 | 35 | char *iggInputTextCallbackDataGetBuf(IggInputTextCallbackData handle) 36 | { 37 | ImGuiInputTextCallbackData *data = reinterpret_cast(handle); 38 | return data->Buf; 39 | } 40 | 41 | void iggInputTextCallbackDataSetBuf(IggInputTextCallbackData handle, char *buf, int size, int textLen) 42 | { 43 | ImGuiInputTextCallbackData *data = reinterpret_cast(handle); 44 | data->Buf = buf; 45 | data->BufSize = size; 46 | data->BufTextLen = textLen; 47 | data->BufDirty = true; 48 | } 49 | 50 | void iggInputTextCallbackDataMarkBufferModified(IggInputTextCallbackData handle) 51 | { 52 | ImGuiInputTextCallbackData *data = reinterpret_cast(handle); 53 | data->BufDirty = true; 54 | } 55 | 56 | int iggInputTextCallbackDataGetBufSize(IggInputTextCallbackData handle) 57 | { 58 | ImGuiInputTextCallbackData *data = reinterpret_cast(handle); 59 | return data->BufSize; 60 | } 61 | 62 | int iggInputTextCallbackDataGetBufTextLen(IggInputTextCallbackData handle) 63 | { 64 | ImGuiInputTextCallbackData *data = reinterpret_cast(handle); 65 | return data->BufTextLen; 66 | } 67 | 68 | void iggInputTextCallbackDataDeleteBytes(IggInputTextCallbackData handle, int offset, int count) 69 | { 70 | ImGuiInputTextCallbackData *data = reinterpret_cast(handle); 71 | data->DeleteChars(offset, count); 72 | } 73 | 74 | void iggInputTextCallbackDataInsertBytes(IggInputTextCallbackData handle, int offset, char *bytes, int count) 75 | { 76 | ImGuiInputTextCallbackData *data = reinterpret_cast(handle); 77 | data->InsertChars(offset, bytes, bytes + count); 78 | } 79 | 80 | int iggInputTextCallbackDataGetCursorPos(IggInputTextCallbackData handle) 81 | { 82 | ImGuiInputTextCallbackData *data = reinterpret_cast(handle); 83 | return data->CursorPos; 84 | } 85 | 86 | void iggInputTextCallbackDataSetCursorPos(IggInputTextCallbackData handle, int value) 87 | { 88 | ImGuiInputTextCallbackData *data = reinterpret_cast(handle); 89 | data->CursorPos = value; 90 | } 91 | 92 | int iggInputTextCallbackDataGetSelectionStart(IggInputTextCallbackData handle) 93 | { 94 | ImGuiInputTextCallbackData *data = reinterpret_cast(handle); 95 | return data->SelectionStart; 96 | } 97 | 98 | void iggInputTextCallbackDataSetSelectionStart(IggInputTextCallbackData handle, int value) 99 | { 100 | ImGuiInputTextCallbackData *data = reinterpret_cast(handle); 101 | data->SelectionStart = value; 102 | } 103 | 104 | int iggInputTextCallbackDataGetSelectionEnd(IggInputTextCallbackData handle) 105 | { 106 | ImGuiInputTextCallbackData *data = reinterpret_cast(handle); 107 | return data->SelectionEnd; 108 | } 109 | 110 | void iggInputTextCallbackDataSetSelectionEnd(IggInputTextCallbackData handle, int value) 111 | { 112 | ImGuiInputTextCallbackData *data = reinterpret_cast(handle); 113 | data->SelectionEnd = value; 114 | } 115 | -------------------------------------------------------------------------------- /wrapper/InputTextCallbackData.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | extern int iggInputTextCallbackDataGetEventFlag(IggInputTextCallbackData handle); 10 | extern int iggInputTextCallbackDataGetFlags(IggInputTextCallbackData handle); 11 | 12 | extern unsigned short iggInputTextCallbackDataGetEventChar(IggInputTextCallbackData handle); 13 | extern void iggInputTextCallbackDataSetEventChar(IggInputTextCallbackData handle, unsigned short value); 14 | extern int iggInputTextCallbackDataGetEventKey(IggInputTextCallbackData handle); 15 | 16 | extern char *iggInputTextCallbackDataGetBuf(IggInputTextCallbackData handle); 17 | extern void iggInputTextCallbackDataSetBuf(IggInputTextCallbackData handle, char *buf, int size, int textLen); 18 | extern void iggInputTextCallbackDataMarkBufferModified(IggInputTextCallbackData handle); 19 | extern int iggInputTextCallbackDataGetBufSize(IggInputTextCallbackData handle); 20 | extern int iggInputTextCallbackDataGetBufTextLen(IggInputTextCallbackData handle); 21 | extern void iggInputTextCallbackDataDeleteBytes(IggInputTextCallbackData handle, int offset, int count); 22 | extern void iggInputTextCallbackDataInsertBytes(IggInputTextCallbackData handle, int offset, char *bytes, int count); 23 | 24 | extern int iggInputTextCallbackDataGetCursorPos(IggInputTextCallbackData handle); 25 | extern void iggInputTextCallbackDataSetCursorPos(IggInputTextCallbackData handle, int value); 26 | extern int iggInputTextCallbackDataGetSelectionStart(IggInputTextCallbackData handle); 27 | extern void iggInputTextCallbackDataSetSelectionStart(IggInputTextCallbackData handle, int value); 28 | extern int iggInputTextCallbackDataGetSelectionEnd(IggInputTextCallbackData handle); 29 | extern void iggInputTextCallbackDataSetSelectionEnd(IggInputTextCallbackData handle, int value); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | -------------------------------------------------------------------------------- /wrapper/Layout.cpp: -------------------------------------------------------------------------------- 1 | #include "ConfiguredImGui.h" 2 | 3 | #include "Layout.h" 4 | #include "WrapperConverter.h" 5 | 6 | void iggPushID(char const *id) 7 | { 8 | ImGui::PushID(id); 9 | } 10 | 11 | void iggPushIDInt(int id) 12 | { 13 | ImGui::PushID(id); 14 | } 15 | 16 | void iggPopID(void) 17 | { 18 | ImGui::PopID(); 19 | } 20 | 21 | void iggSeparator(void) 22 | { 23 | ImGui::Separator(); 24 | } 25 | 26 | void iggSameLine(float posX, float spacingW) 27 | { 28 | ImGui::SameLine(posX, spacingW); 29 | } 30 | 31 | void iggSpacing(void) 32 | { 33 | ImGui::Spacing(); 34 | } 35 | 36 | void iggDummy(IggVec2 const *size) 37 | { 38 | Vec2Wrapper sizeArg(size); 39 | ImGui::Dummy(*sizeArg); 40 | } 41 | 42 | void iggBeginGroup(void) 43 | { 44 | ImGui::BeginGroup(); 45 | } 46 | 47 | void iggEndGroup(void) 48 | { 49 | ImGui::EndGroup(); 50 | } 51 | 52 | void iggBeginDisabled(IggBool disabled) 53 | { 54 | ImGui::BeginDisabled(disabled); 55 | } 56 | 57 | void iggEndDisabled(void) 58 | { 59 | ImGui::EndDisabled(); 60 | } 61 | 62 | void iggIndent(float indent_w) 63 | { 64 | ImGui::Indent(indent_w); 65 | } 66 | 67 | void iggUnindent(float indent_w) 68 | { 69 | ImGui::Unindent(indent_w); 70 | } 71 | 72 | void iggCursorPos(IggVec2 *pos) 73 | { 74 | exportValue(*pos, ImGui::GetCursorPos()); 75 | } 76 | 77 | float iggCursorPosX(void) 78 | { 79 | return ImGui::GetCursorPosX(); 80 | } 81 | 82 | float iggCursorPosY(void) 83 | { 84 | return ImGui::GetCursorPosY(); 85 | } 86 | 87 | void iggCursorStartPos(IggVec2 *pos) 88 | { 89 | exportValue(*pos, ImGui::GetCursorStartPos()); 90 | } 91 | 92 | void iggCursorScreenPos(IggVec2 *pos) 93 | { 94 | exportValue(*pos, ImGui::GetCursorScreenPos()); 95 | } 96 | 97 | void iggSetCursorPos(IggVec2 const *localPos) 98 | { 99 | Vec2Wrapper localPosArg(localPos); 100 | ImGui::SetCursorPos(*localPosArg); 101 | } 102 | 103 | void iggSetCursorScreenPos(IggVec2 const *absPos) 104 | { 105 | Vec2Wrapper absPosArg(absPos); 106 | ImGui::SetCursorScreenPos(*absPosArg); 107 | } 108 | 109 | void iggAlignTextToFramePadding() 110 | { 111 | ImGui::AlignTextToFramePadding(); 112 | } 113 | 114 | float iggGetTextLineHeight(void) 115 | { 116 | return ImGui::GetTextLineHeight(); 117 | } 118 | 119 | float iggGetTextLineHeightWithSpacing(void) 120 | { 121 | return ImGui::GetTextLineHeightWithSpacing(); 122 | } 123 | 124 | float iggGetFrameHeight(void) 125 | { 126 | return ImGui::GetFrameHeight(); 127 | } 128 | 129 | float iggGetFrameHeightWithSpacing(void) 130 | { 131 | return ImGui::GetFrameHeightWithSpacing(); 132 | } -------------------------------------------------------------------------------- /wrapper/Layout.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | extern void iggPushID(char const *id); 10 | extern void iggPushIDInt(int id); 11 | extern void iggPopID(void); 12 | 13 | extern void iggSeparator(void); 14 | extern void iggSameLine(float posX, float spacingW); 15 | extern void iggSpacing(void); 16 | extern void iggDummy(IggVec2 const *size); 17 | extern void iggBeginGroup(void); 18 | extern void iggEndGroup(void); 19 | extern void iggBeginDisabled(IggBool disabled); 20 | extern void iggEndDisabled(void); 21 | extern void iggIndent(float indent_w); 22 | extern void iggUnindent(float indent_w); 23 | 24 | extern void iggCursorPos(IggVec2 *pos); 25 | extern float iggCursorPosX(void); 26 | extern float iggCursorPosY(void); 27 | extern void iggCursorStartPos(IggVec2 *pos); 28 | extern void iggCursorScreenPos(IggVec2 *pos); 29 | 30 | extern void iggSetCursorPos(IggVec2 const *localPos); 31 | extern void iggSetCursorScreenPos(IggVec2 const *absPos); 32 | extern void iggAlignTextToFramePadding(); 33 | extern float iggGetTextLineHeight(void); 34 | extern float iggGetTextLineHeightWithSpacing(void); 35 | extern float iggGetFrameHeight(void); 36 | extern float iggGetFrameHeightWithSpacing(void); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | -------------------------------------------------------------------------------- /wrapper/ListClipper.cpp: -------------------------------------------------------------------------------- 1 | #include "ConfiguredImGui.h" 2 | 3 | #include "ListClipper.h" 4 | #include "WrapperConverter.h" 5 | 6 | static void importValue(ImGuiListClipper &out, IggListClipper const &in); 7 | static void exportValue(IggListClipper &out, ImGuiListClipper const &in); 8 | 9 | typedef TypeWrapper ListClipperWrapper; 10 | 11 | IggBool iggListClipperStep(IggListClipper *clipper) 12 | { 13 | ImGuiListClipper imguiClipper; 14 | importValue(imguiClipper, *clipper); 15 | IggBool returnValue = imguiClipper.Step() ? 1 : 0; 16 | exportValue(*clipper, imguiClipper); 17 | // needs to be done to prevent assert fail, we don't call end because the cursor will move. 18 | imguiClipper.ItemsCount = -1; 19 | return returnValue; 20 | } 21 | 22 | void iggListClipperBegin(IggListClipper *clipper, int items_count, float items_height) 23 | { 24 | ImGuiListClipper imguiClipper; 25 | imguiClipper.Begin(items_count, items_height); 26 | exportValue(*clipper, imguiClipper); 27 | // needs to be done to prevent assert fail, we don't call end because the cursor will move. 28 | imguiClipper.ItemsCount = -1; 29 | } 30 | 31 | void iggListClipperEnd(IggListClipper *clipper) 32 | { 33 | ImGuiListClipper imguiClipper; 34 | importValue(imguiClipper, *clipper); 35 | imguiClipper.End(); 36 | exportValue(*clipper, imguiClipper); 37 | } 38 | 39 | static void importValue(ImGuiListClipper &out, IggListClipper const &in) 40 | { 41 | out.DisplayStart = in.DisplayStart; 42 | out.DisplayEnd = in.DisplayEnd; 43 | out.ItemsCount = in.ItemsCount; 44 | 45 | out.StepNo = in.StepNo; 46 | out.ItemsFrozen = in.ItemsFrozen; 47 | out.ItemsHeight = in.ItemsHeight; 48 | out.StartPosY = in.StartPosY; 49 | } 50 | 51 | static void exportValue(IggListClipper &out, ImGuiListClipper const &in) 52 | { 53 | out.DisplayStart = in.DisplayStart; 54 | out.DisplayEnd = in.DisplayEnd; 55 | out.ItemsCount = in.ItemsCount; 56 | 57 | out.StepNo = in.StepNo; 58 | out.ItemsFrozen = in.ItemsFrozen; 59 | out.ItemsHeight = in.ItemsHeight; 60 | out.StartPosY = in.StartPosY; 61 | } 62 | -------------------------------------------------------------------------------- /wrapper/ListClipper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | typedef struct tagIggListClipper 10 | { 11 | int DisplayStart; 12 | int DisplayEnd; 13 | int ItemsCount; 14 | 15 | int StepNo; 16 | int ItemsFrozen; 17 | float ItemsHeight; 18 | float StartPosY; 19 | } IggListClipper; 20 | 21 | extern IggBool iggListClipperStep(IggListClipper *clipper); 22 | extern void iggListClipperBegin(IggListClipper *clipper, int items_count, float items_height); 23 | extern void iggListClipperEnd(IggListClipper *clipper); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | -------------------------------------------------------------------------------- /wrapper/Main.cpp: -------------------------------------------------------------------------------- 1 | #include "ConfiguredImGui.h" 2 | 3 | #include "Main.h" 4 | 5 | char const *iggGetVersion() 6 | { 7 | return ImGui::GetVersion(); 8 | } 9 | 10 | double iggGetTime() 11 | { 12 | return ImGui::GetTime(); 13 | } 14 | 15 | void iggNewFrame() 16 | { 17 | ImGui::NewFrame(); 18 | } 19 | 20 | void iggRender() 21 | { 22 | ImGui::Render(); 23 | } 24 | 25 | void iggEndFrame() 26 | { 27 | ImGui::EndFrame(); 28 | } 29 | -------------------------------------------------------------------------------- /wrapper/Main.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | extern char const *iggGetVersion(void); 10 | extern double iggGetTime(void); 11 | 12 | extern void iggNewFrame(void); 13 | extern void iggRender(void); 14 | extern void iggEndFrame(void); 15 | 16 | #ifdef __cplusplus 17 | } 18 | #endif 19 | -------------------------------------------------------------------------------- /wrapper/Popup.cpp: -------------------------------------------------------------------------------- 1 | #include "ConfiguredImGui.h" 2 | 3 | #include "Popup.h" 4 | #include "WrapperConverter.h" 5 | 6 | IggBool iggBeginPopup(const char *name, int flags) 7 | { 8 | return ImGui::BeginPopup(name, flags) ? 1 : 0; 9 | } 10 | 11 | IggBool iggBeginPopupModal(const char *name, IggBool *open, int flags) 12 | { 13 | BoolWrapper openArg(open); 14 | return ImGui::BeginPopupModal(name, openArg, flags) ? 1 : 0; 15 | } 16 | 17 | void iggEndPopup(void) 18 | { 19 | ImGui::EndPopup(); 20 | } 21 | 22 | void iggOpenPopup(const char *id, int flags) 23 | { 24 | ImGui::OpenPopup(id, flags); 25 | } 26 | 27 | void iggOpenPopupOnItemClick(const char *id, int flags) 28 | { 29 | ImGui::OpenPopupOnItemClick(id, flags); 30 | } 31 | 32 | void iggCloseCurrentPopup(void) 33 | { 34 | ImGui::CloseCurrentPopup(); 35 | } 36 | 37 | IggBool iggBeginPopupContextItem(const char *id, int flags) 38 | { 39 | return ImGui::BeginPopupContextItem(id, flags) ? 1 : 0; 40 | } 41 | 42 | IggBool iggBeginPopupContextWindow(const char *id, int flags) 43 | { 44 | return ImGui::BeginPopupContextWindow(id, flags) ? 1 : 0; 45 | } 46 | 47 | IggBool iggBeginPopupContextVoid(const char *id, int flags) 48 | { 49 | return ImGui::BeginPopupContextVoid(id, flags) ? 1 : 0; 50 | } 51 | 52 | IggBool iggIsPopupOpen(const char *id, int flags) 53 | { 54 | return ImGui::IsPopupOpen(id, flags) ? 1 : 0; 55 | } 56 | -------------------------------------------------------------------------------- /wrapper/Popup.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | extern IggBool iggBeginPopup(const char *name, int flags); 10 | extern IggBool iggBeginPopupModal(const char *name, IggBool *open, int flags); 11 | extern void iggEndPopup(void); 12 | extern void iggOpenPopup(const char *id, int flags); 13 | extern void iggOpenPopupOnItemClick(const char *id, int flags); 14 | extern void iggCloseCurrentPopup(void); 15 | extern IggBool iggBeginPopupContextItem(const char *id, int flags); 16 | extern IggBool iggBeginPopupContextWindow(const char *id, int flags); 17 | extern IggBool iggBeginPopupContextVoid(const char *id, int flags); 18 | extern IggBool iggIsPopupOpen(const char *id, int flags); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | -------------------------------------------------------------------------------- /wrapper/Scroll.cpp: -------------------------------------------------------------------------------- 1 | #include "ConfiguredImGui.h" 2 | 3 | #include "Scroll.h" 4 | 5 | float iggGetScrollX() 6 | { 7 | return ImGui::GetScrollX(); 8 | } 9 | 10 | float iggGetScrollY() 11 | { 12 | return ImGui::GetScrollY(); 13 | } 14 | 15 | float iggGetScrollMaxX() 16 | { 17 | return ImGui::GetScrollMaxX(); 18 | } 19 | 20 | float iggGetScrollMaxY() 21 | { 22 | return ImGui::GetScrollMaxY(); 23 | } 24 | 25 | void iggSetScrollHereX(float centerXRatio) 26 | { 27 | ImGui::SetScrollHereX(centerXRatio); 28 | } 29 | 30 | void iggSetScrollHereY(float centerYRatio) 31 | { 32 | ImGui::SetScrollHereY(centerYRatio); 33 | } 34 | 35 | void iggSetScrollX(float scrollX) 36 | { 37 | ImGui::SetScrollX(scrollX); 38 | } 39 | 40 | void iggSetScrollY(float scrollY) 41 | { 42 | ImGui::SetScrollY(scrollY); 43 | } -------------------------------------------------------------------------------- /wrapper/Scroll.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | extern float iggGetScrollX(); 10 | extern float iggGetScrollY(); 11 | extern float iggGetScrollMaxX(); 12 | extern float iggGetScrollMaxY(); 13 | extern void iggSetScrollHereX(float centerXRatio); 14 | extern void iggSetScrollHereY(float centerYRatio); 15 | extern void iggSetScrollX(float scrollX); 16 | extern void iggSetScrollY(float scrollY); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | -------------------------------------------------------------------------------- /wrapper/Settings.cpp: -------------------------------------------------------------------------------- 1 | #include "ConfiguredImGui.h" 2 | 3 | #include "Settings.h" 4 | 5 | void iggLoadIniSettingsFromDisk(char const *ini_filename) 6 | { 7 | ImGui::LoadIniSettingsFromDisk(ini_filename); 8 | } 9 | 10 | void iggLoadIniSettingsFromMemory(char const *ini_data) 11 | { 12 | ImGui::LoadIniSettingsFromMemory(ini_data, 0); 13 | } 14 | 15 | void iggSaveIniSettingsToDisk(char const *ini_filename) 16 | { 17 | ImGui::SaveIniSettingsToDisk(ini_filename); 18 | } 19 | 20 | char const *iggSaveIniSettingsToMemory() 21 | { 22 | return ImGui::SaveIniSettingsToMemory(); 23 | } -------------------------------------------------------------------------------- /wrapper/Settings.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | extern void iggLoadIniSettingsFromDisk(char const *ini_filename); 10 | extern void iggLoadIniSettingsFromMemory(char const *ini_data); 11 | extern void iggSaveIniSettingsToDisk(char const *ini_filename); 12 | extern char const *iggSaveIniSettingsToMemory(); 13 | 14 | #ifdef __cplusplus 15 | } 16 | #endif -------------------------------------------------------------------------------- /wrapper/State.cpp: -------------------------------------------------------------------------------- 1 | #include "ConfiguredImGui.h" 2 | 3 | #include "State.h" 4 | #include "WrapperConverter.h" 5 | 6 | void iggClearActiveID(void) 7 | { 8 | ImGui::ClearActiveID(); 9 | } 10 | 11 | IggBool iggIsItemClicked() 12 | { 13 | return ImGui::IsItemClicked() ? 1 : 0; 14 | } 15 | 16 | IggBool iggIsItemHovered(int flags) 17 | { 18 | return ImGui::IsItemHovered(flags) ? 1 : 0; 19 | } 20 | 21 | IggBool iggIsItemActive() 22 | { 23 | return ImGui::IsItemActive() ? 1 : 0; 24 | } 25 | 26 | IggBool iggIsAnyItemActive() 27 | { 28 | return ImGui::IsAnyItemActive() ? 1 : 0; 29 | } 30 | 31 | IggBool iggIsItemVisible() 32 | { 33 | return ImGui::IsItemVisible() ? 1 : 0; 34 | } 35 | 36 | IggBool iggIsItemEdited() 37 | { 38 | return ImGui::IsItemEdited() ? 1 : 0; 39 | } 40 | 41 | IggBool iggIsItemActivated() 42 | { 43 | return ImGui::IsItemActivated() ? 1 : 0; 44 | } 45 | 46 | IggBool iggIsItemDeactivated() 47 | { 48 | return ImGui::IsItemDeactivated() ? 1 : 0; 49 | } 50 | 51 | IggBool iggIsItemDeactivatedAfterEdit() 52 | { 53 | return ImGui::IsItemDeactivatedAfterEdit() ? 1 : 0; 54 | } 55 | 56 | IggBool iggIsItemToggledOpen() 57 | { 58 | return ImGui::IsItemToggledOpen() ? 1 : 0; 59 | } 60 | 61 | void iggSetItemAllowOverlap() 62 | { 63 | ImGui::SetItemAllowOverlap(); 64 | } 65 | 66 | IggBool iggIsWindowAppearing() 67 | { 68 | return ImGui::IsWindowAppearing() ? 1 : 0; 69 | } 70 | 71 | IggBool iggIsWindowCollapsed() 72 | { 73 | return ImGui::IsWindowCollapsed() ? 1 : 0; 74 | } 75 | 76 | IggBool iggIsWindowFocused(int flags) 77 | { 78 | return ImGui::IsWindowFocused(flags) ? 1 : 0; 79 | } 80 | 81 | IggBool iggIsWindowHovered(int flags) 82 | { 83 | return ImGui::IsWindowHovered(flags) ? 1 : 0; 84 | } 85 | 86 | int iggGetKeyIndex(int key) 87 | { 88 | return ImGui::GetKeyIndex(key); 89 | } 90 | 91 | IggBool iggIsKeyDown(int key) 92 | { 93 | return ImGui::IsKeyDown(key); 94 | } 95 | 96 | IggBool iggIsKeyPressed(int key, IggBool repeat) 97 | { 98 | return ImGui::IsKeyPressed(key, repeat); 99 | } 100 | 101 | IggBool iggIsKeyReleased(int key) 102 | { 103 | return ImGui::IsKeyReleased(key); 104 | } 105 | 106 | IggBool iggIsMouseDown(int button) 107 | { 108 | return ImGui::IsMouseDown(button); 109 | } 110 | 111 | IggBool iggIsAnyMouseDown() 112 | { 113 | return ImGui::IsAnyMouseDown(); 114 | } 115 | 116 | IggBool iggIsMouseClicked(int button, IggBool repeat) 117 | { 118 | return ImGui::IsMouseClicked(button, repeat); 119 | } 120 | 121 | IggBool iggIsMouseReleased(int button) 122 | { 123 | return ImGui::IsMouseReleased(button); 124 | } 125 | 126 | IggBool iggIsMouseDoubleClicked(int button) 127 | { 128 | return ImGui::IsMouseDoubleClicked(button); 129 | } 130 | 131 | IggBool iggIsMouseDragging(int button, float lock_threshold) 132 | { 133 | return ImGui::IsMouseDragging(button, lock_threshold); 134 | } 135 | 136 | void iggGetMouseDragDelta(IggVec2 *value, int button, float lock_threshold) 137 | { 138 | exportValue(*value, ImGui::GetMouseDragDelta(button, lock_threshold)); 139 | } 140 | 141 | void iggResetMouseDragDelta(int button) 142 | { 143 | ImGui::ResetMouseDragDelta(button); 144 | } 145 | 146 | void iggMousePos(IggVec2 *pos) 147 | { 148 | exportValue(*pos, ImGui::GetMousePos()); 149 | } 150 | 151 | int iggGetMouseCursor() 152 | { 153 | return ImGui::GetMouseCursor(); 154 | } 155 | 156 | void iggSetMouseCursor(int cursor) 157 | { 158 | ImGui::SetMouseCursor(cursor); 159 | } 160 | 161 | void iggGetItemRectMin(IggVec2 *pos) 162 | { 163 | exportValue(*pos, ImGui::GetItemRectMin()); 164 | } 165 | 166 | void iggGetItemRectMax(IggVec2 *pos) 167 | { 168 | exportValue(*pos, ImGui::GetItemRectMax()); 169 | } 170 | -------------------------------------------------------------------------------- /wrapper/State.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | extern void iggClearActiveID(void); 10 | 11 | extern IggBool iggIsItemClicked(); 12 | extern IggBool iggIsItemHovered(int flags); 13 | extern IggBool iggIsItemActive(); 14 | extern IggBool iggIsItemEdited(); 15 | extern IggBool iggIsItemActivated(); 16 | extern IggBool iggIsItemDeactivated(); 17 | extern IggBool iggIsItemDeactivatedAfterEdit(); 18 | extern IggBool iggIsItemToggledOpen(); 19 | 20 | extern void iggSetItemAllowOverlap(); 21 | 22 | extern IggBool iggIsAnyItemActive(); 23 | extern IggBool iggIsItemVisible(); 24 | 25 | extern IggBool iggIsWindowAppearing(); 26 | extern IggBool iggIsWindowCollapsed(); 27 | extern IggBool iggIsWindowFocused(int flags); 28 | extern IggBool iggIsWindowHovered(int flags); 29 | 30 | extern int iggGetKeyIndex(int key); 31 | extern IggBool iggIsKeyDown(int key); 32 | extern IggBool iggIsKeyPressed(int key, IggBool repeat); 33 | extern IggBool iggIsKeyReleased(int key); 34 | extern IggBool iggIsMouseDown(int button); 35 | extern IggBool iggIsAnyMouseDown(); 36 | extern IggBool iggIsMouseClicked(int button, IggBool repeat); 37 | extern IggBool iggIsMouseReleased(int button); 38 | extern IggBool iggIsMouseDoubleClicked(int button); 39 | extern IggBool iggIsMouseDragging(int button, float threshold); 40 | extern void iggGetMouseDragDelta(IggVec2 *value, int button, float lock_threshold); 41 | extern void iggResetMouseDragDelta(int button); 42 | extern void iggMousePos(IggVec2 *pos); 43 | extern int iggGetMouseCursor(); 44 | extern void iggSetMouseCursor(int cursor); 45 | 46 | extern void iggGetItemRectMax(IggVec2 *pos); 47 | extern void iggGetItemRectMin(IggVec2 *pos); 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | -------------------------------------------------------------------------------- /wrapper/Style.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | extern void iggStyleColorsDark(); 10 | extern void iggStyleColorsClassic(); 11 | extern void iggStyleColorsLight(); 12 | 13 | extern IggGuiStyle iggGetCurrentStyle(void); 14 | 15 | extern void iggPushStyleColor(int index, IggVec4 const *col); 16 | extern void iggPopStyleColor(int count); 17 | extern void iggPushStyleVarFloat(int index, float value); 18 | extern void iggPushStyleVarVec2(int index, IggVec2 const *value); 19 | extern void iggPopStyleVar(int count); 20 | 21 | extern void iggStyleGetItemInnerSpacing(IggGuiStyle handle, IggVec2 *value); 22 | extern void iggStyleGetItemSpacing(IggGuiStyle handle, IggVec2 *value); 23 | extern void iggStyleSetItemInnerSpacing(IggGuiStyle handle, IggVec2 const *value); 24 | extern void iggStyleSetItemSpacing(IggGuiStyle handle, IggVec2 const *value); 25 | 26 | extern void iggStyleGetFramePadding(IggGuiStyle handle, IggVec2 *value); 27 | extern void iggStyleGetWindowPadding(IggGuiStyle handle, IggVec2 *value); 28 | extern void iggStyleGetCellPadding(IggGuiStyle handle, IggVec2 *value); 29 | extern void iggStyleSetFramePadding(IggGuiStyle handle, IggVec2 const *value); 30 | extern void iggStyleSetWindowPadding(IggGuiStyle handle, IggVec2 const *value); 31 | extern void iggStyleSetCellPadding(IggGuiStyle handle, IggVec2 const *value); 32 | 33 | extern void iggStyleSetColor(IggGuiStyle handle, int index, IggVec4 const *color); 34 | extern void iggStyleGetColor(IggGuiStyle handle, int index, IggVec4 *value); 35 | 36 | extern void iggStyleScaleAllSizes(IggGuiStyle handle, float scale); 37 | 38 | extern void iggGetTouchExtraPadding(IggGuiStyle handle, IggVec2 *value); 39 | extern void iggSetTouchExtraPadding(IggGuiStyle handle, IggVec2 const *value); 40 | 41 | extern float iggGetAlpha(IggGuiStyle handle); 42 | extern void iggSetAlpha(IggGuiStyle handle, float alpha); 43 | extern float iggGetDisabledAlpha(IggGuiStyle handle); 44 | extern void iggSetDisabledAlpha(IggGuiStyle handle, float disabledAlpha); 45 | extern float iggGetWindowRounding(IggGuiStyle handle); 46 | extern void iggSetWindowRounding(IggGuiStyle handle, float windowRounding); 47 | extern float iggGetWindowBorderSize(IggGuiStyle handle); 48 | extern void iggSetWindowBorderSize(IggGuiStyle handle, float windowBorderSize); 49 | extern float iggGetChildRounding(IggGuiStyle handle); 50 | extern void iggSetChildRounding(IggGuiStyle handle, float v); 51 | extern float iggGetChildBorderSize(IggGuiStyle handle); 52 | extern void iggSetChildBorderSize(IggGuiStyle handle, float v); 53 | extern float iggGetPopupRounding(IggGuiStyle handle); 54 | extern void iggSetPopupRounding(IggGuiStyle handle, float v); 55 | extern float iggGetPopupBorderSize(IggGuiStyle handle); 56 | extern void iggSetPopupBorderSize(IggGuiStyle handle, float v); 57 | extern float iggGetFrameRounding(IggGuiStyle handle); 58 | extern void iggSetFrameRounding(IggGuiStyle handle, float v); 59 | extern float iggGetFrameBorderSize(IggGuiStyle handle); 60 | extern void iggSetFrameBorderSize(IggGuiStyle handle, float v); 61 | extern float iggGetIndentSpacing(IggGuiStyle handle); 62 | extern void iggSetIndentSpacing(IggGuiStyle handle, float v); 63 | extern float iggGetColumnsMinSpacing(IggGuiStyle handle); 64 | extern void iggSetColumnsMinSpacing(IggGuiStyle handle, float v); 65 | extern float iggGetScrollbarSize(IggGuiStyle handle); 66 | extern void iggSetScrollbarSize(IggGuiStyle handle, float v); 67 | extern float iggGetScrollbarRounding(IggGuiStyle handle); 68 | extern void iggSetScrollbarRounding(IggGuiStyle handle, float v); 69 | extern float iggGetGrabMinSize(IggGuiStyle handle); 70 | extern void iggSetGrabMinSize(IggGuiStyle handle, float v); 71 | extern float iggGetGrabRounding(IggGuiStyle handle); 72 | extern void iggSetGrabRounding(IggGuiStyle handle, float v); 73 | extern float iggGetLogSliderDeadzone(IggGuiStyle handle); 74 | extern void iggSetLogSliderDeadzone(IggGuiStyle handle, float v); 75 | extern float iggGetTabRounding(IggGuiStyle handle); 76 | extern void iggSetTabRounding(IggGuiStyle handle, float v); 77 | extern float iggGetTabBorderSize(IggGuiStyle handle); 78 | extern void iggSetTabBorderSize(IggGuiStyle handle, float v); 79 | extern float iggGetTabMinWidthForCloseButton(IggGuiStyle handle); 80 | extern void iggSetTabMinWidthForCloseButton(IggGuiStyle handle, float v); 81 | extern float iggGetCurveTessellationTol(IggGuiStyle handle); 82 | extern void iggSetCurveTessellationTol(IggGuiStyle handle, float v); 83 | extern float iggGetCircleTessellationMaxError(IggGuiStyle handle); 84 | extern void iggSetCircleTessellationMaxError(IggGuiStyle handle, float v); 85 | extern float iggGetMouseCursorScale(IggGuiStyle handle); 86 | extern void iggSetMouseCursorScale(IggGuiStyle handle, float v); 87 | extern void iggStyleGetWindowMinSize(IggGuiStyle handle, IggVec2 *value); 88 | extern void iggSetWindowMinSize(IggGuiStyle handle, IggVec2 const *value); 89 | extern void iggStyleGetWindowTitleAlign(IggGuiStyle handle, IggVec2 *value); 90 | extern void iggSetWindowTitleAlign(IggGuiStyle handle, IggVec2 const *value); 91 | extern void iggStyleGetButtonTextAlign(IggGuiStyle handle, IggVec2 *value); 92 | extern void iggSetButtonTextAlign(IggGuiStyle handle, IggVec2 const *value); 93 | extern void iggStyleGetSelectableTextAlign(IggGuiStyle handle, IggVec2 *value); 94 | extern void iggSetSelectableTextAlign(IggGuiStyle handle, IggVec2 const *value); 95 | extern void iggStyleGetDisplayWindowPadding(IggGuiStyle handle, IggVec2 *value); 96 | extern void iggSetDisplayWindowPadding(IggGuiStyle handle, IggVec2 const *value); 97 | extern void iggStyleGetDisplaySafeAreaPadding(IggGuiStyle handle, IggVec2 *value); 98 | extern void iggSetDisplaySafeAreaPadding(IggGuiStyle handle, IggVec2 const *value); 99 | extern IggBool iggStyleGetAntiAliasedLines(IggGuiStyle handle); 100 | extern void iggStyleSetAntiAliasedLines(IggGuiStyle handle, IggBool value); 101 | extern IggBool iggStyleGetAntiAliasedLinesUseTex(IggGuiStyle handle); 102 | extern void iggStyleSetAntiAliasedLinesUseTex(IggGuiStyle handle, IggBool value); 103 | extern IggBool iggStyleGetAntiAliasedFill(IggGuiStyle handle); 104 | extern void iggStyleSetAntiAliasedFill(IggGuiStyle handle, IggBool value); 105 | extern IggDir iggStyleGetWindowMenuButtonPosition(IggGuiStyle handle); 106 | extern void iggStyleSetWindowMenuButtonPosition(IggGuiStyle handle, IggDir value); 107 | extern IggDir iggStyleGetColorButtonPosition(IggGuiStyle handle); 108 | extern void iggStyleSetColorButtonPosition(IggGuiStyle handle, IggDir value); 109 | 110 | #ifdef __cplusplus 111 | } 112 | #endif 113 | -------------------------------------------------------------------------------- /wrapper/Tables.cpp: -------------------------------------------------------------------------------- 1 | #include "ConfiguredImGui.h" 2 | 3 | #include "Tables.h" 4 | #include "WrapperConverter.h" 5 | 6 | 7 | IggBool iggBeginTable(char const *str_id, int columns_count, int flags, IggVec2 const *outer_size, float inner_width) 8 | { 9 | Vec2Wrapper outerSizeArg(outer_size); 10 | return ImGui::BeginTable(str_id, columns_count, flags, *outerSizeArg, inner_width) ? 1 : 0; 11 | } 12 | 13 | void iggEndTable(void) 14 | { 15 | ImGui::EndTable(); 16 | } 17 | 18 | void iggTableNextRow(int row_flags, float min_row_height) 19 | { 20 | ImGui::TableNextRow(row_flags, min_row_height); 21 | } 22 | 23 | IggBool iggTableNextColumn(void) 24 | { 25 | return ImGui::TableNextColumn() ? 1 : 0; 26 | } 27 | 28 | IggBool iggTableSetColumnIndex(int column_n) 29 | { 30 | return ImGui::TableSetColumnIndex(column_n) ? 1 : 0; 31 | } 32 | 33 | int iggTableGetColumnIndex(void) 34 | { 35 | return ImGui::TableGetColumnIndex(); 36 | } 37 | 38 | int iggTableGetRowIndex(void) 39 | { 40 | return ImGui::TableGetRowIndex(); 41 | } 42 | 43 | void iggTableSetupColumn(char const *label, int flags, float init_width_or_weight, unsigned int user_id) 44 | { 45 | ImGui::TableSetupColumn(label, flags, init_width_or_weight, user_id); 46 | } 47 | 48 | void iggTableSetupScrollFreeze(int cols, int rows) 49 | { 50 | ImGui::TableSetupScrollFreeze(cols, rows); 51 | } 52 | 53 | void iggTableHeadersRow(void) 54 | { 55 | ImGui::TableHeadersRow(); 56 | } 57 | 58 | void iggTableHeader(char const *label) 59 | { 60 | ImGui::TableHeader(label); 61 | } 62 | 63 | int iggTableGetColumnCount(void) 64 | { 65 | return ImGui::TableGetColumnCount(); 66 | } 67 | 68 | char const *iggTableGetColumnName(int column_n) 69 | { 70 | return ImGui::TableGetColumnName(column_n); 71 | } 72 | 73 | int iggTableGetColumnFlags(int column_n) 74 | { 75 | return ImGui::TableGetColumnFlags(column_n); 76 | } 77 | 78 | void iggTableSetBgColor(int target, IggVec4 const *color, int column_n) 79 | { 80 | Vec4Wrapper colorArg(color); 81 | auto col = ImGui::GetColorU32(*colorArg); 82 | ImGui::TableSetBgColor(target, col, column_n); 83 | } 84 | 85 | IggTableSortSpecs iggTableGetSortSpecs() 86 | { 87 | return static_cast(ImGui::TableGetSortSpecs()); 88 | } 89 | 90 | void iggTableSortSpecsGetSpec(IggTableSortSpecs handle, int index, IggTableColumnSortSpecs *out) 91 | { 92 | ImGuiTableSortSpecs *sort_specs = reinterpret_cast(handle); 93 | ImGuiTableColumnSortSpecs column_spec = sort_specs->Specs[index]; 94 | 95 | out->ColumnUserID = column_spec.ColumnUserID; 96 | out->ColumnIndex = column_spec.ColumnIndex; 97 | out->SortOrder = column_spec.SortOrder; 98 | out->SortDirection = column_spec.SortDirection; 99 | } 100 | 101 | int iggTableSortSpecsGetSpecsCount(IggTableSortSpecs handle) 102 | { 103 | ImGuiTableSortSpecs *sort_specs = reinterpret_cast(handle); 104 | return sort_specs->SpecsCount; 105 | } 106 | 107 | IggBool iggTableSortSpecsGetSpecsDirty(IggTableSortSpecs handle) 108 | { 109 | ImGuiTableSortSpecs *sort_specs = reinterpret_cast(handle); 110 | return sort_specs->SpecsDirty ? 1 : 0; 111 | } 112 | 113 | void iggTableSortSpecsSetSpecsDirty(IggTableSortSpecs handle, IggBool value) 114 | { 115 | ImGuiTableSortSpecs *sort_specs = reinterpret_cast(handle); 116 | sort_specs->SpecsDirty = value != 0; 117 | } 118 | -------------------------------------------------------------------------------- /wrapper/Tables.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | typedef struct tagIggTableColumnSortSpecs 10 | { 11 | unsigned int ColumnUserID; 12 | short ColumnIndex; 13 | short SortOrder; 14 | int SortDirection; 15 | } IggTableColumnSortSpecs; 16 | 17 | extern IggBool iggBeginTable(char const *str_id, int columns_count, int flags, IggVec2 const *outer_size, float inner_width); 18 | extern void iggEndTable(); 19 | extern void iggTableNextRow(int row_flags, float min_row_height); 20 | extern IggBool iggTableNextColumn(); 21 | extern IggBool iggTableSetColumnIndex(int column_n); 22 | extern int iggTableGetColumnIndex(); 23 | extern int iggTableGetRowIndex(); 24 | extern void iggTableSetupColumn(char const *label, int flags, float init_width_or_weight, unsigned int user_id); 25 | extern void iggTableSetupScrollFreeze(int cols, int rows); 26 | extern void iggTableHeadersRow(); 27 | extern void iggTableHeader(char const *label); 28 | extern int iggTableGetColumnCount(); 29 | extern char const *iggTableGetColumnName(int column_n); 30 | extern int iggTableGetColumnFlags(int column_n); 31 | extern void iggTableSetBgColor(int target, IggVec4 const *color, int column_n); 32 | 33 | extern IggTableSortSpecs iggTableGetSortSpecs(); 34 | extern void iggTableSortSpecsGetSpec(IggTableSortSpecs handle, int index, IggTableColumnSortSpecs *out); 35 | extern int iggTableSortSpecsGetSpecsCount(IggTableSortSpecs handle); 36 | extern IggBool iggTableSortSpecsGetSpecsDirty(IggTableSortSpecs handle); 37 | extern void iggTableSortSpecsSetSpecsDirty(IggTableSortSpecs handle, IggBool value); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | -------------------------------------------------------------------------------- /wrapper/Types.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | typedef int IggBool; 11 | typedef int IggDir; 12 | typedef uintptr_t IggTextureID; 13 | 14 | typedef void *IggContext; 15 | typedef void *IggDrawCmd; 16 | typedef void *IggDrawData; 17 | typedef void *IggDrawList; 18 | typedef void *IggFontAtlas; 19 | typedef void *IggFontConfig; 20 | typedef void *IggFont; 21 | typedef void *IggFontGlyph; 22 | typedef void *IggGlyphRanges; 23 | typedef void *IggGuiStyle; 24 | typedef void *IggInputTextCallbackData; 25 | typedef void *IggIO; 26 | typedef unsigned int IggPackedColor; 27 | typedef void *IggPayload; 28 | typedef void *IggTableSortSpecs; 29 | typedef void *IggViewport; 30 | 31 | typedef struct tagIggVec2 32 | { 33 | float x; 34 | float y; 35 | } IggVec2; 36 | 37 | typedef struct tagIggVec4 38 | { 39 | float x; 40 | float y; 41 | float z; 42 | float w; 43 | } IggVec4; 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | -------------------------------------------------------------------------------- /wrapper/Widgets.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | extern void iggTextUnformatted(char const *text); 10 | extern void iggLabelText(char const *label, char const *text); 11 | 12 | extern IggBool iggButton(char const *label, IggVec2 const *size); 13 | extern IggBool iggInvisibleButton(char const *label, IggVec2 const *size, int flags); 14 | extern void iggImage(IggTextureID textureID, 15 | IggVec2 const *size, IggVec2 const *uv0, IggVec2 const *uv1, 16 | IggVec4 const *tintCol, IggVec4 const *borderCol); 17 | extern IggBool iggImageButton(IggTextureID textureID, 18 | IggVec2 const *size, IggVec2 const *uv0, IggVec2 const *uv1, 19 | int framePadding, IggVec4 const *bgCol, 20 | IggVec4 const *tintCol); 21 | extern IggBool iggCheckbox(char const *label, IggBool *selected); 22 | extern IggBool iggRadioButton(char const *label, IggBool active); 23 | extern void iggBullet(); 24 | extern void iggProgressBar(float fraction, IggVec2 const *size, char const *overlay); 25 | 26 | extern IggBool iggBeginCombo(char const *label, char const *previewValue, int flags); 27 | extern void iggEndCombo(void); 28 | extern IggBool iggCombo(char const *label, int *currentItem, char const *itemsSeparatedByZeros, int heightInItems); 29 | 30 | extern IggBool iggDragFloat(char const *label, float *value, float speed, float min, float max, char const *format, int flags); 31 | extern IggBool iggDragFloatN(char const *label, float *value, int n, float speed, float min, float max, char const *format, int flags); 32 | extern IggBool iggDragFloatRange2V(char const *label, float *currentMin, float *currentMax, float speed, float min, float max, char const *format, const char *formatMax, int flags); 33 | extern IggBool iggDragInt(char const *label, int *value, float speed, int min, int max, char const *format, int flags); 34 | extern IggBool iggDragIntN(char const *label, int *value, int n, float speed, int min, int max, char const *format, int flags); 35 | extern IggBool iggDragIntRange2V(char const *label, int *currentMin, int *currentMax, float speed, int min, int max, char const *format, const char *formatMax, int flags); 36 | 37 | extern IggBool iggSliderFloat(char const *label, float *value, float minValue, float maxValue, char const *format, int flags); 38 | extern IggBool iggSliderFloatN(char const *label, float *value, int n, float minValue, float maxValue, char const *format, int flags); 39 | 40 | extern IggBool iggSliderInt(char const *label, int *value, int minValue, int maxValue, char const *format, int flags); 41 | extern IggBool iggSliderIntN(char const *label, int *value, int n, int minValue, int maxValue, char const *format, int flags); 42 | 43 | extern IggBool iggVSliderFloat(char const *label, IggVec2 const *size, float *value, float minValue, float maxValue, char const *format, int flags); 44 | extern IggBool iggVSliderInt(char const *label, IggVec2 const *size, int *value, int minValue, int maxValue, char const *format, int flags); 45 | 46 | extern IggBool iggInputTextSingleline(char const *label, char const *hint, char *buf, unsigned int bufSize, int flags, int callbackKey); 47 | extern IggBool iggInputTextMultiline(char const *label, char *buf, unsigned int bufSize, IggVec2 const *size, int flags, int callbackKey); 48 | 49 | extern IggBool iggInputInt(char const *label, int *value, int step, int step_fast, int flags); 50 | 51 | extern IggBool iggTreeNode(char const *label, int flags); 52 | extern void iggTreePop(void); 53 | extern void iggSetNextItemOpen(IggBool open, int cond); 54 | extern float iggGetTreeNodeToLabelSpacing(void); 55 | 56 | extern IggBool iggCollapsingHeader(const char *label, int flags); 57 | 58 | extern IggBool iggSelectable(char const *label, IggBool selected, int flags, IggVec2 const *size); 59 | extern IggBool iggBeginListBox(char const *label, IggVec2 const *size); 60 | extern void iggEndListBox(); 61 | extern IggBool iggListBox(char const *label, int *currentItem, char const *const items[], int itemCount, int heightItems); 62 | 63 | extern void iggPlotLines(const char *label, const float *values, int valuesCount, int valuesOffset, const char *overlayText, float scaleMin, float scaleMax, IggVec2 const *graphSize); 64 | extern void iggPlotHistogram(const char *label, const float *values, int valuesCount, int valuesOffset, const char *overlayText, float scaleMin, float scaleMax, IggVec2 const *graphSize); 65 | 66 | extern void iggSetTooltip(char const *text); 67 | extern void iggBeginTooltip(void); 68 | extern void iggEndTooltip(void); 69 | 70 | extern IggBool iggBeginMainMenuBar(void); 71 | extern void iggEndMainMenuBar(void); 72 | extern IggBool iggBeginMenuBar(void); 73 | extern void iggEndMenuBar(void); 74 | extern IggBool iggBeginMenu(char const *label, IggBool enabled); 75 | extern void iggEndMenu(void); 76 | extern IggBool iggMenuItem(char const *label, char const *shortcut, IggBool selected, IggBool enabled); 77 | 78 | extern void iggColumns(int count, char const *label, IggBool border); 79 | extern void iggNextColumn(); 80 | extern int iggGetColumnIndex(); 81 | extern int iggGetColumnWidth(int index); 82 | extern void iggSetColumnWidth(int index, float width); 83 | extern float iggGetColumnOffset(int index); 84 | extern void iggSetColumnOffset(int index, float offsetX); 85 | extern int iggGetColumnsCount(); 86 | 87 | extern IggBool iggBeginTabBar(char const *str_id, int flags); 88 | extern void iggEndTabBar(); 89 | extern IggBool iggBeginTabItem(char const *label, IggBool *p_open, int flags); 90 | extern void iggEndTabItem(); 91 | extern IggBool iggTabItemButton(char const *label, int flags); 92 | extern void iggSetTabItemClosed(char const *tab_or_docked_window_label); 93 | 94 | #ifdef __cplusplus 95 | } 96 | #endif 97 | -------------------------------------------------------------------------------- /wrapper/Window.cpp: -------------------------------------------------------------------------------- 1 | #include "ConfiguredImGui.h" 2 | 3 | #include "Window.h" 4 | #include "WrapperConverter.h" 5 | 6 | void iggShowDemoWindow(IggBool *open) 7 | { 8 | BoolWrapper openArg(open); 9 | 10 | ImGui::ShowDemoWindow(openArg); 11 | } 12 | 13 | void iggShowUserGuide(void) 14 | { 15 | ImGui::ShowUserGuide(); 16 | } 17 | 18 | IggBool iggBegin(char const *id, IggBool *open, int flags) 19 | { 20 | BoolWrapper openArg(open); 21 | return ImGui::Begin(id, openArg, flags) ? 1 : 0; 22 | } 23 | 24 | void iggEnd(void) 25 | { 26 | ImGui::End(); 27 | } 28 | 29 | IggBool iggBeginChild(char const *id, IggVec2 const *size, IggBool border, int flags) 30 | { 31 | Vec2Wrapper sizeArg(size); 32 | return ImGui::BeginChild(id, *sizeArg, border, flags) ? 1 : 0; 33 | } 34 | 35 | void iggEndChild(void) 36 | { 37 | ImGui::EndChild(); 38 | } 39 | 40 | void iggWindowPos(IggVec2 *pos) 41 | { 42 | exportValue(*pos, ImGui::GetWindowPos()); 43 | } 44 | 45 | void iggWindowSize(IggVec2 *size) 46 | { 47 | exportValue(*size, ImGui::GetWindowSize()); 48 | } 49 | 50 | float iggWindowWidth(void) 51 | { 52 | return ImGui::GetWindowWidth(); 53 | } 54 | 55 | float iggWindowHeight(void) 56 | { 57 | return ImGui::GetWindowHeight(); 58 | } 59 | 60 | void iggContentRegionAvail(IggVec2 *size) 61 | { 62 | exportValue(*size, ImGui::GetContentRegionAvail()); 63 | } 64 | 65 | void iggGetContentRegionMax(IggVec2 *out) 66 | { 67 | ImVec2 im_out = ImGui::GetContentRegionMax(); 68 | exportValue(*out, im_out); 69 | } 70 | 71 | void iggGetWindowContentRegionMin(IggVec2 *out) 72 | { 73 | ImVec2 im_out = ImGui::GetWindowContentRegionMin(); 74 | exportValue(*out, im_out); 75 | } 76 | 77 | void iggGetWindowContentRegionMax(IggVec2 *out) 78 | { 79 | ImVec2 im_out = ImGui::GetWindowContentRegionMax(); 80 | exportValue(*out, im_out); 81 | } 82 | 83 | void iggSetNextWindowPos(IggVec2 const *pos, int cond, IggVec2 const *pivot) 84 | { 85 | Vec2Wrapper posArg(pos); 86 | Vec2Wrapper pivotArg(pivot); 87 | ImGui::SetNextWindowPos(*posArg, cond, *pivotArg); 88 | } 89 | 90 | void iggSetNextWindowCollapsed(IggBool collapsed, int cond) 91 | { 92 | ImGui::SetNextWindowCollapsed(collapsed, cond); 93 | } 94 | 95 | void iggSetNextWindowSize(IggVec2 const *size, int cond) 96 | { 97 | Vec2Wrapper sizeArg(size); 98 | ImGui::SetNextWindowSize(*sizeArg, cond); 99 | } 100 | 101 | void iggSetNextWindowSizeConstraints(const IggVec2 *size_min, const IggVec2 *size_max) 102 | { 103 | Vec2Wrapper sizeMinArg(size_min); 104 | Vec2Wrapper sizeMaxArg(size_max); 105 | ImGui::SetNextWindowSizeConstraints(*sizeMinArg, *sizeMaxArg); 106 | } 107 | 108 | void iggSetNextWindowContentSize(IggVec2 const *size) 109 | { 110 | Vec2Wrapper sizeArg(size); 111 | ImGui::SetNextWindowContentSize(*sizeArg); 112 | } 113 | 114 | void iggSetNextWindowFocus(void) 115 | { 116 | ImGui::SetNextWindowFocus(); 117 | } 118 | 119 | void iggSetNextWindowBgAlpha(float value) 120 | { 121 | ImGui::SetNextWindowBgAlpha(value); 122 | } 123 | 124 | void iggPushItemWidth(float width) 125 | { 126 | ImGui::PushItemWidth(width); 127 | } 128 | 129 | void iggPopItemWidth(void) 130 | { 131 | ImGui::PopItemWidth(); 132 | } 133 | 134 | void iggSetNextItemWidth(float width) 135 | { 136 | ImGui::SetNextItemWidth(width); 137 | } 138 | 139 | void iggPushItemFlag(int options, IggBool enabled) 140 | { 141 | ImGui::PushItemFlag(options, enabled); 142 | } 143 | 144 | void iggPopItemFlag(void) 145 | { 146 | ImGui::PopItemFlag(); 147 | } 148 | 149 | float iggCalcItemWidth(void) 150 | { 151 | return ImGui::CalcItemWidth(); 152 | } 153 | 154 | void iggPushTextWrapPos(float wrapPosX) 155 | { 156 | ImGui::PushTextWrapPos(wrapPosX); 157 | } 158 | 159 | void iggPopTextWrapPos(void) 160 | { 161 | ImGui::PopTextWrapPos(); 162 | } 163 | 164 | void iggPushAllowKeyboardFocus(IggBool allow) 165 | { 166 | ImGui::PushAllowKeyboardFocus(allow); 167 | } 168 | 169 | void iggPopAllowKeyboardFocus() 170 | { 171 | ImGui::PopAllowKeyboardFocus(); 172 | } 173 | 174 | void iggPushButtonRepeat(IggBool repeat) 175 | { 176 | ImGui::PushButtonRepeat(repeat); 177 | } 178 | 179 | void iggPopButtonRepeat() 180 | { 181 | ImGui::PopButtonRepeat(); 182 | } 183 | 184 | IggViewport iggGetMainViewport() 185 | { 186 | return static_cast(ImGui::GetMainViewport()); 187 | } 188 | 189 | int iggViewportGetFlags(IggViewport handle) 190 | { 191 | ImGuiViewport *viewport = reinterpret_cast(handle); 192 | return viewport->Flags; 193 | } 194 | 195 | void iggViewportGetPos(IggViewport handle, IggVec2 *out) 196 | { 197 | ImGuiViewport *viewport = reinterpret_cast(handle); 198 | exportValue(*out, viewport->Pos); 199 | } 200 | 201 | void iggViewportGetSize(IggViewport handle, IggVec2 *out) 202 | { 203 | ImGuiViewport *viewport = reinterpret_cast(handle); 204 | exportValue(*out, viewport->Size); 205 | } 206 | 207 | void iggViewportGetWorkPos(IggViewport handle, IggVec2 *out) 208 | { 209 | ImGuiViewport *viewport = reinterpret_cast(handle); 210 | exportValue(*out, viewport->WorkPos); 211 | } 212 | 213 | void iggViewportGetWorkSize(IggViewport handle, IggVec2 *out) 214 | { 215 | ImGuiViewport *viewport = reinterpret_cast(handle); 216 | exportValue(*out, viewport->WorkSize); 217 | } 218 | 219 | void iggViewportGetCenter(IggViewport handle, IggVec2 *out) 220 | { 221 | ImGuiViewport *viewport = reinterpret_cast(handle); 222 | exportValue(*out, viewport->GetCenter()); 223 | } 224 | 225 | void iggViewportGetWorkCenter(IggViewport handle, IggVec2 *out) 226 | { 227 | ImGuiViewport *viewport = reinterpret_cast(handle); 228 | exportValue(*out, viewport->GetWorkCenter()); 229 | } 230 | -------------------------------------------------------------------------------- /wrapper/Window.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | extern void iggShowDemoWindow(IggBool *open); 10 | extern void iggShowUserGuide(void); 11 | 12 | extern IggBool iggBegin(char const *id, IggBool *open, int flags); 13 | extern void iggEnd(void); 14 | extern IggBool iggBeginChild(char const *id, IggVec2 const *size, IggBool border, int flags); 15 | extern void iggEndChild(void); 16 | 17 | extern void iggWindowPos(IggVec2 *pos); 18 | extern void iggWindowSize(IggVec2 *size); 19 | extern float iggWindowWidth(void); 20 | extern float iggWindowHeight(void); 21 | extern void iggContentRegionAvail(IggVec2 *size); 22 | extern void iggGetContentRegionMax(IggVec2 *out); 23 | extern void iggGetWindowContentRegionMin(IggVec2 *out); 24 | extern void iggGetWindowContentRegionMax(IggVec2 *out); 25 | 26 | extern void iggSetNextWindowPos(IggVec2 const *pos, int cond, IggVec2 const *pivot); 27 | extern void iggSetNextWindowSize(IggVec2 const *size, int cond); 28 | extern void iggSetNextWindowCollapsed(IggBool collapsed, int cond); 29 | extern void iggSetNextWindowSizeConstraints(const IggVec2 *size_min, const IggVec2 *size_max); 30 | extern void iggSetNextWindowContentSize(IggVec2 const *size); 31 | extern void iggSetNextWindowFocus(void); 32 | extern void iggSetNextWindowBgAlpha(float value); 33 | 34 | extern void iggPushItemWidth(float width); 35 | extern void iggPopItemWidth(void); 36 | extern void iggSetNextItemWidth(float width); 37 | extern void iggPushItemFlag(int flag, IggBool enabled); 38 | extern void iggPopItemFlag(void); 39 | extern float iggCalcItemWidth(void); 40 | extern void iggPushTextWrapPos(float wrapPosX); 41 | extern void iggPopTextWrapPos(void); 42 | extern void iggPushAllowKeyboardFocus(IggBool allow); 43 | extern void iggPopAllowKeyboardFocus(); 44 | extern void iggPushButtonRepeat(IggBool repeat); 45 | extern void iggPopButtonRepeat(void); 46 | 47 | extern IggViewport iggGetMainViewport(); 48 | extern int iggViewportGetFlags(IggViewport handle); 49 | extern void iggViewportGetPos(IggViewport handle, IggVec2 *out); 50 | extern void iggViewportGetSize(IggViewport handle, IggVec2 *out); 51 | extern void iggViewportGetWorkPos(IggViewport handle, IggVec2 *out); 52 | extern void iggViewportGetWorkSize(IggViewport handle, IggVec2 *out); 53 | extern void iggViewportGetCenter(IggViewport handle, IggVec2 *out); 54 | extern void iggViewportGetWorkCenter(IggViewport handle, IggVec2 *out); 55 | 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | -------------------------------------------------------------------------------- /wrapper/WrapperConverter.cpp: -------------------------------------------------------------------------------- 1 | #include "ConfiguredImGui.h" 2 | 3 | #include "Types.h" 4 | #include "WrapperConverter.h" 5 | 6 | void importValue(bool &out, IggBool const &in) 7 | { 8 | out = in != 0; 9 | } 10 | 11 | void exportValue(IggBool &out, bool const &in) 12 | { 13 | out = in ? 1 : 0; 14 | } 15 | 16 | void importValue(ImVec2 &out, IggVec2 const &in) 17 | { 18 | out.x = in.x; 19 | out.y = in.y; 20 | } 21 | 22 | void exportValue(IggVec2 &out, ImVec2 const &in) 23 | { 24 | out.x = in.x; 25 | out.y = in.y; 26 | } 27 | 28 | void importValue(ImVec4 &out, IggVec4 const &in) 29 | { 30 | out.x = in.x; 31 | out.y = in.y; 32 | out.z = in.z; 33 | out.w = in.w; 34 | } 35 | 36 | void exportValue(IggVec4 &out, ImVec4 const &in) 37 | { 38 | out.x = in.x; 39 | out.y = in.y; 40 | out.z = in.z; 41 | out.w = in.w; 42 | } 43 | -------------------------------------------------------------------------------- /wrapper/WrapperConverter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | extern void importValue(bool &out, IggBool const &in); 4 | extern void exportValue(IggBool &out, bool const &in); 5 | 6 | extern void importValue(ImVec2 &out, IggVec2 const &in); 7 | extern void exportValue(IggVec2 &out, ImVec2 const &in); 8 | 9 | extern void importValue(ImVec4 &out, IggVec4 const &in); 10 | extern void exportValue(IggVec4 &out, ImVec4 const &in); 11 | 12 | template 13 | class TypeWrapper 14 | { 15 | public: 16 | TypeWrapper(IggType *iggValue) 17 | : iggValue(iggValue) 18 | , imguiValue(nullptr) 19 | { 20 | if (iggValue != nullptr) 21 | { 22 | imguiValue = &imguiBuffer; 23 | importValue(*imguiValue, *iggValue); 24 | } 25 | } 26 | 27 | TypeWrapper(IggType const *constIggValue) 28 | : iggValue(nullptr) 29 | , imguiValue(nullptr) 30 | { 31 | if (constIggValue != nullptr) 32 | { 33 | imguiValue = &imguiBuffer; 34 | importValue(*imguiValue, *constIggValue); 35 | } 36 | } 37 | 38 | ~TypeWrapper() 39 | { 40 | if (iggValue != nullptr) 41 | { 42 | exportValue(*iggValue, *imguiValue); 43 | } 44 | } 45 | 46 | operator ImGuiType *() 47 | { 48 | return imguiValue; 49 | } 50 | 51 | private: 52 | IggType *iggValue; 53 | ImGuiType *imguiValue; 54 | ImGuiType imguiBuffer; 55 | }; 56 | 57 | typedef TypeWrapper BoolWrapper; 58 | typedef TypeWrapper Vec2Wrapper; 59 | typedef TypeWrapper Vec4Wrapper; 60 | -------------------------------------------------------------------------------- /wrapper/govendorkeep.go: -------------------------------------------------------------------------------- 1 | package cgowrapper 2 | -------------------------------------------------------------------------------- /wrapper_cgo_hack.go: -------------------------------------------------------------------------------- 1 | // +build required 2 | 3 | package imgui 4 | 5 | // This file exists purely to prevent the golang toolchain from stripping 6 | // away the c source directories and files when `go mod vendor` is used 7 | // to populate a `vendor/` directory of a project depending on `imgui-go`. 8 | // https://github.com/golang/go/issues/26366 9 | // 10 | // How it works: 11 | // - every directory which only includes c source files receives a govendorkeep.go file. 12 | // - every directory we want to preserve is included here as a _ import. 13 | // - this file is given a build to exclude it from the regular build. 14 | 15 | import ( 16 | // Prevent go tooling from stripping out the c source files. 17 | _ "github.com/inkyblackness/imgui-go/v4/imgui" 18 | _ "github.com/inkyblackness/imgui-go/v4/wrapper" 19 | _ "github.com/inkyblackness/imgui-go/v4/imgui/misc/freetype" 20 | ) 21 | --------------------------------------------------------------------------------