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

#5077 After update, more and more Wrap are added every time the mouse is moved. #5084

Closed
rustbasic opened this issue Sep 6, 2024 · 5 comments · Fixed by #5161
Closed

#5077 After update, more and more Wrap are added every time the mouse is moved. #5084

rustbasic opened this issue Sep 6, 2024 · 5 comments · Fixed by #5161
Assignees
Labels
bug Something is broken

Comments

@rustbasic
Copy link
Contributor

rustbasic commented Sep 6, 2024

#5076 #5077 After update (May be #5077),
wrap(line breaks) are happening more and more strangely.
In case of on_hover_text_at_pointer(), more and more Wrap(line breaks) are added every time the mouse is moved.

@rustbasic rustbasic added the bug Something is broken label Sep 6, 2024
@rustbasic rustbasic changed the title #5077 After update, Wrap are happening more and more strangely. #5077 After update, more and more Wrap are added every time the mouse is moved. Sep 7, 2024
@rustbasic
Copy link
Contributor Author

rustbasic commented Sep 9, 2024

My.egui.App.2024-09-09.22-19-59.mp4
use eframe::egui::*;

fn main() -> eframe::Result {
    let options = eframe::NativeOptions {
        viewport: egui::ViewportBuilder::default().with_inner_size([320.0, 240.0]),
        ..Default::default()
    };
    eframe::run_native(
        "My egui App",
        options,
        Box::new(|_cc| Ok(Box::<MyApp>::default())),
    )
}

#[derive(Default)]
struct MyApp {
    temp_value: usize,
    _text: String,
}

impl eframe::App for MyApp {
    fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
        egui::CentralPanel::default().show(ctx, |ui| {
            ui.horizontal(|ui| {
                let response = ui.button("⟲").on_hover_text_at_pointer(
                    "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
                );
                let response = ui.button("⟲").on_hover_text_at_pointer(
                    "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
                );
                let response = ui.button("⟲").on_hover_text_at_pointer(
                    "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
                );
                let response = ui.button("⟲").on_hover_text_at_pointer(
                    "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
                );
                let response = ui.button("⟲").on_hover_text_at_pointer(
                    "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
                );
                if response.clicked() {
                    self.temp_value = 255;
                }
            });
            ui.separator();

            ctx.settings_ui(ui);
        });
    }
}

@rustbasic
Copy link
Contributor Author

rustbasic commented Sep 10, 2024

Someone, please refer to #5093 and fix the bug correctly by referring to this part.
I'm working on something else so I can't look into it in detail.

@rustbasic
Copy link
Contributor Author

This issue has been resolved in #5106

@emilk emilk added this to the Next Major Release milestone Sep 13, 2024
@emilk
Copy link
Owner

emilk commented Sep 16, 2024

This seems to only happen when pixels_per_point is non-integer, so probably some parts of egui is rounding to pixels, and some other part is rounding to points…

@rustbasic
Copy link
Contributor Author

This seems to only happen when pixels_per_point is non-integer, so probably some parts of egui is rounding to pixels, and some other part is rounding to points…

Yes, it seems so.
I think the solution is #5106.
Are there any other better ways?

@emilk emilk self-assigned this Sep 25, 2024
@emilk emilk closed this as completed in f97f850 Sep 25, 2024
hacknus pushed a commit to hacknus/egui that referenced this issue Oct 30, 2024
…k#5161)

* Closes emilk#5106
* Closes emilk#5084


Protect against rounding errors in egui layout code.

Say the user asks to wrap at width 200.0.
The text layout wraps, and reports that the final width was 196.0
points.
This than trickles up the `Ui` chain and gets stored as the width for a
tooltip (say).
On the next frame, this is then set as the max width for the tooltip,
and we end up calling the text layout code again, this time with a wrap
width of 196.0.
Except, somewhere in the `Ui` chain with added margins etc, a rounding
error was introduced,
so that we actually set a wrap-width of 195.9997 instead.
Now the text that fit perfectly at 196.0 needs to wrap one word earlier,
and so the text re-wraps and reports a new width of 185.0 points.
And then the cycle continues.

So this PR limits the text wrap-width to be an integer.

Related issues:
* emilk#4927
* emilk#4928
* emilk#5163

--- 

Pleas test this @rustbasic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment