Skip to content

Slider 2D & Slider 3D #3484

Open
Open

Description

@soufianekhiat

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

Activity

  1. ocornut commented on Sep 27, 2020

    @ocornut
    Owner

    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.

  2. zhihaoy commented on Oct 28, 2020

    @zhihaoy

    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.
  3. soufianekhiat commented on Mar 16, 2021

    @soufianekhiat
    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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址