diff --git a/src/app/RackWidget.cpp b/src/app/RackWidget.cpp index bc361141..2a279179 100644 --- a/src/app/RackWidget.cpp +++ b/src/app/RackWidget.cpp @@ -345,18 +345,13 @@ void RackWidget::step() { Widget *rail = rails->children.front(); Rect bound = getViewport(Rect(Vec(), box.size)); if (!rails->box.contains(bound)) { - // Add a margin around the otherwise tight bound, so that scrolling slightly will not require a re-render of rails. - Vec margin = Vec(100, 100); - bound.pos = bound.pos.minus(margin); - bound.size = bound.size.plus(margin.mult(2)); - rails->box = bound; - // Compute offset of rail within rails framebuffer - Vec grid = Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT); - Vec gridPos = bound.pos.div(grid).floor().mult(grid); - bound.pos = gridPos.minus(bound.pos); - bound.size = bound.size.minus(bound.pos); - rail->box = bound; + Vec cellMargin = Vec(20, 1); + rails->box.pos = bound.pos.div(RACK_GRID_SIZE).floor().minus(cellMargin).mult(RACK_GRID_SIZE); + rails->box.size = bound.size.plus(cellMargin.mult(RACK_GRID_SIZE).mult(2)); + printf("%f %f %f %f\n", rails->box.pos.x, rails->box.pos.y, rails->box.size.x, rails->box.size.y); rails->dirty = true; + + rail->box.size = rails->box.size; } // Autosave every 15 seconds diff --git a/src/widgets/FramebufferWidget.cpp b/src/widgets/FramebufferWidget.cpp index 030cc2ce..5ce1319a 100644 --- a/src/widgets/FramebufferWidget.cpp +++ b/src/widgets/FramebufferWidget.cpp @@ -53,13 +53,15 @@ void FramebufferWidget::draw(NVGcontext *vg) { if (dirty) { dirty = false; - internal->box.pos = Vec(0, 0); - internal->box.size = box.size.mult(s).ceil().plus(Vec(1, 1)); + internal->box = getChildrenBoundingBox(); + internal->box.pos = internal->box.pos.mult(s).floor(); + internal->box.size = internal->box.size.mult(s).ceil().plus(Vec(1, 1)); + Vec fbSize = internal->box.size.mult(gPixelRatio * oversample); - // assert(fbSize.isFinite()); - // Reject zero area size - if (fbSize.x <= 0.0 || fbSize.y <= 0.0) + if (!fbSize.isFinite()) + return; + if (fbSize.isZero()) return; // printf("rendering framebuffer %f %f\n", fbSize.x, fbSize.y); @@ -81,6 +83,7 @@ void FramebufferWidget::draw(NVGcontext *vg) { nvgScale(gFramebufferVg, gPixelRatio * oversample, gPixelRatio * oversample); // Use local scaling nvgTranslate(gFramebufferVg, bf.x, bf.y); + nvgTranslate(gFramebufferVg, internal->box.pos.x, internal->box.pos.y); nvgScale(gFramebufferVg, s.x, s.y); Widget::draw(gFramebufferVg);