How to Program a Canvas (Scrollbars, Zoom, Scrolled Window, Scale, ...)

Hello,

some time ago I wrote a demo program that demonstrates how to use and implement scrollbars, canvas, zoom, scrolled windows. I used GtkAda. Please finde the code here:

I’m looking forward to your feedback :slight_smile:

6 Likes

I’m glad in introduce the text book that describes the mechanisms in detail. It is a comprehensive book on the matter. It is free for download available here:

http://www.blunk-electronic.de/pub/buecher/canvas/2025-06-04_canvas_en.pdf

I’m looking forward to your feedback !

6 Likes

Basics on Programming a Canvas

291 pages

I kneel.

2 Likes

Wow, that’s a great undertaking. It deserves sharing outside the Ada circles. People interested in the topic might also think, “nice language used in the code examples”.

I’ve shared it on Hacker News: Basics on Programming a Canvas for a CAD-System [pdf] | Hacker News

It is a great work. Now, some comments:

  • You should really make it Windows friendly. There is no need in any bash and make files.
  • When using Cairo, one likely would do that asynchronously, because typical applications in engineering and gaming are such that rendering and input are separated. As an example you could consider an oscilloscope or clock in Cairo.
  • Gtk does not support tasking. Consider examples like oscilloscope or others to illustrate this issue in Ada.
  • You could add examples explaining how widget sizes are computed in Gtk. It is a very complicated model Gtk users must learn to implement.

If it takes 291 pages to describe the basics of using a canvas, then this must be a very badly designed library.

Gtk is far from perfect. But other frameworks like Qt or Windows GDI are not better. Then designing a GUI is never easy. You quicky sink into countless details. The design of API turns all program logic upside down etc.

I have an Ada library that makes using vector graphics with Gtk / Cairo pretty easy: Ada industrial control widget library