mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 10:50:00 +00:00
Replace show()/hide() in the WindowAdapter with set_visible(bool)
This makes for a smaller interface.
This commit is contained in:
parent
bde0ae7585
commit
af97435463
12 changed files with 179 additions and 235 deletions
|
@ -66,8 +66,9 @@ class WindowAdapter
|
|||
[](void *wa) {
|
||||
return reinterpret_cast<WindowAdapter *>(wa)->renderer().renderer_handle();
|
||||
},
|
||||
[](void *wa) { reinterpret_cast<const WindowAdapter *>(wa)->show(); },
|
||||
[](void *wa) { reinterpret_cast<const WindowAdapter *>(wa)->hide(); },
|
||||
[](void *wa, bool visible) {
|
||||
reinterpret_cast<WindowAdapter *>(wa)->set_visible(visible);
|
||||
},
|
||||
[](void *wa) { reinterpret_cast<WindowAdapter *>(wa)->request_redraw(); },
|
||||
[](void *wa) -> cbindgen_private::IntSize {
|
||||
return reinterpret_cast<const WindowAdapter *>(wa)->physical_size();
|
||||
|
@ -84,14 +85,10 @@ public:
|
|||
explicit WindowAdapter() { }
|
||||
virtual ~WindowAdapter() = default;
|
||||
|
||||
/// This function is called by Slint when the slint window is shown.
|
||||
/// This function is called by Slint when the slint window is shown or hidden.
|
||||
///
|
||||
/// Re-implement this function to forward the call to show to the native window
|
||||
virtual void show() const { }
|
||||
/// This function is called by Slint when the slint window is hidden.
|
||||
///
|
||||
/// Re-implement this function to forward the call to hide to the native window
|
||||
virtual void hide() const { }
|
||||
/// Re-implement this function to forward the call to show/hide the native window
|
||||
virtual void set_visible(bool) { }
|
||||
|
||||
/// This function is called when Slint detects that the window need to be repainted.
|
||||
///
|
||||
|
@ -474,12 +471,8 @@ public:
|
|||
|
||||
/// Slint's Skia renderer.
|
||||
///
|
||||
/// To be used as a template parameter of the WindowAdapter.
|
||||
///
|
||||
/// The show() and hide() function must be called from the WindowAdapter's re-implementation
|
||||
/// of the homonymous functions
|
||||
///
|
||||
/// Use render to perform the rendering.
|
||||
/// Create the renderer when you have created a native window with a non-zero size.
|
||||
/// Call the render() function to render the scene into the window.
|
||||
class SkiaRenderer : public AbstractRenderer
|
||||
{
|
||||
mutable cbindgen_private::SkiaRendererOpaque inner;
|
||||
|
|
|
@ -10,7 +10,7 @@ use i_slint_core::platform::{Platform, PlatformError};
|
|||
use i_slint_core::renderer::Renderer;
|
||||
use i_slint_core::software_renderer::{RepaintBufferType, Rgb565Pixel, SoftwareRenderer};
|
||||
use i_slint_core::window::ffi::WindowAdapterRcOpaque;
|
||||
use i_slint_core::window::{WindowAdapter, WindowAdapterInternal};
|
||||
use i_slint_core::window::WindowAdapter;
|
||||
|
||||
type WindowAdapterUserData = *mut c_void;
|
||||
|
||||
|
@ -27,8 +27,7 @@ pub struct CppWindowAdapter {
|
|||
drop: unsafe extern "C" fn(WindowAdapterUserData),
|
||||
/// Safety: the returned pointer must live for the lifetime of self
|
||||
get_renderer_ref: unsafe extern "C" fn(WindowAdapterUserData) -> RendererPtr,
|
||||
show: unsafe extern "C" fn(WindowAdapterUserData),
|
||||
hide: unsafe extern "C" fn(WindowAdapterUserData),
|
||||
set_visible: unsafe extern "C" fn(WindowAdapterUserData, bool),
|
||||
request_redraw: unsafe extern "C" fn(WindowAdapterUserData),
|
||||
size: unsafe extern "C" fn(WindowAdapterUserData) -> IntSize,
|
||||
}
|
||||
|
@ -44,6 +43,11 @@ impl WindowAdapter for CppWindowAdapter {
|
|||
&self.window
|
||||
}
|
||||
|
||||
fn set_visible(&self, visible: bool) -> Result<(), PlatformError> {
|
||||
unsafe { (self.set_visible)(self.user_data, visible) };
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn size(&self) -> PhysicalSize {
|
||||
let s = unsafe { (self.size)(self.user_data) };
|
||||
PhysicalSize::new(s.width, s.height)
|
||||
|
@ -53,33 +57,17 @@ impl WindowAdapter for CppWindowAdapter {
|
|||
unsafe { core::mem::transmute((self.get_renderer_ref)(self.user_data)) }
|
||||
}
|
||||
|
||||
fn internal(&self, _: i_slint_core::InternalToken) -> Option<&dyn WindowAdapterInternal> {
|
||||
Some(self)
|
||||
}
|
||||
|
||||
fn request_redraw(&self) {
|
||||
unsafe { (self.request_redraw)(self.user_data) }
|
||||
}
|
||||
}
|
||||
|
||||
impl WindowAdapterInternal for CppWindowAdapter {
|
||||
fn show(&self) -> Result<(), PlatformError> {
|
||||
unsafe { (self.show)(self.user_data) };
|
||||
Ok(())
|
||||
}
|
||||
fn hide(&self) -> Result<(), PlatformError> {
|
||||
unsafe { (self.hide)(self.user_data) }
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn slint_window_adapter_new(
|
||||
user_data: WindowAdapterUserData,
|
||||
drop: unsafe extern "C" fn(WindowAdapterUserData),
|
||||
get_renderer_ref: unsafe extern "C" fn(WindowAdapterUserData) -> RendererPtr,
|
||||
show: unsafe extern "C" fn(WindowAdapterUserData),
|
||||
hide: unsafe extern "C" fn(WindowAdapterUserData),
|
||||
set_visible: unsafe extern "C" fn(WindowAdapterUserData, bool),
|
||||
request_redraw: unsafe extern "C" fn(WindowAdapterUserData),
|
||||
size: unsafe extern "C" fn(WindowAdapterUserData) -> IntSize,
|
||||
target: *mut WindowAdapterRcOpaque,
|
||||
|
@ -89,9 +77,8 @@ pub unsafe extern "C" fn slint_window_adapter_new(
|
|||
user_data,
|
||||
drop,
|
||||
get_renderer_ref,
|
||||
show,
|
||||
set_visible,
|
||||
request_redraw,
|
||||
hide,
|
||||
size,
|
||||
});
|
||||
|
||||
|
|
|
@ -71,12 +71,7 @@ struct MyWindowAdapter : public slint_platform::WindowAdapter
|
|||
return slint::PhysicalSize({ uint32_t(r.right - r.left), uint32_t(r.bottom - r.top) });
|
||||
}
|
||||
|
||||
void show() const override { ShowWindow(hwnd, SW_SHOWNORMAL); }
|
||||
|
||||
void hide() const override
|
||||
{
|
||||
// TODO: destroy window
|
||||
}
|
||||
void set_visible(bool visible) override { ShowWindow(hwnd, visible ? SW_SHOWNORMAL : SW_HIDE); }
|
||||
|
||||
void request_redraw() override { InvalidateRect(hwnd, nullptr, false); }
|
||||
|
||||
|
|
|
@ -100,14 +100,14 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void show() const override
|
||||
void set_visible(bool visible) override
|
||||
{
|
||||
const_cast<WindowAdapter *>(static_cast<const WindowAdapter *>(this))
|
||||
->dispatch_scale_factor_change_event(devicePixelRatio());
|
||||
auto window = const_cast<QWindow *>(static_cast<const QWindow *>(this));
|
||||
window->QWindow::show();
|
||||
if (visible) {
|
||||
dispatch_scale_factor_change_event(devicePixelRatio());
|
||||
}
|
||||
this->QWindow::setVisible(visible);
|
||||
}
|
||||
void hide() const override { const_cast<MyWindow *>(this)->QWindow::hide(); }
|
||||
|
||||
slint::PhysicalSize physical_size() const override
|
||||
{
|
||||
auto windowSize = slint::LogicalSize({ float(width()), float(height()) });
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue