feat: adiciona suporte para sugestão de velocidade com base nas durações de vídeo e faixas de áudio/legenda

This commit is contained in:
2026-03-01 14:54:49 -03:00
parent 1ef47b3a07
commit e70612f5ea
5 changed files with 167 additions and 5 deletions
+38
View File
@@ -10,6 +10,8 @@ pub struct SyncOffsetField {
/// Percentual de velocidade original (ex: "99.983" → scale 0.99983). Padrão: "100.00".
pub drift_raw: String,
drift_error: Option<String>,
/// Velocidade sugerida calculada externamente (% inteiro). Exibida como botão 💡.
suggestion_pct: Option<f64>,
}
impl SyncOffsetField {
@@ -20,9 +22,16 @@ impl SyncOffsetField {
error: None,
drift_raw: "100.00".to_string(),
drift_error: None,
suggestion_pct: None,
}
}
/// Define a velocidade sugerida (%) calculada a partir das durações do vídeo e da faixa.
/// `None` remove o botão de sugestão.
pub fn set_suggestion(&mut self, pct: Option<f64>) {
self.suggestion_pct = pct;
}
/// Renderiza o campo de offset (sem o campo de drift).
pub fn ui(&mut self, ui: &mut egui::Ui, label: &str) -> bool {
let mut changed = false;
@@ -60,6 +69,35 @@ impl SyncOffsetField {
"Instale MKVToolNix para usar correção de drift de velocidade.",
);
}
// Botão de sugestão calculada a partir das durações
if mkvmerge_available {
if let Some(pct) = self.suggestion_pct {
let warn = (pct - 100.0).abs() > 0.5;
let hover = format!(
"Velocidade sugerida: {:.3}%{}",
pct,
if warn {
"\n⚠ Diferença >0.5% — verifique se é o mesmo conteúdo"
} else {
" — clique para aplicar"
}
);
let color = if warn {
egui::Color32::from_rgb(255, 160, 0)
} else {
egui::Color32::from_rgb(80, 180, 80)
};
if ui
.add(egui::Button::new(
egui::RichText::new("💡").color(color).small(),
))
.on_hover_text(hover)
.clicked()
{
self.drift_raw = format!("{:.3}", pct);
}
}
}
if let Ok(pct) = self.drift_raw.trim().parse::<f64>() {
if (pct - 100.0).abs() > 0.001 {
ui.colored_label(