pan & zoom boundaries + related gifs

This commit is contained in:
Martin Kavík 2024-06-14 20:28:18 +02:00
parent f324b57f71
commit 09eab06e4e
11 changed files with 106 additions and 52 deletions

View file

@ -4,11 +4,23 @@
--- ---
<p align="center"> <p align="center">
<img width="800" src="docs/screenshot_firefox.png" alt="fastwave_screenshot_firefox" /> <img width="800" src="docs/screenshot_firefox.png" alt="Fastwave - Browser (Firefox)" />
Browser (Firefox)
</p> </p>
<p align="center"> <p align="center">
<img width="800" src="docs/video_desktop.gif" alt="fastwave_video_desktop" /> <img width="800" src="docs/video_desktop.gif" alt="Fastwave - Desktop, miller columns and tree" />
Desktop, miller columns and tree
</p>
<p align="center">
<img width="800" src="docs/video_zoom_formatting_simple.gif" alt="Fastwave - Zoom, pan and basic number formats" />
Zoom, pan and basic number formats
</p>
<p align="center">
<img width="800" src="docs/video_zoom_formatting.gif" alt="Fastwave - Zoom and all formats" />
Zoom and all formats
</p> </p>
--- ---

View file

Before

Width:  |  Height:  |  Size: 434 KiB

After

Width:  |  Height:  |  Size: 434 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 612 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 KiB

View file

@ -44,7 +44,8 @@ pub async fn load_signal_and_get_timeline(
timeline_viewport_x, timeline_viewport_x,
block_height, block_height,
var_format, var_format,
).await )
.await
} }
pub async fn unload_signal(signal_ref: wellen::SignalRef) { pub async fn unload_signal(signal_ref: wellen::SignalRef) {

View file

@ -87,16 +87,15 @@ pub(super) async fn load_signal_and_get_timeline(
waveform.load_signals_multi_threaded(&[signal_ref]); waveform.load_signals_multi_threaded(&[signal_ref]);
let signal = waveform.get_signal(signal_ref).unwrap(); let signal = waveform.get_signal(signal_ref).unwrap();
let time_table = waveform.time_table(); let time_table = waveform.time_table();
let timeline = let timeline = shared::signal_to_timeline(
shared::signal_to_timeline( signal,
signal, time_table,
time_table, timeline_zoom,
timeline_zoom, timeline_viewport_width,
timeline_viewport_width, timeline_viewport_x,
timeline_viewport_x, block_height,
block_height, var_format,
var_format, );
);
timeline timeline
} }

View file

@ -53,7 +53,12 @@ impl PixiCanvas {
let task_with_controller = Mutable::new(None); let task_with_controller = Mutable::new(None);
// -- FastWave-specific -- // -- FastWave-specific --
let timeline_getter = Rc::new(Closure::new( let timeline_getter = Rc::new(Closure::new(
|signal_ref_index, timeline_zoom, timeline_viewport_width, timeline_viewport_x, row_height, var_format| { |signal_ref_index,
timeline_zoom,
timeline_viewport_width,
timeline_viewport_x,
row_height,
var_format| {
future_to_promise(async move { future_to_promise(async move {
let signal_ref = wellen::SignalRef::from_index(signal_ref_index).unwrap_throw(); let signal_ref = wellen::SignalRef::from_index(signal_ref_index).unwrap_throw();
let timeline = platform::load_signal_and_get_timeline( let timeline = platform::load_signal_and_get_timeline(
@ -84,15 +89,17 @@ impl PixiCanvas {
})) }))
.update_raw_el(|raw_el| { .update_raw_el(|raw_el| {
// @TODO rewrite to a native Zoon API // @TODO rewrite to a native Zoon API
raw_el.event_handler(clone!((controller) move |event: events_extra::WheelEvent| { raw_el.event_handler(
if let Some(controller) = controller.lock_ref().as_ref() { clone!((controller) move |event: events_extra::WheelEvent| {
controller.zoom_or_pan( if let Some(controller) = controller.lock_ref().as_ref() {
event.delta_y(), controller.zoom_or_pan(
event.shift_key(), event.delta_y(),
event.offset_x() as u32, event.shift_key(),
); event.offset_x() as u32,
} );
})) }
}),
)
}) })
.after_insert(clone!((controller, timeline_getter) move |element| { .after_insert(clone!((controller, timeline_getter) move |element| {
Task::start(async move { Task::start(async move {
@ -140,8 +147,16 @@ mod js_bridge {
type TimelineViewportX = i32; type TimelineViewportX = i32;
type RowHeight = u32; type RowHeight = u32;
type VarFormatJs = JsValue; type VarFormatJs = JsValue;
type TimelineGetter = type TimelineGetter = Closure<
Closure<dyn FnMut(SignalRefIndex, TimelineZoom, TimelineViewportWidth, TimelineViewportX, RowHeight, VarFormatJs) -> TimelinePromise>; dyn FnMut(
SignalRefIndex,
TimelineZoom,
TimelineViewportWidth,
TimelineViewportX,
RowHeight,
VarFormatJs,
) -> TimelinePromise,
>;
// Note: Add all corresponding methods to `frontend/typescript/pixi_canvas/pixi_canvas.ts` // Note: Add all corresponding methods to `frontend/typescript/pixi_canvas/pixi_canvas.ts`
#[wasm_bindgen(module = "/typescript/bundles/pixi_canvas.js")] #[wasm_bindgen(module = "/typescript/bundles/pixi_canvas.js")]
@ -184,7 +199,12 @@ mod js_bridge {
pub fn set_var_format(this: &PixiController, index: usize, var_format: JsValue); pub fn set_var_format(this: &PixiController, index: usize, var_format: JsValue);
#[wasm_bindgen(method)] #[wasm_bindgen(method)]
pub fn zoom_or_pan(this: &PixiController, wheel_delta_y: f64, shift_key: bool, offset_x: u32); pub fn zoom_or_pan(
this: &PixiController,
wheel_delta_y: f64,
shift_key: bool,
offset_x: u32,
);
#[wasm_bindgen(method)] #[wasm_bindgen(method)]
pub fn remove_var(this: &PixiController, index: usize); pub fn remove_var(this: &PixiController, index: usize);

View file

@ -35223,10 +35223,22 @@ var PixiController = class {
} else { } else {
const offset_x_ratio = offset_x / this.timeline_viewport_width; const offset_x_ratio = offset_x / this.timeline_viewport_width;
const old_timeline_width = this.timeline_viewport_width * this.timeline_zoom; const old_timeline_width = this.timeline_viewport_width * this.timeline_zoom;
this.timeline_zoom -= Math.sign(wheel_delta_y) * this.timeline_zoom * 0.5; const new_zoom = this.timeline_zoom - Math.sign(wheel_delta_y) * this.timeline_zoom * 0.5;
const new_timeline_width = this.timeline_viewport_width * this.timeline_zoom; const new_timeline_width = this.timeline_viewport_width * new_zoom;
const timeline_width_difference = new_timeline_width - old_timeline_width; if (new_timeline_width < this.timeline_viewport_width) {
this.timeline_viewport_x += timeline_width_difference * offset_x_ratio; this.timeline_zoom = 1;
this.timeline_viewport_x = 0;
} else {
const timeline_width_difference = new_timeline_width - old_timeline_width;
this.timeline_viewport_x += timeline_width_difference * offset_x_ratio;
this.timeline_zoom = new_zoom;
}
}
const timeline_width = this.timeline_viewport_width * this.timeline_zoom;
if (this.timeline_viewport_x < 0) {
this.timeline_viewport_x = 0;
} else if (this.timeline_viewport_x + this.timeline_viewport_width > timeline_width) {
this.timeline_viewport_x = timeline_width - this.timeline_viewport_width;
} }
this.redraw_all_rows(); this.redraw_all_rows();
} }

View file

@ -151,13 +151,24 @@ export class PixiController {
if (shift_key) { if (shift_key) {
this.timeline_viewport_x += Math.sign(wheel_delta_y) * 20; this.timeline_viewport_x += Math.sign(wheel_delta_y) * 20;
} else { } else {
// @TODO bounds
const offset_x_ratio = offset_x / this.timeline_viewport_width; const offset_x_ratio = offset_x / this.timeline_viewport_width;
const old_timeline_width = this.timeline_viewport_width * this.timeline_zoom; const old_timeline_width = this.timeline_viewport_width * this.timeline_zoom;
this.timeline_zoom -= Math.sign(wheel_delta_y) * this.timeline_zoom * 0.5; const new_zoom = this.timeline_zoom - Math.sign(wheel_delta_y) * this.timeline_zoom * 0.5;
const new_timeline_width = this.timeline_viewport_width * this.timeline_zoom; const new_timeline_width = this.timeline_viewport_width * new_zoom;
const timeline_width_difference = new_timeline_width - old_timeline_width; if (new_timeline_width < this.timeline_viewport_width) {
this.timeline_viewport_x += timeline_width_difference * offset_x_ratio; this.timeline_zoom = 1;
this.timeline_viewport_x = 0;
} else {
const timeline_width_difference = new_timeline_width - old_timeline_width;
this.timeline_viewport_x += timeline_width_difference * offset_x_ratio;
this.timeline_zoom = new_zoom;
}
}
const timeline_width = this.timeline_viewport_width * this.timeline_zoom;
if (this.timeline_viewport_x < 0) {
this.timeline_viewport_x = 0;
} else if (this.timeline_viewport_x + this.timeline_viewport_width > timeline_width) {
this.timeline_viewport_x = timeline_width - this.timeline_viewport_width;
} }
this.redraw_all_rows(); this.redraw_all_rows();
} }

View file

@ -56,16 +56,15 @@ async fn load_signal_and_get_timeline(
waveform.load_signals_multi_threaded(&[signal_ref]); waveform.load_signals_multi_threaded(&[signal_ref]);
let signal = waveform.get_signal(signal_ref).unwrap(); let signal = waveform.get_signal(signal_ref).unwrap();
let time_table = waveform.time_table(); let time_table = waveform.time_table();
let timeline = let timeline = shared::signal_to_timeline(
shared::signal_to_timeline( signal,
signal, time_table,
time_table, timeline_zoom,
timeline_zoom, timeline_viewport_width,
timeline_viewport_width, timeline_viewport_x,
timeline_viewport_x, block_height,
block_height, var_format,
var_format, );
);
Ok(serde_json::to_value(timeline).unwrap()) Ok(serde_json::to_value(timeline).unwrap())
} }