What is the recommended way to create/extend imgui with my own widgets?

I have created a custom PlotEx() (with plotlines and plothistogram helpers) that plots horizontally and vertically, forward and backwards, i.e. mirroring the plot directions in 2 dimensions. I did this by passing two extra arguments with some predefined constant values and some bit maps. I have put a lot of effort in minimizing the changes to PlotEx()… but by reading the community entries here and in github, it is apparent that these sort of changes will never rollup to the main imgui, so why bother in trying to minimize deltas. Therefore, I guess I have created my own fancy widget, but I would still like to: 1-make it available 2- contain the code 3- minimize the locations of change when upgrades come out.

What is the ImGui best practice to achieve this? I have read some entries about #including a file… but they are a few years old.

The easiest is to just provide the new code in your own file and make zero change to dear imgui.

PlotEx() is currently too limited. While waiting for a better plot/graph api it is reasoanble to just copy it and make your own.

it is apparent that these sort of changes will never rollup to the main imgui,

Just to clarify, improvement to Plot functions are very desirable but adding new parameters to the existing public function is just going to lead us into a bigger problem. I think the direction to head up is to completely redesign the plot API.

OK. I understand. So let’s say I have a customized PlotExXX() and a customized PlotLinesXX()… where should I store them (.h, .cpp), and what headers to include?

I would like your advice to make this as painless as possible.

Store them in your own files… e.g. my_imgui_extensions.cpp/.h.
You need to include imgui.h and imgui_internal.h to access the internal structures from your .cpp file (but don’t need to expose them to the rest of the code)

Sorry for use this thread, but its related to this extend questions :slight_smile:

there are some statics helper method, or static data types in some files, not for plot but for slider behavior or text behavior.

likes :

  • func SingleStringGetter
  • type ImGuiDataTypeInfo
  • func PatchFormatStringFloatToInt
  • func DataTypeFormatString
    etc

is there a way for use theses static method who are not available in header files.

if i need to copy/past, after each version i will haver some issues.

Regards

Please don’t go all “etc.” : for example there’s no reason you should ever need PatchFormatStringFloatToInt() in your code, that’s entirely to handle legacy imgui api.

If there are specific function you use I’ll move them to imgui_internal but please describe which one and why you need them. E.g why do you need ImGuiDataTypeInfo and GDataTypeInfo access?

i have created my SliderBehavior for have ( like said in this post <https://discourse.dearimgui.org/t/is-there-a-easy-way-to-step-sliders/239/3>) a step slider. and have recreate all slider function for support my stepped code. so i needed to have acces to many static type and functions; like ImGuiDataTypeInfo you are using in SliderScalar. the goal was to not touch to original imgui code

i have also rewrote all inputs for support my bicolor theme, when i need whitet text on input zone, and black text on orange buttons

You are not being specific!
Everything that SliderBehavior() uses depends on function exposed in .h files.
SliderFloat() depends on PatchFormatStringFloatToInt() and DataTypeFormatString.
The earlier I argued you don’t need to be calling it if you create a new api. The later I agree we can add it the header file and I will.

If there are any other function please be specific, I just want a specific list without “etc.”

Committed this:

You should not need to use PatchFormatStringFloatToInt() in a new function.

If you want to add stepping you could probably use SliderBehavior() unmodified and handle the Step operation on return, so you shouldn’t need to copy that much code but only the outer function SliderScalar().

thanks for this commit.

for been specific :

in my sliders, i needed acces to :

  • GDataTypeInfo
  • PatchFormatStringFloatToInt
  • DataTypeFormatString

and the static type limits : (used in SliderBehavior, (not the template version))

static const ImS32 IM_S32_MIN = INT_MIN; // (-2147483647 - 1), (0x80000000);
static const ImS32 IM_S32_MAX = INT_MAX; // (2147483647), (0x7FFFFFFF)
static const ImU32 IM_U32_MIN = 0;
static const ImU32 IM_U32_MAX = UINT_MAX; // (0xFFFFFFFF)
#ifdef LLONG_MIN
static const ImS64 IM_S64_MIN = LLONG_MIN; // (-9223372036854775807ll - 1ll);
static const ImS64 IM_S64_MAX = LLONG_MAX; // (9223372036854775807ll);
#else
static const ImS64 IM_S64_MIN = -9223372036854775807LL - 1;
static const ImS64 IM_S64_MAX = 9223372036854775807LL;
#endif
static const ImU64 IM_U64_MIN = 0;
#ifdef ULLONG_MAX
static const ImU64 IM_U64_MAX = ULLONG_MAX; // (0xFFFFFFFFFFFFFFFFull);
#else
static const ImU64 IM_U64_MAX = (2ULL * 9223372036854775807LL + 1);

for the inputs , i needed acces to :

  • DataTypeApplyOp
  • DataTypeApplyOpFromText

i just needed to rewrite InputScalar, for my bicolor theme.

in same way i have rewrote some combo for have my arrow. is there a way for have function pointer for these two renderiing function (used by many widgets) :

  • RenderBullet
  • RenderArrow

Thanks

Did you look at my message above? If you only want a stepping slider you shouldn’t need to replace SliderBehavior or SliderBehaviorT<>, you can do it all in your copy of SliderFloat/SliderScalar.

Why are you copying InputScalar ?

RenderBullet and RenderArrow are already in imgui_internal.h.

i seen your message, but i have not tested it. btw i responded to your needs to be specific. thats all. by the way as a user of this lib we can be able to use yours static method, to do our components, so why keep these static things only in implementation files ?

i copied InputScalar due to my bicolor theme, when i need black text on input zone, and white text on step buttons.

i know RenderBullet and RenderArrow is in imgui_internal. but i speak about some pointers on these functions, because for my bicolor theme i need white test and black arrow, and due to that, i have copied your combo widgets in the same way as InputScalar. so with pointers i could let imgui draw the widget with my custom RenderBullet and RenderArrow

btw i currently working on a rangebehavior for my new rangeslider widget (who is not working at this moment) and i will do my best for support the same things of you SldierBehavior, so i will need for keep compatibility, to used your helper methods (i could create a pull request if working as expected by the way it can be unusual for you :slight_smile: )

, so why keep these static things only in implementation files ?

Because I don’t want to encourage people copying code if there is a way they can solve the problem without.

For the bi-color theme you may have to wait until this is implemented in dear imgui.

At the moment to be honest it’ll be easier for you to just add new color in the theme enum and hack the existing code to use them, rather than copy so much code.

i was doing like that before the last month. but i got tired to merge my code with imgui after each update, so i decided to copy code. because i thought the code of Sliders or Inputs may not evolve often time. and i know, now, that its wrong, due to the many errors i encounter in the last merge :slight_smile:

but i understand your point of view.

what is you idea to implement this multi color style in ImGui ? im curious on the way you have in mind. i thinkc it is very flexible and general. :slight_smile:

Half of it is not a point of view but a fact. You do NOT need to copy Slider to implement the step solution.

For the Input +/- button you DO need to either make a copy either make a change in the code.

There are discussion about the style on the github. I don’t have the full design yet.

its a fact in the case of this stepping, maybe not with other…

but ok ok, sorry if annoying you, no problem.

bye

maybe i not understood fine, what you said, but

if i put my step code after the slider func call, i can round the value, yes. but cant update the grab pos according to this rounding value :
2019-05-08_19-25-56
you see the tooltip with the good stepped value, but the grab is not stepped.

whit my adapatation i got this : ( but need a lot of code and imgui copy)
2019-05-08_19-26-59
and as i seen, the gab pos, is calc and exported from SldierBehavior.

so i not see another choice to keep my way ?