Re: [spam score 10.00/10.0 -pobox] Newbie seeks advice (mixing text, widgets, images on a scrollable canvas)



Pascal Haakmat <a haakmat chello nl> writes: 
Basically, the application I am trying to write is a browser. That means I
need to render text, images and form elements onto some kind of canvas, and
have the entire canvas be scrollable. What I am ultimately looking for is
the best way to implement this using GTK, but I'll first explain where my
current hackish implementation breaks down.

Right now, I am using a GtkFixed container widget as my canvas. Text is
drawn directly onto the GtkFixed container widget and I add form elements
using gtk_fixed_put().

I would suggest using GtkLayout instead. Unlike GtkFixed, it has an
infinite scrolling area, and you won't need the viewport.

Another suggestion is to look at the source code for the GtkHTML
widget. You can get that from GNOME CVS or ftp.

The first problem is that I get into endless redraw loops:

1. I get a "draw" signal for the GtkFixed widget.
2. I draw some text.
3. I add a form element and show it.
4. This triggers another "draw" signal on the GtkFixed widget.
5. Go to 1.

What would be the best solution to avoid this loop? Should I render the text
onto a pixmap and use that as the background for the GtkFixed widget? Should
I subclass GtkFixed? Should I write my own widget alltogether?

Don't do 3 in a "draw" signal handler. "draw" should just draw.

The second problem concerns scrolling. Currently, the GtkFixed widget is
inside a GtkViewport, which is inside a GtkScrolledWindow. What I would
really like to do is to get rid of the GtkViewport and implement scrolling
natively in the GtkFixed container widget, but I do not understand how to do
this. Is it necessary to write my own widget? And if so, do I have to start
from scratch or is GtkFixed a good place to start at?


Scrolling is much easier with GtkLayout, where you basically just have
to offset your coordinates by layout->xoffset layout->yoffset before
drawing. GnomeCanvas is a GtkLayout subclass, I wouldn't be surprised
if GtkHTML was also.

Havoc




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