What's the definition of 1.dp? I've been trying to...
# compose
m
What's the definition of 1.dp? I've been trying to wrap my head around it but can't figure it out. Is 1.dp an equal percentage of the screen on a 720p display compared to a 4k display (i.e. max(width, height)/100 or similar)? Or is it always guaranteed to be X pixels? It seems to follow the former in regards to layouts and padding, but the latter when it comes to things like fonts, hence why I'm so confused.
r
None of the above. 1 dp is 1 pixel at a density of 160 pixels per inch (density of the first Android phone)
So it has nothing to do with resolution, it's about density
Another name for dp is dip, or "density independent pixel"
Anyway, 1dp is 1px at 160dpi, and 2px at 320dpi
c
I like to think of it as a physical measurement. 160dp is 1 inch wide on a tv, phone, tablet, etc.
m
So there's no good way to make things X% of screen width/height?
Also, why doesn't that mean my desktop app stays the same size on both of my monitors, which have exactly 2x DPI from each other? And how does it get the DPI from a webbrowser?
s
DPI is set system wide. I think in windows the default is 96 dpi.
c
percentage is easy. use weight. 4 columns with a weight of 1f each will each take up 25%. or just give each column a width of 0.25F
m
How do I apply weight to fonts?
s
Text
takes
fontWeight
as an argument.
c
@martmists im not sure i understand your question. You can set weight modifier on Text if you need.
z
If you’re trying to get text to take up a percentage of the screen, that would require autosize text, which we’re planning to support but don’t have a nice api for it yet. You can implement it using TextMeasurer yourself for now though (it’s been asked before, I’m sure if you search the channel you’ll find some code)
👍 1
Font weight has nothing to do with layout weight btw, completely separate concepts
☝️ 1