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

Rich text appears to capture mouse interactions #2630

Open
4 tasks done
kiedtl opened this issue Oct 7, 2024 · 3 comments
Open
4 tasks done

Rich text appears to capture mouse interactions #2630

kiedtl opened this issue Oct 7, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@kiedtl
Copy link
Contributor

kiedtl commented Oct 7, 2024

Is your issue REALLY a bug?

  • My issue is indeed a bug!
  • I am not crazy! I will not fill out this form just to ask a question or request a feature. Pinky promise.

Is there an existing issue for this?

  • I have searched the existing issues.

Is this issue related to iced?

  • My hardware is compatible and my graphics drivers are up-to-date.

What happened?

I've noticed that clicking a rich-text element embedded inside a button does not trigger the on_press.

MRE (forgive unnecessary use of daemon):

use iced::window;
use iced::{Element, Task};
use iced::widget::{text, button, span, rich_text, column};

fn main() -> iced::Result {
    iced::daemon(Example::title, Example::update, Example::view)
        .run_with(Example::new)
}

struct Example {
    // Nuh uh
}

#[derive(Debug, Clone)]
enum Message {
    Nuhuh,
    Pressed,
}

impl Example {
    fn new() -> (Self, Task<Message>) {
        let (_id, open) = window::open(window::Settings::default());

        (Self {}, open.map(|_| Message::Nuhuh))
    }

    fn title(&self, _: window::Id) -> String {
        "Test".to_owned()
    }

    fn update(&mut self, message: Message) -> Task<Message> {
        match message {
            Message::Nuhuh => { }
            Message::Pressed => {
                println!("hi");
            }
        }

        Task::none()
    }

    fn view(&self, _: window::Id) -> Element<Message> {
        button(column![
            text("clicking this yields Message::Pressed!"),
            rich_text([
                span("but clicking this doesn't do anything!"),
                span("\nand neither does this!"),
            ])
        ])
            .on_press(Message::Pressed)
            .into()
    }
}

In the above example, clicking on the first text element causes the button to be clicked, but clicking the spans does not.

What is the expected behavior?

Clicking any area of the button should yield the appropriate event.

Version

crates.io release

Operating System

Both Windows and Linux (X11) were tested.

Do you have any log output?

No response

@kiedtl kiedtl added the bug Something isn't working label Oct 7, 2024
@kiedtl
Copy link
Contributor Author

kiedtl commented Oct 7, 2024

Alright, I've done some digging and this appears to be... intentional?

Surely this is leftover code, right? Captured this and tracking which span is pressed doesn't seem to be used at all. It's not even available to the user. Maybe I'm missing something?

@Koranir
Copy link
Contributor

Koranir commented Oct 13, 2024

Rich text can include links, which is handled as part of the widget (you missed this, the selected span is used just a few blocks beneath your link).
Indeed, a better solution would be to only intercept the input if the selected span is a link.

@kiedtl
Copy link
Contributor Author

kiedtl commented Oct 13, 2024

Ah, my bad, I see the issue. I’ll see if I can whip up a PR at some point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants