Iced Rich_Text + Span - duplicate a buttons status functionality

⚓ Rust    📅 2026-04-09    👤 surdeus    👁️ 4      

surdeus

I am attempting to better utilize the built in functionality of Rust & Iced. I had a view which incorporated 3 buttons wrapped in a column wrapped in a container. I discovered rich_text and spans which to me simplified the code. What I have not been able to determine is can I duplicate the status functionality of a button. With the buttons I had a style which utilized its status (active, selected...) to change the text color. With the spans I can hard code a text color and add an underline. What I would like to do is somehow capture the mouse hoover event and use it to change the span text color and turn the underline on and off. As it is now, I run the mouse over any of the span text and the mouse pointer changes so some functionality is present that recognizes the mouse is hovering over a span (due no doubt to the associated link). Below is the updated section of the view. Any assistance will be appreciated.

widget::container(
    widget::rich_text![
        span("Max Closing Value\n")
            .underline(true)
            .link("Max"),
        span("Min Closing Value\n")
            .underline(true)
            .link("Min"),
        span("Selected Closing Values\n")
            .underline(true)
            .link("Selected"),
    ]
    .on_link_click(|string| {
        match string {
            "Max" => Message::MaxClosing,
            "Min" => Message::MinClosing,
            "Selected" => Message::SelectedClosings,
            _ => Message::Empty,
        }
    })
    .line_height(1.8)
    .color(color!(0x0000ff))
    .size(20.0)
    .font(Font::DEFAULT)
    .align_x(Horizontal::Center),

) // end of container
.padding(iced::padding::top(20))
.height(Length::FillPortion(8))
.width(Length::Fill)
.align_x(iced::alignment::Horizontal::Center)
.align_y(iced::alignment::Vertical::Top),

1 post - 1 participant

Read full topic

🏷️ Rust_feed