Pixel-Width of StaticText-content?

Hey there,

I’m playing around with some GUI stuff and I wondered if there is any method of getting the actual pixelwidth of a string of text? My idea would be to make multiple well-aligned StaticText’s that are only as wide as their containing string and then assign different mouseDownActions to them.

a = View(nil, 600@100);
a.addFlowLayout(0@0, 0@0);

b = StaticText(a, 300@100)
.font_(Font("Arial", 24, usePointSize: true))
.string_("how wide am i in pixels?")
.align_(\topLeft);

c = StaticText(a, 300@100)
.font_(Font("Arial", 24, usePointSize: true))
.string_("and what is my width?")
.align_(\topLeft);
a.front;
)

All best,
moritz

See String’s bounds method.

hjh

2 Likes

Amazing, thank you! The only place I didn’t look for it…