9#include <misc/cpp/imgui_stdlib.h>
27static const char* getVectorValue(
void* vec,
int idx )
29 auto& vector = *
static_cast<std::vector<std::string>*
>( vec );
30 if ( idx < 0 || idx >=
static_cast< int >( vector.size() ) )
32 assert(
false &&
"Combo: getVectorValue invalid index" );
35 return vector.at( idx ).c_str();
38[[deprecated]]
static auto vector_getter = [] (
void* vec,
int idx ) ->
const char*
40 return getVectorValue( vec, idx );
43inline bool Combo(
const char* label,
int* idx,
const std::vector<std::string>& values )
47 return Combo( label, idx, getVectorValue,
const_cast<void*
>(
static_cast<const void*
>( &values ) ), (
int) values.size() );
50inline bool Combo(
const char* label,
int* idx, std::function<
const char*(
int )> getter,
int itemsCount )
52 auto func = [] (
void* data,
int i ) ->
const char*
54 auto& getter = *
reinterpret_cast< std::function<
const char*(
int )
> * >( data );
55 const char* s = getter( i );
60 assert(
false &&
"Combo: getter return nullptr" );
64 return Combo( label, idx, func,
reinterpret_cast< void*
>( &getter ), itemsCount );
67inline bool ListBox(
const char* label,
int* idx,
const std::vector<std::string>& values )
71 return ListBox( label, idx, getVectorValue,
const_cast<void*
>(
static_cast<const void*
>( &values ) ), (
int) values.size() );
74inline bool InputText(
const char* label, std::string &str, ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = NULL,
void* user_data = NULL)
76 return InputText( label, &str, flags, callback, user_data );
83MRVIEWER_API
bool DragFloatValid(
const char *label,
float* value,
float speed=1.0f,
84 float min = std::numeric_limits<float>::lowest(),
85 float max = std::numeric_limits<float>::max(),
86 const char* format =
"%.3f", ImGuiSliderFlags flags = 0 );
103 float min = std::numeric_limits<float>::lowest(),
104 float max = std::numeric_limits<float>::max(),
105 const char* format =
"%.3f", ImGuiSliderFlags flags = 0,
106 const char* ( *tooltips )[2] =
nullptr );
113 float min = std::numeric_limits<float>::lowest(),
114 float max = std::numeric_limits<float>::max(),
115 const char* format =
"%.3f", ImGuiSliderFlags flags = 0,
116 const char* (*tooltips)[3] =
nullptr );
121MRVIEWER_API
bool DragIntValid(
const char *label,
int* value,
float speed = 1,
122 int min = std::numeric_limits<int>::lowest(),
123 int max = std::numeric_limits<int>::max(),
124 const char* format =
"%d" );
131 int min = std::numeric_limits<int>::lowest(),
132 int max = std::numeric_limits<int>::max(),
133 const char* format =
"%d",
134 const char* ( *tooltips )[3] =
nullptr );
139MRVIEWER_API
bool InputIntValid(
const char* label,
int* value,
int min,
int max,
140 int step = 1,
int step_fast = 100, ImGuiInputTextFlags flags = 0 );
143template<
typename GetValueFunc,
typename SetValueFunc>
144inline bool Checkbox(
const char* label, GetValueFunc getValue, SetValueFunc setValue)
146 bool value = getValue();
167 std::function<
float(
int idx )> values_getter,
168 std::function<
void(
int idx )> tooltip,
169 std::function<
void(
int idx )> on_click,
170 int values_count,
int values_offset = 0,
171 float scale_min = FLT_MAX,
float scale_max = FLT_MAX,
172 ImVec2 frame_size = ImVec2( 0, 0 ),
int selectedBarId = -1,
int hoveredBarId = -1,
173 const std::vector<HistogramGridLine>& gridIndexes = {},
174 const std::vector<HistogramGridLine>& gridValues = {} );
199 ImGuiWindowFlags
flags = ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize;
224MRVIEWER_API std::pair<ImVec2, bool>
LoadSavedWindowPos(
const char* label, ImGuiWindow* window,
float width,
const ImVec2* position =
nullptr );
225MRVIEWER_API std::pair<ImVec2, bool>
LoadSavedWindowPos(
const char* label,
float width,
const ImVec2* position =
nullptr );
260MRVIEWER_API
bool InputIntBitSet(
const char* label,
int* v,
const MR::BitSet& bs,
int step = 1,
int step_fast = 100, ImGuiInputTextFlags flags = 0 );
267MRVIEWER_API
bool DragInputInt(
const char* label,
int* value,
float speed = 1,
int min = std::numeric_limits<int>::lowest(),
268 int max = std::numeric_limits<int>::max(),
const char* format =
"%d", ImGuiSliderFlags flags = ImGuiSliderFlags_None );
274MRVIEWER_API
bool Link(
const char* label, uint32_t color =
MR::Color( 60, 120, 255 ).getUInt32() );
297 std::
string& presetName,
299 bool* fixZero =
nullptr,
301 float min = std::numeric_limits<
float>::lowest(),
302 float max = std::numeric_limits<
float>::max()
326MRVIEWER_API
void Image(
const MR::ImGuiImage& image,
const ImVec2& size,
const ImVec4& multColor = { 1, 1, 1, 1 } );
342inline float getExpSpeed(
float val,
float frac = 0.01f,
float min = 1e-5f )
343 {
return std::max( val * frac, min ); }
348 return 0.2126f * col.x + 0.7152f * col.y + 0.0722f * col.z;
354#ifdef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
357MRVIEWER_API ImVec2 GetWindowContentRegionMax();
361inline ImVec2 GetContentRegionMax()
363 return GetContentRegionAvail() + GetCursorScreenPos() - GetWindowPos();
#define MR_MAKE_FLAG_OPERATORS(T)
Generates operators for a enum (at namespace scope).
Definition MRFlagOperators.h:6
Definition MRImGuiImage.h:18
Definition ImGuiHelpers.h:25
bool BeginSavedWindowPos(const std::string &name, bool *open, const SavedWindowPosParams ¶ms)
bool Link(const char *label, uint32_t color=MR::Color(60, 120, 255).getUInt32())
Draw text as link, calls callback on click.
bool BeginStatePlugin(const char *label, bool *open, float width)
begin typical state plugin window
float getExpSpeed(float val, float frac=0.01f, float min=1e-5f)
get exponential speed for this value
Definition ImGuiHelpers.h:342
PlaneWidgetFlags
Parameters for the Plane( MR::PlaneWidget& ... ) function.
Definition ImGuiHelpers.h:307
@ DisableVisibility
Default setup.
Definition ImGuiHelpers.h:309
PaletteChanges
Definition ImGuiHelpers.h:279
@ Reset
Definition ImGuiHelpers.h:281
@ None
Definition ImGuiHelpers.h:280
@ Ranges
texture and legend must be updated
Definition ImGuiHelpers.h:283
@ Texture
reset palette
Definition ImGuiHelpers.h:282
@ All
uv-coordinates must be recomputed for the same values
Definition ImGuiHelpers.h:284
bool DragFloatValid(const char *label, float *value, float speed=1.0f, float min=std::numeric_limits< float >::lowest(), float max=std::numeric_limits< float >::max(), const char *format="%.3f", ImGuiSliderFlags flags=0)
bool ListBox(const char *label, int *idx, const std::vector< std::string > &values)
Definition ImGuiHelpers.h:67
bool InputText(const char *label, std::string &str, ImGuiInputTextFlags flags=0, ImGuiInputTextCallback callback=NULL, void *user_data=NULL)
Definition ImGuiHelpers.h:74
ImVec2 GetDownPosition(const float width)
bool ModalExitButton()
draw exit button with close cross (i.e. for settings modal popup )
bool InputIntBitSet(const char *label, int *v, const MR::BitSet &bs, int step=1, int step_fast=100, ImGuiInputTextFlags flags=0)
same as ImGui::InputInt
MR::Vector2i GetImagePointerCoord(const MR::ImGuiImage &image, const ImVec2 &size, const ImVec2 &imagePos)
get image coordinates under cursor considering Y-direction flipping
float GetTitleBarHeght()
Calculate and return the height of the window title.
void Plane(MR::PlaneWidget &planeWidget, PlaneWidgetFlags flags={})
bool ModalBigTitle(const char *title)
draw big title with close cross (i.e. for settings modal popup )
bool isMultiViewportEnabled()
return true if ImGui Multi Viewport enabled
void PlotCustomHistogram(const char *str_id, std::function< float(int idx)> values_getter, std::function< void(int idx)> tooltip, std::function< void(int idx)> on_click, int values_count, int values_offset=0, float scale_min=FLT_MAX, float scale_max=FLT_MAX, ImVec2 frame_size=ImVec2(0, 0), int selectedBarId=-1, int hoveredBarId=-1, const std::vector< HistogramGridLine > &gridIndexes={}, const std::vector< HistogramGridLine > &gridValues={})
MultiDragRes DragFloatValid2(const char *label, float v[2], float v_speed=1.0f, float min=std::numeric_limits< float >::lowest(), float max=std::numeric_limits< float >::max(), const char *format="%.3f", ImGuiSliderFlags flags=0, const char *(*tooltips)[2]=nullptr)
bool Direction(MR::DirectionWidget &dirWidget, bool &editDragging, const std::string &historyName)
std::pair< ImVec2, bool > LoadSavedWindowPos(const char *label, ImGuiWindow *window, float width, const ImVec2 *position=nullptr)
bool InputIntValid(const char *label, int *value, int min, int max, int step=1, int step_fast=100, ImGuiInputTextFlags flags=0)
bool BeginCustomStatePlugin(const char *label, bool *open, const CustomStatePluginWindowParameters ¶ms={})
void EndCustomStatePlugin()
end state plugin window with custom style
MultiDragRes DragFloatValid3(const char *label, float v[3], float v_speed=1.0f, float min=std::numeric_limits< float >::lowest(), float max=std::numeric_limits< float >::max(), const char *format="%.3f", ImGuiSliderFlags flags=0, const char *(*tooltips)[3]=nullptr)
bool DragIntValid(const char *label, int *value, float speed=1, int min=std::numeric_limits< int >::lowest(), int max=std::numeric_limits< int >::max(), const char *format="%d")
bool DragInputInt(const char *label, int *value, float speed=1, int min=std::numeric_limits< int >::lowest(), int max=std::numeric_limits< int >::max(), const char *format="%d", ImGuiSliderFlags flags=ImGuiSliderFlags_None)
Combine of ImGui::DragInt and ImGui::InputInt.
PaletteChanges Palette(const char *label, MR::Palette &palette, std::string &presetName, float width, bool *fixZero=nullptr, float speed=1.0f, float min=std::numeric_limits< float >::lowest(), float max=std::numeric_limits< float >::max())
bool BeginModalNoAnimation(const char *label, bool *open=nullptr, ImGuiWindowFlags flags=0)
starts modal window with no animation for background
bool Combo(const char *label, int *idx, const std::vector< std::string > &values)
Definition ImGuiHelpers.h:43
float getLuminance(const ImVec4 &col)
A crude conversion to grayscale. Good enough for our purposes.
Definition ImGuiHelpers.h:346
bool DragFloatValidLineWidth(const char *label, float *value)
similar to ImGui::DragFloatValid but use available line width range
void SaveWindowPosition(const char *label, ImGuiWindow *window)
void Image(const MR::ImGuiImage &image, const ImVec2 &size, const MR::Color &multColor)
draw image with Y-direction inversed up-down
bool Checkbox(const char *label, GetValueFunc getValue, SetValueFunc setValue)
draw check-box that takes initial value from Getter and then saves the final value in Setter
Definition ImGuiHelpers.h:144
MultiDragRes DragIntValid3(const char *label, int v[3], float speed=1, int min=std::numeric_limits< int >::lowest(), int max=std::numeric_limits< int >::max(), const char *format="%d", const char *(*tooltips)[3]=nullptr)
void Spinner(float radius)
draw spinner in given place, radius with respect to scaling
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Structure that contains parameters for State plugin window with custom style.
Definition ImGuiHelpers.h:181
std::function< void()> helpBtnFn
reaction on press "Help" button
Definition ImGuiHelpers.h:205
float width
window width (should be already scaled with UI::scale())
Definition ImGuiHelpers.h:189
float height
window height, usually calculated internally (if value is zero)
Definition ImGuiHelpers.h:191
std::function< void()> customHeaderFn
draw custom header items immediately after the caption
Definition ImGuiHelpers.h:203
ImGuiWindowFlags flags
window flags, ImGuiWindowFlags_NoScrollbar and ImGuiWindow_NoScrollingWithMouse are forced inside Beg...
Definition ImGuiHelpers.h:199
bool allowScrollbar
If false, will never show the scrollbar.
Definition ImGuiHelpers.h:193
ImVec2 * position
start Position
Definition ImGuiHelpers.h:195
bool closeWithEscape
if true esc button closes the plugin
Definition ImGuiHelpers.h:207
ImVec2 * changedSize
outside owned parameter for windows with resize option
Definition ImGuiHelpers.h:201
ImVec2 pivot
the position of the starting point of the window
Definition ImGuiHelpers.h:197
bool * collapsed
Definition ImGuiHelpers.h:187
helper structure for PlotCustomHistogram describing background grid line and label
Definition ImGuiHelpers.h:154
std::string tooltip
label tooltip
Definition ImGuiHelpers.h:160
std::string label
label text
Definition ImGuiHelpers.h:158
float value
value on the corresponding axis where the line and label are located
Definition ImGuiHelpers.h:156
Definition ImGuiHelpers.h:92
bool itemDeactivatedAfterEdit
any of N
Definition ImGuiHelpers.h:94
bool valueChanged
Definition ImGuiHelpers.h:93
Parameters drawing classic ImGui::Begin with loading / saving window position.
Definition ImGuiHelpers.h:235
const ImVec2 * pos
(optional) preliminary window position
Definition ImGuiHelpers.h:239
ImVec2 size
window size
Definition ImGuiHelpers.h:237
ImGuiWindowFlags flags
Definition ImGuiHelpers.h:240