diff options
author | David Robillard <d@drobilla.net> | 2020-07-30 21:14:41 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-07-30 21:14:41 +0200 |
commit | 1d33505fa45fe69010719e45546de4523254d510 (patch) | |
tree | f3849dcfa78f32fc2cead41b686b06bfb1d294fd /src | |
parent | 6d41e6aad3255a62af3c1b566921eedca6dad931 (diff) | |
download | ganv-1d33505fa45fe69010719e45546de4523254d510.tar.gz ganv-1d33505fa45fe69010719e45546de4523254d510.tar.bz2 ganv-1d33505fa45fe69010719e45546de4523254d510.zip |
Expand canvas automatically to fit nodes
Diffstat (limited to 'src')
-rw-r--r-- | src/Canvas.cpp | 7 | ||||
-rw-r--r-- | src/node.c | 32 |
2 files changed, 39 insertions, 0 deletions
diff --git a/src/Canvas.cpp b/src/Canvas.cpp index 73e32bc..744fe78 100644 --- a/src/Canvas.cpp +++ b/src/Canvas.cpp @@ -1993,6 +1993,13 @@ ganv_canvas_class_init(GanvCanvasClass* klass) } void +ganv_canvas_get_size(GanvCanvas* canvas, double* width, double* height) +{ + *width = canvas->impl->width; + *height = canvas->impl->height; +} + +void ganv_canvas_resize(GanvCanvas* canvas, double width, double height) { if (width != canvas->impl->width || height != canvas->impl->height) { @@ -116,6 +116,36 @@ ganv_node_destroy(GtkObject* object) item->impl->canvas = NULL; } +/// Expands the canvas to contain a moved/resized node if necessary +static void +ganv_node_expand_canvas(GanvNode* node) +{ + GanvItem* item = GANV_ITEM(node); + GanvCanvas* canvas = ganv_item_get_canvas(item); + + if (item->impl->parent == ganv_canvas_root(canvas)) { + const double pad = 10.0; + + double x1 = 0.0; + double y1 = 0.0; + double x2 = 0.0; + double y2 = 0.0; + ganv_item_get_bounds(item, &x1, &y1, &x2, &y2); + + ganv_item_i2w(item, &x1, &y1); + ganv_item_i2w(item, &x2, &y2); + + double canvas_w = 0.0; + double canvas_h = 0.0; + ganv_canvas_get_size(canvas, &canvas_w, &canvas_h); + if (x2 + pad > canvas_w || y2 + pad > canvas_h) { + ganv_canvas_resize(canvas, + MAX(x1 + pad, canvas_w), + MAX(y2 + pad, canvas_h)); + } + } +} + static void ganv_node_update(GanvItem* item, int flags) { @@ -130,6 +160,8 @@ ganv_node_update(GanvItem* item, int flags) } GANV_ITEM_CLASS(parent_class)->update(item, flags); + + ganv_node_expand_canvas(node); } static void |