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

Constants given correct type.#141

Merged
dertseha merged 26 commits intoinkyblackness:masterfrom
JetSetIlly:master
Feb 21, 2021
Merged

Constants given correct type.#141
dertseha merged 26 commits intoinkyblackness:masterfrom
JetSetIlly:master

Conversation

@JetSetIlly
Copy link
Copy Markdown
Contributor

@JetSetIlly JetSetIlly commented Feb 15, 2021

Values in Condition.go do not have the correct type.

Only ConditionAlways has the correct Condition type. The Condition type is defined in the same file.

The other values are all of type int. This means those values must be cast to the Condition type in those places where you would expect them to be used. For example, SetNextWindowPosV()

Same comments for other constants.

@JetSetIlly
Copy link
Copy Markdown
Contributor Author

JetSetIlly commented Feb 15, 2021

Seeing as there are breaking changes coming v4 soon, what do you think about giving the other flags there own type?

For example, the various WindowFlags are all of type int and imgui.BeginV() for example, expects type int. However, it would be an improvement I think, if we define a new type, WindowFlags.

@JetSetIlly JetSetIlly changed the title "Condition" constants given correct type. "Condition" / "SliderFlags" constants given correct type. Feb 15, 2021
@JetSetIlly JetSetIlly changed the title "Condition" / "SliderFlags" constants given correct type. Constants given correct type. Feb 15, 2021
@dertseha
Copy link
Copy Markdown
Member

Thank you for noticing this. I did not have time to go through those as well - perhaps @the-goodies can assist/double check, they provided the 1.81 upgrade.

I'm OK with unifying the flag values to be typed. However please avoid switching them back to be iota based. They were originally so, someone else changed them to be explicit (to match imgui.h), now they would be going back to iota. Neither approach ensures they match the header, sadly.

Please tell when you are done with this change.

@JetSetIlly
Copy link
Copy Markdown
Contributor Author

I should point out that this isn't an issue that was introduced in the recent merge. The flag values I've changed have always had type int, despite there existing in those cases a special purpose type and the function signatures requiring values of that type.

Understood and agree with the iota. As you say, neither way ensures consistency with imgui.h but at least with the non-iota option it is self-documenting.

I'll make the changes to WindowFlags etc. and let you know when I've finished.

Have you considered enabling the Discussions feature for the repository? I think it would be good for people to ask questions, coordinate what they're doing or planning to do, without opening up an issue. It might turn out to be unpopular but it's worth experimenting with I think.

these values must match what's in imgui.h and it is better if the values
are explicitely defined, rather than relying on ordering.
ComboFlag* to ComboFlags* matches the convention elsewhere in the
library and also in the imgui.h file
ConfigFlag* to ConfigFlags* matches the convention elsewhere in the
library and also in the imgui.h file
BackendFlag* to BackendFlags* matches the convention elsewhere in the
library and also in the imgui.h file
renamed MouseCursor() to CurrentMouseCursor() to avoid conflict with new
type. note that CurrentMouseCursor() is called GetMouseCursor() in the
parest dear imgui code, but Go idiom discourages use of Get*() function
names.
this change matches naming conventions elsewhere in the package.
@JetSetIlly
Copy link
Copy Markdown
Contributor Author

JetSetIlly commented Feb 16, 2021

All flags and other constant types now have their own type. This makes navigation of documentation more straightforward and should make tab-completion type tools return better results.

Moreover, effective use of the type system helps in detecting programming errors. Indeed, I've already detected one error in my project's code base due to the use of an incorrect flag type.

The only set of constants I've not touched are the Key values defined in IO.go. I'm not sure how to handle that and what it would mean.

I've made a couple of choices which might not be liked. For example, the MouseCursor type is used to specify the mouse cursor for the SetMouseCursor() function. This conflicts with the MouseCursor() function, the Go function that calls GetMouseCursor(). I've renamed that function to CurrentMouseCursor() to avoid the conflict.

The alternative would be to name the type, MouseCursorID, but that doesn't seem right to me. No right-or-wrong answer, I don't think, and I'll be happy to change it if necessary.

I've also renamed StyleVarID and StyleColorID to StyleVar and StyleColor. Again, this is a question of personal-taste and I did it to align with what seems to me to be the overall naming convention in the project. I'll be happy to change them back if opinions differ.

One other breaking change I would like to make is to replace color definitions that use imgui.Vec4 with something like imgui.Color. The field names in the Vec4 type aren't well suited to specifying colors IMO.

With a bit of work we could maybe even use the color package from the go standard library, but that might be too big of a change.

@dertseha
Copy link
Copy Markdown
Member

We need to be cautious about how much to change in one go.

To rename the majority of constants from singular case to plural case seems like a lot to break. Originally I saw one constant to be singular, but it seems that wasn't followed anymore at one point - and keeping the plural form also for constants probably is closer to the original. So, OK on that change - thank you for the tedious work there. (still too bad to have no enum-equivalent in Go)

As for other things:

  • StyleVar and StyleColor - No, please back to *ID for the type name. Because they aren't a color (or variable), but identify them.
  • This then allows to answer for MouseCursor: Make the type MouseCursorID, keep the names of the current constants (e.g. MouseCursorHand) - and keep the original function of MouseCursor().
  • Color changes: Also, no. Without better knowledge on how imgui-go is widely used, it's difficult to say whether to stick to the original interface of the wrapped library, or completely abstract things away. So far my intent was to lean towards a thin wrapper, without additional intelligence. Also, fearing calculations to be done for every frame and color usage, I see it better to have a pre-calculated item.

Please have another pass at this, then we can be closer to a v4 release.

MouseCursor type is now MouseCursorID. CurrentMouseCursor() reverted to
MouseCursor()
inadvertently changed in previous commit
@JetSetIlly
Copy link
Copy Markdown
Contributor Author

We need to be cautious about how much to change in one go.

Agreed.

To rename the majority of constants from singular case to plural case seems like a lot to break

I think I only did this with BackendFlags* and ConfigFlags*. This matches the convention in the parent imgui project.

StyleVar and StyleColor - No, please back to *ID for the type name. Because they aren't a color (or variable), but identify them.

This then allows to answer for MouseCursor: Make the type MouseCursorID, keep the names of the current constants (e.g. MouseCursorHand) - and keep the original function of MouseCursor().

Agreed. Both reverted.

Color changes: Also, no.

Understood. On reflection, I agree with your policy of keeping the package as thin as possible.

@dertseha dertseha merged commit 4a537c8 into inkyblackness:master Feb 21, 2021
@dertseha
Copy link
Copy Markdown
Member

Perfect - thank you again for the contribution!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants