Files
reasampler/src/core/ui/overflow_menu.cpp
T

43 lines
1.5 KiB
C++

// overflow_menu — pure implementation. See overflow_menu.h. NO REAPER / SWELL / LICE / vendor.
#include "core/ui/overflow_menu.h"
namespace reasampler::ui {
int menuButtonReserve(const MenuBarRect& bar, const MenuButtonSpec& spec) {
if (bar.width <= 0 || bar.height <= 0 || spec.buttonWidth <= 0) return 0;
// The reserve is the button width plus a right gap (rightInset) and a matching left gap
// (also rightInset) so the frequent buttons have breathing room before the menu button.
return spec.buttonWidth + 2 * spec.rightInset;
}
MenuButtonRect computeMenuButton(const MenuBarRect& bar, const MenuButtonSpec& spec) {
MenuButtonRect btn;
if (bar.width <= 0 || bar.height <= 0 || spec.buttonWidth <= 0) return btn;
const int right = bar.x + bar.width - spec.rightInset;
const int left = right - spec.buttonWidth;
if (left < bar.x + spec.minLeftInset) return btn; // too narrow — suppress
int top = bar.y + spec.verticalInset;
int height = bar.height - 2 * spec.verticalInset;
if (height <= 0) { // thin band: clamp to the band's own extents rather than go negative
top = bar.y;
height = bar.height;
}
btn.x = left;
btn.y = top;
btn.width = spec.buttonWidth;
btn.height = height;
return btn;
}
bool hitTestMenuButton(int px, int py, const MenuButtonRect& button) {
if (button.empty()) return false;
return px >= button.x && px < button.x + button.width &&
py >= button.y && py < button.y + button.height;
}
} // namespace reasampler::ui