mirror of
https://github.com/ocornut/imgui.git
synced 2026-11-08 19:02:56 +00:00
Non-integer sized fonts (Fringe issue: ScrollToBringRectIntoView() does not work properly when ScaleAllSizes() was called with non-multiple of 0.5) #3164
Labels
No labels
accidentally closed
android
backends
bug
building
clipper
coloredit
color spaces
cplusplus
data types
demo
disabled
doc
docking
dpi
drag drop
drawing/drawlist
dropped
dx12
enhancement
focus
font/text
gallery
help wanted
idle/power saving
ime
in progress
inputs
inputtext
internals
label/id and id stack
language bindings
layout
linux/bsd
menus
multi-contexts
multi-threading
multi-viewports
nav
news/info
opengl
optimization
osx/ios
overlap
plot/graph
popups
question
scrolling
selection
settings
sliders/drags
style
tables/columns
tabs
test wanted
tools
tooltips
tree
tricks & tips
useful widgets
vulkan
web
window pos/depth
window sizing
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ocornut/imgui#3164
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Version and branch:
Version: 1.77 WIP (17601)
Branch: Tables
Compiler, platform, backends:*
Visual C++ 2019, Windows 10, SDL2 + OpenGL 3
My Issue/Question:
This will probably never be a problem in itself, but it might still be useful to find out what causes it.
When you call
ScaleAllSizes()with a number that is not a multiple of 0.5,ScrollToBringRectIntoView()scrolls by an incorrect (insufficient) amount.Values 1, 2, and 1.5 are all ok, but 1.75 is not.
This may only be true when working with tables, I didn't check that.
I tried to debug, but was unable to pinpoint the cause. It would have to be a combination of multiplication by 2 and using floor(), but I couldn't put my finger on it.
Screenshots/Video
In this screenshot, the button has been clicked and row 350 should be fully in view, but the scrolling only made it to ~ 343:
Example
Hello,
I have copy and pasted your example and cannot repro the bug so I assume there's something else causing it. What's your font size? Did you actually repro with the code your copied? No list clipper?
ScaleAllSizes() rounds all values so I don't think it would have a side effect?
However if you were to scale your font by that same factor and have them not be integer-sized you could run into problems presently.
Hi Omar, yes that is the code I used. But you're right about the font: I'm scaling that with the same factor. If the font size is used in any of the calculations and is being rounded, that would account for the effect nicely.
In my case, the font is Arial, size 1.75 * 14 = 24.5
EDIT: confirming that rounding the font size removes the problem.
I'll add extra comments and perhaps rounding on the side of the font system.
It occurred to me that my use case is perhaps not as unusual as I thought.
I'm calculating the DPI scaling factor based on the size of the display, with the following formula:
The idea is to have the font size be independent of the screen's resolution, using a factor of 1 for Full HD and 2 for 4K. But there are plenty of other resolutions out there, so non-standard factors can happen very easily.
P.S. I should probably use the vertical resolution instead of the horizontal one, to account for ultra-wide "flight-sim" type displays.
I have updated my code sample to include font size calculation and loading.
Rounding font size is still fine, unless your base font size is 1. Your formula yields 1.(3) scaling factor on 1440p screens, which upscales 16px font to
21.(3)which we round to 21px. With rounding you lose or gain at most 0.5px of font size which is hardly perceivable anyway.@rokups True, and I have no issue with having to round the font size. I'm not quite sure it is required by FreeType though, since it would have to do grid-fitting and anti-aliasing anyway.
But if Dear ImGui does require the font size to be rounded, then I'd be grateful if it does so automatically, or provides some kind of check.
I added enforcing of font size rounding in
bd63a9fNote that using io.FontGlobalScale or SetWindowFontScale(), with are legacy-ish/partially supported features but sitll somehow convenient in some situation, can still lead to unrounded sizes and same issues.