Re: Label widgets



Mike Aubury wrote:

I've got an application written using GTK - but I have hit some issues
with the creation of display of labels..

Basically, the application needs to represent something like the
display on an old VT style terminal, so I have up to 80x24 labels
(each within a GtkEventBox so I can set a background) to create and
update when displaying to the 'screen' (I'm using a GtkFixed to put
them on)..

This runs fine (but slowly)....

Also - when I update the screen, it tends to 'flow' across rather
slowly as each cell gets updated..

1) Is there a better way to do this?
I can't do much to remove the old cell mechanism - its the way the
application needs to run. Also - I need to be able to set foreground
and background attributes for any 'cell', so its difficult to even try
to use a single label for the whole line (using fixed width fonts)...

2) Is there anyway to speed up the create ?

3) Is there anyway to remove the flickering/flowing (eg  by suspending
redraws on the gtkfixed so the fixed is only redrawn after all cells
have been updated). ?

All of the above issues can easily be solved by simply using one
GtkTextView instead of numerous GtkLabels. See things like:

http://developer.gnome.org/doc/API/2.0/gtk/TextWidget.html
http://developer.gnome.org/doc/API/2.0/gtk/GtkTextTag.html

This way actually works similar to the way the old terminals generated
their different display attributes. If you want a close emulation of the
behaviour of old terminals with a good performance you should create two
memory buffers of the desired matrix size, i.e. 80 x 24 x 2 bytes. One
buffer would hold character data while the other buffer would hold
simple attribute data, such as foreground and background colors and bold
attributes. (Blinking doesn't seem to be supported by GTK+.) You would
write only into the buffers (and not directly into the GtkTextBuffer).

Whenever you feel like it (instantaneous or delayed) you would call a
custom refresh function (which you would have to write) which translates
the contents of the two buffers into a text + tags mixture suitable for
the GtkTextView, and replace the former contents with it. In fact, this
is basically the same strategy which is used by real terminal based
libraries like Ncurses to operate and access their text console screens.

While a small portion of flicker may remain when GtkTextViews frequently
get entirely refilled, it is certainly less than any other technique
which bases on multiple widgets like labels. The refilling operation of
the GtkTextView could likely be optimised further for many cases to just
replace parts of the GtkTextBuffer which have actually changed, but this
would probably be rather complex to implement and not being worth it.

I've looked into using something like a 80x24 table widget - but thats
even slower. And I can't even use something like the zvt library - as
I want to intermix the GUI components (like entry fields and buttons)
in between the labels, as well as embed frames for further old style
'windows'..

Mixing other GUI components between the lines of a multiline text widget
is the only thing not accomplishable by using a GtkTextView. However,
you could still use a widget-specific popup menu to offer extra
functions, such as copy & paste or dynamic data entry (using other popup
windows). If you need persistent widgets (like buttons) you should place
them alongside or beneath the textview.

Embedding frames for "old style windows" isn't a problem, as the three
standard characters "+", "-" and "|" do a good job on it in many real
text consoles as well. You would likely want to write a basic set of
functions to access your off-screen buffer, i.e. to draw such frames at
it, save "window" backgrounds and so on. Again, that's how libraries
like Ncurses work as well.



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