aspect ratio presets for capture frame
This commit is contained in:
@@ -604,6 +604,21 @@ fn hide_overlay(app: AppHandle) -> Result<(), String> {
|
||||
win.hide().map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn set_overlay_size(app: AppHandle, width: u32, height: u32) -> Result<(), String> {
|
||||
use tauri::{LogicalSize, Size};
|
||||
let win = app
|
||||
.get_webview_window("overlay")
|
||||
.ok_or_else(|| "overlay window not found".to_string())?;
|
||||
// Add the titlebar + border to the logical content size so the captured
|
||||
// region matches the requested preset.
|
||||
let final_w = width as f64 + (OVERLAY_BORDER_LOGICAL_PX * 2.0);
|
||||
let final_h =
|
||||
height as f64 + OVERLAY_TITLEBAR_LOGICAL_PX + (OVERLAY_BORDER_LOGICAL_PX * 2.0);
|
||||
win.set_size(Size::Logical(LogicalSize::new(final_w, final_h)))
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn get_overlay_rect(app: AppHandle) -> Result<CaptureRect, String> {
|
||||
let win = app
|
||||
@@ -857,6 +872,7 @@ pub fn run() {
|
||||
open_url,
|
||||
show_overlay,
|
||||
hide_overlay,
|
||||
set_overlay_size,
|
||||
get_overlay_rect,
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
|
||||
+22
-1
@@ -271,10 +271,20 @@
|
||||
capture frame: {useFrame ? "on" : "off"}
|
||||
</button>
|
||||
</section>
|
||||
{#if useFrame}
|
||||
<div class="presets">
|
||||
<span class="presets-label">preset:</span>
|
||||
<button class="small" onclick={() => api.setOverlaySize(1280, 720)}>720p</button>
|
||||
<button class="small" onclick={() => api.setOverlaySize(1920, 1080)}>1080p</button>
|
||||
<button class="small" onclick={() => api.setOverlaySize(800, 800)}>1:1</button>
|
||||
<button class="small" onclick={() => api.setOverlaySize(540, 960)}>9:16</button>
|
||||
</div>
|
||||
{/if}
|
||||
<p class="hint">
|
||||
{#if useFrame}
|
||||
The green frame stays visible during recording but is excluded from
|
||||
the capture itself. Drag it to position the region.
|
||||
the capture itself. Drag it to position the region, or pick a preset
|
||||
above for common dimensions.
|
||||
{:else}
|
||||
Captures your full primary monitor. Toggle the capture frame on to
|
||||
record a region instead.
|
||||
@@ -617,6 +627,17 @@
|
||||
border-color: #4a8;
|
||||
color: #4a8;
|
||||
}
|
||||
.presets {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
margin: 0.75rem 0 0;
|
||||
justify-content: center;
|
||||
}
|
||||
.presets-label {
|
||||
font-size: 0.8rem;
|
||||
color: #888;
|
||||
}
|
||||
button.stop {
|
||||
background: #c33;
|
||||
border-color: #c33;
|
||||
|
||||
@@ -109,6 +109,8 @@ export const api = {
|
||||
revealInExplorer: (path: string) => invoke<void>("reveal_in_explorer", { path }),
|
||||
showOverlay: () => invoke<void>("show_overlay"),
|
||||
hideOverlay: () => invoke<void>("hide_overlay"),
|
||||
setOverlaySize: (width: number, height: number) =>
|
||||
invoke<void>("set_overlay_size", { width, height }),
|
||||
getOverlayRect: () => invoke<CaptureRect>("get_overlay_rect"),
|
||||
extractThumbnails: (fps: number) =>
|
||||
invoke<string[]>("extract_thumbnails", { fps }),
|
||||
|
||||
Reference in New Issue
Block a user