From: Andy Gimblett <haskell@gi...> - 2009-08-19 17:44:25
Finally, I can stop asking meta-questions, and ask an actual gtk2hs
usage question :-)
I'm trying to figure out some aspects of packing and layout, and in
particular I want a label which
* Takes up the fill width of the vbox into which it is packed
* Is right-aligned
and I haven't yet figured out how to do this. Here is some simple
code attempting to achieve this, which I've also copied to hpaste to
make downloading simpler (http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8337
). We have a label and a button, packed into a vbox. The button is
quite wide, to simulate the effect of having a wide window; I want the
label to be the whole width of that window. Oh, and I've made the
label white-on-black so its size is clearly visible (and also because
it happens that's what I want in my application).
main :: IO ()
main = do
-- Create a right-justified big white-on-black label.
l <- labelNew Nothing
labelSetMarkup l $ markSpan [FontSize $ SizePoint 20
,FontForeground "white"] "hello"
labelSetJustify l JustifyRight
-- Create a wide button.
b <- buttonNewWithLabel "Long Labelled Button Hello"
-- Pack the label & the button into a vbox, and go.
v <- vBoxNew False 0
boxPackStart v l PackNatural 0
boxPackStart v b PackNatural 0
w <- windowNew
set w [containerChild := v]
onDestroy w mainQuit
Unfortunately, the result is that the label is centred, doesn't expand
to the full width of the window, and (as such) is not noticeably right-
aligned. Screenshot: http://skitch.com/gimboland/b57qa/labelquestion
Please can someone advise me on what I am failing to "get" here? As I
understand it, the "False" passed to vBoxNew is about how the widgets
are spaced when the vbox grows, and the "PackNatural"s passed to
boxPackStart are about how they expand _vertically_ when it grows.
But what about horizontal expansion?
All help appreciated.
Wednesday, August 19, 2009, 9:44:08 PM, you wrote:
> Please can someone advise me on what I am failing to "get" here? As I
> understand it, the "False" passed to vBoxNew is about how the widgets
> are spaced when the vbox grows, and the "PackNatural"s passed to
> boxPackStart are about how they expand _vertically_ when it grows.
> But what about horizontal expansion?
not sure that it's the only way but you can try to put hbox inside
vbox and label inside hbox. then you can force it to fill entire box
gtk2hs (and gtk) are really too verbose :(
From: Andy Gimblett <haskell@gi...> - 2009-08-19 22:30:13
On 19 Aug 2009, at 19:28, Bulat Ziganshin wrote:
> not sure that it's the only way but you can try to put hbox inside
> vbox and label inside hbox. then you can force it to fill entire box
> with PackGrow
Like this? http://hpaste.org/fastcgi/hpaste.fcgi/view?id=8337#a8347
Doesn't work, alas: looks the same.
> gtk2hs (and gtk) are really too verbose :(
I'm going to try some of the higher-level frameworks, but thought it
was worth getting (at least a bit) to grips with gtk and wx first.