dk / Prima

prima.eu.org
Other
106 stars 27 forks source link

problem with pack and groupbox #113

Closed kenietz closed 3 months ago

kenietz commented 3 months ago

Hi ,

firstly, thank you for the good work! Its a very nice library!

Now, i would like to report a 'bug' i think. But could be that i don't understand something... :)

Sooo, i am trying to use Prima::GroupBox in order to group widgets. So, i create one and then insert a button using pack. However, the inserted button overlays the border of the GroupBox . I would expect that pack should insert the button under that. The only way to "properly" see everything is to use pady=70, which works but creates problems down the line :)

Btw, i tried to ComboBox as well. Just in case. Found it has the same problem.

So how can i solve that problem? If possible at all. Any hints will be appreciated. Is there another way to group widgets?

Cheers Dimitar

PS: example code

!/usr/bin/perl

use strict; use warnings; use Prima qw(Application Buttons);

my $mw = Prima::MainWindow->new(

width   => 300,
height  => 200,

);

###################################### ########### MAIN FRAME ########## my $mainFrame=$mw->insert('Prima::GroupBox', pack => { fill => 'both', expand => 1, padx => 12, pady => 12, }, name => 'Bla', border => 1 );

my $newProjNameInput=$mainFrame->insert('Prima::Button', pack => { side => 'top', padx => 4 }, name => 'Click',

);

######### run Prima;


dk commented 3 months ago

Hi, thanks for the kind words! You got it right actually, pad 70 or something is exactly what is needed. Groupbox doesnt feature an internal widget that serves as a clipping rectangle for children widgets, but you can insert a widget there with pad 70 and then insert buttons in it.

kenietz commented 3 months ago

Hi, thank you for the quick response.

Yeah, setting pady 70 works but it creates space on both sides(top and bottom) of the widget which offsets the following widget. Aka second widget will be definitely y=70 apart from the first. Not cool :)

I've been trying to add the first widget(another groupbox with height=1) with place method, very close to the 'label' of the groupbox and then add the button. But the button goes at the same spot as the original scenario....

So is there a way to add such clipping rectangle to the groupbox so that the packing goes correctly? I tried to fiddle with the on_paint method of groupbox with clipRect but to no avail haha

Or which other widget can be used in the same manner as groupbox? To have border and label...

Cheers D.

dk commented 3 months ago

Aha I see. If that doesn't work for you there are two scenarios for you. The first, you don't use pack at all when placing buttons, but use growMode instead with explicit coordinates. The second, you can use pack but inside a yet another widget that you place accurately in the groupbox with growMode = gm::Client and origin and size that match the clipping box you need. And then you insert buttons inside that widget.

There is no way groupbox alone can impose clipping on children widgets. Thats why if this is an issue if a groupbox gets too small and buttons get over the groupbox edges, the second scenario would be best. There is no default functionality for this though because the programmer may want the inside widget to be something else, f ex a scrollable widget, to display scrollbars when getting too small to show all buttons at once. Or another backColor or something. I don't think that functionality is needed in the base toolkit because it is really trivial to create such a widget.

Hope this helps

dk commented 3 months ago

Does this work for you? Should we close the ticket?

kenietz commented 3 months ago

Hi didn't have the time to try it yet. But I think we can close the issue. I also thought of using origin and exact coordinates plus grow.. Will try and let you know of the results! Thank you for all the help and ideas!

On Sat, Mar 30, 2024, 6:16 PM Dmitry Karasik @.***> wrote:

Does this work for you? Should we close the ticket?

— Reply to this email directly, view it on GitHub https://github.com/dk/Prima/issues/113#issuecomment-2028002752, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE6NPVOLTVPZSTKDJMBPBQ3Y2Z7H3AVCNFSM6AAAAABFKMTV4OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMRYGAYDENZVGI . You are receiving this because you authored the thread.Message ID: @.***>