Rich text appears to capture mouse interactions
Is your issue REALLY a bug?
- [X] My issue is indeed a bug!
- [X] 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?
- [X] I have searched the existing issues.
Is this issue related to iced?
- [X] 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
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?
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.
Ah, my bad, I see the issue. I’ll see if I can whip up a PR at some point.
I just checked and this is fixed in master, likely as a consequence of the reactive rendering work.
Good to know, thanks.