Skip to content

Commit 25b77a9

Browse files
committed
[*] refactor
1 parent a0796f7 commit 25b77a9

File tree

20 files changed

+93
-31
lines changed

20 files changed

+93
-31
lines changed

lib/video-editor/src/filters/subtitle/style.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ pub struct SubtitleStyle {
4343

4444
pub font_path: PathBuf,
4545

46+
#[derivative(Default(value = "String::new()"))]
47+
pub font_family: String,
48+
4649
pub background_color: Option<Rgba<u8>>,
4750

4851
#[derivative(Default(value = "Some(Rgba([255, 255, 255, 255]))"))]

lib/video-editor/src/filters/subtitle/style/font_path.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ use std::path::PathBuf;
99
pub struct FontPathFilter {
1010
#[derivative(Default(value = "PathBuf::from(\"\")"))]
1111
pub font_path: PathBuf,
12+
13+
#[derivative(Default(value = "String::new()"))]
14+
pub font_family: String,
1215
}
1316

1417
impl FontPathFilter {
1518
pub const NAME: &'static str = "font path";
1619

17-
pub fn new(font_path: PathBuf) -> Self {
18-
Self { font_path }
20+
pub fn new(font_path: PathBuf, font_family: String) -> Self {
21+
Self { font_path, font_family }
1922
}
2023
}
2124

@@ -24,5 +27,6 @@ impl SubtitleFilter for FontPathFilter {
2427

2528
fn apply(&self, style: &mut SubtitleStyle) {
2629
style.font_path = self.font_path.clone();
30+
style.font_family = self.font_family.clone();
2731
}
2832
}

todo.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
## 问题
2-
- subtitle需要重新设计
3-
4-
- preview相关界面中,没有filter的也会进入编辑模式
2+
- 添加字幕文件时需要给每个segment添加默认filter
3+
- subtile设置的字体没有显示
54

65
## 待验证
7-
- 选中的font没有显示在字体列表中
8-
- 选中segment边框颜色不能写,可以增加边框宽度
9-
- font列表刷新成功应该显示toast
106

117
- 视频轨道分离字幕
128

wayshot/src/logic/video_editor/common_type.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ pub struct MarkedFiltersConfig {
174174
pub struct FontStyleConfig {
175175
pub font_path: String,
176176

177+
pub font_family: String,
178+
177179
#[derivative(Default(value = "20"))]
178180
pub font_size: i32,
179181

@@ -221,6 +223,7 @@ impl From<UIFontStyle> for FontStyleConfig {
221223
fn from(ui: UIFontStyle) -> Self {
222224
Self {
223225
font_path: ui.font_path.font_path.into(),
226+
font_family: ui.font_path.font_family.into(),
224227
font_size: ui.font_size.font_size,
225228
padding: ui.padding.padding,
226229
margin_vertical: ui.margin_vertical.margin,
@@ -253,6 +256,7 @@ impl From<FontStyleConfig> for UIFontStyle {
253256
Self {
254257
font_path: FontPathDetail {
255258
font_path: config.font_path.into(),
259+
font_family: config.font_family.into(),
256260
},
257261
font_size: FontSizeDetail {
258262
font_size: config.font_size,

wayshot/src/logic/video_editor/filters/conversion.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,7 @@ impl From<FontPathFilter> for UIFontPathDetail {
584584
fn from(f: FontPathFilter) -> Self {
585585
Self {
586586
font_path: f.font_path.to_string_lossy().to_string().into(),
587+
font_family: f.font_family.into(),
587588
}
588589
}
589590
}
@@ -592,6 +593,7 @@ impl From<UIFontPathDetail> for FontPathFilter {
592593
fn from(d: UIFontPathDetail) -> Self {
593594
Self {
594595
font_path: PathBuf::from(d.font_path.as_str()),
596+
font_family: d.font_family.as_str().into(),
595597
}
596598
}
597599
}

wayshot/src/logic/video_editor/filters/subtitle.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ fn extract_font_style_from_filters(filters: &[Arc<SubtitleFilterWrapper>]) -> Fo
298298
if filter_name == FontPathFilter::NAME {
299299
if let Some(f) = filter.as_any().downcast_ref::<FontPathFilter>() {
300300
config.font_path = f.font_path.to_string_lossy().to_string();
301+
config.font_family = f.font_family.clone();
301302
}
302303
} else if filter_name == FontSizeFilter::NAME {
303304
if let Some(f) = filter.as_any().downcast_ref::<FontSizeFilter>() {

wayshot/src/logic/video_editor/preview.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -211,26 +211,31 @@ fn update_edit_mode_for_seek(ui: &AppWindow, position: Duration) {
211211
return;
212212
}
213213

214-
// Find the segment under the playhead first
215-
let segment_under_playhead = with_history_manager(|state| {
216-
for (track_idx, track) in state.tracks_manager.iter().enumerate() {
217-
for (seg_idx, segment) in track.segments().iter().enumerate() {
218-
let seg_start = segment.timeline_offset;
219-
let seg_end = seg_start + segment.duration;
220-
if position >= seg_start && position < seg_end {
221-
return Some((track_idx, seg_idx));
214+
let edited_track_index = global_store!(ui).get_video_editor_current_edited_track_index();
215+
216+
let edited_segment_at_position = if edited_track_index >= 0 {
217+
with_history_manager(|state| {
218+
if let Some(track) = state.tracks_manager.iter().nth(edited_track_index as usize) {
219+
for (seg_idx, segment) in track.segments().iter().enumerate() {
220+
let seg_start = segment.timeline_offset;
221+
let seg_end = seg_start + segment.duration;
222+
if position >= seg_start && position < seg_end {
223+
return Some((edited_track_index as usize, seg_idx));
224+
}
222225
}
223226
}
224-
}
227+
None
228+
})
229+
} else {
225230
None
226-
});
231+
};
227232

228-
// Check if the segment under playhead is selected
229-
let is_edit_mode = if let Some((track_idx, seg_idx)) = segment_under_playhead {
233+
// Check if the edited segment is selected
234+
let is_edit_mode = if let Some((track_idx, seg_idx)) = edited_segment_at_position {
230235
let selected_segments = get_selected_segment_indices(ui);
231236
selected_segments.contains(&(track_idx, seg_idx))
232237
} else {
233-
false
238+
false // Edited track has no segment at this position
234239
};
235240

236241
global_ve_filter!(ui).set_is_in_edit_mode(is_edit_mode);

wayshot/src/logic/video_editor/subtitle.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,10 @@ fn create_filters_from_font_style(config: &FontStyleConfig) -> Vec<Box<dyn Subti
119119
let mut filters: Vec<Box<dyn SubtitleFilter>> = Vec::new();
120120

121121
if !config.font_path.is_empty() {
122-
filters.push(Box::new(FontPathFilter::new(PathBuf::from(
123-
&config.font_path,
124-
))));
122+
filters.push(Box::new(FontPathFilter::new(
123+
PathBuf::from(&config.font_path),
124+
config.font_family.clone(),
125+
)));
125126
}
126127

127128
if config.font_size > 0 {

wayshot/ui/panel/desktop/video-editor/filter.slint

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ export struct BackgroundColorDetail {
236236
}
237237

238238
export struct FontPathDetail {
239+
font-family: string,
239240
font-path: string,
240241
}
241242

wayshot/ui/panel/desktop/video-editor/preview/preview-crop-layers.slint

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ export component PreviewCropLayers inherits Rectangle {
2929
width: img.width;
3030
height: img.height;
3131

32+
TouchArea {
33+
scroll-event(event) => {
34+
accept
35+
}
36+
}
37+
3238
img := Image {
3339
private property <length> parent-width: rec.width;
3440
private property <length> parent-height: rec.height;

0 commit comments

Comments
 (0)