1
1
use std:: sync:: Mutex ;
2
2
3
3
use serde:: { Deserialize , Serialize } ;
4
- use tauri:: { webview, LogicalPosition , LogicalSize , Manager , Result } ;
4
+ use tauri:: {
5
+ webview, LogicalPosition , LogicalSize , Manager , Result ,
6
+ } ;
5
7
6
8
use crate :: { api:: resp:: Response , r_ok} ;
7
9
#[ derive( Default , Serialize , Deserialize , Eq , PartialEq , Debug , Clone ) ]
8
10
pub struct Tab {
9
11
pub id : String ,
10
12
pub name : Option < String > ,
11
13
}
12
- static TAB_BAR_HEIGHT : u32 = 50 ;
14
+ static TAB_BAR_HEIGHT : f64 = 50. ;
13
15
#[ tauri:: command]
14
16
pub async fn tab_change ( app : tauri:: AppHandle , tab : Tab ) -> Result < Response < ( ) > > {
15
17
// first we should check webview is created? if it has, show it hidden others.
@@ -34,10 +36,12 @@ pub async fn tab_change(app: tauri::AppHandle, tab: Tab) -> Result<Response<()>>
34
36
& tab. id ,
35
37
tauri:: WebviewUrl :: App ( format ! ( "/#/tab/{}/main/info" , & tab. id) . parse ( ) . unwrap ( ) ) ,
36
38
) ;
37
- let size = view. inner_size ( ) ?;
39
+ let fac = view. current_monitor ( ) ?. unwrap ( ) . scale_factor ( ) ;
40
+ let size = view. inner_size ( ) ?. to_logical :: < f64 > ( fac) ;
41
+ println ! ( "{:#?}" , size) ;
38
42
view. add_child (
39
43
v,
40
- LogicalPosition :: new ( 0 , TAB_BAR_HEIGHT ) ,
44
+ LogicalPosition :: < f64 > :: new ( 0. , TAB_BAR_HEIGHT ) ,
41
45
LogicalSize :: new ( size. width , size. height - TAB_BAR_HEIGHT ) ,
42
46
) ?;
43
47
// here we hide other views
@@ -60,8 +64,9 @@ pub async fn tab_change(app: tauri::AppHandle, tab: Tab) -> Result<Response<()>>
60
64
if tab. id == "main" {
61
65
return Ok ( r_ok ! ( ( ) , None ) ) ;
62
66
}
63
- vb. set_position ( LogicalPosition :: new ( 0 , TAB_BAR_HEIGHT ) ) ?;
64
- let size = view. inner_size ( ) ?;
67
+ vb. set_position ( LogicalPosition :: < f64 > :: new ( 0. , TAB_BAR_HEIGHT ) ) ?;
68
+ let fac = view. current_monitor ( ) ?. unwrap ( ) . scale_factor ( ) ;
69
+ let size = view. inner_size ( ) ?. to_logical :: < f64 > ( fac) ;
65
70
vb. set_size ( LogicalSize :: new ( size. width , size. height - TAB_BAR_HEIGHT ) ) ?;
66
71
vb. show ( ) ?;
67
72
}
@@ -116,8 +121,9 @@ pub async fn tab_view_resize(app: tauri::AppHandle, id: String) -> Result<Respon
116
121
if let Some ( vb) = app. app_handle ( ) . get_webview ( & id) {
117
122
// first we should check webview is created? if it has, show it and hidden others.
118
123
let view = app. app_handle ( ) . get_window ( "main" ) . unwrap ( ) ;
119
- vb. set_position ( LogicalPosition :: new ( 0 , TAB_BAR_HEIGHT ) ) ?;
120
- let size = view. inner_size ( ) ?;
124
+ vb. set_position ( LogicalPosition :: new ( 0. , TAB_BAR_HEIGHT ) ) ?;
125
+ let fac = view. current_monitor ( ) ?. unwrap ( ) . scale_factor ( ) ;
126
+ let size = view. inner_size ( ) ?. to_logical :: < f64 > ( fac) ;
121
127
vb. set_size ( LogicalSize :: new ( size. width , size. height - TAB_BAR_HEIGHT ) ) ?;
122
128
vb. show ( ) ?;
123
129
}
0 commit comments