Pack style engine width not correct size on linux?
Describe the bug
On linux, when I set the width of labels using the Pack style engine, the width isn't correct. Here is a screenshot:
Steps to reproduce
- Create a toga label and use the pack style engine to set the width to 2 (I only tested it with a width of 2)
- Run the toga app on linux
Expected behavior
The expected behavior is the toga label should be cut off because the width is too short for the text, but its not
Screenshots
No response
Environment
- Operating System: Ubuntu 25.04
- Python version: 3.13.3
- Software versions:
- Briefcase: 0.3.25
- Toga: 0.5.2
Logs
No response
Additional context
No response
Thanks for the report.
From the look of it, Pack is doing the right thing; but GTK doesn't clip the widget to its allocated bounding box. See the following example:
import toga
from toga.style.pack import ROW
class HelloWorld(toga.App):
def startup(self):
main_box = toga.Box(children=[
toga.Label("Hello World", width=10),
toga.Label("and goodbye")
], direction=ROW)
self.main_window = toga.MainWindow(title=self.formal_name)
self.main_window.content = main_box
self.main_window.show()
def main():
return HelloWorld("Hello", "org.example.hello")
if __name__ == "__main__":
main().main_loop()
On Windows and macOS, you get a bit of the H, followed by "and goodbye". On GTK, the position of "and goodbye" is correct, but the text of "Hello World" isn't clipped to its bounding box.
Is using ellipsis allowed? If so https://docs.gtk.org/gtk3/method.Label.set_ellipsize.html will work.
It's certainly allowed - but from a quick check, it doesn't solve the problem on its own.