-
Notifications
You must be signed in to change notification settings - Fork 281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include comments in enum output #212
Comments
I could add an option to parse comments. |
I have been playing with patterns in cpp2ffi.lua in order to parse the preprocessed file with comments included. int function(int a) // {} this is a comment
{
return a + 1;
} would confuse the parser in thinking that the function definition is int function(int a) // {} So I prefer to continue stripping comments in preprocessor. |
I guess the advantage of parsing the preprocessed file is that you get the right branch of ifdef'd code? You could generate two versions of the preprocessed file: one with and one without comments. I'm not sure how the preprocessing works, but I submitted a PR that parses imgui.h directly and uses those results to populate enum and function comments. |
I prefer not using your PR by now and trying to do it with the preprocessed output and the line number information. |
Question: what are you using the comments for? |
I'm using lua, but not luajit so I can't use ffi to get enum constants. Instead, I generate lua files containing the constant values. I output the comments there for reference. Also makes the comments easily findable for our designers who write lua, but not C++. |
How can you use cimgui without LuaJIT? |
calc_value field gives you enum constants value |
I wrote a lua script that loads cimgui's lua output and generates lua files. It uses calc_value. It's much simpler for a user to look at my generated lua file than to look at structs_and_enums.lua and more accurate than looking at imgui.h (since I'm using tables instead of many globals). Example:
I have my own imgui integration into a game with embedded lua 5.4. I'm only using cimgui to generate my enum files. |
Would struct fields comments be desired as well? |
If running docking_inter with Are this comments ok for you? |
With last commit nothing fails. |
@idbrii ? |
I wouldn't use them at the moment.
I have a deadline now and can't check this out until sometime next week. |
@sonoro1234, was interested in this as well, so I checked it out - and the comments look pretty great to me! A minor problem I saw is that if the enum value doesn't have a comment e.g. |
Another thing - is it possible to generate enum/struct comments as well? \ For example, given this enum: // Flags for ImGui::IsWindowFocused()
enum ImGuiFocusedFlags_
{
ImGuiFocusedFlags_None = 0,
...
}; ... extract or: // [Internal] Storage used by IsKeyDown(), IsKeyPressed() etc functions.
// If prior to 1.87 you used io.KeysDownDuration[] (which was marked as internal), you should use GetKeyData(key)->DownDuration and *NOT* io.KeysData[key]->DownDuration.
struct ImGuiKeyData
{
bool Down; // True for if key is down
float DownDuration; // Duration the key has been down (<0.0f: not pressed, 0.0f: just pressed, >0.0f: time held)
float DownDurationPrev; // Last frame duration the key has been down
float AnalogValue; // 0.0f..1.0f for gamepad values
}; extract to |
I will look into it!! |
Great! Looking forward to it. I also noticed that some comments should don't have whitespace trimmed on the left, e.g. {
"calc_value": 1,
"comment": " // Enable anti-aliased lines/borders (*2 the number of triangles for 1.0f wide line or lines thin enough to be drawn using textures, otherwise *3 the number of triangles)",
"name": "ImDrawListFlags_AntiAliasedLines",
"value": "1 << 0"
}, |
I am not sure to understand. Which is the desired comment? |
Where should this comment be saved to? |
The comment starts with a space: And I'm still not 100% sure if "//" is worth keeping or not. It would be easier for bindings in other languages if the commend didn't start with So maybe the "comment" can be just "Enable anti-aliased lines/borders". If the comment contains several "//", then it's okay to keep the second one, e.g. "comment": " // [DataType] // ColorEdit, ColorPicker, ColorButton: _display_ values formatted as 0..255.", can become "comment": "[DataType] // ColorEdit, ColorPicker, ColorButton: _display_ values formatted as 0..255.", and then in Python, for example, it can become a comment like this: ImGuiColorEditFlags_Uint8 # [DataType] // ColorEdit, ColorPicker, ColorButton: _display_ values formatted as 0..255.
Hmm, I just noticed that structs and enums are arrays in JSON... that's a bit problematic. Ideally it would be something like this (in structs_and_enums.json): "ImGuiKeyData": {
"comment": "// [Internal] Storage used by IsKeyDown(), IsKeyPressed()...",
"members": [
{
"comment": " // True for if key is down",
"name": "Down",
"type": "bool"
},
]
} ... but that would break existing cimgui API. Maybe you can do something like this to not break the API? {
"enums": "...",
"structs": "...",
"comments": {
"enums": { },
"structs": {
"ImGuiKeyData": "// [Internal] Storage used by IsKeyDown(), IsKeyPressed() etc functions..."
}
}
} |
Just pushed branch comments4000. It keeps comments in struct_comments and enum_comments. |
Nice. Looks good overall, however, there are some problems.
|
This will be handled when other issues are finished
Thats the key problem: All comments previous to an item are keept as this is the only way to keep comments before a struct or an enum. Empty line could be used as a mark for not appending previous comments but I am not sure if it will solve issues. |
I've looked through the whole imgui.h - I think that it will. Of course, I can post-process the comment later when generating a binding manually, though... As for the enum values and struct fields: the "above" comments are irrelevant, only comments on the same line are relevant, |
I have pushed a change for not keeping coments above empty lines |
Didn't work right for // Flags for ImDrawList instance. Those are set automatically by ImGui:: functions from ImGuiIO settings, and generally not manipulated directly.
// It is however possible to temporarily alter flags between calls to ImDrawList:: functions. ... but it only left the second line - there's no empty lines in the comment above. Same for |
New try!!! |
Much better! Only two issues now:
// comment
struct SomeStruct {
...
}; so, a blank line immediately above the struct indicates that the comment doesn't belong to
type ImFontAtlas struct {
...
// [Internal]
// NB: Access texture data via GetTexData*() calls! Which will setup a default font for you.
TexReady bool // Set when texture was built matching current font input
TexPixelsUseColors bool // Tell whether our texture data is known to use colors (rather than just alpha channel), in order to help backend select a format.
...
} by knowing which part was before the member and which part was on the same line as the member. |
Now using empty lines as marks and prevcomments separated from comments |
Looks good! Though maybe "comment.above" and "comment.sameline" would be a bit more descriptive? Also, it's a bit weird that when something doesn't have a comment, the "comment" field is an empty array, not an empty object in JSON. |
done? |
The last issue I have it untrimmed whitespace in the beginning of some comments. |
solved? |
Not solved here, for example. |
Just solved |
Everything looks great now. I'll try to generate Go binding with comments later and see if things work as I expect and there are no useful comments missing. |
Sorry for not checking this out sooner. Output generally looks really good! Capturing the above comments is awesome and your generator captures a bunch that mine missed (ImGuiWindowFlags_AlwaysVerticalScrollbar, ImGuiSortDirection_Descending). Would be nice for the initial
That way languages with a different comment leader can add their own and use multiline comments without messing with the text. In the generated lua, could use Are there any guarantees which comments may be multiline? ImGuiColorEditFlags_'s comments are a bit weird with the double comment, but that's how it is in imgui.h's so 🤷🏽 . Seems like the indent is to make [category] stand out. When you generate without comments, it still generates a Thanks for implementing this! |
That's how most of struct members are documented. If we trim the leading "//", the remaining comment should stay as-is, I think
From what I've seen, there are no "same line" comments which are multiline. |
@sonoro1234 is there any progress here? comments400 branch seems to b dead for a while... |
All progress is done in docking_inter branch. To generate with comments just add "comments" option to generator.sh (.bat) and generate. To try another imgui branch checkout from imgui folder and generate. |
oh ok, thank you! |
hmm, I think I hit #232 again 😿 |
Just add '-DIMGUI_USE_WCHAR32' as an option |
@sonoro1234 I meant that I can't generate with comments without editing |
I see, but why not introduce some simple way to make this script more customizable with command-line flags? (just like I did in #238 ) |
I generated lua tables for enums with cimgui and
https://github.com/cimgui/cimgui/blob/master/generator/output/structs_and_enums.lua doesn't include the comments. I did something like this:
Something similar could probably work for other types too.
The text was updated successfully, but these errors were encountered: