@@ -1392,19 +1392,30 @@ void ScreenshotTool::DrawAnnotationToolbar()
13921392 const float sel_y = m_selection.get_y ();
13931393 const float sel_h = m_selection.get_height ();
13941394
1395- // Prefer placing the toolbar below the selection; flip it above when it
1396- // would otherwise run off the bottom of the screen.
1397- // The height estimate mirrors the approach used in HandleColorPickerInput(): one row of 24 px
1398- // image-buttons plus window padding is comfortably covered by 40 px.
13991395 constexpr float k_toolbar_offset = 10 .0f ;
14001396 constexpr float k_approx_toolbar_h = 40 .0f ;
1401- const float display_h = ImGui::GetIO ().DisplaySize .y ;
1402- const float toolbar_y = (sel_y + sel_h + k_toolbar_offset + k_approx_toolbar_h > display_h)
1403- ? sel_y - k_approx_toolbar_h - k_toolbar_offset
1404- : sel_y + sel_h + k_toolbar_offset;
1397+
1398+ const float display_h = ImGui::GetIO ().DisplaySize .y ;
1399+
1400+ float below_y = sel_y + sel_h + k_toolbar_offset;
1401+ float above_y = sel_y - k_toolbar_offset - k_approx_toolbar_h;
1402+
1403+ float toolbar_y = below_y;
1404+
1405+ // Prefer below
1406+ if (below_y + k_approx_toolbar_h > display_h)
1407+ {
1408+ // Try above
1409+ toolbar_y = above_y;
1410+
1411+ // If above also invalid, clamp
1412+ if (toolbar_y < 0 .0f )
1413+ toolbar_y = ImClamp (below_y, 0 .0f , display_h - k_approx_toolbar_h);
1414+ }
14051415
14061416 const ImVec2 toolbar_pos (sel_x, toolbar_y);
14071417 ImGui::SetNextWindowPos (toolbar_pos);
1418+
14081419 ImGui::Begin (" ##annotation_toolbar" ,
14091420 nullptr ,
14101421 ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove |
0 commit comments