gyscos / cursive

A Text User Interface library for the Rust programming language
MIT License
4.26k stars 243 forks source link

[BUG] Form elements (e.g. `Checkbox`) take focus on scroll #649

Open arxanas opened 2 years ago

arxanas commented 2 years ago

Describe the bug

When trying to scroll, if the mouse is over an element like a Checkbox, instead of scrolling in the parent view, focus is moved to that element.

To Reproduce

Reproduces in cargo run --example list_view. Move your mouse over the checkbox, and then scroll. The checkbox takes focus. Actually, the issue reproduces for all of the form controls — I don't want any of them to be taking focus in this situation

Expected behavior

The containing ScrollView should scroll.

Environment

Additional context

I tried adjusting take_focus as follows:

    fn take_focus(&mut self, direction: Direction) -> Result<EventResult, CannotFocus> {
        match direction {
            Direction::Abs(Absolute::None) => Ok(EventResult::Ignored),
            _ => self.enabled.then(EventResult::consumed).ok_or(CannotFocus),
        }
    }

Of course, this means that the element no longer responds to mouse click events, which is also not desirable. Is there any workaround to make these elements respond to clicks but not scrolls?

gyscos commented 2 years ago

Hi, and thanks for the report!

Indeed we probably don't want to change the selection with this. We should be able to forward mouse wheel events down the view tree without changing selection to let users scroll a view that's not selected, as well as not select regular views like checkboxes or edit views in the process.