Draw resize handle in UI rather than custom opengl; Set min size

Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
falkTX 2021-12-14 22:14:44 +00:00
parent 43951635e9
commit 36f144e501
No known key found for this signature in database
GPG key ID: CDBAA37ABC74FBA0
4 changed files with 67 additions and 24 deletions

View file

@ -46,11 +46,58 @@ namespace rack {
namespace app {
struct ResizeHandle : widget::OpaqueWidget {
void draw(const DrawArgs& args) override {
nvgStrokeColor(args.vg, nvgRGBf(1, 1, 1));
nvgStrokeWidth(args.vg, 1);
nvgBeginPath(args.vg);
nvgMoveTo(args.vg, box.size.x, 0);
nvgLineTo(args.vg, 0, box.size.y);
nvgStroke(args.vg);
nvgBeginPath(args.vg);
nvgMoveTo(args.vg, box.size.x + 5, 0);
nvgLineTo(args.vg, 0, box.size.y + 5);
nvgStroke(args.vg);
nvgBeginPath(args.vg);
nvgMoveTo(args.vg, box.size.x + 10, 0);
nvgLineTo(args.vg, 0, box.size.y + 10);
nvgStroke(args.vg);
nvgStrokeColor(args.vg, nvgRGBf(0, 0, 0));
nvgBeginPath(args.vg);
nvgMoveTo(args.vg, box.size.x+1, 0);
nvgLineTo(args.vg, 0, box.size.y+1);
nvgStroke(args.vg);
nvgBeginPath(args.vg);
nvgMoveTo(args.vg, box.size.x + 6, 0);
nvgLineTo(args.vg, 0, box.size.y + 6);
nvgStroke(args.vg);
nvgBeginPath(args.vg);
nvgMoveTo(args.vg, box.size.x + 11, 0);
nvgLineTo(args.vg, 0, box.size.y + 11);
nvgStroke(args.vg);
}
};
struct Scene::Internal {
ResizeHandle* resizeHandle;
bool heldArrowKeys[4] = {};
};
void hideResizeHandle(Scene* scene) {
scene->internal->resizeHandle->hide();
}
Scene::Scene() {
internal = new Internal;
@ -65,6 +112,10 @@ Scene::Scene() {
browser = browserCreate();
browser->hide();
addChild(browser);
internal->resizeHandle = new ResizeHandle;
internal->resizeHandle->box.size = math::Vec(16, 16);
addChild(internal->resizeHandle);
}
@ -79,6 +130,8 @@ math::Vec Scene::getMousePos() {
void Scene::step() {
internal->resizeHandle->box.pos = box.size.minus(internal->resizeHandle->box.size);
// Resize owned descendants
menuBar->box.size.x = box.size.x;
rackScroll->box.pos.y = menuBar->box.size.y;

View file

@ -325,6 +325,9 @@ math::Vec Window::getSize() {
void Window::setSize(math::Vec size) {
internal->size = size.max(minWindowSize);
if (DISTRHO_NAMESPACE::UI* const ui = internal->ui)
ui->setSize(internal->size.x, internal->size.y);
}