pharo-graphics / Toplo

A widget framework on top of Bloc
MIT License
17 stars 8 forks source link

Question : Image as a Button ? #69

Open Enzo-Demeulenaere opened 11 months ago

Enzo-Demeulenaere commented 11 months ago

Hello, I'd like to have a button with an image and a text below and I tried something like this:

container := ToButton new layout: BlLinearLayout vertical;
    constraintsDo: [ :c | c horizontal fitContent. c vertical fitContent ].

background := (BlElement new background: Color purple; size: 200 asPoint).
label := BlTextElement new 
    text: 'test';
    constraintsDo: [ :c | c horizontal matchParent.
        c vertical matchParent ].

container addChild: label;
    addChild: background;
    openInSpace

to have something similar to this:

image

but with the ability to click on the purple. I know I could make my purple element as a button but I'd have 2 buttons available to click and I wanted to know If there's a possibility to make one and only button.

Thanks a lot

plantec commented 11 months ago

something like that ?


example_toButtonWithTextAndIconVertical

    | but space |
    but := ToButton new padding: (BlInsets all: 4); beVertical.
    but label: (ToLabel text: 'Button').
    but iconImage: (BlElement new
             size: 60 @ 20;
             background: (Color blue alpha: 0.2);
             yourself).
    but layout cellSpacing: 5.
    but whenClickedDo: [ :ann | but icon background: Color random ].
    space := BlSpace new.
    space root addChild: but.
    space show
plantec commented 11 months ago

if you want to fully manage the look, set the skin to nil.


but := ToButton new padding: (BlInsets all: 4); beVertical; withSkin: nil.```
Enzo-Demeulenaere commented 11 months ago

Oh that's exactly what I needed and I didn't even see this example :/

Thanks a lot