mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
LibWebView: Do floating-point-error-free zoom calculation using rounding
The current min/max zoom levels are supposed to be: 30% and 500%. Before, due to floating point error accumulation in incremental addition of zoom-step into zoom-level, one extra zoom step would get allowed, enabling user to zoom 20%-to-510%. Now, using rounding, the intermediate zoom-level values should be as close to the theoretical value as FP32 can represent. E.g. zoom-level of 70% (theoretical multiplier 0.7) is 0.69... .
This commit is contained in:
parent
276ad23b70
commit
96335f31d5
Notes:
github-actions[bot]
2024-09-20 06:16:04 +00:00
Author: https://github.com/ronak69 Commit: https://github.com/LadybirdBrowser/ladybird/commit/96335f31d5a Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1427 Reviewed-by: https://github.com/tcl3 ✅
1 changed files with 2 additions and 2 deletions
|
@ -107,7 +107,7 @@ void ViewImplementation::zoom_in()
|
|||
{
|
||||
if (m_zoom_level >= ZOOM_MAX_LEVEL)
|
||||
return;
|
||||
m_zoom_level += ZOOM_STEP;
|
||||
m_zoom_level = round_to<int>((m_zoom_level + ZOOM_STEP) * 100) / 100.0f;
|
||||
update_zoom();
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,7 @@ void ViewImplementation::zoom_out()
|
|||
{
|
||||
if (m_zoom_level <= ZOOM_MIN_LEVEL)
|
||||
return;
|
||||
m_zoom_level -= ZOOM_STEP;
|
||||
m_zoom_level = round_to<int>((m_zoom_level - ZOOM_STEP) * 100) / 100.0f;
|
||||
update_zoom();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue