-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib:border - del_border + does not work with “acceptFirstMouse”: true #141
Comments
I added two new functions, See the PR: #149 usage: let border = window.border().expect("window has no border");
// to accept the first mouse click
border.set_accepts_first_mouse(true);
// to remove the border from the parent view
border.remove(); I have renamed the |
Let me know if this resolves your issue. Thank you. |
I tried different options but couldn't get this to work inside
If you set the border inside fn switch_to_panel(app_handle: &AppHandle) {
let window = app_handle.get_webview_window("main").unwrap();
let panel = window.to_panel().unwrap();
let delegate = panel_delegate!(MyPanelDelegate {
window_did_become_key,
window_did_resign_key,
});
window.add_border(None);
let border = window.border().expect("window has no border");
border.set_accepts_first_mouse(true);
let window_clone = window.clone();
window.listen("window:pin:toggle", move |event| {
let border = window_clone.border().expect("window has no border");
if data.is_pinned {
border.set_accepts_first_mouse(true);
border.set_line_width(3.0);
border.set_line_color(Color(36, 211, 238, 255));
border.set_inset(0.0);
border.set_corner_radius(12.0);
} else {
border.remove();
}
}
.... |
try and send it to the main thread. do all the window appearance stuff on the main thread: app_handle.run_on_main_thread() |
I'm not quite sure where to use it |
let handle = app_handle.clone();
window.listen("window:pin:toggle", move |event| {
let app_handle = handle.clone();
handle.run_on_main_thread(move || {
let window = app_handle.get_webview_window("window name" );
let border = window.border().expect("window has no border");
if data.is_pinned {
border.set_accepts_first_mouse(true);
border.set_line_width(3.0);
border.set_line_color(Color(36, 211, 238, 255));
border.set_inset(0.0);
border.set_corner_radius(12.0);
} else {
border.remove();
}
});
} roughly like that. inside the |
It works only once, then at each event instead of the set color, the border is layered with gray color, I think there is a conflict because at each event the border is added |
Since I don't have a clear picture of your code, I can suggest how I think it should work:
|
you can always check if border already exits to prevent adding duplicates: if window.border().is_none() {
// add your border
window.add_border(None);
} |
Yes, this option works, thanks. Only it seems let app_handle = handle.clone();
let _ = handle.run_on_main_thread(move || {
let window = app_handle.get_webview_window("main").unwrap();
if window.border().is_none() {
window.add_border(None);
}
let border = window.border().expect("window has no border");
border.set_accepts_first_mouse(true);
if data.is_pinned {
border.set_line_width(5.0);
border.set_line_color(Color(36, 211, 238, 255));
border.set_inset(0.0);
border.set_corner_radius(12.0);
border.set_auto_resizing();
} else {
border.remove();
}
}); |
remove the |
this. |
I can implement a |
This one will be better. |
well, but not really, it's better to reuse objects than to create and destroy them every time. |
Here is the commit 44e3d9f. Help test it. Let me know how it goes. run |
If you remove |
I'm not sure how your setup is. However, I think you should only call |
The color change just refuses to work. Only the initial border is let window = app_handle.get_webview_window("main").unwrap();
window.add_border(None);
let border = window.border().expect("window has no border");
border.set_accepts_first_mouse(true);
border.set_line_width(5.0);
border.set_line_color(Color(36, 211, 238, 255));
border.set_inset(0.0);
border.set_corner_radius(12.0);
border.set_auto_resizing();
switch_to_panel(app_handle);
setup_shortcut(app_handle);
Ok(())
})
.run(tauri::generate_context!())
.expect("unable to run Tauri application");
...
let app_handle = handle.clone();
let _ = handle.run_on_main_thread(move || {
let window = app_handle.get_webview_window("main").unwrap();
let border = window.border().expect("window has no border");
if data.is_pinned {
border.set_line_color(Color(36, 111, 111, 111));
} else {
border.set_line_color(Color(56, 67, 145, 123));
}
}); |
I'll play around with this to see what's wrong. |
Hi Victor, can you tell me how to delete a border? The current solution doesn't work
And it seems
set_auto_resizing
doesn't work, even if you specify it manually, border overlaps content if you specify for exampleline_width: 10.0
.Found another problem,
"acceptFirstMouse": true
stops working after settingadd_border
.Looks like
use tauri::Color;
is not the correct use, usetauri::window::Color;
.The text was updated successfully, but these errors were encountered: