pharo-graphics / Toplo

A widget framework on top of Bloc
MIT License
19 stars 9 forks source link

Button with icon and text that matches parent extent #43

Open tinchodias opened 1 year ago

tinchodias commented 1 year ago

How do you recommend to build a button like this in morphic?

Screenshot 2023-06-01 at 13 42 31

I started with an example in ToSandbox, with a ToButton, but I think I should use ToGeneralButton. Am I right?

but := ToButton new.
but label: 
    ((ToLabel text: 'Make something cool happen')
        matchParent;
        alignCenterLeft;
        yourself).
but icon: 
    ((ToImage inner: (self iconNamed: #remove))
        matchParent;
        layoutDo: [ :l |
            l verticalAlignment: BlElementAlignment vertical center.
            l horizontalAlignment: BlElementAlignment horizontal end ];
    yourself).
but matchParent.

space := OBlSpace new.
space root addChild: but.
space show 
Screenshot 2023-06-01 at 13 39 54
plantec commented 1 year ago

Yes, a ToButton is more for vFitContent. Have a look at this example:

example_toBasicButton2

| but lab |
lab := ToLabel new text:
           (('Button' asRopedText)
                fontSize: 40;
                yourself).
but := ToGeneralButton new dresser: ToGeneralButtonDresser new.
but matchParent.
but addChild: lab.
but layout alignCenter.
but whenClickedDo: [ self inform: 'clicked' ].
but openInOBlSpace 
plantec commented 1 year ago

but it should be possible with a ToButton. I will have a look and push a fixe if it is an issue

plantec commented 1 year ago

with a ToGeneralButton:

example_toBasicButton4

| but lab ico pane |
pane := ToPane new.
pane fitContent.
pane layout alignCenter.
lab := ToLabel new text: 'Button'.
ico := ToImage inner: (self iconNamed: #remove).
pane addChildren: { lab. ico }.
but := ToGeneralButton new dresser: ToGeneralButtonDresser new.
but matchParent.
but addChild: pane.
but layout alignCenter.
but whenClickedDo: [ self inform: 'clicked' ].
but openInOBlSpace 
tinchodias commented 1 year ago

Many thanks!