Is it possible for giving a fontSize in DP in Comp...
# compose
o
Is it possible for giving a fontSize in DP in Compose?
f
What are you trying to achieve? Making Text that does not scale with users scaling setting?
o
Yes
f
What is your usecase? 🤔
o
Just the requirements the app has of a card UI text not getting ugly because of user system settings
f
Just my personal opinions but I don't think that's good enough reason. You should make it work some other way that does not hurt users with bad sight.
o
Yeah that's the best UX solution
f
The solution should be to introduce your own
LocalDensity
with constant
fontScale
. But again, I highly doubt non-scaling text is good UX. I think it's just a bad compromise for "nice" UI. There is a reason why it's not a straightforward solution.
e
@Filip Wiesner I hear your argument a lot, but there are times where design calls for hero text. Absolutely nothing is gained by scaling it up, because it's already quite large. Whether design should call for hero text or not is a whole different discussion.
f
But is hero text still a hero text when everything is bigger? 🙂 I would argue that than it would lose it's importance. But yeah, every rule has an exception. That's why it's not impossible to do, only more complicated. And there might be better solution. The
LocalDensity
override was just the first thing that I thought of.
a
If you really want to do that,
fontSize = with(LocalDensity.current) { 20.dp.toSp() }
should be enough.