-
Notifications
You must be signed in to change notification settings - Fork 50
Added rotation behaviour. #9
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
base: main
Are you sure you want to change the base?
Conversation
Added two new flags ImGuiKnobFlags_RotateRelative and ImGuiKnobFlags_RotateAbsolute. With them you have to move around the knob in a circular way. Keyboard input is not currently implemented for these modes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for this PR, it's a good idea. I've left some comments. In general the code style needs to be in line with the other code, eg. brace placements, use kebab case, spacing around operators and control flow, etc.
|
||
angle_min = IMGUIKNOBS_PI * 0.75f; | ||
angle_max = IMGUIKNOBS_PI * 2.25f; | ||
center = {screen_pos[0] + radius, screen_pos[1] + radius}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this moved?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The center value is needed in RotateBehavior.
imgui-knobs.cpp
Outdated
{ | ||
ImVec2 dir(aMousePos.x-aPos.x,aMousePos.y-aPos.y); | ||
float angle=atan2(-dir.y,-dir.x); | ||
angle+=(3.141592f*2.5f); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use the Pi constant instead? Here and other places
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, sorry. I was using the previous version with IMGUIKNOBS_PI using double and forgot to fix it when I updated.
imgui-knobs.cpp
Outdated
//Re-maps a number from one range to another. | ||
//Numbers outside the range are not clamped to 0 and 1. | ||
template<typename T> | ||
inline T Map(const T& aValue,const T& aIStart,const T& aIStop,const T& aOStart,const T& aOStop) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Map
is only used inside MapC
, can you inline it there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I copied it from code I was using. As I did not know if you wanted to merge I did not modified it.
imgui-knobs.cpp
Outdated
|
||
// Re-Maps clamped | ||
template<typename T> | ||
inline T MapC(const T& aValue,const T& aIStart,const T& aIStop,const T& aOStart,const T& aOStop) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use kebab case, and maybe use a more descriptive name, like map_range_clamped
. Also don't add the a
for paramteres, just name them value
, in_start
, out_stop
, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I'll try to do this week end.
Thanks for taking the time to review the commit. Added a new commit. Let me know what you think about it. |
Also, modified code is written with my preferred style as it seems that upstream is not interested in merging.
Added two new flags:
With them you have to move around the knob in a circular way. Keyboard input is not currently implemented for these modes.
I attach a video of the relative mode.