Skip to content
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

Slider 2D & Slider 3D #3484

Open
soufianekhiat opened this issue Sep 21, 2020 · 3 comments
Open

Slider 2D & Slider 3D #3484

soufianekhiat opened this issue Sep 21, 2020 · 3 comments

Comments

@soufianekhiat
Copy link

Hello,

Here an example of an implementation of a slider 2D & slider 3D.
Usage:

bool SliderScalar2D(char const* pLabel, float* pValueX, float* pValueY, float const fMinX, float const fMaxX, float const fMinY, float const fMaxY, float const fScale = 1.0f);
bool SliderScalar3D(char const* pLabel, float* pValueX, float* pValueY, float* pValueZ, float const fMinX, float const fMaxX, float const fMinY, float const fMaxY, float const fMinZ, float const fMaxZ, float const fScale = 1.0f);

bool InputVec2(const char* label, ImVec2* value, ImVec2 const vMinValue, ImVec2 const vMaxValue, float const fScale = 1.0f);
bool InputVec3(const char* label, ImVec4* value, ImVec4 const vMinValue, ImVec4 const vMaxValue, float const fScale = 1.0f);

Core available here.

Results:
iK8hn7V87Z

Possible improvement:

  • Move graphical choose to style (thickness, color, ...)
  • Make the visibility of "Values" optionnal
@ocornut
Copy link
Owner

ocornut commented Sep 27, 2020

Nice work!

As a suggestion, you should use InvisibleButton() (or lower-level ButtonBehavior() to process inputs).
Using IsMouseHoveringRect() is incorrect and won't handle window overlaps, inputs inhibition by popups, drag and drop and other features.

@zhihaoy
Copy link

zhihaoy commented Oct 28, 2020

I cloned this widget in Python with pyimgui. Here are some words:

  1. We need the slider to work on integers as well. That's actually what my implementation is doing.
  2. Invisible buttons (one for clicking and dragging on the board, two for the X, Y handles) work very well. However, to detect dragging for a specific widget, I have to save a global state (id of widget being pressed (imgui.is_item_hovered() and imgui.is_mouse_down()) and not released since then (imgui.is_mouse_released())) somewhere. In C++ we should be able to manage the state with ImGui::GetStateStorage().
  3. There should be an option to choose in which directory Y value grows. My version places (0, 0) on top-left corner and the Y value grows top->bottom.
  4. The label of the widget shouldn't be mandatory. The "Values" display shouldn't be mandatory. With the values returned, users can easily choose from drag_int, input_int2, etc.
  5. The x position of X handle and y position of Y handle should never change. When dragging int, I compute the maximum digits of min_value_y and max_value_y, use that to set Y handle.
  6. Although my version is also a strict square, an option to let the slider match the ration of delta X and delta Y may be interesting.

@soufianekhiat
Copy link
Author

@zhihaoy:
Thanks for the feedback.
I released a new version with various other Widgets, check out here for an updated version here:
https://github.com/soufianekhiat/DearWidgets

  1. We need the slider to work on integers as well. That's actually what my implementation is doing.
  • Fixed [For any type we have a Scalar Version]
  1. Invisible buttons (one for clicking and dragging on the board, two for the X, Y handles) work very well. However, to detect dragging for a specific widget, I have to save a global state (id of widget being pressed (imgui.is_item_hovered() and imgui.is_mouse_down()) and not released since then (imgui.is_mouse_released())) somewhere. In C++ we should be able to manage the state with ImGui::GetStateStorage().
  • Now it's implemented with ImGui::ButtonBehavior(frame_bb, ImGui::GetID("##Zone"), &hovered, &held);
  • Can be extended to store state (IsPressed) etc, not done yet.
  1. There should be an option to choose in which directory Y value grows. My version places (0, 0) on top-left corner and the Y value grows top->bottom.
  • For me it's as design, it is just a decision to fit with regular plot XY {X left to right, Y bottom to up}.
  1. The label of the widget shouldn't be mandatory. The "Values" display shouldn't be mandatory. With the values returned, users can easily choose from drag_int, input_int2, etc.
  • Not sure I understand, but I plan to extend with Style to handle some of those use cases.
  1. The x position of X handle and y position of Y handle should never change. When dragging int, I compute the maximum digits of min_value_y and max_value_y, use that to set Y handle.
  • Good point, I'll do similar thing.
  1. Although my version is also a strict square, an option to let the slider match the ration of delta X and delta Y may be interesting.
  • For now I think I'll keep it like that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants