The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.
Rust ffmpegfree-video-editormodel-context-protocolnon-linear-editoroffline-firstopen-source-video-editorself-hostedvideo-editingvideo-editing-automationvideo-editing-softwarevideo-editing-toolsvideo-editorvoice-cloningyoutube-automationyoutube-shorts
fix(timeline): a short cut tiles its body with its own frames, never black
Jareer2025191a6561
diff --git a/engine/crates/concat-host/src/media.rs b/engine/crates/concat-host/src/media.rsindex cbdfdcd5..e4a60eae 100644--- a/engine/crates/concat-host/src/media.rs+++ b/engine/crates/concat-host/src/media.rs@@ -359,6 +359,30 @@ const STRIP_SEQUENTIAL_FRAMES: f64 = 3000.0;/// reports no duration there is nothing to space frames across, so this/// refuses rather than guessing.pub fn filmstrip(path: &str, count: u32, height: u32) -> Result<Frame, String> {+ filmstrip_between(path, 0.0, f64::INFINITY, count, height)+}++/// The same strip, sampled across one stretch of the footage - `from` to+/// `to`, in seconds - rather than the whole of it.+///+/// This is what a clip cut down to a few seconds of a long file tiles its+/// body with: the file's own strip has one frame per twenty-fourth of the+/// footage, and a cut shorter than that is that one frame repeated to the+/// end of the clip. The window is held inside the file, and never shorter+/// than a frame per tile, which is the finest the file can show.+///+/// No tile is ever left black. A tile whose instant would not decode - a+/// seek the index refuses, a duration the container overstated - takes the+/// nearest picture before it, or the first one after when there is none+/// before. The strip was a black canvas the frames were painted onto, and+/// a cut that landed wholly on a hole was a clip with a black body.+pub fn filmstrip_between(+ path: &str,+ from: f64,+ to: f64,+ count: u32,+ height: u32,+) -> Result<Frame, String> {let count = count.clamp(1, 60);let height = height.clamp(16, 240);@@ -369,54 +393,112 @@ pub fn filmstrip(path: &str, count: u32, height: u32) -> Result<Frame, String> {.map(|duration| duration.as_f64()).filter(|seconds| *seconds > 0.0).ok_or_else(|| format!("{path} reports no duration"))?;- let fps = video.frame_rate.fps().as_f64();+ let fps = video.frame_rate.fps().as_f64().max(1.0);// Aspect-correct and even, which is what the scaler is happiest with.let width = ((f64::from(height) * f64::from(video.width) / f64::from(video.height)).round()as u32).max(2)& !1;+ // The window, inside the file and at least a frame per tile long.+ let least = (f64::from(count) / fps).min(duration);+ let mut from = from.clamp(0.0, duration);+ let mut to = to.clamp(from, duration);+ if to - from < least {+ to = (from + least).min(duration);+ from = (to - least).max(0.0);+ }+ let span = to - from;+// Sample the middle of each slice, so the first frame is not always the// file's own first (often black) frame.- let instant = |index: u32| duration * (f64::from(index) + 0.5) / f64::from(count);- let mut strip = Frame::black(width * count, height);- let mut last: Option<Frame> = None;+ let instant = |index: usize| from + span * (index as f64 + 0.5) / f64::from(count);+ let mut tiles: Vec<Option<Frame>> = (0..count).map(|_| None).collect();- if duration * fps <= STRIP_SEQUENTIAL_FRAMES {- let mut decoder = Decoder::open(path, &DecodeOptions::default().scaled_to(width, height))- .map_err(describe)?;- let mut index = 0;- let mut produced = 0u64;- while index < count {- let Ok(Some(frame)) = decoder.next_frame() else {- break;- };- // Where this frame is: its own stamp, or its count when the- // container stamps nothing.- let at = decoder- .position()- .map(|position| position.as_f64())- .unwrap_or(produced as f64 / fps.max(1.0));- produced += 1;- // Every tile whose instant this frame has reached takes it; a- // file with fewer frames than tiles hands one frame to several.- while index < count && at >= instant(index) {- strip.blit(&frame, index * width, 0);- index += 1;- }- last = Some(frame);+ if span * fps <= STRIP_SEQUENTIAL_FRAMES {+ read_through(path, from, fps, &instant, width, height, &mut tiles)?;+ } else {+ seek_each(path, &instant, width, height, &mut tiles)?;+ if tiles.iter().all(Option::is_none) {+ // An index that will not seek at all: read the file instead, as+ // far as the tiles reach.+ read_through(path, from, fps, &instant, width, height, &mut tiles)?;}- // Past the last frame - a duration the container overstated - the- // last picture fills what is left rather than leaving holes.- if let Some(frame) = &last {- while index < count {- strip.blit(frame, index * width, 0);- index += 1;- }+ }++ let first = tiles+ .iter()+ .position(Option::is_some)+ .ok_or_else(|| format!("no frame to show for {path}"))?;+ let mut strip = Frame::black(width * count, height);+ let mut shown = first;+ for index in 0..tiles.len() {+ if tiles[index].is_some() {+ shown = index;+ }+ if let Some(frame) = &tiles[shown] {+ strip.blit(frame, index as u32 * width, 0);+ }+ }+ Ok(strip)+}++/// One pass through the footage from `from`, each tile taking the first+/// frame at or past its instant. Exact, and cheap while the pass is short.+fn read_through(+ path: &str,+ from: f64,+ fps: f64,+ instant: &dyn Fn(usize) -> f64,+ width: u32,+ height: u32,+ tiles: &mut [Option<Frame>],+) -> Result<(), String> {+ let mut options = DecodeOptions::default().scaled_to(width, height);+ if from > 0.0 {+ options = options.starting_at(Rational::approximate(from).unwrap_or(Rational::ZERO));+ }+ let mut decoder = Decoder::open(path, &options).map_err(describe)?;+ let count = tiles.len();+ let mut index = 0;+ let mut produced = 0u64;+ let mut last: Option<Frame> = None;+ while index < count {+ let Ok(Some(frame)) = decoder.next_frame() else {+ break;+ };+ // Where this frame is: its own stamp, or its count when the+ // container stamps nothing.+ let at = decoder+ .position()+ .map(|position| position.as_f64())+ .unwrap_or(from + produced as f64 / fps);+ produced += 1;+ // Every tile whose instant this frame has reached takes it; a+ // file with fewer frames than tiles hands one frame to several.+ while index < count && at >= instant(index) {+ tiles[index] = Some(frame.clone());+ index += 1;}- return Ok(strip);+ last = Some(frame);+ }+ // Past the last frame - a duration the container overstated - the last+ // picture stands for what is left; the caller spreads it.+ if index < count && let Some(frame) = last {+ tiles[index] = Some(frame);}+ Ok(())+}+/// One seek per tile, to the keyframe at or before its instant. Near+/// enough for a thumbnail, and one decode each however long the file.+fn seek_each(+ path: &str,+ instant: &dyn Fn(usize) -> f64,+ width: u32,+ height: u32,+ tiles: &mut [Option<Frame>],+) -> Result<(), String> {let mut decoder = Decoder::open(path,&DecodeOptions::default()@@ -424,21 +506,98 @@ pub fn filmstrip(path: &str, count: u32, height: u32) -> Result<Frame, String> {.nearest_keyframes(),).map_err(describe)?;- for index in 0..count {+ for (index, tile) in tiles.iter_mut().enumerate() {let time = Rational::approximate(instant(index)).unwrap_or(Rational::ZERO);- let frame = match decoder.seek(time).and_then(|()| decoder.next_frame()) {- Ok(Some(frame)) => Some(frame),- // Past the last frame, or a stretch that will not decode: repeat- // the last picture rather than leaving a hole.- _ => None,- };- let frame = frame.or_else(|| last.take());- if let Some(frame) = &frame {- strip.blit(frame, index * width, 0);+ if let Ok(Some(frame)) = decoder.seek(time).and_then(|()| decoder.next_frame()) {+ *tile = Some(frame);}- last = frame;}- Ok(strip)+ Ok(())+}++/// The fraction of the footage a cell at `level` spans.+pub fn window_span(level: u32) -> f64 {+ 1.0 / f64::from(1u32 << level)+}++/// Where cell `cell` at `level` begins, as a fraction of the footage.+pub fn window_start(level: u32, cell: u32) -> f64 {+ f64::from(cell) / f64::from(1u32 << (level + 1))+}++/// The cell a cut wants its frames sampled across, or `None` when the+/// file's own strip already shows it as more than a few frames.+///+/// `start` and `span` are the cut as fractions of the footage, `duration`+/// the footage in seconds. The level is the finest whose half-cell still+/// holds the cut, so the cut covers at least half the strip it is drawn+/// from and at least twelve of its frames; it stops at the level where a+/// cell is a second long, under which the file has no more pictures to+/// give, and at [`WINDOW_LEVELS`] regardless. Cuts over a quarter of the+/// footage get no cell: the file's strip has six or more frames across them.+pub fn strip_window(start: f64, span: f64, duration: f64) -> Option<(u32, u32)> {+ if span.is_nan() || span <= 0.0 || duration.is_nan() || duration <= 1.0 {+ return None;+ }+ let finest = (duration.log2().floor() as i64).min(i64::from(WINDOW_LEVELS));+ let level = ((1.0 / span).log2().floor() as i64 - 1).min(finest);+ if level < 1 {+ return None;+ }+ let level = level as u32;+ let steps = 1u32 << (level + 1);+ // The last cell is the one that ends at the end of the footage.+ let cell = ((start.clamp(0.0, 1.0) * f64::from(steps)).floor() as u32).min(steps - 2);+ Some((level, cell))+}++/// The finest cell grid: 1/65536 of the footage, where a cut is a frame or+/// two of even the longest file.+pub const WINDOW_LEVELS: u32 = 16;++#[cfg(test)]+mod window_tests {+ use super::*;++ /// The cell a cut is given holds the whole cut, at every level.+ #[test]+ fn a_cut_fits_in_its_cell() {+ let duration = 3600.0;+ let mut span = 0.25;+ while span > 1.0 / 200_000.0 {+ let mut start = 0.0;+ while start + span <= 1.0 {+ let (level, cell) = strip_window(start, span, duration).expect("a cell");+ let from = window_start(level, cell);+ let to = from + window_span(level);+ assert!(from <= start && start + span <= to + 1e-12, "{start} {span} at {level}/{cell}");+ assert!(to <= 1.0 + 1e-12, "cell {level}/{cell} runs past the footage");+ // and, short of the cap, the cut is at least a quarter of+ // it: the cell is the finest whose half still holds the cut+ let finest = duration.log2().floor() as u32;+ assert!(level == finest || span * 4.0 >= window_span(level) - 1e-12);+ start += span * 0.37;+ }+ span *= 0.7;+ }+ }++ #[test]+ fn wide_cuts_and_short_files_keep_the_files_own_strip() {+ assert_eq!(strip_window(0.0, 0.5, 3600.0), None);+ assert_eq!(strip_window(0.1, 0.26, 3600.0), None);+ assert_eq!(strip_window(0.1, 0.01, 0.5), None);+ assert_eq!(strip_window(0.1, 0.0, 3600.0), None);+ assert_eq!(strip_window(0.1, f64::NAN, 3600.0), None);+ }++ #[test]+ fn the_grid_stops_at_a_second_and_at_the_finest_level() {+ // 10s of footage: a cell no shorter than a second is level 3+ assert_eq!(strip_window(0.0, 1e-6, 10.0), Some((3, 0)));+ // and a day of footage stops at WINDOW_LEVELS+ assert_eq!(strip_window(0.0, 1e-9, 86400.0).map(|(level, _)| level), Some(WINDOW_LEVELS));+ }}/// A small poster frame for one project, as a JPEG, for the launch screen'sdiff --git a/engine/crates/concat/src/host.rs b/engine/crates/concat/src/host.rsindex b33018ee..20b391f9 100644--- a/engine/crates/concat/src/host.rs+++ b/engine/crates/concat/src/host.rs@@ -20,6 +20,7 @@ use concat_host::export::Exporter;use concat_host::playback::{Playback, PlaybackEvents};use concat_host::preview::Monitor;use concat_host::{AppDirs, media};+pub use concat_host::media::{strip_window, window_span, window_start};use concat_speech::{Speech, Transcriber};use crate::gpu::Gpu;@@ -437,6 +438,102 @@ fn save_frame_jpeg(Ok(())}+/// A filmstrip of one stretch of a media item, restored from the cache.+///+/// The stretches are cells on a grid over the footage: at `level` k a cell+/// spans 1/2^k of it, and cell `j` starts at j/2^(k+1), so cells overlap by+/// half and any cut no longer than half a cell fits wholly in one. See+/// [`strip_window`].+pub fn cached_window_art(+ project: &str,+ id: &str,+ path: &str,+ level: u32,+ cell: u32,+) -> Option<CachedStrip> {+ let dir = art_cache_dir(project);+ let stem = art_cache_stem(id, path);+ let prefix = format!("{stem}.win.{level}.{cell}.");+ std::fs::read_dir(&dir).ok()?.filter_map(Result::ok).find_map(|entry| {+ let name = entry.file_name();+ let name = name.to_str()?;+ let rest = name.strip_prefix(&prefix)?.strip_suffix(".jpg")?;+ let mut parts = rest.split('.');+ let frames: u32 = parts.next()?.parse().ok()?;+ let frame_width: u32 = parts.next()?.parse().ok()?;+ let height: u32 = parts.next()?.parse().ok()?;+ if parts.next().is_some() {+ return None;+ }+ let image = image_at(&entry.path())?;+ Some(CachedStrip {+ image,+ frames,+ frame_width,+ height,+ })+ })+}++fn save_window_art_cache(+ project: &str,+ id: &str,+ path: &str,+ level: u32,+ cell: u32,+ frame: &concat_core::frame::Frame,+ frames: u32,+) {+ let dir = art_cache_dir(project);+ if std::fs::create_dir_all(&dir).is_err() {+ return;+ }+ let stem = art_cache_stem(id, path);+ let frames = frames.max(1);+ let frame_width = frame.width() / frames;+ let name = format!(+ "{stem}.win.{level}.{cell}.{frames}.{frame_width}.{}.jpg",+ frame.height()+ );+ let _ = save_frame_jpeg(&dir.join(name), frame, 78);+}++/// The strip of one cell of a media item, decoded on a worker.+pub struct WindowArt {+ /// The media id the strip belongs to.+ pub id: String,+ pub level: u32,+ pub cell: u32,+ /// The frames, side by side, and how many there are.+ pub strip: Option<(concat_core::frame::Frame, u32)>,+}++/// Samples the frames of one cell of a media item - see [`strip_window`] -+/// and writes them to the project's artwork cache beside the file's own.+pub fn window_art(+ id: String,+ path: String,+ project: String,+ level: u32,+ cell: u32,+ duration: f64,+) -> WindowArt {+ let from = window_start(level, cell) * duration;+ let to = from + window_span(level) * duration;+ let strip = media::filmstrip_between(&path, from, to, STRIP_FRAMES, STRIP_HEIGHT)+ .ok()+ .map(|frame| (frame, STRIP_FRAMES));+ if let Some((frame, frames)) = &strip {+ save_window_art_cache(&project, &id, &path, level, cell, frame, *frames);+ }+ WindowArt {+ id,+ level,+ cell,+ strip,+ }+}+/// A probe's error, in the words a toast can use.pub fn probe_error(error: &str) -> String {format!("Could not import: {error}")diff --git a/engine/crates/concat/src/studio.rs b/engine/crates/concat/src/studio.rsindex 6824158d..e466ac45 100644--- a/engine/crates/concat/src/studio.rs+++ b/engine/crates/concat/src/studio.rs@@ -52,7 +52,9 @@ use crate::format::{bytes, colour_of, eta, frames_timecode, hex_of, hex_with_alpha, wave_path, when_phrase,};use crate::host::{- Host, MediaArt, cached_media_art, image_at, image_of, media_art, on_ui, spawn, spawn_art,+ CachedStrip, Host, MediaArt, WindowArt, cached_media_art, cached_window_art, image_at,+ image_of, media_art, on_ui, spawn, spawn_art, strip_window, window_art, window_span,+ window_start,};use crate::i18n::{self, t, tf};use crate::prefs::Preferences;@@ -98,6 +100,39 @@ pub struct Strip {pub height: i32,}+impl From<CachedStrip> for Strip {+ fn from(strip: CachedStrip) -> Self {+ Self {+ image: strip.image,+ frames: strip.frames as i32,+ frame_width: strip.frame_width as i32,+ height: strip.height as i32,+ }+ }+}++impl Strip {+ /// A decoded strip of `frames` frames.+ fn of(frame: &concat_core::frame::Frame, frames: u32) -> Self {+ Self {+ image: image_of(frame),+ frames: frames as i32,+ frame_width: (frame.width() / frames.max(1)) as i32,+ height: frame.height() as i32,+ }+ }+}++/// The key a cell's strip is held under: the media and the cell.+fn window_key(media_id: &str, level: u32, cell: u32) -> String {+ format!("{media_id}|{level}|{cell}")+}++/// How many cell strips are kept before the ones no clip on the current+/// timeline shows are let go. Each is a picture the size of the file's own+/// strip; a trim walks through several levels on its way down.+const WINDOWS_KEPT: usize = 96;+/// Steps per second the drawn waveform is quantised to. See `Studio::wave`:/// it is what keeps a trim from synthesising a new envelope on every pointer/// event, and the grid is fine enough that no step of it is visible.@@ -662,7 +697,12 @@ pub struct Studio {/// Filmstrips by media id: the picture, how many frames are in it, one/// frame's width and the strip's height, in the picture's own pixels.pub strips: HashMap<String, Strip>,+ /// Filmstrips of one cell of a file each, by `window_key`, for the cuts+ /// too short a piece of their footage for the file's strip to show as+ /// more than one frame repeated. See `host::strip_window`.+ pub windows: HashMap<String, Strip>,art_pending: HashSet<String>,+ window_pending: HashSet<String>,/// Envelopes, keyed by the things they are computed from. A move/// changes none of them, and a publish happens on every frame of one.waves: RefCell<HashMap<String, SharedString>>,@@ -1343,7 +1383,9 @@ impl Studio {peaks: HashMap::new(),thumbs: HashMap::new(),strips: HashMap::new(),+ windows: HashMap::new(),art_pending: HashSet::new(),+ window_pending: HashSet::new(),waves: RefCell::new(HashMap::new()),lane_view: HashMap::new(),selection: Vec::new(),@@ -2265,15 +2307,7 @@ impl Studio {self.thumbs.insert(id.clone(), image);}if let Some(strip) = cached.strip {- self.strips.insert(- id.clone(),- Strip {- image: strip.image,- frames: strip.frames as i32,- frame_width: strip.frame_width as i32,- height: strip.height as i32,- },- );+ self.strips.insert(id.clone(), strip.into());}pictures = !self.thumbs.contains_key(&id) || !self.strips.contains_key(&id);}@@ -2300,13 +2334,7 @@ impl Studio {studio.thumbs.insert(art.id.clone(), image_of(&frame));}if let Some((frame, frames)) = art.strip {- let strip = Strip {- image: image_of(&frame),- frames: frames as i32,- frame_width: (frame.width() / frames.max(1)) as i32,- height: frame.height() as i32,- };- studio.strips.insert(art.id.clone(), strip);+ studio.strips.insert(art.id.clone(), Strip::of(&frame, frames));}if let Some(peaks) = art.peaks {let prefix = format!("{key}|");@@ -2319,6 +2347,107 @@ impl Studio {},);}+ self.request_window_art();+ }++ /// Decodes a cell strip for every picture clip on the current timeline+ /// whose cut is too short a piece of its footage for the file's own+ /// strip - see `host::strip_window` - and lets go of the cells nothing+ /// shows once there are more than `WINDOWS_KEPT` of them.+ fn request_window_art(&mut self) {+ let Some(session) = self.session.as_ref() else {+ return;+ };+ let project_path = session.path().to_owned();+ struct Want {+ key: String,+ id: String,+ path: String,+ level: u32,+ cell: u32,+ duration: f64,+ }+ let mut shown: HashSet<String> = HashSet::new();+ let mut wanted: Vec<Want> = Vec::new();+ for clip in &self.timeline().clips {+ if clip.kind != model::ClipKind::Video {+ continue;+ }+ let Some(item) = self.project().media_by_id(&clip.media_id) else {+ continue;+ };+ if item.placeholder || item.path.is_empty() {+ continue;+ }+ let Some((start, span, duration)) = self.cut_of(clip) else {+ continue;+ };+ let Some((level, cell)) = strip_window(start, span, duration) else {+ continue;+ };+ let key = window_key(&clip.media_id, level, cell);+ if !shown.insert(key.clone())+ || self.windows.contains_key(&key)+ || self.window_pending.contains(&key)+ {+ continue;+ }+ wanted.push(Want {+ key,+ id: item.id.clone(),+ path: item.path.clone(),+ level,+ cell,+ duration,+ });+ }+ if self.windows.len() > WINDOWS_KEPT {+ self.windows.retain(|key, _| shown.contains(key));+ }+ for want in wanted {+ let Want {+ key,+ id,+ path,+ level,+ cell,+ duration,+ } = want;+ if let Some(strip) = cached_window_art(&project_path, &id, &path, level, cell) {+ self.windows.insert(key, strip.into());+ continue;+ }+ self.window_pending.insert(key);+ let project = project_path.clone();+ spawn_art(+ move || window_art(id, path, project, level, cell, duration),+ |studio, _, _, art: WindowArt| {+ let key = window_key(&art.id, art.level, art.cell);+ studio.window_pending.remove(&key);+ if let Some((frame, frames)) = art.strip {+ studio.windows.insert(key, Strip::of(&frame, frames));+ }+ },+ );+ }+ }++ /// A picture clip's cut as fractions of its footage - where it begins+ /// and how much it covers - with the footage's length in seconds.+ /// `None` for a still or footage of unknown length: one frame, all of it.+ fn cut_of(&self, clip: &Clip) -> Option<(f64, f64, f64)> {+ let seconds = self+ .project()+ .media+ .iter()+ .find(|item| item.id == clip.media_id)+ .and_then(|item| item.duration)+ .filter(|seconds| *seconds > 0.0)?;+ Some((+ (clip.source_start / seconds).clamp(0.0, 1.0),+ (clip.duration * clip.speed / seconds).clamp(0.0, 1.0),+ seconds,+ ))}/// The clip's filmstrip, with the window of the strip its cut covers:@@ -2329,24 +2458,25 @@ impl Studio {if !matches!(clip.kind, model::ClipKind::Video | model::ClipKind::Image) {return StripData::default();}- let Some(strip) = self.strips.get(&clip.media_id) else {+ let Some(mut strip) = self.strips.get(&clip.media_id) else {return StripData::default();};- let footage = self- .project()- .media- .iter()- .find(|item| item.id == clip.media_id)- .and_then(|item| item.duration)- .filter(|seconds| *seconds > 0.0);- let (start, span) = match footage {- Some(seconds) => (- (clip.source_start / seconds).clamp(0.0, 1.0),- (clip.duration * clip.speed / seconds).clamp(0.0, 1.0),- ),- // A still, or footage of unknown length: one frame, all of it.- None => (0.0, 1.0),- };+ let (mut start, mut span) = (0.0, 1.0);+ if let Some((cut_start, cut_span, duration)) = self.cut_of(clip) {+ start = cut_start;+ span = cut_span;+ // The cell strip, once it is here: the cut re-expressed as a+ // window of that cell rather than of the whole file. Until it+ // arrives the file's strip stands in, and the tiles repeat.+ if let Some((level, cell)) = strip_window(start, span, duration)+ && let Some(window) = self.windows.get(&window_key(&clip.media_id, level, cell))+ {+ let (cell_start, cell_span) = (window_start(level, cell), window_span(level));+ start = ((start - cell_start) / cell_span).clamp(0.0, 1.0);+ span = (span / cell_span).clamp(0.0, 1.0);+ strip = window;+ }+ }StripData {image: strip.image.clone(),frames: strip.frames,diff --git a/engine/crates/concat/ui/timeline/lanes.slint b/engine/crates/concat/ui/timeline/lanes.slintindex 8eabdecd..6e972aac 100644--- a/engine/crates/concat/ui/timeline/lanes.slint+++ b/engine/crates/concat/ui/timeline/lanes.slint@@ -215,7 +215,11 @@ component Clip inherits Rectangle {// along the clip wants the frame at start + span * f. Every tile is// one Image with a source clip, so a zoom changes how many tiles// there are and which frame each picks, never the picture itself.- if root.item.strip.frames > 0 && root.width > 8px: Rectangle {+ //+ // Drawn at any width. A clip narrower than a tile shows the left+ // of one frame, cut where the clip ends - a sliver of the picture+ // is still the picture, and the well it would leave showing is not.+ if root.item.strip.frames > 0 && root.width > 0px: Rectangle {x: 0;y: 0;width: parent.width;