Skip to content

Commit

Permalink
fix build issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Noy-Zini committed Oct 7, 2024
1 parent 37d72fe commit de34ecc
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 135 deletions.
4 changes: 3 additions & 1 deletion common/device-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ namespace rs2
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, sensor_bg);

label = rsutils::string::from() << "## " << id;
if (ImGui::Combo(label.c_str(), &playback_speed_index, "Speed: x0.25\0Speed: x0.5\0Speed: x1\0Speed: x1.5\0Speed: x2\0\0", -1, false))
if (ImGui::Combo(label.c_str(), &playback_speed_index, "Speed: x0.25\0Speed: x0.5\0Speed: x1\0Speed: x1.5\0Speed: x2\0\0", -1))
{
float speed = 1;
switch (playback_speed_index)
Expand Down Expand Up @@ -1952,6 +1952,7 @@ namespace rs2
ImGui_ScopePushStyleColor(ImGuiCol_ButtonActive, button_color + 0.1f);
ImVec2 padding{ 2,2 };
ImGui_ScopePushStyleVar(ImGuiStyleVar_FramePadding, padding);
ImGui::PushStyleColor(ImGuiCol_PopupBg, black);
///////////////////////////////////////////
// Go over the loaded files and add them to the combo box
std::vector<std::string> full_files_names(advanced_mode_settings_file_names.begin(), advanced_mode_settings_file_names.end());
Expand Down Expand Up @@ -2023,6 +2024,7 @@ namespace rs2
return is_clicked;
};
sub->options_metadata[RS2_OPTION_VISUAL_PRESET].custom_draw_method = draw_preset_combo_box;
ImGui::PopStyleColor(1);
if (sub->draw_option(RS2_OPTION_VISUAL_PRESET, dev.is<playback>() || update_read_only_options, error_message, *viewer.not_model))
{
get_curr_advanced_controls = true;
Expand Down
2 changes: 1 addition & 1 deletion common/model-views.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include <librealsense2/rs.hpp>

#include "realsense_imgui.h""
#include <realsense_imgui.h>
#include "model-views.h"
#include "subdevice-model.h"
#include "stream-model.h"
Expand Down
1 change: 1 addition & 0 deletions examples/align-gl/rs-align-gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <librealsense2/rs.hpp>
#include "example-imgui.hpp"
#include <librealsense2-gl/rs_processing_gl.hpp> // Include GPU-Processing API
#include <common/cli.h>
#include "imgui_impl_glfw.h"
#include <imgui_impl_opengl3.h>
#include<realsense_imgui.h>
Expand Down
130 changes: 0 additions & 130 deletions third-party/imgui/realsense_imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,133 +341,3 @@ void ImGui::RenderCollapseTriangle(ImVec2 p_min, bool is_open, float scale, bool
window->DrawList->AddTriangleFilled(ImVec2(2+a.x, 2+a.y), ImVec2(2+b.x, 2+b.y), ImVec2(2+c.x, 2+c.y), GetColorU32(ImGuiCol_BorderShadow));
window->DrawList->AddTriangleFilled(a, b, c, GetColorU32(ImGuiCol_Text));
}
// Combo box function.
bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(void*, int, const char**), void* data, int items_count, int height_in_items, bool show_arrow_down)
{
ImGuiWindow* window = GetCurrentWindow();
if (window->SkipItems)
return false;

ImGuiContext& g = *GImGui;
const ImGuiStyle& style = g.Style;
const ImGuiID id = window->GetID(label);
const float w = CalcItemWidth();

const ImVec2 label_size = CalcTextSize(label, NULL, true);
const ImRect frame_bb(window->DC.CursorPos, ImVec2(w+ window->DC.CursorPos.x, label_size.y + style.FramePadding.y * 2.0f+ window->DC.CursorPos.y));
const ImRect total_bb(frame_bb.Min,ImVec2(frame_bb.Max.x+label_size.x > frame_bb.Max.x + 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f+ frame_bb.Max.x, 0.0f+ frame_bb.Max.x));
ItemSize(total_bb, style.FramePadding.y);
if (!ItemAdd(total_bb, id))
return false;

const float arrow_size = show_arrow_down ? (g.FontSize + style.FramePadding.x * 2.0f) : 0;
const bool hovered = IsHovered(frame_bb, id);
bool popup_open = IsPopupOpen(id, ImGuiPopupFlags_AnyPopupLevel);
bool popup_opened_now = false;

const ImRect value_bb(frame_bb.Min, ImVec2(frame_bb.Max.x-arrow_size, frame_bb.Max.y-0.0f));
if (show_arrow_down)
{
RenderFrame(frame_bb.Min, frame_bb.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding);
RenderFrame(ImVec2(frame_bb.Max.x - arrow_size, frame_bb.Min.y), frame_bb.Max, GetColorU32(popup_open || hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button), true, style.FrameRounding); // FIXME-ROUNDING
RenderCollapseTriangle(ImVec2(frame_bb.Max.x - arrow_size+ style.FramePadding.x, frame_bb.Min.y+ style.FramePadding.y), true);
}
if (*current_item >= 0 && *current_item < items_count)
{
const char* item_text;
if (items_getter(data, *current_item, &item_text))
RenderTextClipped(ImVec2(frame_bb.Min.x + style.FramePadding.x, frame_bb.Min.y + style.FramePadding.y), value_bb.Max, item_text, NULL, NULL);
}

if (label_size.x > 0)
RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);

