On some em-based websites I’ve seen them break at high zoom levels defeating the purpose.
[1] https://developer.mozilla.org/en-US/docs/Web/API/Window/devi...
This is common among visual technologies.
There are logical pixels, an abstract description of size.
And there are physical pixels, that are the actual dots of color.
---
This is not unlike a printed page of text.
The font size is measured in points.
The physical output is dots and determined by DPI.
I targeted Firefox and ended up with some bonkers magic constant where a pixel was actually like 1.05 pixels or something.
If I don't render enough it'll be blurry. If I render too many it's wasteful. If I am slightly off then the filtering will make it look weird
It's not a phone with a Bayer matrix, it's not VR, I don't know why they have to be weird about it
The browser can do pixel perfect rendering, it has to for sharp text. But in WebGL there is no reliable way to get the coordinates to do so as well. Browser specific ways to do so exist, but using standard APIs doesn't work browser zooms like 130% or DPI scales like 1.25 in combination with certain resolutions.
But yes you can have "bonkers" devicePixelRatio. Namely, when the browser is zoomed.
Logical pixels measure UI "size." And Physical pixels (logical pixels * devicePixelRatio) is the number of dots.
Your game layout should target logical pixels. And rasterization, textures, etc should target physical pixels.
If weird devicePixelRatio causes problems with a lot of pixel-exact UI, you may choose to use your own logical pixels that has a rounded devicePixelRatio.
---
I have a MacBook with a retina display. Versus a non-retina display, I would not expect that everything is 2x smaller, but rather 2x more detailed (or, if not that, the same level of detail but same size). That important distinction is reason for two different constants.
Exactly that is unfortunately not possible, you may or may not get off by one resolution.
> I would not expect that everything is 2x smaller
Of course.
> but rather 2x more detailed
That's specifically the thing you cannot guarantee, as sometimes due to lack of standarization, it maybe 2.01x size, leading to those UI elements being the right size, but slightly blurry due to pixel grid mismatches.
There are two approaches these days though: https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/W...
I'm aware of those, it's just sad nothing is nailed as a standard. Those are two workarounds unfortunately. A browser API not supported on Apple Safari and pixel-presnap with JS doing the CSS px calculation backwards + snapping and even that code has an extra branch to fix a macOS+Chrome bug. The whole situation smells of duct tape.
alberth•4mo ago
lmm•4mo ago
tyleo•4mo ago
duskwuff•4mo ago
Anyways, CSS is fine. The problem space is complicated.
lmm•4mo ago
Nested tables and inline styling yeah. It works better. It's always worked better, unless you're handwriting your HTML, and virtually no-one does that anymore.
baggy_trough•4mo ago
maxbond•4mo ago
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
https://css-tricks.com/snippets/css/complete-guide-grid/
As an aside, hand-rolling HTML templates is still pretty common (such as for SSG themes), which is substantially similar to hand-rolling HTML. You just get `if` and `for` and a couple other primitives.
rjh29•4mo ago
fijiaarone•4mo ago
geuis•4mo ago
I still remember the star selector pattern to prevent IE6 from reading malformed css. So me old.
But having grown up in my early career during the transition from embedding styles into html to sites like css zen garden, I am extremely critical of modern "frameworks".
I still see so much bloat in poor performing pages and often when I dig deeper it's tailwind in addition to other inefficiencies adding repeated cruft that doesn't help with site rendering.
A proper 20 year old understanding of css class style inheritance isn't hard, and it negates 80-90% of the complexity of maintaining complex web apps (react components mainly).
CSS grids are cute and useful, but for a hell of a lot of web interfaces a simple float and clear:left still works wonders.
bryanrasmussen•4mo ago
easyThrowaway•4mo ago
A new styling language, with better syntax, written taking into account real-world scenarios, widely deployed across all browsers (or at least cross-compiling into CSS)?
I wouldn't hold my breath.
geuis•4mo ago
It has never translated well to custom font settings from a user browser, but it turns out those are exceptionally rare vs people who just ctl/cmd +/- on the keyboard or pinch and zoom on the phone.
paulddraper•4mo ago
bryanrasmussen•4mo ago