jonegil / gui-with-gio

Tutorials for Gio, the GUI framework in Go.
https://jonegil.github.io/gui-with-gio/
Other
193 stars 40 forks source link

Teleprompter example unit handling #20

Closed whereswaldon closed 1 year ago

whereswaldon commented 2 years ago

Hi @jonegil, I noticed an issue in your teleprompter program on my HiDPI screen. Namely, no text is visible. :D

These lines (259-262) are the big problem: https://github.com/jonegil/gui-with-gio/blob/main/teleprompter/code/main.go#L259

You are converting a value measured in pixels into DP with a cast. On my HiDPI screen, this means that if the value was originally 200 Px, it's now 200 Dp which is 400 Px. Setting the margins so high made no space for text to appear between them on my screen, so I saw nothing.

It would be best to convert your codebase to work almost entirely in Dp and Sp. Raw pixel values are only for times when you need to directly invoke Ops (like clipping). Whenever working with layouts, try to use Dp (and Sp for text).

I tried to convert your codebase to doing this for you, but there are a few places that you're using an integer value to modify both text size and positioning of elements, and changing that led to design decisions I didn't want to make for you. I suggest that you redefine all of the values at the top of draw() as one of the unit types and then handle the necessary conversions throughout your layout code. I'm happy to answer any questions you may have about how to do this.

jonegil commented 2 years ago

Thanks for reviewing @whereswaldon , appreciated.

I finally had a quiet Saturday, and as always, your recommendation makes perfect sense. I've updated the code as to the best of my knowledge. Would you mind having a look?