aspect ratio presets for capture frame

This commit is contained in:
2026-05-12 01:40:27 +03:00
parent 63e41297e9
commit c1d474325f
3 changed files with 40 additions and 1 deletions
+16
View File
@@ -604,6 +604,21 @@ fn hide_overlay(app: AppHandle) -> Result<(), String> {
win.hide().map_err(|e| e.to_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] #[tauri::command]
fn get_overlay_rect(app: AppHandle) -> Result<CaptureRect, String> { fn get_overlay_rect(app: AppHandle) -> Result<CaptureRect, String> {
let win = app let win = app
@@ -857,6 +872,7 @@ pub fn run() {
open_url, open_url,
show_overlay, show_overlay,
hide_overlay, hide_overlay,
set_overlay_size,
get_overlay_rect, get_overlay_rect,
]) ])
.run(tauri::generate_context!()) .run(tauri::generate_context!())
+22 -1
View File
@@ -271,10 +271,20 @@
capture frame: {useFrame ? "on" : "off"} capture frame: {useFrame ? "on" : "off"}
</button> </button>
</section> </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"> <p class="hint">
{#if useFrame} {#if useFrame}
The green frame stays visible during recording but is excluded from 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} {:else}
Captures your full primary monitor. Toggle the capture frame on to Captures your full primary monitor. Toggle the capture frame on to
record a region instead. record a region instead.
@@ -617,6 +627,17 @@
border-color: #4a8; border-color: #4a8;
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 { button.stop {
background: #c33; background: #c33;
border-color: #c33; border-color: #c33;
+2
View File
@@ -109,6 +109,8 @@ export const api = {
revealInExplorer: (path: string) => invoke<void>("reveal_in_explorer", { path }), revealInExplorer: (path: string) => invoke<void>("reveal_in_explorer", { path }),
showOverlay: () => invoke<void>("show_overlay"), showOverlay: () => invoke<void>("show_overlay"),
hideOverlay: () => invoke<void>("hide_overlay"), hideOverlay: () => invoke<void>("hide_overlay"),
setOverlaySize: (width: number, height: number) =>
invoke<void>("set_overlay_size", { width, height }),
getOverlayRect: () => invoke<CaptureRect>("get_overlay_rect"), getOverlayRect: () => invoke<CaptureRect>("get_overlay_rect"),
extractThumbnails: (fps: number) => extractThumbnails: (fps: number) =>
invoke<string[]>("extract_thumbnails", { fps }), invoke<string[]>("extract_thumbnails", { fps }),