Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Round widgets to integer coordinates #5197

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft

Conversation

emilk
Copy link
Owner

@emilk emilk commented Sep 30, 2024

After implementing this, I think this is taking it too far.

I think instead we should round to something like 1/16th. That will remove precision issues, but still give us very accurate layouts, smooth scrolling, etc.

To implement this we could do something like

const ROUND_FACTOR: f32 = 1.0 / 16.0

trait GuiRounding {
    /// Round to a multiple of [`ROUND_FACTOR`], to remove precision problems.
    fn round_gui(&self) -> Self;
}

impl GuiRounding for f32 { … }
impl GuiRounding for Vec2 { … }
impl GuiRounding for Pos2 { … }
impl GuiRounding for Rect { … }

@emilk emilk added layout Related to widget layout egui labels Sep 30, 2024
Copy link

Preview available at https://egui-pr-preview.github.io/pr/5197-emilk/round-widgets
Note that it might take a couple seconds for the update to show up after the preview_build workflow has completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
egui layout Related to widget layout
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant