Skip to content

Commit 396af68

Browse files
committed
fix: context menu flags/location being ignored
1 parent 9c4f735 commit 396af68

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

implot3d.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,11 +1253,13 @@ bool BeginPlot(const char* title_id, const ImVec2& size, ImPlot3DFlags flags) {
12531253
plot.ID = ID;
12541254
plot.JustCreated = just_created;
12551255
if (just_created) {
1256-
plot.Flags = flags;
12571256
plot.Rotation = init_rotation;
12581257
for (int i = 0; i < 3; i++)
12591258
plot.Axes[i] = ImPlot3DAxis();
12601259
}
1260+
if (plot.PreviousFlags != flags)
1261+
plot.Flags = flags;
1262+
plot.PreviousFlags = flags;
12611263
plot.SetupLocked = false;
12621264
plot.OpenContextThisFrame = false;
12631265

@@ -1382,7 +1384,9 @@ void SetupAxis(ImAxis3D idx, const char* label, ImPlot3DAxisFlags flags) {
13821384
// Get plot and axis
13831385
ImPlot3DPlot& plot = *gp.CurrentPlot;
13841386
ImPlot3DAxis& axis = plot.Axes[idx];
1385-
axis.Flags = flags;
1387+
if (axis.PreviousFlags != flags)
1388+
axis.Flags = flags;
1389+
axis.PreviousFlags = flags;
13861390
axis.SetLabel(label);
13871391
}
13881392

@@ -1420,8 +1424,12 @@ void SetupLegend(ImPlot3DLocation location, ImPlot3DLegendFlags flags) {
14201424
IM_ASSERT_USER_ERROR(gp.CurrentItems != nullptr,
14211425
"SetupLegend() needs to be called within an itemized context!");
14221426
ImPlot3DLegend& legend = gp.CurrentItems->Legend;
1423-
legend.Location = location;
1424-
legend.Flags = flags;
1427+
if (legend.PreviousLocation != location)
1428+
legend.Location = location;
1429+
legend.PreviousLocation = location;
1430+
if (legend.PreviousFlags != flags)
1431+
legend.Flags = flags;
1432+
legend.PreviousFlags = flags;
14251433
}
14261434

14271435
//-----------------------------------------------------------------------------

implot3d_internal.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,17 +303,19 @@ struct ImPlot3DItem {
303303
// Holds legend state
304304
struct ImPlot3DLegend {
305305
ImPlot3DLegendFlags Flags;
306+
ImPlot3DLegendFlags PreviousFlags;
306307
ImPlot3DLocation Location;
308+
ImPlot3DLocation PreviousLocation;
307309
ImVector<int> Indices;
308310
ImGuiTextBuffer Labels;
309311
ImRect Rect;
310312
bool Hovered;
311313
bool Held;
312314

313315
ImPlot3DLegend() {
314-
Flags = ImPlot3DLegendFlags_None;
316+
PreviousFlags = Flags = ImPlot3DLegendFlags_None;
315317
Hovered = Held = false;
316-
Location = ImPlot3DLocation_NorthWest;
318+
PreviousLocation = Location = ImPlot3DLocation_NorthWest;
317319
}
318320

319321
void Reset() {
@@ -424,6 +426,7 @@ struct ImPlot3DTicker {
424426
// Holds axis information
425427
struct ImPlot3DAxis {
426428
ImPlot3DAxisFlags Flags;
429+
ImPlot3DAxisFlags PreviousFlags;
427430
ImPlot3DRange Range;
428431
ImPlot3DCond RangeCond;
429432
ImGuiTextBuffer Label;
@@ -440,7 +443,7 @@ struct ImPlot3DAxis {
440443

441444
// Constructor
442445
ImPlot3DAxis() {
443-
Flags = ImPlot3DAxisFlags_None;
446+
PreviousFlags = Flags = ImPlot3DAxisFlags_None;
444447
// Range
445448
Range.Min = 0.0f;
446449
Range.Max = 1.0f;
@@ -510,6 +513,7 @@ struct ImPlot3DAxis {
510513
struct ImPlot3DPlot {
511514
ImGuiID ID;
512515
ImPlot3DFlags Flags;
516+
ImPlot3DFlags PreviousFlags;
513517
ImGuiTextBuffer Title;
514518
bool JustCreated;
515519
// Bounding rectangles
@@ -540,7 +544,7 @@ struct ImPlot3DPlot {
540544
bool OpenContextThisFrame;
541545

542546
ImPlot3DPlot() {
543-
Flags = ImPlot3DFlags_None;
547+
PreviousFlags = Flags = ImPlot3DFlags_None;
544548
JustCreated = true;
545549
Rotation = ImPlot3DQuat(0.0f, 0.0f, 0.0f, 1.0f);
546550
for (int i = 0; i < 3; i++)

0 commit comments

Comments
 (0)