Skip to content

Commit 37c5727

Browse files
committed
[*] add video editor ui
1 parent db775ac commit 37c5727

File tree

5 files changed

+101
-10
lines changed

5 files changed

+101
-10
lines changed

wayshot/ui/base/playhead.slint

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { Theme } from "theme.slint";
2+
import { Util } from "util.slint";
3+
4+
export component Playhead inherits Rectangle {
5+
out property pressed <=> ta.pressed;
6+
out property mouse-x <=> ta.mouse-x;
7+
out property mouse-y <=> ta.mouse-y;
8+
out property pressed-x <=> ta.pressed-x;
9+
out property pressed-y <=> ta.pressed-y;
10+
in-out property line-color <=> line.background;
11+
12+
in-out property <length> handle-width: Theme.default-font-size;
13+
in-out property <length> handle-height: Theme.default-font-size * Theme.golden-ratio;
14+
in-out property <length> line-width: Theme.default-border-width * 2;
15+
16+
callback moved <=> ta.moved;
17+
callback clicked <=> ta.clicked;
18+
19+
width: handle-width;
20+
21+
ta := TouchArea {
22+
mouse-cursor: MouseCursor.pointer;
23+
}
24+
25+
Path {
26+
y: -1px;
27+
width: handle-width;
28+
height: handle-height;
29+
fill: line.background;
30+
31+
MoveTo {
32+
x: 0;
33+
y: 0;
34+
}
35+
36+
LineTo {
37+
x: handle-width / line.width;
38+
y: handle-height / 1px;
39+
}
40+
41+
LineTo {
42+
x: handle-width / 1px;
43+
y: 0;
44+
}
45+
46+
Close { }
47+
}
48+
49+
line := Rectangle {
50+
background: Theme.thirdly-brand-color;
51+
width: line-width;
52+
}
53+
}

wayshot/ui/base/widgets.slint

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ import { AudioLevel } from "audio-level.slint";
141141
import { GentleBackground } from "gentle-backgound.slint";
142142
import { SoundWaveForm } from "sound-wave-form.slint";
143143
import { MovingDivider } from "moving-divider.slint";
144+
import { Playhead } from "playhead.slint";
144145

