Skip to content

Commit a5cd75e

Browse files
committed
tool: flip annotation toolbar when almost outside of screen
1 parent f52a934 commit a5cd75e

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/screenshot_tool.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,8 +1265,18 @@ void ScreenshotTool::DrawAnnotationToolbar()
12651265
const float sel_y = m_selection.get_y();
12661266
const float sel_h = m_selection.get_height();
12671267

1268-
const ImVec2 toolbar_pos(sel_x, sel_y + sel_h + 10);
1269-
1268+
// Prefer placing the toolbar below the selection; flip it above when it
1269+
// would otherwise run off the bottom of the screen.
1270+
// The height estimate mirrors the approach used in HandleColorPickerInput(): one row of 24 px
1271+
// image-buttons plus window padding is comfortably covered by 40 px.
1272+
constexpr float k_toolbar_offset = 10.0f;
1273+
constexpr float k_approx_toolbar_h = 40.0f;
1274+
const float display_h = ImGui::GetIO().DisplaySize.y;
1275+
const float toolbar_y = (sel_y + sel_h + k_toolbar_offset + k_approx_toolbar_h > display_h)
1276+
? sel_y - k_approx_toolbar_h - k_toolbar_offset
1277+
: sel_y + sel_h + k_toolbar_offset;
1278+
1279+
const ImVec2 toolbar_pos(sel_x, toolbar_y);
12701280
ImGui::SetNextWindowPos(toolbar_pos);
12711281
ImGui::Begin("##annotation_toolbar",
12721282
nullptr,

0 commit comments

Comments
 (0)