Re: Using a TextView as a sort of Hbox with wrapping

2014-01-27 Thread Chris Angelico
On Tue, Jan 28, 2014 at 1:30 AM, Tristan Van Berkom
tris...@upstairslabs.com wrote:
 You can get the behavior you are looking for with EggWrapBox:
   https://git.gnome.org/browse/libegg/tree/libegg/wrapbox

 Just copy the eggwrapbox.[ch] and compile it as a part of your
 code (or compile a libegg separately and link to it if LGPL is
 a problem for you).

That looks fairly decent! Unfortunately I can't compile in extra C
code (I'm doing this in a high level language, Pike, and I want this
to work on an unmodified install of Pike - I do build my own Pike on
Linux, but my clients generally use a pre-built), so I can't use this
directly. And... that is a LOT of code (2641 lines), though a lot of
it looks like stuff that would be way shorter in a high level
language. I don't know that I want to port it to Pike, even if it's
possible to do that.

But it does look good, and it answers the big question (I can't be
the first person to want this, so what did other people do?).

 ... also the EggWrapBox
 handles height-for-width geometry well for it's children,
 while textview itself does some height-for-width, I'm not
 sure it is done well for embedded child widgets

What do you mean by height-for-width here? I just tried on GTK
2.24.10 on Windows and it failed to wrap the way I expected, so I'm
not sure what's going on (the same version of GTK on Linux worked
fine). Is that the sort of issue you mean?

ChrisA
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Using a TextView as a sort of Hbox with wrapping

2014-01-27 Thread Tristan Van Berkom
On Tue, 2014-01-28 at 01:56 +1100, Chris Angelico wrote:
 On Tue, Jan 28, 2014 at 1:30 AM, Tristan Van Berkom
 tris...@upstairslabs.com wrote:
  You can get the behavior you are looking for with EggWrapBox:
https://git.gnome.org/browse/libegg/tree/libegg/wrapbox
 
  Just copy the eggwrapbox.[ch] and compile it as a part of your
  code (or compile a libegg separately and link to it if LGPL is
  a problem for you).
 
 That looks fairly decent! Unfortunately I can't compile in extra C
 code (I'm doing this in a high level language, Pike, and I want this
 to work on an unmodified install of Pike - I do build my own Pike on
 Linux, but my clients generally use a pre-built), so I can't use this
 directly. And... that is a LOT of code (2641 lines), though a lot of
 it looks like stuff that would be way shorter in a high level
 language. I don't know that I want to port it to Pike, even if it's
 possible to do that.
 
 But it does look good, and it answers the big question (I can't be
 the first person to want this, so what did other people do?).
 
  ... also the EggWrapBox
  handles height-for-width geometry well for it's children,
  while textview itself does some height-for-width, I'm not
  sure it is done well for embedded child widgets
 
 What do you mean by height-for-width here? I just tried on GTK
 2.24.10 on Windows and it failed to wrap the way I expected, so I'm
 not sure what's going on (the same version of GTK on Linux worked
 fine). Is that the sort of issue you mean?

Sorry I did not take into account that you were working with the
GTK+2 library and not GTK+3.

height for width is a geometry management system which says to
the widget:
  o What is your minimum width and what is your natural width ?
  o Oh... so you can fit into 40 pixels but you would prefer 80 !
  o Ok I've decided that, taking into account all horizontal space, you
will receive 60 pixels in width, how much height do you need for
a width of 60 pixels ?
  o Ah, you want 20 height ? we're done here, you will receive 60 
pixels in width and 20 pixels in height.

This geometry management is more complex than just:
what is your width  height
but allows dynamic content such as wrapping labels to unwrap
and fit the window allocation, leaving more vertical space
for other widgets above or below a wrapping label which might
desire that space.

GtkTextView had it's own way of doing height-for-width internally,
insomuch that it would eventually ask for enough height to fit the
wrapping text into whatever width you had given it.

GTK+3 has this geometry management built-in, but GTK+2 does not
(so doing things like EggWrapBox with GTK+2 is more tricky).

If you are stuck with GTK+2, I suggest you take a look into
GtkToolPalette, you might be able to trick your statusbar
items into being GtkToolItems and use the wrapping behaviour
of GtkToolPalette to achieve the same effect (or at least use
some prior art in there, I think you are stuck with the
expanders if you use GtkToolPalette directly... GtkToolItemGroup
would have the precise code you are looking for).

Cheers,
-Tristan

 
 ChrisA
 ___
 gtk-app-devel-list mailing list
 gtk-app-devel-list@gnome.org
 https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Using a TextView as a sort of Hbox with wrapping

2014-01-27 Thread Chris Angelico
On Tue, Jan 28, 2014 at 3:00 AM, Tristan Van Berkom
tris...@upstairslabs.com wrote:
 Sorry I did not take into account that you were working with the
 GTK+2 library and not GTK+3.

Ah, I should have mentioned, sorry. There has been talk of supporting
GTK3 in Pike, but I won't move to it till I can confidently expect
that my clients will have it. (It's kinda weird. I'm using a language
that's more designed for servers - web servers, MUD servers, and so on
- and writing a client in it. More often than you might think, I run
into Pike bugs and have to fix them before I can move on. Fortunately
it's an open source language!)

 height for width is a geometry management system which says to
 the widget:
   o What is your minimum width and what is your natural width ?
   o Oh... so you can fit into 40 pixels but you would prefer 80 !
   o Ok I've decided that, taking into account all horizontal space, you
 will receive 60 pixels in width, how much height do you need for
 a width of 60 pixels ?
   o Ah, you want 20 height ? we're done here, you will receive 60
 pixels in width and 20 pixels in height.

 This geometry management is more complex than just:
 what is your width  height
 but allows dynamic content such as wrapping labels to unwrap
 and fit the window allocation, leaving more vertical space
 for other widgets above or below a wrapping label which might
 desire that space.

Ah, gotcha. That makes a lot of sense, since there'll be a good few
widgets that can wrap like that.

 GtkTextView had it's own way of doing height-for-width internally,
 insomuch that it would eventually ask for enough height to fit the
 wrapping text into whatever width you had given it.

That's actually the exact behaviour I want here. The status bar will
fill whatever width the window is sized to, and then I want it to
claim as much or as little height as it needs. (The bulk of the
window's height is taken up with a ScrolledWindow, so it makes little
difference to the layout if there's another row of status.)

 GTK+3 has this geometry management built-in, but GTK+2 does not
 (so doing things like EggWrapBox with GTK+2 is more tricky).

 If you are stuck with GTK+2, I suggest you take a look into
 GtkToolPalette, you might be able to trick your statusbar
 items into being GtkToolItems and use the wrapping behaviour
 of GtkToolPalette to achieve the same effect (or at least use
 some prior art in there, I think you are stuck with the
 expanders if you use GtkToolPalette directly... GtkToolItemGroup
 would have the precise code you are looking for).

Yeah, I looked into that, but wasn't able to make it do what I wanted.
I'll give that another shot tomorrow; it might be better suited to
what I'm trying to do (especially if it works properly on Windows and
Mac). It's called GTK2.Toolbar in Pike, but I'm assuming that's the
same thing as GtkToolPalette.

ChrisA
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Using a TextView as a sort of Hbox with wrapping

2014-01-27 Thread Tristan Van Berkom
On Mon, 2014-01-27 at 03:49 +1100, Chris Angelico wrote:
 On Mon, Jan 27, 2014 at 3:43 AM, James Tappin jtap...@gmail.com wrote:
If I interpret what you are trying to do correctly (not necessarily a
  given), then I would have thought that GtkScrolledWindow (possibly in
  conjunction with GtkViewport) would be the tool for the job.
 
 Not scrolling, wrapping. The window might be large enough to hold all
 the statusbar entries (and I expect that it normally will be), but if
 it's not, I would prefer the more graceful degradation of doubling the
 height of the status bar and moving the excess to a new row rather
 than widening the window. Scrolling would force the user to
 consciously manipulate the status bar, which is contrary to its goal
 of being subtle and just there. Suddenly expanding to double its
 normal height isn't perfect either, but maybe someone will actually
 want it to be taller, who knows.
 
 I could use a Table, or a Vbox with multiple Hboxes in it, but then
 I'd need to decide in advance which elements drop to the next row. I
 want it to be automatic: if there's room, use one row, otherwise wrap
 to a second (and third, and fourth, if necessary, but I would hope
 that's never the case!).

You can get the behavior you are looking for with EggWrapBox:
  https://git.gnome.org/browse/libegg/tree/libegg/wrapbox

Just copy the eggwrapbox.[ch] and compile it as a part of your
code (or compile a libegg separately and link to it if LGPL is
a problem for you).

EggWrapBox has been modified and added to GTK+ as GtkFlowBox,
however the GTK+ version is lacking the primary feature that
you want, i.e. children do not wrap freely but instead they
are forced to appear in columns.

Perhaps if you use the EggWrapBox and prove to the GTK+ team
that the free-form wrapping is useful and important, we can
get the free flowing behavior back into GtkFlowBox.

FWIW I would certainly rather use the EggWrapBox widget for
the purpose you describe rather than to repurpose a GtkTextView
for that (the text view is much more complex for such a
simple purpose as wrapping widgets - also the EggWrapBox
handles height-for-width geometry well for it's children,
while textview itself does some height-for-width, I'm not
sure it is done well for embedded child widgets).

Cheers,
-Tristan

 
 ChrisA
 ___
 gtk-app-devel-list mailing list
 gtk-app-devel-list@gnome.org
 https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Using a TextView as a sort of Hbox with wrapping

2014-01-27 Thread Tristan Van Berkom
On Tue, 2014-01-28 at 03:08 +1100, Chris Angelico wrote:
 On Tue, Jan 28, 2014 at 3:00 AM, Tristan Van Berkom
 tris...@upstairslabs.com wrote:
  Sorry I did not take into account that you were working with the
  GTK+2 library and not GTK+3.
 
 Ah, I should have mentioned, sorry. There has been talk of supporting
 GTK3 in Pike, but I won't move to it till I can confidently expect
 that my clients will have it. (It's kinda weird. I'm using a language
 that's more designed for servers - web servers, MUD servers, and so on
 - and writing a client in it. More often than you might think, I run
 into Pike bugs and have to fix them before I can move on. Fortunately
 it's an open source language!)
 
  height for width is a geometry management system which says to
  the widget:
o What is your minimum width and what is your natural width ?
o Oh... so you can fit into 40 pixels but you would prefer 80 !
o Ok I've decided that, taking into account all horizontal space, you
  will receive 60 pixels in width, how much height do you need for
  a width of 60 pixels ?
o Ah, you want 20 height ? we're done here, you will receive 60
  pixels in width and 20 pixels in height.
 
  This geometry management is more complex than just:
  what is your width  height
  but allows dynamic content such as wrapping labels to unwrap
  and fit the window allocation, leaving more vertical space
  for other widgets above or below a wrapping label which might
  desire that space.
 
 Ah, gotcha. That makes a lot of sense, since there'll be a good few
 widgets that can wrap like that.
 
  GtkTextView had it's own way of doing height-for-width internally,
  insomuch that it would eventually ask for enough height to fit the
  wrapping text into whatever width you had given it.
 
 That's actually the exact behaviour I want here. The status bar will
 fill whatever width the window is sized to, and then I want it to
 claim as much or as little height as it needs. (The bulk of the
 window's height is taken up with a ScrolledWindow, so it makes little
 difference to the layout if there's another row of status.)
 
  GTK+3 has this geometry management built-in, but GTK+2 does not
  (so doing things like EggWrapBox with GTK+2 is more tricky).
 
  If you are stuck with GTK+2, I suggest you take a look into
  GtkToolPalette, you might be able to trick your statusbar
  items into being GtkToolItems and use the wrapping behaviour
  of GtkToolPalette to achieve the same effect (or at least use
  some prior art in there, I think you are stuck with the
  expanders if you use GtkToolPalette directly... GtkToolItemGroup
  would have the precise code you are looking for).
 
 Yeah, I looked into that, but wasn't able to make it do what I wanted.
 I'll give that another shot tomorrow; it might be better suited to
 what I'm trying to do (especially if it works properly on Windows and
 Mac). It's called GTK2.Toolbar in Pike, but I'm assuming that's the
 same thing as GtkToolPalette.

No, GtkToolbar != GtkToolPalette, they are separate things.

The GtkToolPalette is what we use in Glade to show all the
widget icons for example - there is a demo of it if you run
gtk-demo you should be able to see it in action, and I'm quite
sure that it exists in one of the later versions of GTK+2
(it should really be there in 2.24).

Cheers,
-Tristan

 
 ChrisA
 ___
 gtk-app-devel-list mailing list
 gtk-app-devel-list@gnome.org
 https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Using a TextView as a sort of Hbox with wrapping

2014-01-27 Thread Chris Angelico
On Tue, Jan 28, 2014 at 3:19 AM, Tristan Van Berkom
tris...@upstairslabs.com wrote:
 No, GtkToolbar != GtkToolPalette, they are separate things.

 The GtkToolPalette is what we use in Glade to show all the
 widget icons for example - there is a demo of it if you run
 gtk-demo you should be able to see it in action, and I'm quite
 sure that it exists in one of the later versions of GTK+2
 (it should really be there in 2.24).

Ah, okay. Looks like I don't have ToolPalette, so I can't depend on
it. Just tried Toolbar again and its problem is that it doesn't wrap,
it offers a hey, look, there's more button - so it's like scrolling
again. Pity. :(

ChrisA
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Using a TextView as a sort of Hbox with wrapping

2014-01-26 Thread James Tappin
Chris,
  If I interpret what you are trying to do correctly (not necessarily a
given), then I would have thought that GtkScrolledWindow (possibly in
conjunction with GtkViewport) would be the tool for the job.

James


On 26 January 2014 14:50, Chris Angelico ros...@gmail.com wrote:

 My application has a status bar which can have an arbitrary number of
 items added to it. Currently, I use an Hbox with no padding, which
 works fine as long as there aren't too many statusbar elements added;
 but if there are a lot, the tail starts wagging the dog, in that the
 size of the window becomes dictated by the status bar (which normally
 is supposed to be subtle, not intrusive/controlling). So I figured
 that wrapping elements onto another line of status bar would be a more
 useful way to lay them out, but that's really tricky. Enter TextView:
 it's a widget designed to handle wrapping, and it can have child
 widgets embedded in it.

 Here's some proof of concept code. (This is in Pike, so you may not be
 able to run it directly.)

 int main()
 {
 GTK2.setup_gtk();
 object
 buf=GTK2.TextBuffer(),view=GTK2.TextView(buf)-set_editable(0)-set_wrap_mode(GTK2.WRAP_WORD)-set_cursor_visible(0);
 view-modify_base(GTK2.STATE_NORMAL,GTK2.GdkColor(240,240,240));
 foreach (({Asdf asdf,Qwer qwer,Zxcv zxcv,Testing,
 testing,1, 2, 3, 4}),string x)
 {

 view-add_child_at_anchor(GTK2.Frame()-add(GTK2.Label(x))-set_shadow_type(GTK2.SHADOW_ETCHED_OUT),
 buf-create_child_anchor(buf-get_end_iter()));
 buf-insert(buf-get_end_iter(),  ,-1);
 }

 GTK2.Window(GTK2.WindowToplevel)-set_default_size(500,300)-add(GTK2.Vbox(0,0)
 -add(GTK2.Label(Blah blah blah, this\nhas lots and\nlots of
 content\n\nLorem ipsum dolor sit\namet))
 -pack_start(GTK2.Button(This sets the base width),0,0,0)
 -pack_start(view,0,0,0)
 )-show_all()-signal_connect(delete-event,lambda() {exit(0);});
 return -1;
 }

 Two questions.

 Firstly: Is this a really REALLY stupid thing to do? When I Googled
 for a wrapping layout manager, nothing mentioned this possibility, so
 I'm wondering if this is somehow fundamentally bad and I just haven't
 seen it.

 And secondly: The TextArea defaults to having a white background, but
 I want to use the window's default background. On my system, setting
 the color to (240,240,240) does that, but that means I'm explicitly
 setting a color, so it's going to be grey even if the UI theme
 specifies that a window's background should be vibrant orange. Is
 there a way to tell the TextView not to draw its background, or
 alternatively, a way to query the default background color for a
 window?

 Thanks in advance!

 ChrisA
 ___
 gtk-app-devel-list mailing list
 gtk-app-devel-list@gnome.org
 https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Using a TextView as a sort of Hbox with wrapping

2014-01-26 Thread Chris Angelico
On Mon, Jan 27, 2014 at 3:43 AM, James Tappin jtap...@gmail.com wrote:
   If I interpret what you are trying to do correctly (not necessarily a
 given), then I would have thought that GtkScrolledWindow (possibly in
 conjunction with GtkViewport) would be the tool for the job.

Not scrolling, wrapping. The window might be large enough to hold all
the statusbar entries (and I expect that it normally will be), but if
it's not, I would prefer the more graceful degradation of doubling the
height of the status bar and moving the excess to a new row rather
than widening the window. Scrolling would force the user to
consciously manipulate the status bar, which is contrary to its goal
of being subtle and just there. Suddenly expanding to double its
normal height isn't perfect either, but maybe someone will actually
want it to be taller, who knows.

I could use a Table, or a Vbox with multiple Hboxes in it, but then
I'd need to decide in advance which elements drop to the next row. I
want it to be automatic: if there's room, use one row, otherwise wrap
to a second (and third, and fourth, if necessary, but I would hope
that's never the case!).

ChrisA
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list