Summary
Currently the way to change the cursor's icon is through miniquad's re-exported set_mouse_cursor function. However calling it multiple times per frame can cause the cursor to flicker because calling it actually changes the cursor right away. It would be convenient to have a mechanism that wraps this and call the function once per frame max.
Motivation
It's very common to change the cursor's icon, when a button is hovered for example. Right now the workaround is to carry a variable that holds the cursor's final value and call set_mouse_cursor at the end of the frame. This is not very natural, and becomes more and more tedious as the rendering tree grows.
Proposed API
Re-export miniquad's CursorIcon in the prelude and add .cursor() to ElementBuilder:
let mut cursor = None;
if is_hovered {
cursor = Some(CursorIcon::Pointer);
}
ui.element().cursor(cursor).empty();
It takes an Option so we can chain the functions nicely regardless of whether or not we want to display a cursor, otherwise we would have to do:
let mut elt = ui.element();
if is_hovered {
elt = elt.cursor(CursorIcon::Pointer;
}
elt.empty();
// Very ugly!
Behavior
- The cursor is stored in the root
Ply (or the root element, not sure how this works exactly yet).
- The cursor associated with each element is stored. When
ui.show() is called, it takes the one with the highest z-index and displays it through set_window_cursor (defaulting to CursorIcon::Default if none was specified).
- Even though
.cursor() is a member of ElementBuilder, it updates the cursor regardless of whether or not the element is hovered (contrary to CSS's cursor attribute).
Summary
Currently the way to change the cursor's icon is through miniquad's re-exported
set_mouse_cursorfunction. However calling it multiple times per frame can cause the cursor to flicker because calling it actually changes the cursor right away. It would be convenient to have a mechanism that wraps this and call the function once per frame max.Motivation
It's very common to change the cursor's icon, when a button is hovered for example. Right now the workaround is to carry a variable that holds the cursor's final value and call
set_mouse_cursorat the end of the frame. This is not very natural, and becomes more and more tedious as the rendering tree grows.Proposed API
Re-export miniquad's
CursorIconin the prelude and add.cursor()toElementBuilder:It takes an
Optionso we can chain the functions nicely regardless of whether or not we want to display a cursor, otherwise we would have to do:Behavior
Ply(or the root element, not sure how this works exactly yet).ui.show()is called, it takes the one with the highest z-index and displays it throughset_window_cursor(defaulting toCursorIcon::Defaultif none was specified)..cursor()is a member ofElementBuilder, it updates the cursor regardless of whether or not the element is hovered (contrary to CSS'scursorattribute).