145146
export {
146147
AppPosType,
@@ -291,4 +292,5 @@ export {
291292
GentleBackground,
292293
SoundWaveForm,
293294
MovingDivider,
295+
Playhead,
294296
}

wayshot/ui/logic.slint

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,14 +275,19 @@ export global Logic {
275275
callback video-editor-toggle-locked-track(index: int);
276276
callback video-editor-toggle-hiding-track(index: int);
277277
callback video-editor-toggle-muted-track(index: int);
278-
pure callback video-editor-contain-audio-track(index: int) -> bool;
279-
pure callback video-editor-contain-subtitle-track(index: int) -> bool;
280-
pure callback video-editor-is-selected-track(selected-tracks: [int], index: int) -> bool;
281278
callback video-editor-detach-audio-track(index: int);
282279
callback video-editor-detach-subtitle-track(index: int);
283280
callback video-editor-add-selected-track(index: int);
284281
callback video-editor-select-all-tracks();
285282

283+
pure callback video-editor-contain-audio-track(index: int) -> bool;
284+
pure callback video-editor-contain-subtitle-track(index: int) -> bool;
285+
pure callback video-editor-is-selected-track(selected-tracks: [int], index: int) -> bool;
286+
pure callback video-editor-calc-timeline-offset(index: int, total-index: int) -> string;
287+
video-editor-calc-timeline-offset(index, total-index) => {
288+
return "00:00:00";
289+
}
290+
286291
pure public function fps-to-int(fps: Fps) -> int {
287292
if (fps == Fps.Fps24) {
288293
return 24;

wayshot/ui/panel/desktop/video-editor/tracks/timeline.slint

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ import {
1313

1414
export component Timeline inherits Rectangle {
1515
in property <length> header-width;
16+
in property <length> timeline-width;
17+
out property pressed-x <=> ta.pressed-x;
1618
in-out property viewport-x <=> flick.viewport-x;
1719
in-out property viewport-width <=> flick.viewport-width;
1820
private property <length> label-width: Theme.default-font-size * 6;
1921

22+
callback clicked <=> ta.clicked;
23+
2024
height: Theme.icon-size * 1.3;
2125
background: Theme.table-item-second;
2226

@@ -26,7 +30,7 @@ export component Timeline inherits Rectangle {
2630
width: max(header-width, ouput-lb.preferred-width);
2731

2832
ouput-lb := Label {
29-
text: Logic.tr("Track");
33+
text: Logic.tr("Tracks");
3034
}
3135

3236
TouchArea {
@@ -37,8 +41,12 @@ export component Timeline inherits Rectangle {
3741
}
3842

3943
flick := Flickable {
44+
interactive: false;
45+
4046
HorizontalLayout {
41-
for index in root.width / label-width: HorizontalLayout {
47+
private property <int> total-index: root.timeline-width / label-width;
48+
49+
for index in total-index: HorizontalLayout {
4250
spacing: Theme.spacing;
4351

4452
VerticalLayout {
@@ -53,12 +61,14 @@ export component Timeline inherits Rectangle {
5361
}
5462

5563
Label {
56-
text: "00:00:00";
64+
text: Logic.video-editor-calc-timeline-offset(index, total-index);
5765
font-size: Theme.default-font-size * 0.8;
5866
color: Theme.regular-text-color;
5967
}
6068
}
6169
}
70+
71+
ta := TouchArea { }
6272
}
6373
}
6474
}

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

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ListView } from "std-widgets.slint";
1+
import { ListView, StyleMetrics } from "std-widgets.slint";
22
import {
33
Theme,
44
Store,
@@ -14,6 +14,7 @@ import {
1414
import {
1515
Divider,
1616
IconBtn,
17+
Playhead,
1718
PopupActionEntry,
1819
PopupActionSetting,
1920
ClickAndEditLabel,
@@ -58,7 +59,7 @@ component TrackSegment inherits Rectangle {
5859
index: index;
5960
segment: segment;
6061

61-
width: 500px;
62+
width: 5000px;
6263
background: green;
6364
}
6465
}
@@ -127,9 +128,15 @@ export component Tracks inherits Rectangle {
127128
spacing: Theme.spacing;
128129

129130
timeline := Timeline {
130-
header-width: tl.track-header-width;
131-
viewport-width: tl.viewport-width;
132131
viewport-x: tl.viewport-x;
132+
viewport-width: tl.viewport-width;
133+
header-width: tl.track-header-width;
134+
timeline-width: tl.viewport-width;
135+
136+
clicked => {
137+
let offset-x = self.pressed-x - abs(self.viewport-x);
138+
playhead.x = clamp(playhead.start-x + offset-x, playhead.start-x, playhead.end-x);
139+
}
133140
}
134141

135142
tl := TracksList { }
@@ -143,4 +150,18 @@ export component Tracks inherits Rectangle {
143150
height: tlvbox.height;
144151
background: Theme.regular-text-color;
145152
}
153+
154+
playhead := Playhead {
155+
x: tlvbox.x + tl.track-header-width - self.width / 2;
156+
y: timeline.y + timeline.height + self.handle-height;
157+
height: tlvbox.height;
158+
159+
out property <length> start-x: tlvbox.x + tl.track-header-width - self.width / 2;
160+
out property <length> end-x: root.width - self.handle-width / 2;
161+
162+
moved => {
163+
let offset-x = self.mouse-x - self.pressed-x;
164+
self.x = clamp(self.x + offset-x, start-x, end-x);
165+
}
166+
}
146167
}

0 commit comments

Comments
 (0)