mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 18:58:36 +00:00
Add sixtyfps::Window::request_redraw()
This allows scheduling a redraw of a Window explicitly. Unfortunately it comes with a winit caveat :(
This commit is contained in:
parent
8959eac3d0
commit
18bba6ede4
5 changed files with 34 additions and 4 deletions
|
@ -29,6 +29,7 @@ as well as the [Rust migration guide for the `sixtyfps` crate](api/sixtyfps-rs/m
|
|||
|
||||
- `TextEdit::font-size` and `LineEdit::font-size` have been added to control the size of these widgets.
|
||||
- Added `sixtyfps::Window::set_rendering_notifier` to get a callback before and after a new frame is being rendered.
|
||||
- Added `sixtyfps::Window::request_redraw()` to schedule redrawing of the window contents.
|
||||
|
||||
### Fixed
|
||||
|
||||
|
|
|
@ -268,6 +268,7 @@ fn gen_corelib(
|
|||
"sixtyfps_windowrc_set_component",
|
||||
"sixtyfps_windowrc_show_popup",
|
||||
"sixtyfps_windowrc_set_rendering_notifier",
|
||||
"sixtyfps_windowrc_request_redraw",
|
||||
"sixtyfps_new_path_elements",
|
||||
"sixtyfps_new_path_events",
|
||||
"sixtyfps_color_brighter",
|
||||
|
|
|
@ -158,6 +158,8 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void request_redraw() const { cbindgen_private::sixtyfps_windowrc_request_redraw(&inner); }
|
||||
|
||||
private:
|
||||
cbindgen_private::WindowRcOpaque inner;
|
||||
};
|
||||
|
@ -177,7 +179,8 @@ constexpr inline ItemTreeNode make_dyn_node(std::uintptr_t offset, std::uint32_t
|
|||
parent_index } };
|
||||
}
|
||||
|
||||
inline ItemRef get_item_ref(ComponentRef component, cbindgen_private::Slice<ItemTreeNode> item_tree, int index)
|
||||
inline ItemRef get_item_ref(ComponentRef component, cbindgen_private::Slice<ItemTreeNode> item_tree,
|
||||
int index)
|
||||
{
|
||||
const auto &item = item_tree.ptr[index].item.item;
|
||||
return ItemRef { item.vtable, reinterpret_cast<char *>(component.instance) + item.offset };
|
||||
|
@ -341,6 +344,9 @@ public:
|
|||
return inner.set_rendering_notifier(std::forward<F>(callback));
|
||||
}
|
||||
|
||||
/// This function issues a request to the windowing system to redraw the contents of the window.
|
||||
void request_redraw() const { inner.request_redraw(); }
|
||||
|
||||
/// \private
|
||||
private_api::WindowRc &window_handle() { return inner; }
|
||||
/// \private
|
||||
|
@ -429,7 +435,8 @@ inline SharedVector<float> solve_box_layout(const cbindgen_private::BoxLayoutDat
|
|||
cbindgen_private::Slice<int> repeater_indexes)
|
||||
{
|
||||
SharedVector<float> result;
|
||||
cbindgen_private::Slice<uint32_t> ri { reinterpret_cast<uint32_t *>(repeater_indexes.ptr), repeater_indexes.len };
|
||||
cbindgen_private::Slice<uint32_t> ri { reinterpret_cast<uint32_t *>(repeater_indexes.ptr),
|
||||
repeater_indexes.len };
|
||||
cbindgen_private::sixtyfps_solve_box_layout(&data, ri, &result);
|
||||
return result;
|
||||
}
|
||||
|
@ -467,7 +474,8 @@ inline SharedVector<float> solve_path_layout(const cbindgen_private::PathLayoutD
|
|||
cbindgen_private::Slice<int> repeater_indexes)
|
||||
{
|
||||
SharedVector<float> result;
|
||||
cbindgen_private::Slice<uint32_t> ri { reinterpret_cast<uint32_t *>(repeater_indexes.ptr), repeater_indexes.len };
|
||||
cbindgen_private::Slice<uint32_t> ri { reinterpret_cast<uint32_t *>(repeater_indexes.ptr),
|
||||
repeater_indexes.len };
|
||||
cbindgen_private::sixtyfps_solve_path_layout(&data, ri, &result);
|
||||
return result;
|
||||
}
|
||||
|
@ -490,7 +498,8 @@ struct AbstractRepeaterView
|
|||
using ModelPeer = std::weak_ptr<AbstractRepeaterView>;
|
||||
|
||||
template<typename M>
|
||||
auto access_array_index(const M &model, int index) {
|
||||
auto access_array_index(const M &model, int index)
|
||||
{
|
||||
model->track_row_data_changes(index);
|
||||
if (const auto v = model->row_data(index)) {
|
||||
return *v;
|
||||
|
|
|
@ -119,6 +119,18 @@ impl Window {
|
|||
) -> std::result::Result<(), SetRenderingNotifierError> {
|
||||
self.0.set_rendering_notifier(Box::new(callback))
|
||||
}
|
||||
|
||||
/// This function issues a request to the windowing system to redraw the contents of the window.
|
||||
pub fn request_redraw(&self) {
|
||||
self.0.request_redraw();
|
||||
|
||||
// When this function is called by the user, we want it to translate to a requestAnimationFrame()
|
||||
// on the web. If called through the rendering notifier (so from within the event loop processing),
|
||||
// unfortunately winit will only do that if set the control flow to Poll. This hack achieves that.
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
crate::animations::CURRENT_ANIMATION_DRIVER
|
||||
.with(|driver| driver.set_has_active_animations());
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::window::WindowHandleAccess for Window {
|
||||
|
|
|
@ -729,4 +729,11 @@ pub mod ffi {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// This function issues a request to the windowing system to redraw the contents of the window.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sixtyfps_windowrc_request_redraw(handle: *const WindowRcOpaque) {
|
||||
let window = &*(handle as *const WindowRc);
|
||||
window.request_redraw();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue