11use crate :: window_handler:: OpenWindowExample ;
22use crate :: ExamplePluginMainThread ;
3- use baseview:: dpi:: PhysicalSize ;
3+ use baseview:: dpi:: { LogicalSize , PhysicalSize , Size } ;
44use baseview:: gl:: GlConfig ;
55use baseview:: { WindowHandle , WindowOpenOptions , WindowSize } ;
66use clack_extensions:: gui:: {
@@ -39,8 +39,12 @@ impl PluginGuiImpl for ExamplePluginMainThread {
3939 gui. handle . close ( )
4040 }
4141
42- fn set_scale ( & mut self , _scale : f64 ) -> Result < ( ) , PluginError > {
43- // Unsupported
42+ fn set_scale ( & mut self , scale : f64 ) -> Result < ( ) , PluginError > {
43+ let Some ( gui) = & self . gui else {
44+ return Err ( PluginError :: Message ( "set_scale called without a GUI active" ) ) ;
45+ } ;
46+ gui. handle . suggest_scale_factor ( scale) ?;
47+
4448 Ok ( ( ) )
4549 }
4650
@@ -49,19 +53,26 @@ impl PluginGuiImpl for ExamplePluginMainThread {
4953 }
5054
5155 fn can_resize ( & mut self ) -> bool {
52- false // Non-resizeable windows not supported yet
56+ true // Non-resizeable windows not supported yet
5357 }
5458
5559 fn get_resize_hints ( & mut self ) -> Option < GuiResizeHints > {
5660 None // Not supported yet
5761 }
5862
59- fn adjust_size ( & mut self , _size : GuiSize ) -> Option < GuiSize > {
60- None // Not supported yet
63+ fn adjust_size ( & mut self , size : GuiSize ) -> Option < GuiSize > {
64+ Some ( size ) // Not supported yet
6165 }
6266
63- fn set_size ( & mut self , _size : GuiSize ) -> Result < ( ) , PluginError > {
64- Ok ( ( ) ) // Not supported yet
67+ fn set_size ( & mut self , size : GuiSize ) -> Result < ( ) , PluginError > {
68+ let Some ( gui) = & self . gui else {
69+ return Err ( PluginError :: Message ( "set_size called without a GUI active" ) ) ;
70+ } ;
71+
72+ let size = gui_size_to_window_size ( size) ;
73+ gui. handle . resize ( size) ?;
74+
75+ Ok ( ( ) )
6576 }
6677
6778 #[ allow( deprecated) ]
@@ -111,3 +122,14 @@ fn window_size_to_gui_size(size: WindowSize) -> GuiSize {
111122 GuiSize { width : size. width , height : size. height }
112123 }
113124}
125+
126+ fn gui_size_to_window_size ( size : GuiSize ) -> Size {
127+ #[ cfg( target_os = "macos" ) ]
128+ {
129+ Size :: Logical ( LogicalSize :: new ( size. width , size. height ) . cast ( ) )
130+ }
131+ #[ cfg( not( target_os = "macos" ) ) ]
132+ {
133+ Size :: Physical ( PhysicalSize :: new ( size. width , size. height ) )
134+ }
135+ }
0 commit comments