toga icon indicating copy to clipboard operation
toga copied to clipboard

Pack style engine width not correct size on linux?

Open SmallCoder13 opened this issue 3 months ago • 3 comments

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:

Image

Steps to reproduce

  1. 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)
  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

SmallCoder13 avatar Sep 25 '25 20:09 SmallCoder13

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.

freakboy3742 avatar Sep 25 '25 22:09 freakboy3742

Is using ellipsis allowed? If so https://docs.gtk.org/gtk3/method.Label.set_ellipsize.html will work.

johnzhou721 avatar Sep 26 '25 01:09 johnzhou721

It's certainly allowed - but from a quick check, it doesn't solve the problem on its own.

freakboy3742 avatar Sep 26 '25 06:09 freakboy3742