mirror of
https://github.com/gwm17/implot.git
synced 2024-11-22 18:28:53 -05:00
add ImPlotAxisFlags_NoSideSwitch and ImPlotAxisFlags_NoHighlight
This commit is contained in:
parent
f33a5990d7
commit
7a470b2e17
|
@ -2640,7 +2640,7 @@ void SetupFinish() {
|
||||||
ImPlotAxis& ax = plot.XAxis(i);
|
ImPlotAxis& ax = plot.XAxis(i);
|
||||||
if (!ax.Enabled)
|
if (!ax.Enabled)
|
||||||
continue;
|
continue;
|
||||||
if ((ax.Hovered || ax.Held) && !plot.Held)
|
if ((ax.Hovered || ax.Held) && !plot.Held && !ImHasFlag(ax.Flags, ImPlotAxisFlags_NoHighlight))
|
||||||
DrawList.AddRectFilled(ax.HoverRect.Min, ax.HoverRect.Max, ax.Held ? ax.ColorAct : ax.ColorHov);
|
DrawList.AddRectFilled(ax.HoverRect.Min, ax.HoverRect.Max, ax.Held ? ax.ColorAct : ax.ColorHov);
|
||||||
else if (ax.ColorHiLi != IM_COL32_BLACK_TRANS) {
|
else if (ax.ColorHiLi != IM_COL32_BLACK_TRANS) {
|
||||||
DrawList.AddRectFilled(ax.HoverRect.Min, ax.HoverRect.Max, ax.ColorHiLi);
|
DrawList.AddRectFilled(ax.HoverRect.Min, ax.HoverRect.Max, ax.ColorHiLi);
|
||||||
|
@ -2679,7 +2679,7 @@ void SetupFinish() {
|
||||||
ImPlotAxis& ax = plot.YAxis(i);
|
ImPlotAxis& ax = plot.YAxis(i);
|
||||||
if (!ax.Enabled)
|
if (!ax.Enabled)
|
||||||
continue;
|
continue;
|
||||||
if ((ax.Hovered || ax.Held) && !plot.Held)
|
if ((ax.Hovered || ax.Held) && !plot.Held && !ImHasFlag(ax.Flags, ImPlotAxisFlags_NoHighlight))
|
||||||
DrawList.AddRectFilled(ax.HoverRect.Min, ax.HoverRect.Max, ax.Held ? ax.ColorAct : ax.ColorHov);
|
DrawList.AddRectFilled(ax.HoverRect.Min, ax.HoverRect.Max, ax.Held ? ax.ColorAct : ax.ColorHov);
|
||||||
else if (ax.ColorHiLi != IM_COL32_BLACK_TRANS) {
|
else if (ax.ColorHiLi != IM_COL32_BLACK_TRANS) {
|
||||||
DrawList.AddRectFilled(ax.HoverRect.Min, ax.HoverRect.Max, ax.ColorHiLi);
|
DrawList.AddRectFilled(ax.HoverRect.Min, ax.HoverRect.Max, ax.ColorHiLi);
|
||||||
|
@ -2939,6 +2939,8 @@ void EndPlot() {
|
||||||
trigger_rect.Expand(-10);
|
trigger_rect.Expand(-10);
|
||||||
for (int i = 0; i < IMPLOT_NUM_X_AXES; ++i) {
|
for (int i = 0; i < IMPLOT_NUM_X_AXES; ++i) {
|
||||||
ImPlotAxis& x_axis = plot.XAxis(i);
|
ImPlotAxis& x_axis = plot.XAxis(i);
|
||||||
|
if (ImHasFlag(x_axis.Flags, ImPlotAxisFlags_NoSideSwitch))
|
||||||
|
continue;
|
||||||
if (x_axis.Held && plot.PlotRect.Contains(mouse_pos)) {
|
if (x_axis.Held && plot.PlotRect.Contains(mouse_pos)) {
|
||||||
const bool opp = ImHasFlag(x_axis.Flags, ImPlotAxisFlags_Opposite);
|
const bool opp = ImHasFlag(x_axis.Flags, ImPlotAxisFlags_Opposite);
|
||||||
if (!opp) {
|
if (!opp) {
|
||||||
|
@ -2961,6 +2963,8 @@ void EndPlot() {
|
||||||
}
|
}
|
||||||
for (int i = 0; i < IMPLOT_NUM_Y_AXES; ++i) {
|
for (int i = 0; i < IMPLOT_NUM_Y_AXES; ++i) {
|
||||||
ImPlotAxis& y_axis = plot.YAxis(i);
|
ImPlotAxis& y_axis = plot.YAxis(i);
|
||||||
|
if (ImHasFlag(y_axis.Flags, ImPlotAxisFlags_NoSideSwitch))
|
||||||
|
continue;
|
||||||
if (y_axis.Held && plot.PlotRect.Contains(mouse_pos)) {
|
if (y_axis.Held && plot.PlotRect.Contains(mouse_pos)) {
|
||||||
const bool opp = ImHasFlag(y_axis.Flags, ImPlotAxisFlags_Opposite);
|
const bool opp = ImHasFlag(y_axis.Flags, ImPlotAxisFlags_Opposite);
|
||||||
if (!opp) {
|
if (!opp) {
|
||||||
|
|
22
implot.h
22
implot.h
|
@ -145,20 +145,22 @@ enum ImPlotFlags_ {
|
||||||
// Options for plot axes (see SetupAxis).
|
// Options for plot axes (see SetupAxis).
|
||||||
enum ImPlotAxisFlags_ {
|
enum ImPlotAxisFlags_ {
|
||||||
ImPlotAxisFlags_None = 0, // default
|
ImPlotAxisFlags_None = 0, // default
|
||||||
ImPlotAxisFlags_NoLabel = 1 << 0, // the axis label will not be displayed (axis labels also hidden if the supplied string name is NULL)
|
ImPlotAxisFlags_NoLabel = 1 << 0, // the axis label will not be displayed (axis labels are also hidden if the supplied string name is NULL)
|
||||||
ImPlotAxisFlags_NoGridLines = 1 << 1, // no grid lines will be displayed
|
ImPlotAxisFlags_NoGridLines = 1 << 1, // no grid lines will be displayed
|
||||||
ImPlotAxisFlags_NoTickMarks = 1 << 2, // no tick marks will be displayed
|
ImPlotAxisFlags_NoTickMarks = 1 << 2, // no tick marks will be displayed
|
||||||
ImPlotAxisFlags_NoTickLabels = 1 << 3, // no text labels will be displayed
|
ImPlotAxisFlags_NoTickLabels = 1 << 3, // no text labels will be displayed
|
||||||
ImPlotAxisFlags_NoInitialFit = 1 << 4, // axis will not be initially fit to data extents on the first rendered frame
|
ImPlotAxisFlags_NoInitialFit = 1 << 4, // axis will not be initially fit to data extents on the first rendered frame
|
||||||
ImPlotAxisFlags_NoMenus = 1 << 5, // the user will not be able to open context menus with right-click
|
ImPlotAxisFlags_NoMenus = 1 << 5, // the user will not be able to open context menus with right-click
|
||||||
ImPlotAxisFlags_Opposite = 1 << 6, // axis ticks and labels will be rendered on the conventionally opposite side (i.e, right or top)
|
ImPlotAxisFlags_NoSideSwitch = 1 << 6, // the user will not be able to switch the axis side by dragging it
|
||||||
ImPlotAxisFlags_Foreground = 1 << 7, // grid lines will be displayed in the foreground (i.e. on top of data) in stead of the background
|
ImPlotAxisFlags_NoHighlight = 1 << 7, // the axis will not have its background highlighted when hovered or held
|
||||||
ImPlotAxisFlags_Invert = 1 << 8, // the axis will be inverted
|
ImPlotAxisFlags_Opposite = 1 << 8, // axis ticks and labels will be rendered on the conventionally opposite side (i.e, right or top)
|
||||||
ImPlotAxisFlags_AutoFit = 1 << 9, // axis will be auto-fitting to data extents
|
ImPlotAxisFlags_Foreground = 1 << 9, // grid lines will be displayed in the foreground (i.e. on top of data) instead of the background
|
||||||
ImPlotAxisFlags_RangeFit = 1 << 10, // axis will only fit points if the point is in the visible range of the **orthogonal** axis
|
ImPlotAxisFlags_Invert = 1 << 10, // the axis will be inverted
|
||||||
ImPlotAxisFlags_PanStretch = 1 << 11, // panning in a locked or constrained state will cause the axis to stretch if possible
|
ImPlotAxisFlags_AutoFit = 1 << 11, // axis will be auto-fitting to data extents
|
||||||
ImPlotAxisFlags_LockMin = 1 << 12, // the axis minimum value will be locked when panning/zooming
|
ImPlotAxisFlags_RangeFit = 1 << 12, // axis will only fit points if the point is in the visible range of the **orthogonal** axis
|
||||||
ImPlotAxisFlags_LockMax = 1 << 13, // the axis maximum value will be locked when panning/zooming
|
ImPlotAxisFlags_PanStretch = 1 << 13, // panning in a locked or constrained state will cause the axis to stretch if possible
|
||||||
|
ImPlotAxisFlags_LockMin = 1 << 14, // the axis minimum value will be locked when panning/zooming
|
||||||
|
ImPlotAxisFlags_LockMax = 1 << 15, // the axis maximum value will be locked when panning/zooming
|
||||||
ImPlotAxisFlags_Lock = ImPlotAxisFlags_LockMin | ImPlotAxisFlags_LockMax,
|
ImPlotAxisFlags_Lock = ImPlotAxisFlags_LockMin | ImPlotAxisFlags_LockMax,
|
||||||
ImPlotAxisFlags_NoDecorations = ImPlotAxisFlags_NoLabel | ImPlotAxisFlags_NoGridLines | ImPlotAxisFlags_NoTickMarks | ImPlotAxisFlags_NoTickLabels,
|
ImPlotAxisFlags_NoDecorations = ImPlotAxisFlags_NoLabel | ImPlotAxisFlags_NoGridLines | ImPlotAxisFlags_NoTickMarks | ImPlotAxisFlags_NoTickLabels,
|
||||||
ImPlotAxisFlags_AuxDefault = ImPlotAxisFlags_NoGridLines | ImPlotAxisFlags_Opposite
|
ImPlotAxisFlags_AuxDefault = ImPlotAxisFlags_NoGridLines | ImPlotAxisFlags_Opposite
|
||||||
|
@ -923,7 +925,7 @@ IMPLOT_API bool DragLineX(int id, double* x, const ImVec4& col, float thickness
|
||||||
// Shows a draggable horizontal guide line at a y-value. #col defaults to ImGuiCol_Text.
|
// Shows a draggable horizontal guide line at a y-value. #col defaults to ImGuiCol_Text.
|
||||||
IMPLOT_API bool DragLineY(int id, double* y, const ImVec4& col, float thickness = 1, ImPlotDragToolFlags flags=0);
|
IMPLOT_API bool DragLineY(int id, double* y, const ImVec4& col, float thickness = 1, ImPlotDragToolFlags flags=0);
|
||||||
// Shows a draggable and resizeable rectangle.
|
// Shows a draggable and resizeable rectangle.
|
||||||
IMPLOT_API bool DragRect(int id, double* x_min, double* y_min, double* x_max, double* y_max, const ImVec4& col, ImPlotDragToolFlags flags=0);
|
IMPLOT_API bool DragRect(int id, double* x1, double* y1, double* x2, double* y2, const ImVec4& col, ImPlotDragToolFlags flags=0);
|
||||||
|
|
||||||
// Shows an annotation callout at a chosen point. Clamping keeps annotations in the plot area. Annotations are always rendered on top.
|
// Shows an annotation callout at a chosen point. Clamping keeps annotations in the plot area. Annotations are always rendered on top.
|
||||||
IMPLOT_API void Annotation(double x, double y, const ImVec4& col, const ImVec2& pix_offset, bool clamp, bool round = false);
|
IMPLOT_API void Annotation(double x, double y, const ImVec4& col, const ImVec2& pix_offset, bool clamp, bool round = false);
|
||||||
|
|
|
@ -1508,11 +1508,16 @@ void Demo_DragRects() {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
ImPlotPoint FindCentroid(const ImVector<ImPlotPoint>& data, ImPlotRect& bounds, int& cnt) {
|
ImPlotPoint FindCentroid(const ImVector<ImPlotPoint>& data, const ImPlotRect& bounds, int& cnt) {
|
||||||
cnt = 0;
|
cnt = 0;
|
||||||
ImPlotPoint avg;
|
ImPlotPoint avg;
|
||||||
|
ImPlotRect bounds_fixed;
|
||||||
|
bounds_fixed.X.Min = bounds.X.Min < bounds.X.Max ? bounds.X.Min : bounds.X.Max;
|
||||||
|
bounds_fixed.X.Max = bounds.X.Min < bounds.X.Max ? bounds.X.Max : bounds.X.Min;
|
||||||
|
bounds_fixed.Y.Min = bounds.Y.Min < bounds.Y.Max ? bounds.Y.Min : bounds.Y.Max;
|
||||||
|
bounds_fixed.Y.Max = bounds.Y.Min < bounds.Y.Max ? bounds.Y.Max : bounds.Y.Min;
|
||||||
for (int i = 0; i < data.size(); ++i) {
|
for (int i = 0; i < data.size(); ++i) {
|
||||||
if (bounds.Contains(data[i].x, data[i].y)) {
|
if (bounds_fixed.Contains(data[i].x, data[i].y)) {
|
||||||
avg.x += data[i].x;
|
avg.x += data[i].x;
|
||||||
avg.y += data[i].y;
|
avg.y += data[i].y;
|
||||||
cnt++;
|
cnt++;
|
||||||
|
@ -1702,7 +1707,7 @@ void Demo_DragAndDrop() {
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::BeginChild("DND_RIGHT",ImVec2(-1,400));
|
ImGui::BeginChild("DND_RIGHT",ImVec2(-1,400));
|
||||||
// plot 1 (time series)
|
// plot 1 (time series)
|
||||||
ImPlotAxisFlags flags = ImPlotAxisFlags_NoTickLabels | ImPlotAxisFlags_NoGridLines;
|
ImPlotAxisFlags flags = ImPlotAxisFlags_NoTickLabels | ImPlotAxisFlags_NoGridLines | ImPlotAxisFlags_NoHighlight;
|
||||||
if (ImPlot::BeginPlot("##DND1", ImVec2(-1,195))) {
|
if (ImPlot::BeginPlot("##DND1", ImVec2(-1,195))) {
|
||||||
ImPlot::SetupAxis(ImAxis_X1, NULL, flags|ImPlotAxisFlags_Lock);
|
ImPlot::SetupAxis(ImAxis_X1, NULL, flags|ImPlotAxisFlags_Lock);
|
||||||
ImPlot::SetupAxis(ImAxis_Y1, "[drop here]", flags);
|
ImPlot::SetupAxis(ImAxis_Y1, "[drop here]", flags);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user