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

button hitbox is offset from where the button actually is #331

Closed
Eisverygoodletter opened this issue Dec 8, 2021 · 8 comments · Fixed by #343
Closed

button hitbox is offset from where the button actually is #331

Eisverygoodletter opened this issue Dec 8, 2021 · 8 comments · Fixed by #343
Labels
help wanted Extra attention is needed

Comments

@Eisverygoodletter
Copy link

using this code

use macroquad::prelude::*;
use macroquad::math::vec2;
use macroquad::ui::{root_ui, widgets};
#[macroquad::main("button testing")]
async fn main() {
    loop {
        clear_background(BLACK);
        if widgets::Button::new("push me").size(vec2(100.0, 100.0)).position(vec2(100.0, 100.0)).ui(&mut *root_ui()) {
            println!("button was pushed");
        }
        next_frame().await;
    }
}

This shows up
The yellow rectangle was added in by me to show approximately where the button could be clicked, and it doesn't line up with the actual button
button testing
The hitbox (clickbox?) seems to have different offsets if I move the button to different parts of the screen. However, it always offsets towards the top left of the button.
any help?

@Eisverygoodletter
Copy link
Author

update: after moving the button around a lot, it seems like the closer the "visual button" is closer to the bottom right corner, the larger the offset between the "visual button" and the "hitbox button". Also, they always seem to line up perfectly with the top left corner, so I think it might be a scaling issue.

@Eisverygoodletter
Copy link
Author

Update 2: I believe the problem may be in the inconsistencies between screen_height() and macroquad::input::mouse_position() and their width counterparts. By using screen_height(), I get a value of 600 for the height. However, if I move my mouse down to the bottom of the screen, macroquad::input::mouse_position().1 will give me 745 for the height. I think this may be causing scaling issues for the hitbox

@not-fl3
Copy link
Owner

not-fl3 commented Dec 9, 2021

Thanks for your research! It probably was caused by this PR: not-fl3/miniquad#248

Unfortunately, it is one of those rare bugs that do not reproduce under wine for me and I do not have a real windows machine right now.
So it may take a bit of time to fix :(

@Eisverygoodletter
Copy link
Author

After messing around by resizing and moving the window around a bit, I found out that both screen_height() and mouse_position().1 (when cursor positioned at bottom of screen) will both shrink proportionally to the window size. Basically they're shrinking on the same scale, and as the window gets smaller the distance between them get closer.
Resizing the window doesn't change the button hitbox offset at all, so I'm still not sure what's happening. (screen_height() and mouse_position() differences might be another issue in itself)

@not-fl3 not-fl3 added the help wanted Extra attention is needed label Dec 10, 2021
@vpzomtrrfrt
Copy link
Contributor

I believe I've also seen this issue on a linux system now

@vpzomtrrfrt
Copy link
Contributor

Yes, under Ubuntu at least, enabling "Fractional Scaling" in the settings and selecting a non-100% scale causes this issue

@vpzomtrrfrt
Copy link
Contributor

vpzomtrrfrt commented Dec 18, 2021

Bisecting shows faf5c7f as the relevant change, so presumably the input values were missed when implementing hidpi

@not-fl3
Copy link
Owner

not-fl3 commented Dec 18, 2021

Bisecting shows faf5c7f as the relevant change, so presumably the input values were missed when implementing hidpi

Thank you very much for your time on the bisecting, good catch!

Feel free to reopen if the problem will still happen after the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants