summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS6
-rw-r--r--ganv/Canvas.hpp1
-rw-r--r--ganv/canvas.h8
-rw-r--r--src/Canvas.cpp7
-rw-r--r--src/node.c32
-rw-r--r--wscript2
6 files changed, 55 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index 5d72bc5..800be1a 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,9 @@
+ganv (1.7.0) unstable;
+
+ * Expand canvas automatically to fit nodes
+
+ -- David Robillard <d@drobilla.net> Thu, 30 Jul 2020 19:13:38 +0000
+
ganv (1.6.0) stable;
* Add API to specify module port order.
diff --git a/ganv/Canvas.hpp b/ganv/Canvas.hpp
index 1a11408..eaf08fd 100644
--- a/ganv/Canvas.hpp
+++ b/ganv/Canvas.hpp
@@ -58,6 +58,7 @@ public:
METHOD0(ganv_canvas, clear)
METHODRET0(ganv_canvas, gboolean, empty)
+ METHOD2(ganv_canvas, get_size, double*, width, double*, height)
METHOD2(ganv_canvas, resize, double, width, double, height)
METHOD4(ganv_canvas, set_scroll_region, double, x1, double, y1, double, x2, double, y2)
METHOD4(ganv_canvas, get_scroll_region, double*, x1, double*, y1, double*, x2, double*, y2)
diff --git a/ganv/canvas.h b/ganv/canvas.h
index 3ffb55c..5d1c5ee 100644
--- a/ganv/canvas.h
+++ b/ganv/canvas.h
@@ -134,6 +134,14 @@ gboolean
ganv_canvas_empty(const GanvCanvas* canvas);
/**
+ * ganv_canvas_get_size:
+ *
+ * Gets the width and height of the canvas.
+ */
+void
+ganv_canvas_get_size(GanvCanvas* canvas, double* width, double* height);
+
+/**
* ganv_canvas_resize:
*
* Resize the canvas to the given dimensions.
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) {
diff --git a/src/node.c b/src/node.c
index 28acb80..c7648de 100644
--- a/src/node.c
+++ b/src/node.c
@@ -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
diff --git a/wscript b/wscript
index 9a5464e..d8bae95 100644
--- a/wscript
+++ b/wscript
@@ -9,7 +9,7 @@ from waflib.extras import autowaf
# major increment <=> incompatible changes
# minor increment <=> compatible changes (additions)
# micro increment <=> no interface changes
-GANV_VERSION = '1.6.0'
+GANV_VERSION = '1.7.0'
GANV_MAJOR_VERSION = '1'
# Mandatory waf variables