Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question : Image as a Button ? #69

Open
Enzo-Demeulenaere opened this issue Jul 25, 2023 · 3 comments
Open

Question : Image as a Button ? #69

Enzo-Demeulenaere opened this issue Jul 25, 2023 · 3 comments

Comments

@Enzo-Demeulenaere
Copy link

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
Copy link
Collaborator

plantec commented Jul 25, 2023

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
Copy link
Collaborator

plantec commented Jul 25, 2023

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
Copy link
Author

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

Thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants