feat: zoom in/out with Cmd+/Cmd-/Cmd+0
This commit is contained in:
@@ -418,6 +418,11 @@ async fn unbind_face(uuid: String, face_id: String, file_uuid: String) -> Result
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command(rename_all = "camelCase")]
|
||||
async fn set_zoom(window: tauri::WebviewWindow, zoom_factor: f64) -> Result<(), String> {
|
||||
window.set_zoom(zoom_factor).map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_shell::init())
|
||||
@@ -437,7 +442,8 @@ fn main() {
|
||||
get_face_candidates,
|
||||
merge_identities,
|
||||
bind_face,
|
||||
unbind_face
|
||||
unbind_face,
|
||||
set_zoom
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
|
||||
28
src/App.vue
28
src/App.vue
@@ -32,6 +32,34 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, onUnmounted, ref } from 'vue'
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
|
||||
let currentZoom = ref(1.0)
|
||||
|
||||
function handleKeydown(e: KeyboardEvent) {
|
||||
if ((e.metaKey || e.ctrlKey)) {
|
||||
if (e.key === '=' || e.key === '+') {
|
||||
e.preventDefault()
|
||||
currentZoom.value = Math.min(currentZoom.value + 0.1, 3.0)
|
||||
invoke('set_zoom', { zoomFactor: currentZoom.value }).catch(() => {})
|
||||
} else if (e.key === '-') {
|
||||
e.preventDefault()
|
||||
currentZoom.value = Math.max(currentZoom.value - 0.1, 0.5)
|
||||
invoke('set_zoom', { zoomFactor: currentZoom.value }).catch(() => {})
|
||||
} else if (e.key === '0') {
|
||||
e.preventDefault()
|
||||
currentZoom.value = 1.0
|
||||
invoke('set_zoom', { zoomFactor: 1.0 }).catch(() => {})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => document.addEventListener('keydown', handleKeydown))
|
||||
onUnmounted(() => document.removeEventListener('keydown', handleKeydown))
|
||||
</script>
|
||||
|
||||
<style>
|
||||
@import './assets/wordpress-exact.css';
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user