minimal.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include <gflow-0.4.h>
  2. #include <gtk/gtk.h>
  3. #include <gtkflow-0.4.h>
  4. GtkFlowNodeView *nv;
  5. static void on_button_clicked();
  6. static void activate(GtkApplication *app, gpointer user_data) {
  7. GtkWidget *window;
  8. window = gtk_application_window_new(app);
  9. gtk_window_set_title(GTK_WINDOW(window), "Window");
  10. gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);
  11. GtkWidget *sw = gtk_scrolled_window_new(0, 0);
  12. nv = gtk_flow_node_view_new();
  13. GtkWidget *button = gtk_button_new_with_label("Add Node");
  14. GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
  15. gtk_container_add(GTK_CONTAINER(sw), GTK_WIDGET(nv));
  16. gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(button), 0, 0, 0);
  17. gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(sw), 1, 1, 1);
  18. gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(vbox));
  19. g_signal_connect(button, "clicked", G_CALLBACK(on_button_clicked), 0);
  20. gtk_widget_show_all(window);
  21. }
  22. static void on_button_clicked() {
  23. GFlowSimpleNode *n = gflow_simple_node_new();
  24. GValue sink_v = G_VALUE_INIT;
  25. g_value_init(&sink_v, G_TYPE_INT);
  26. GValue source_v = G_VALUE_INIT;
  27. g_value_init(&source_v, G_TYPE_INT);
  28. GFlowSimpleSink *sink = gflow_simple_sink_new(&sink_v);
  29. GFlowSimpleSource *source = gflow_simple_source_new(&source_v);
  30. gflow_dock_set_name(GFLOW_DOCK(sink), "sink");
  31. gflow_dock_set_name(GFLOW_DOCK(source), "source");
  32. gflow_node_add_source(GFLOW_NODE(n), GFLOW_SOURCE(source), 0);
  33. gflow_node_add_sink(GFLOW_NODE(n), GFLOW_SINK(sink), 0);
  34. gflow_node_set_name(GFLOW_NODE(n), "node");
  35. gtk_flow_node_view_add_node(nv, GFLOW_NODE(n));
  36. }
  37. int main(int argc, char **argv) {
  38. GtkApplication *app;
  39. int status;
  40. app = gtk_application_new("org.gtk.example", G_APPLICATION_FLAGS_NONE);
  41. g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
  42. status = g_application_run(G_APPLICATION(app), argc, argv);
  43. g_object_unref(app);
  44. return status;
  45. }