Help on Gtk::Layout and Gtk::ScrolledWindow


I am learning Gtk+ with gtkmm and my goal is to create a node based interface for visual programming. I started a thread on the Gnome discourse :

Basically what I want is to have my custom node widgets on a "canvas" so I can be able to move them by dragging them. If anyone knows Blender's node editor, it should also be possible to pan with middle mouse button and also zoom.

The Gtk::Layout component seems the right one when it comes to put nodes at specific location on the interface. I also want to draw a custom grid so this so the documentation seems adapted :

Infinite scrollable area containing child widgets and/or custom drawing.

Now the "infinite scrollable area" concept interest me because I want to be able to move on the node tree. The documentation says that I can just put the layout into a Gtk::ScrolledWindow and it supports scrolling natively.

I am struggling to understand how it works with the Gtk::Adjustments, do I need to create them when I instantiate a Gtk::ScrolledWindow? Or are they are controlled by the Gtk::Layout child?

This is a small example to make it work (compile it with g++ gtk_layout.cpp -o gtk_layout `pkg-config gtkmm-3.0 --cflags --libs`):

#include <gtkmm.h>

int main(int argc, char *argv[])
  auto app = Gtk::Application::create(argc, argv, "org.gtkmm.example");

  Gtk::Window window;
  Gtk::ScrolledWindow scrolled_window(Gtk::Adjustment::create(0, 0, 5000), Gtk::Adjustment::create(0, 0, 5000));
  Gtk::Layout layout;

  Gtk::Button button("Hello World!");
  layout.put(button, 100, 100);

  scrolled_window.set_policy(Gtk::POLICY_ALWAYS, Gtk::POLICY_ALWAYS);



  return app->run(window);

How can I get an infinite scrollable area?

Thanks in advance

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]