Skip to content

Commit

Permalink
fixed popup on panel
Browse files Browse the repository at this point in the history
  • Loading branch information
ypujante committed Jan 20, 2023
1 parent dacd8c5 commit fdd2aa0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 21 deletions.
24 changes: 5 additions & 19 deletions src/cpp/re/edit/Panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,31 +88,15 @@ std::shared_ptr<Widget> Panel::getWidget(int id) const
//------------------------------------------------------------------------
// Panel::draw
//------------------------------------------------------------------------
void Panel::draw(AppContext &iCtx, ReGui::Canvas &iCanvas)
void Panel::draw(AppContext &iCtx, ReGui::Canvas &iCanvas, ImVec2 const &iPopupWindowPadding)
{
// ImVec2 backgroundScreenPosition;
// auto const cp = ImGui::GetCursorScreenPos();
// auto &io = ImGui::GetIO();
// // Implementation note: this fixes the issue that if a widget is dragged outside the panel, it cannot
// // be picked up again. But this entire positioning, needs to be revisited (the panel should be centered when more
// // space available)
// auto clickableArea = ImGui::GetCurrentWindowRead()->OuterRectClipped.GetSize() - (ImGui::GetStyle().WindowPadding * 2);
// auto backgroundSize = getSize() * iCtx.getZoom();
// clickableArea = {std::max(clickableArea.x, backgroundSize.x), std::max(clickableArea.y, backgroundSize.y)};

// rails are always below
if(iCtx.fShowRackRails)
drawRails(iCtx, iCanvas);

if(iCtx.fPanelRendering != AppContext::EPanelRendering::kNone)
drawPanel(iCtx, iCanvas);

// backgroundScreenPosition = ImGui::GetItemRectMin(); // accounts for scrollbar!
//
// // we use an invisible button to capture mouse events
// ImGui::SetCursorScreenPos(cp); // TextureItem moves the cursor so we restore it
// ImGui::InvisibleButton("canvas", clickableArea, ImGuiButtonFlags_MouseButtonLeft);

// always draw decals first
drawWidgets(iCtx, iCanvas, fDecalsOrder);

Expand Down Expand Up @@ -164,18 +148,20 @@ void Panel::draw(AppContext &iCtx, ReGui::Canvas &iCanvas)
if(iCanvas.canReceiveInput())
handleCanvasInputs(iCtx, iCanvas);

ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, iPopupWindowPadding);
if(ImGui::BeginPopupContextItem())
{
if(!fPopupLocation)
fPopupLocation = mousePos; // accounts for scrollbars
auto widgetLocation = *fPopupLocation / iCtx.getZoom();
fPopupLocation = mousePos;
auto widgetLocation = *fPopupLocation;
if(renderSelectedWidgetsMenu(iCtx, fComputedSelectedWidgets, widgetLocation))
ImGui::Separator();
renderAddWidgetMenu(iCtx, widgetLocation);
ImGui::EndPopup();
}
else
fPopupLocation = std::nullopt;
ImGui::PopStyleVar();

if(fMoveWidgetsAction && fComputedSelectedRect && (!ReGui::AnySpecialKey() || ImGui::GetIO().KeyAlt))
{
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/re/edit/Panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class Panel : public Editable

void setDeviceHeightRU(int iDeviceHeightRU);

void draw(AppContext &iCtx, ReGui::Canvas &iCanvas);
void draw(AppContext &iCtx, ReGui::Canvas &iCanvas, ImVec2 const &iPopupWindowPadding);
void editView(AppContext &iCtx);
void editOrderView(AppContext &iCtx);
void markEdited() override;
Expand Down
3 changes: 2 additions & 1 deletion src/cpp/re/edit/PanelState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,14 @@ void PanelState::renderWidgets(AppContext &iCtx)
//------------------------------------------------------------------------
void PanelState::renderPanel(AppContext &iCtx)
{
auto windowPadding = ImGui::GetStyle().WindowPadding;
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{});
if(auto l = iCtx.fPanelWindow.begin())
{
auto &canvas = iCtx.getPanelCanvas();
auto dpiScale = Application::GetCurrent().getCurrentFontDpiScale();
canvas.begin(fPanel.getSize(), {iCtx.getZoom(), iCtx.isZoomFitContent(), Panel::kZoomMin * dpiScale, Panel::kZoomMax * dpiScale});
fPanel.draw(iCtx, canvas);
fPanel.draw(iCtx, canvas, windowPadding);
iCtx.setZoom(canvas.end());
}
ImGui::PopStyleVar();
Expand Down

0 comments on commit fdd2aa0

Please sign in to comment.