mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 06:11:16 +00:00
Start a new sixtyfps::Window API for Rust, C++, the interpreters and JS
The generated component now provides access to a Window type via the window() accessor function. This is part of #333
This commit is contained in:
parent
5fd63b63f1
commit
66891a299c
14 changed files with 200 additions and 50 deletions
|
@ -82,6 +82,7 @@ using cbindgen_private::KeyEvent;
|
|||
class WindowRc
|
||||
{
|
||||
public:
|
||||
explicit WindowRc(cbindgen_private::WindowRcOpaque adopted_inner) : inner(adopted_inner) { }
|
||||
WindowRc() { cbindgen_private::sixtyfps_windowrc_init(&inner); }
|
||||
~WindowRc() { cbindgen_private::sixtyfps_windowrc_drop(&inner); }
|
||||
WindowRc(const WindowRc &other)
|
||||
|
@ -89,7 +90,15 @@ public:
|
|||
cbindgen_private::sixtyfps_windowrc_clone(&other.inner, &inner);
|
||||
}
|
||||
WindowRc(WindowRc &&) = delete;
|
||||
WindowRc &operator=(const WindowRc &) = delete;
|
||||
WindowRc &operator=(WindowRc &&) = delete;
|
||||
WindowRc &operator=(const WindowRc &other)
|
||||
{
|
||||
if (this != &other) {
|
||||
cbindgen_private::sixtyfps_windowrc_drop(&inner);
|
||||
cbindgen_private::sixtyfps_windowrc_clone(&other.inner, &inner);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void show() const { sixtyfps_windowrc_show(&inner); }
|
||||
void hide() const { sixtyfps_windowrc_hide(&inner); }
|
||||
|
@ -257,6 +266,40 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
/// This class represents a window towards the windowing system, that's used to render the
|
||||
/// scene of a component. It provides API to control windowing system specific aspects such
|
||||
/// as the position on the screen.
|
||||
class Window
|
||||
{
|
||||
public:
|
||||
/// \private
|
||||
/// Internal function used by the generated code to construct a new instance of this
|
||||
/// public API wrapper.
|
||||
explicit Window(const private_api::WindowRc &windowrc) : inner(windowrc) { }
|
||||
/// Copy-constructs a new window from \a other. Window instances are explicitly
|
||||
/// shared and reference counted. Creating a copy will not create a second window
|
||||
/// on the screen.
|
||||
Window(const Window &other) = default;
|
||||
/// Copy-constructs the window \a other to this and returns a reference to this.
|
||||
/// Window instances are explicitly shared and reference counted. Creating a copy
|
||||
/// will not create a second window on the screen.
|
||||
Window &operator=(const Window &other) = default;
|
||||
Window(Window &&other) = delete;
|
||||
Window &operator=(Window &&other) = delete;
|
||||
/// Destroys this window. Window instances are explicitly shared and reference counted.
|
||||
/// If this window instance is the last one referencing the window towards the windowing
|
||||
/// system, then it will also become hidden and destroyed.
|
||||
~Window() = default;
|
||||
|
||||
/// Registers the window with the windowing system in order to make it visible on the screen.
|
||||
void show() const { inner.show(); }
|
||||
/// De-registers the window from the windowing system, therefore hiding it.
|
||||
void hide() const { inner.hide(); }
|
||||
|
||||
private:
|
||||
private_api::WindowRc inner;
|
||||
};
|
||||
|
||||
/// A Timer that can call a callback at repeated interval
|
||||
///
|
||||
/// Use the static single_shot function to make a single shot timer
|
||||
|
|
|
@ -585,6 +585,15 @@ public:
|
|||
{
|
||||
cbindgen_private::sixtyfps_interpreter_component_instance_show(inner(), false);
|
||||
}
|
||||
/// Returns the Window associated with this component. The window API can be used
|
||||
/// to control different aspects of the integration into the windowing system,
|
||||
/// such as the position on the screen.
|
||||
sixtyfps::Window window() const
|
||||
{
|
||||
cbindgen_private::WindowRcOpaque win;
|
||||
cbindgen_private::sixtyfps_interpreter_component_instance_window(inner(), &win);
|
||||
return sixtyfps::Window(sixtyfps::private_api::WindowRc(win));
|
||||
}
|
||||
/// This is a convenience function that first calls show(), followed by
|
||||
/// sixtyfps::run_event_loop() and hide().
|
||||
void run() const
|
||||
|
|
|
@ -13,7 +13,8 @@ LICENSE END */
|
|||
|
||||
namespace sixtyfps::testing {
|
||||
|
||||
inline void init() {
|
||||
inline void init()
|
||||
{
|
||||
cbindgen_private::sixtyfps_testing_init_backend();
|
||||
}
|
||||
|
||||
|
@ -25,7 +26,7 @@ template<typename Component>
|
|||
inline void send_mouse_click(const Component *component, float x, float y)
|
||||
{
|
||||
auto crc = *component->self_weak.into_dyn().lock();
|
||||
cbindgen_private::sixtyfps_send_mouse_click(&crc, x, y, &component->window);
|
||||
cbindgen_private::sixtyfps_send_mouse_click(&crc, x, y, &component->window_);
|
||||
}
|
||||
|
||||
template<typename Component>
|
||||
|
@ -33,7 +34,7 @@ inline void send_keyboard_string_sequence(const Component *component,
|
|||
const sixtyfps::SharedString &str,
|
||||
cbindgen_private::KeyboardModifiers modifiers = {})
|
||||
{
|
||||
cbindgen_private::send_keyboard_string_sequence(&str, modifiers, &component->window);
|
||||
cbindgen_private::send_keyboard_string_sequence(&str, modifiers, &component->window_);
|
||||
}
|
||||
|
||||
#define assert_eq(A, B) \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue