Skip to content

Commit

Permalink
ImageDisplayResizable: can accept null size ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed May 12, 2024
1 parent acc20a8 commit 63b0b93
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/immvision/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,12 +306,12 @@ namespace ImmVision
);

// ImageDisplayResizable: display the image, with no user interaction (by default)
// The image can be resized by the user (and the new size will be stored in the size parameter)
// The image can be resized by the user (and the new size will be stored in the size parameter, if provided)
// The label will not be displayed (but it will be used as an id, and must be unique)
IMMVISION_API cv::Point2d ImageDisplayResizable(
const std::string& label_id,
const cv::Mat& mat,
ImVec2* size,
ImVec2* size = nullptr,
bool refreshImage = false,
bool resizable = true,
bool showOptionsButton = false,
Expand Down
12 changes: 11 additions & 1 deletion src/immvision/internal/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,9 @@ namespace ImmVision
return params.MouseInfo.MousePosition;
}


static std::map<ImGuiID, ImVec2> s_ImageDisplayResizable_Sizes;

IMMVISION_API cv::Point2d ImageDisplayResizable(
const std::string& label_id,
const cv::Mat& mat,
Expand All @@ -687,7 +690,14 @@ namespace ImmVision
bool isBgrOrBgra
)
{
IM_ASSERT(size != nullptr && "ImageDisplayResizable: size must not be null");
if (size == nullptr)
{
ImGuiID id = ImGui::GetID(label_id.c_str());
if (s_ImageDisplayResizable_Sizes.find(id) == s_ImageDisplayResizable_Sizes.end())
s_ImageDisplayResizable_Sizes[id] = ImVec2(0, 0);
size = &s_ImageDisplayResizable_Sizes[id];
}

ImGuiID id = ImGui::GetID(label_id.c_str());
static std::map<ImGuiID, ImageParams> s_Params;
if (s_Params.find(id) == s_Params.end())
Expand Down
16 changes: 13 additions & 3 deletions src_all_in_one/immvision/immvision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,12 @@ namespace ImmVision
);

// ImageDisplayResizable: display the image, with no user interaction (by default)
// The image can be resized by the user (and the new size will be stored in the size parameter)
// The image can be resized by the user (and the new size will be stored in the size parameter, if provided)
// The label will not be displayed (but it will be used as an id, and must be unique)
IMMVISION_API cv::Point2d ImageDisplayResizable(
const std::string& label_id,
const cv::Mat& mat,
ImVec2* size,
ImVec2* size = nullptr,
bool refreshImage = false,
bool resizable = true,
bool showOptionsButton = false,
Expand Down Expand Up @@ -10132,6 +10132,9 @@ namespace ImmVision
return params.MouseInfo.MousePosition;
}


static std::map<ImGuiID, ImVec2> s_ImageDisplayResizable_Sizes;

IMMVISION_API cv::Point2d ImageDisplayResizable(
const std::string& label_id,
const cv::Mat& mat,
Expand All @@ -10142,7 +10145,14 @@ namespace ImmVision
bool isBgrOrBgra
)
{
IM_ASSERT(size != nullptr && "ImageDisplayResizable: size must not be null");
if (size == nullptr)
{
ImGuiID id = ImGui::GetID(label_id.c_str());
if (s_ImageDisplayResizable_Sizes.find(id) == s_ImageDisplayResizable_Sizes.end())
s_ImageDisplayResizable_Sizes[id] = ImVec2(0, 0);
size = &s_ImageDisplayResizable_Sizes[id];
}

ImGuiID id = ImGui::GetID(label_id.c_str());
static std::map<ImGuiID, ImageParams> s_Params;
if (s_Params.find(id) == s_Params.end())
Expand Down
4 changes: 2 additions & 2 deletions src_all_in_one/immvision/immvision.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,12 @@ namespace ImmVision
);

// ImageDisplayResizable: display the image, with no user interaction (by default)
// The image can be resized by the user (and the new size will be stored in the size parameter)
// The image can be resized by the user (and the new size will be stored in the size parameter, if provided)
// The label will not be displayed (but it will be used as an id, and must be unique)
IMMVISION_API cv::Point2d ImageDisplayResizable(
const std::string& label_id,
const cv::Mat& mat,
ImVec2* size,
ImVec2* size = nullptr,
bool refreshImage = false,
bool resizable = true,
bool showOptionsButton = false,
Expand Down

0 comments on commit 63b0b93

Please sign in to comment.