-
Notifications
You must be signed in to change notification settings - Fork 115
Expand file tree
/
Copy pathgui.rs
More file actions
100 lines (78 loc) · 2.84 KB
/
Copy pathgui.rs
File metadata and controls
100 lines (78 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
use crate::window_handler::OpenWindowExample;
use crate::ExamplePluginMainThread;
use baseview::dpi::PhysicalSize;
use baseview::gl::GlConfig;
use baseview::{WindowHandle, WindowOpenOptions};
use clack_extensions::gui::{
GuiApiType, GuiConfiguration, GuiResizeHints, GuiSize, PluginGuiImpl, Window as ClapWindow,
};
use clack_plugin::plugin::PluginError;
#[allow(deprecated)]
use raw_window_handle::HasRawWindowHandle;
pub struct ExamplePluginGui {
handle: WindowHandle,
}
impl PluginGuiImpl for ExamplePluginMainThread {
fn is_api_supported(&mut self, configuration: GuiConfiguration) -> bool {
!configuration.is_floating
&& Some(configuration.api_type) == GuiApiType::default_for_current_platform()
}
fn get_preferred_api(&mut self) -> Option<GuiConfiguration<'_>> {
Some(GuiConfiguration {
api_type: GuiApiType::default_for_current_platform()?,
is_floating: false,
})
}
fn create(&mut self, _configuration: GuiConfiguration) -> Result<(), PluginError> {
// Delay creation until set_parent
Ok(())
}
fn destroy(&mut self) {
let Some(gui) = self.gui.take() else { return };
gui.handle.close()
}
fn set_scale(&mut self, _scale: f64) -> Result<(), PluginError> {
// Unsupported
Ok(())
}
fn get_size(&mut self) -> Option<GuiSize> {
// Unsupported
Some(GuiSize { width: 400, height: 200 })
}
fn can_resize(&mut self) -> bool {
false // Non-resizeable windows not supported yet
}
fn get_resize_hints(&mut self) -> Option<GuiResizeHints> {
None // Not supported yet
}
fn adjust_size(&mut self, _size: GuiSize) -> Option<GuiSize> {
None // Not supported yet
}
fn set_size(&mut self, _size: GuiSize) -> Result<(), PluginError> {
Ok(()) // Not supported yet
}
#[allow(deprecated)]
fn set_parent(&mut self, window: ClapWindow) -> Result<(), PluginError> {
let parent = window.raw_window_handle()?;
let parent = unsafe { raw_window_handle::WindowHandle::borrow_raw(parent) };
let options = WindowOpenOptions::new()
.with_size(PhysicalSize::new(400, 200))
.with_gl_config(GlConfig::default())
.with_parent(&parent);
let window = baseview::create_window(options, OpenWindowExample::new)?;
self.gui = Some(ExamplePluginGui { handle: window });
Ok(())
}
fn set_transient(&mut self, _window: ClapWindow) -> Result<(), PluginError> {
unimplemented!() // Not supported yet
}
fn suggest_title(&mut self, _title: &str) {
// Not supported yet
}
fn show(&mut self) -> Result<(), PluginError> {
Ok(()) // Not supported yet
}
fn hide(&mut self) -> Result<(), PluginError> {
Ok(()) // Not supported yet
}
}