Skip to content

Commit

Permalink
fix: auto fit giggle
Browse files Browse the repository at this point in the history
  • Loading branch information
brenocq committed Jan 14, 2025
1 parent 3e5f062 commit 01a71cd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
18 changes: 12 additions & 6 deletions implot3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1861,8 +1861,10 @@ void HandleInput(ImPlot3DPlot& plot) {
// Adjust plot range to translate the plot
for (int i = 0; i < 3; i++) {
if (plot.Axes[i].Hovered) {
plot.Axes[i].SetMin(plot.Axes[i].Range.Min - delta_plot[i]);
plot.Axes[i].SetMax(plot.Axes[i].Range.Max - delta_plot[i]);
if (!plot.Axes[i].IsInputLocked()) {
plot.Axes[i].SetMin(plot.Axes[i].Range.Min - delta_plot[i]);
plot.Axes[i].SetMax(plot.Axes[i].Range.Max - delta_plot[i]);
}
plot.Axes[i].Held = true;
}
// If no axis was held before (user started translating in this frame), set the held edge/plane indices
Expand All @@ -1883,8 +1885,10 @@ void HandleInput(ImPlot3DPlot& plot) {
// Apply translation to the selected axes
for (int i = 0; i < 3; i++) {
if (plot.Axes[i].Hovered) {
plot.Axes[i].SetMin(plot.Axes[i].Range.Min - delta_plot[i]);
plot.Axes[i].SetMax(plot.Axes[i].Range.Max - delta_plot[i]);
if (!plot.Axes[i].IsInputLocked()) {
plot.Axes[i].SetMin(plot.Axes[i].Range.Min - delta_plot[i]);
plot.Axes[i].SetMax(plot.Axes[i].Range.Max - delta_plot[i]);
}
plot.Axes[i].Held = true;
}
if (!any_axis_held) {
Expand Down Expand Up @@ -2012,8 +2016,10 @@ void HandleInput(ImPlot3DPlot& plot) {

// Set new range after zoom
if (plot.Axes[i].Hovered) {
plot.Axes[i].SetMin(new_min);
plot.Axes[i].SetMax(new_max);
if (!plot.Axes[i].IsInputLocked()) {
plot.Axes[i].SetMin(new_min);
plot.Axes[i].SetMax(new_max);
}
plot.Axes[i].Held = true;
}

Expand Down
3 changes: 3 additions & 0 deletions implot3d_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,9 @@ struct ImPlot3DAxis {
inline bool IsLockedMin() const { return IsRangeLocked() || ImPlot3D::ImHasFlag(Flags, ImPlot3DAxisFlags_LockMin); }
inline bool IsLockedMax() const { return IsRangeLocked() || ImPlot3D::ImHasFlag(Flags, ImPlot3DAxisFlags_LockMax); }
inline bool IsLocked() const { return IsLockedMin() && IsLockedMax(); }
inline bool IsInputLockedMin() const { return IsLockedMin() || IsAutoFitting(); }
inline bool IsInputLockedMax() const { return IsLockedMax() || IsAutoFitting(); }
inline bool IsInputLocked() const { return IsLocked() || IsAutoFitting(); }

inline void SetLabel(const char* label) {
Label.Buf.shrink(0);
Expand Down

0 comments on commit 01a71cd

Please sign in to comment.