cimgui / cimgui

c-api for imgui (https://github.com/ocornut/imgui) Look at: https://github.com/cimgui for other widgets
MIT License
1.48k stars 284 forks source link

ImVector usage #72

Closed sonoro1234 closed 5 years ago

sonoro1234 commented 5 years ago

I am most interested in ImVector use cases. Has anybody been able to use an ImVector not just reading from it but also creating an ImVector before using it?

Also, to really expose it as a C interface we should define several new structs as for example

typedef struct ImVector_ImWchar_t { int Size; int Capacity; ImWchar* Data; } ImVector_ImWchar;

sonoro1234 commented 5 years ago

I am testing https://github.com/sonoro1234/cimgui/tree/GlyphRanges only cimgui.cpp and cimgui.h manually edited _init and _create version work for ImVector_ImWchar I still dont know which is better

sonoro1234 commented 5 years ago

Updated cimgui for exposing constructors and destructor except for ImVector where only ImVector_Wchar was manually written to test GlyphRangesBuilder

sonoro1234 commented 5 years ago

Added ImVector template C structs

Gekkio commented 5 years ago

This looks very promising, but right now the cimgui.h is unusable with C compilers due to compiler errors:

test.c:

#include <cimgui.h>
$ gcc --version                                                                                                                                                                                                                                                                                                                                      
gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ gcc -std=c99 -DCIMGUI_DEFINE_ENUMS_AND_STRUCTS=1 -I. test.c
In file included from test.c:1:0:
./cimgui.h:591:60: error: ‘ImVector_float’ redeclared as different kind of symbol
 struct ImVector_float {int Size;int Capacity;float* Data;} ImVector_float;
                                                            ^~~~~~~~~~~~~~
In file included from test.c:1:0:
./cimgui.h:66:31: note: previous declaration of ‘ImVector_float’ was here
 typedef struct ImVector_float ImVector_float;
                               ^~~~~~~~~~~~~~

... a lot of errors involving various ImVector types
$ clang --version
clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
$ clang -std=c99 -DCIMGUI_DEFINE_ENUMS_AND_STRUCTS=1 -I. test.c
./cimgui.h:591:60: error: redefinition of 'ImVector_float' as different kind of symbol
struct ImVector_float {int Size;int Capacity;float* Data;} ImVector_float;
                                                           ^
./cimgui.h:66:31: note: previous definition is here
typedef struct ImVector_float ImVector_float;

... a lot of errors involving various ImVector types
sonoro1234 commented 5 years ago

@Gekkio Just pushed correction. Is it ok now?

I need your feedback because it was compiling ok for me before

It was without DCIMGUI_DEFINE_ENUMS_AND_STRUCTS

Gekkio commented 5 years ago

Thanks for the quick fix! Works perfectly now :smile: