Skip to content

Commit 6abc403

Browse files
committed
wip
1 parent 6e7dec0 commit 6abc403

3 files changed

Lines changed: 26 additions & 4 deletions

File tree

examples/plugin_clack/src/gui.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::window_handler::OpenWindowExample;
22
use crate::ExamplePluginMainThread;
33
use baseview::dpi::PhysicalSize;
44
use baseview::gl::GlConfig;
5-
use baseview::{WindowHandle, WindowOpenOptions};
5+
use baseview::{WindowHandle, WindowOpenOptions, WindowSize};
66
use clack_extensions::gui::{
77
GuiApiType, GuiConfiguration, GuiResizeHints, GuiSize, PluginGuiImpl, Window as ClapWindow,
88
};
@@ -45,8 +45,7 @@ impl PluginGuiImpl for ExamplePluginMainThread {
4545
}
4646

4747
fn get_size(&mut self) -> Option<GuiSize> {
48-
// Unsupported
49-
Some(GuiSize { width: 400, height: 200 })
48+
Some(window_size_to_gui_size(self.gui.as_ref()?.handle.size()))
5049
}
5150

5251
fn can_resize(&mut self) -> bool {
@@ -98,3 +97,17 @@ impl PluginGuiImpl for ExamplePluginMainThread {
9897
Ok(()) // Not supported yet
9998
}
10099
}
100+
101+
fn window_size_to_gui_size(size: WindowSize) -> GuiSize {
102+
#[cfg(target_os = "macos")]
103+
{
104+
let size = size.logical.cast();
105+
GuiSize { width: size.width, height: size.height }
106+
}
107+
108+
#[cfg(not(target_os = "macos"))]
109+
{
110+
let size = size.physical.cast();
111+
GuiSize { width: size.width, height: size.height }
112+
}
113+
}

src/platform/macos/window.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use dpi::LogicalSize;
1+
use dpi::{LogicalSize, PhysicalSize};
22
use objc2::rc::{autoreleasepool, Retained, Weak};
33
use objc2::MainThreadMarker;
44
use objc2_app_kit::{NSApplication, NSPasteboard, NSPasteboardTypeString, NSView, NSWindow};
@@ -91,6 +91,10 @@ impl WindowHandle {
9191
pub fn is_open(&self) -> bool {
9292
self.state.closed.get()
9393
}
94+
95+
pub fn size(&self) -> WindowSize {
96+
WindowSize::from_logical(self.state.size.get(), self.state.scale_factor.get())
97+
}
9498
}
9599

96100
fn create_window_with_options(

src/window.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ impl WindowHandle {
2020
Ok(())
2121
}
2222

23+
/// The current size of the window.
24+
pub fn size(&self) -> WindowSize {
25+
self.window_handle.size()
26+
}
27+
2328
/// Close the window
2429
pub fn close(self) {
2530
drop(self)

0 commit comments

Comments
 (0)