Skip to content

Feat: Custom Input Map #134

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Feat: Custom Input Map #134

wants to merge 3 commits into from

Conversation

ACvanWyk
Copy link
Contributor

@ACvanWyk ACvanWyk commented Jul 8, 2025

Closes #97

Added Input Map support for #97 . @brenocq if you get a chance can you maybe take a look and let me know if I am going in the right direction.
This is not done yet and requires some more work:

  • Finish adding to the demo which shows support for different mappings
  • Keep support for ImGuiMouseButton_Middle button. Should still work like before where the ImGuiMouseButton_Middle does what it did previously so that it can be used to reset the plot
  • Figure out what the OverrideMod affects. In ImPlot it comes after the FitThisFrame and Hovered which is what I tried replicating
  • Add more missing control parameters if needed

Copy link
Contributor Author

@ACvanWyk ACvanWyk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am unsure of a couple of things. I tried adding most of the functionality after the Style blocks of code.
@brenocq if you could please just provide some feedback I would really appreciate it.

@@ -1974,7 +1977,8 @@ void HandleInput(ImPlot3DPlot& plot) {
}

// If the user is no longer pressing the translation/zoom buttons, set axes as not held
if (!ImGui::IsMouseDown(ImGuiMouseButton_Left) && !ImGui::IsMouseDown(ImGuiMouseButton_Middle)) {
if (!(ImPlot3D::ImHasFlag(IO.KeyMods, gp.InputMap.PanMod) && ImGui::IsMouseDown(gp.InputMap.Pan)) &&
!(ImPlot3D::ImHasFlag(IO.KeyMods, gp.InputMap.ZoomMod) && ImGui::IsMouseDown(ImGuiMouseButton_Middle))) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Should gp.InputMap.ZoomMod also be applied here and later on for the ImGui::IsMouseDown(ImGuiMouseButton_Middle) and ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Middle) checks?
  2. Should we add ImGuiMouseButton_Middle as a option for Zoom together with ZoomMod or should we just keep it as it since it is previous behaviour? Zoom might not make a lot of sense though since it does not use it for zoom ad is for fit(already have option for Fit though), maybe call it something else?

@@ -2014,7 +2018,8 @@ void HandleInput(ImPlot3DPlot& plot) {
ImPlot3DPoint mouse_pos_plot = PixelsToPlotPlane(mouse_pos, mouse_plane, false);

// Handle translation/zoom fit with double click
if (plot_clicked && (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left) || ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Middle))) {
if (plot_clicked && (ImGui::IsMouseDoubleClicked(gp.InputMap.Fit) ||
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add support for FitMod? This is not in ImPlot and I think it might be because it is only triggered on double click which does not happen very often.

@@ -2027,8 +2032,12 @@ void HandleInput(ImPlot3DPlot& plot) {
plot.Axes[i].FitThisFrame = true;
}

// cancel due to DND activity
if (GImGui->DragDropActive || ImPlot3D::ImHasFlag(IO.KeyMods, gp.InputMap.OverrideMod))
Copy link
Contributor Author

@ACvanWyk ACvanWyk Jul 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure where to put this? I put it here after the FitThisFrame has been set for the plot which means that the auto fit can be applied to the plot. ImPlot has similar behavior. Should the data be fitted to the plot if OverrideMod is valid?

map.ResetRotate = ImGuiMouseButton_Right;
map.Rotate = ImGuiMouseButton_Right;
map.RotateMod = ImGuiMod_None;
map.Menu = ImGuiMouseButton_Right;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add MenuMod and FitMod as well?
Add small overhead for some more control.

ImGuiMouseButton Pan; // LMB enables panning when held,
int PanMod; // none optional modifier that must be held for panning/fitting
ImGuiMouseButton Fit; // LMB initiates fit when double clicked
ImGuiMouseButton ResetRotate; // RMB initiates reset of the rotate when double clicked. When double clicked over the axis change to 2D view of the axis
Copy link
Contributor Author

@ACvanWyk ACvanWyk Jul 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure of the name ResetRotate here. Open to suggestions for a better name?

@@ -890,6 +941,7 @@ void ShowAllDemos() {
if (ImGui::BeginTabItem("Custom")) {
DemoHeader("Custom Styles", DemoCustomStyles);
DemoHeader("Custom Rendering", DemoCustomRendering);
DemoHeader("Show Input Mapping", ShowInputMapping);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure where to put this? I put it here for now and this will affect all the plots. Open to moving/changing this

@ACvanWyk ACvanWyk marked this pull request as ready for review July 8, 2025 19:43
@ACvanWyk ACvanWyk requested a review from brenocq as a code owner July 8, 2025 19:43
float delta = ImGui::IsMouseDown(ImGuiMouseButton_Middle) ? (-0.01f * IO.MouseDelta.y) : (-0.1f * IO.MouseWheel);
const bool middle_mouse_button_down = ImGui::IsMouseDown(ImGuiMouseButton_Middle);
if (middle_mouse_button_down || IO.MouseWheel != 0.0f) {
float delta = middle_mouse_button_down ? (-0.01f * IO.MouseDelta.y) : (-gp.InputMap.ZoomRate * IO.MouseWheel);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When middle_mouse_button_down is true should the delta be a function of the ZoomRate? Maybe (-gp.InputMap.ZoomRate * IO.MouseDelta.y / 10.0f) instead of (-0.01f * IO.MouseDelta.y)?
Can always create a new variable specifically just for zoom rate with button press(MouseDelta.y) which is separate from the ZoomRate(MouseWheel) ?

@ACvanWyk ACvanWyk marked this pull request as draft July 8, 2025 21:18
@brenocq brenocq added type:feat New feature or request prio:medium Medium priority status:review The task is under review labels Jul 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
prio:medium Medium priority status:review The task is under review type:feat New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Custom Input Map
2 participants