if (hovered)
{
SetHoveredID(id);
if (g.IO.MouseClicked[0])
{
SetActiveID(0,NULL);
if (IsPopupOpen(id, ImGuiPopupFlags_AnyPopupLevel))
{
ClosePopup(id);
}
else
{
FocusWindow(window);
OpenPopup(label);
popup_open = popup_opened_now = true;
}
}
}

bool value_changed = false;
if (IsPopupOpen(id, ImGuiPopupFlags_AnyPopupLevel))
{
// Size default to hold ~7 items
if (height_in_items < 0)
height_in_items = 7;

float popup_height = (label_size.y + style.ItemSpacing.y) * ImMin(items_count, height_in_items) + (style.FramePadding.y * 3);
float popup_y1 = frame_bb.Max.y;
float popup_y2 = ImClamp(popup_y1 + popup_height, popup_y1, g.IO.DisplaySize.y - style.DisplaySafeAreaPadding.y);
if ((popup_y2 - popup_y1) < ImMin(popup_height, frame_bb.Min.y - style.DisplaySafeAreaPadding.y))
{
// Position our combo ABOVE because there's more space to fit! (FIXME: Handle in Begin() or use a shared helper. We have similar code in Begin() for popup placement)
popup_y1 = ImClamp(frame_bb.Min.y - popup_height, style.DisplaySafeAreaPadding.y, frame_bb.Min.y);
popup_y2 = frame_bb.Min.y;
}
ImRect popup_rect(ImVec2(frame_bb.Min.x, popup_y1), ImVec2(frame_bb.Max.x, popup_y2));
SetNextWindowPos(popup_rect.Min);
SetNextWindowSize(popup_rect.GetSize());
PushStyleVar(ImGuiStyleVar_WindowPadding, style.FramePadding);

const ImGuiWindowFlags flags = ImGuiWindowFlags_NoCollapse;
if (BeginPopupEx((ImGuiID)label, flags))
{
// Display items
Spacing();
for (int i = 0; i < items_count; i++)
{
PushID((void*)(intptr_t)i);
const bool item_selected = (i == *current_item);
const char* item_text;
if (!items_getter(data, i, &item_text))
item_text = "*Unknown item*";
if (Selectable(item_text, item_selected))
{
ClearActiveID();
value_changed = true;
*current_item = i;
}
if (item_selected && popup_opened_now)
SetScrollHereY();
PopID();
}
EndPopup();
}
PopStyleVar();
}
return value_changed;
}

// Combo box helper allowing to pass an array of strings.
bool ImGui::Combo(const char* label, int* current_item, const char** items, int items_count, int height_in_items, bool show_arrow_down)
{
const bool value_changed = Combo(label, current_item, Items_ArrayGetter, (void*)items, items_count, height_in_items,false);
return value_changed;
}

// Combo box helper allowing to pass all items in a single string.
bool ImGui::Combo(const char* label, int* current_item, const char* items_separated_by_zeros, int height_in_items, bool show_arrow_down)
{
int items_count = 0;
const char* p = items_separated_by_zeros; // FIXME-OPT: Avoid computing this, or at least only when combo is open
while (*p)
{
p += strlen(p) + 1;
items_count++;
}
bool value_changed = Combo(label, current_item, Items_SingleStringGetter, (void*)items_separated_by_zeros, items_count, height_in_items, show_arrow_down);
return value_changed;
}
3 changes: 0 additions & 3 deletions third-party/imgui/realsense_imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ namespace ImGui
//IMGUI_API bool VSliderFloatadd(const char* label, const ImVec2& size, float* v, float v_min, float v_max, const char* display_format, float power, bool render_bg);
IMGUI_API bool SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_min, float v_max, float power, int decimal_precision, ImGuiSliderFlags flags, bool render_bg);
IMGUI_API float RoundScalar(float value, int decimal_precision);
IMGUI_API bool Combo(const char* label, int* current_item, const char** items, int items_count, int height_in_items = -1, bool show_arrow_down = true);
IMGUI_API bool Combo(const char* label, int* current_item, const char* items_separated_by_zeros, int height_in_items = -1, bool show_arrow_down = true); // separate items with \0, end item-list with \0\0
IMGUI_API bool Combo(const char* label, int* current_item, bool (*items_getter)(void* data, int idx, const char** out_text), void* data, int items_count, int height_in_items = -1, bool show_arrow_down = true);
}
#define CONCAT_(x,y) x##y
#define CONCAT(x,y) CONCAT_(x,y)
Expand Down

0 comments on commit de34ecc

Please sign in to comment.