set_var_format
This commit is contained in:
parent
d654714c0d
commit
1881d62c56
11 changed files with 145 additions and 35 deletions
|
@ -33,8 +33,9 @@ pub async fn load_signal_and_get_timeline(
|
|||
signal_ref: wellen::SignalRef,
|
||||
screen_width: u32,
|
||||
block_height: u32,
|
||||
var_format: shared::VarFormat,
|
||||
) -> shared::Timeline {
|
||||
platform::load_signal_and_get_timeline(signal_ref, screen_width, block_height).await
|
||||
platform::load_signal_and_get_timeline(signal_ref, screen_width, block_height, var_format).await
|
||||
}
|
||||
|
||||
pub async fn unload_signal(signal_ref: wellen::SignalRef) {
|
||||
|
|
|
@ -78,13 +78,14 @@ pub(super) async fn load_signal_and_get_timeline(
|
|||
signal_ref: wellen::SignalRef,
|
||||
screen_width: u32,
|
||||
block_height: u32,
|
||||
var_format: shared::VarFormat,
|
||||
) -> shared::Timeline {
|
||||
let mut waveform_lock = STORE.waveform.lock().unwrap();
|
||||
let waveform = waveform_lock.as_mut().unwrap();
|
||||
waveform.load_signals_multi_threaded(&[signal_ref]);
|
||||
let signal = waveform.get_signal(signal_ref).unwrap();
|
||||
let time_table = waveform.time_table();
|
||||
let timeline = signal_to_timeline(signal, time_table, screen_width, block_height);
|
||||
let timeline = signal_to_timeline(signal, time_table, screen_width, block_height, var_format);
|
||||
timeline
|
||||
}
|
||||
|
||||
|
@ -100,11 +101,12 @@ fn signal_to_timeline(
|
|||
time_table: &[wellen::Time],
|
||||
screen_width: u32,
|
||||
block_height: u32,
|
||||
var_format: shared::VarFormat,
|
||||
) -> shared::Timeline {
|
||||
const MIN_BLOCK_WIDTH: u32 = 3;
|
||||
// Courier New, 16px, sync with `label_style` in `pixi_canvas.rs`
|
||||
const LETTER_WIDTH: f64 = 9.61;
|
||||
const LETTER_HEIGHT: u32 = 21;
|
||||
const LETTER_HEIGHT: u32 = 18;
|
||||
const LABEL_X_PADDING: u32 = 10;
|
||||
|
||||
let Some(last_time) = time_table.last().copied() else {
|
||||
|
@ -139,7 +141,7 @@ fn signal_to_timeline(
|
|||
}
|
||||
|
||||
// @TODO cache?
|
||||
let value = shared::VarFormat::default().format(value);
|
||||
let value = var_format.format(value);
|
||||
|
||||
let value_width = (value.chars().count() as f64 * LETTER_WIDTH) as u32;
|
||||
// @TODO Ellipsis instead of hiding?
|
||||
|
|
|
@ -21,11 +21,18 @@ pub(super) async fn load_signal_and_get_timeline(
|
|||
signal_ref: wellen::SignalRef,
|
||||
screen_width: u32,
|
||||
block_height: u32,
|
||||
var_format: shared::VarFormat,
|
||||
) -> shared::Timeline {
|
||||
let var_format = serde_wasm_bindgen::to_value(&var_format).unwrap_throw();
|
||||
serde_wasm_bindgen::from_value(
|
||||
tauri_glue::load_signal_and_get_timeline(signal_ref.index(), screen_width, block_height)
|
||||
.await
|
||||
.unwrap_throw(),
|
||||
tauri_glue::load_signal_and_get_timeline(
|
||||
signal_ref.index(),
|
||||
screen_width,
|
||||
block_height,
|
||||
var_format,
|
||||
)
|
||||
.await
|
||||
.unwrap_throw(),
|
||||
)
|
||||
.unwrap_throw()
|
||||
}
|
||||
|
@ -56,6 +63,7 @@ mod tauri_glue {
|
|||
signal_ref_index: usize,
|
||||
screen_width: u32,
|
||||
block_height: u32,
|
||||
var_format: JsValue,
|
||||
) -> Result<JsValue, JsValue>;
|
||||
|
||||
#[wasm_bindgen(catch)]
|
||||
|
|
|
@ -13,6 +13,7 @@ const ROW_GAP: u32 = 4;
|
|||
pub struct WaveformPanel {
|
||||
selected_var_refs: MutableVec<wellen::VarRef>,
|
||||
hierarchy: Mutable<Option<Rc<wellen::Hierarchy>>>,
|
||||
canvas_controller: Mutable<ReadOnlyMutable<Option<PixiController>>>,
|
||||
}
|
||||
|
||||
impl WaveformPanel {
|
||||
|
@ -23,6 +24,7 @@ impl WaveformPanel {
|
|||
Self {
|
||||
selected_var_refs,
|
||||
hierarchy,
|
||||
canvas_controller: Mutable::new(Mutable::default().read_only()),
|
||||
}
|
||||
.root()
|
||||
}
|
||||
|
@ -54,11 +56,13 @@ impl WaveformPanel {
|
|||
fn canvas(&self, selected_vars_panel_height: ReadOnlyMutable<u32>) -> impl Element {
|
||||
let selected_var_refs = self.selected_var_refs.clone();
|
||||
let hierarchy = self.hierarchy.clone();
|
||||
let canvas_controller = self.canvas_controller.clone();
|
||||
PixiCanvas::new(ROW_HEIGHT, ROW_GAP)
|
||||
.s(Align::new().top())
|
||||
.s(Width::fill())
|
||||
.s(Height::exact_signal(selected_vars_panel_height.signal()))
|
||||
.task_with_controller(move |controller| {
|
||||
canvas_controller.set(controller.clone());
|
||||
selected_var_refs.signal_vec().delay_remove(clone!((hierarchy) move |var_ref| {
|
||||
clone!((var_ref, hierarchy) async move {
|
||||
if let Some(hierarchy) = hierarchy.get_cloned() {
|
||||
|
@ -112,12 +116,15 @@ impl WaveformPanel {
|
|||
) {
|
||||
let hierarchy = hierarchy.get_cloned().unwrap();
|
||||
|
||||
let var_format = shared::VarFormat::default();
|
||||
|
||||
let var = hierarchy.get(var_ref);
|
||||
let signal_ref = var.signal_ref();
|
||||
let timeline = platform::load_signal_and_get_timeline(
|
||||
signal_ref,
|
||||
controller.screen_width(),
|
||||
ROW_HEIGHT,
|
||||
var_format,
|
||||
)
|
||||
.await;
|
||||
|
||||
|
@ -128,7 +135,8 @@ impl WaveformPanel {
|
|||
// Note: Sync `timeline`'s type with the `Timeline` in `frontend/typescript/pixi_canvas/pixi_canvas.ts'
|
||||
let timeline = serde_wasm_bindgen::to_value(&timeline).unwrap_throw();
|
||||
let signal_ref_index = signal_ref.index();
|
||||
controller.push_var(signal_ref_index, timeline);
|
||||
let var_format = serde_wasm_bindgen::to_value(&var_format).unwrap_throw();
|
||||
controller.push_var(signal_ref_index, timeline, var_format);
|
||||
}
|
||||
|
||||
fn selected_var_panel(
|
||||
|
@ -141,8 +149,8 @@ impl WaveformPanel {
|
|||
};
|
||||
let var = hierarchy.get(var_ref);
|
||||
Row::new()
|
||||
.item(self.selected_var_name_button(var.name(&hierarchy), index))
|
||||
.item(self.selected_var_format_button())
|
||||
.item(self.selected_var_name_button(var.name(&hierarchy), index.clone()))
|
||||
.item(self.selected_var_format_button(index))
|
||||
.apply(Some)
|
||||
}
|
||||
|
||||
|
@ -174,9 +182,10 @@ impl WaveformPanel {
|
|||
})
|
||||
}
|
||||
|
||||
fn selected_var_format_button(&self) -> impl Element {
|
||||
fn selected_var_format_button(&self, index: ReadOnlyMutable<Option<usize>>) -> impl Element {
|
||||
let var_format = Mutable::new(shared::VarFormat::default());
|
||||
let (hovered, hovered_signal) = Mutable::new_and_signal(false);
|
||||
let canvas_controller = self.canvas_controller.clone();
|
||||
Button::new()
|
||||
.s(Height::exact(ROW_HEIGHT))
|
||||
.s(Width::exact(70))
|
||||
|
@ -191,6 +200,18 @@ impl WaveformPanel {
|
|||
.child_signal(var_format.signal().map(|format| format.as_static_str())),
|
||||
)
|
||||
.on_hovered_change(move |is_hovered| hovered.set_neq(is_hovered))
|
||||
.on_press(move || var_format.update(|format| format.next()))
|
||||
.on_press(move || {
|
||||
let next_format = var_format.get().next();
|
||||
var_format.set(next_format);
|
||||
if let Some(canvas_controller) = canvas_controller.get_cloned().lock_ref().as_ref()
|
||||
{
|
||||
if let Some(index) = index.get() {
|
||||
canvas_controller.set_var_format(
|
||||
index,
|
||||
serde_wasm_bindgen::to_value(&next_format).unwrap_throw(),
|
||||
);
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,13 +52,14 @@ impl PixiCanvas {
|
|||
let task_with_controller = Mutable::new(None);
|
||||
// -- FastWave-specific --
|
||||
let timeline_getter = Rc::new(Closure::new(
|
||||
|signal_ref_index, screen_width, row_height| {
|
||||
|signal_ref_index, screen_width, row_height, var_format| {
|
||||
future_to_promise(async move {
|
||||
let signal_ref = wellen::SignalRef::from_index(signal_ref_index).unwrap_throw();
|
||||
let timeline = platform::load_signal_and_get_timeline(
|
||||
signal_ref,
|
||||
screen_width,
|
||||
row_height,
|
||||
serde_wasm_bindgen::from_value(var_format).unwrap_throw(),
|
||||
)
|
||||
.await;
|
||||
let timeline = serde_wasm_bindgen::to_value(&timeline).unwrap_throw();
|
||||
|
@ -114,8 +115,9 @@ mod js_bridge {
|
|||
type SignalRefIndex = usize;
|
||||
type ScreenWidth = u32;
|
||||
type RowHeight = u32;
|
||||
type VarFormatJs = JsValue;
|
||||
type TimelineGetter =
|
||||
Closure<dyn FnMut(SignalRefIndex, ScreenWidth, RowHeight) -> TimelinePromise>;
|
||||
Closure<dyn FnMut(SignalRefIndex, ScreenWidth, RowHeight, VarFormatJs) -> TimelinePromise>;
|
||||
|
||||
// Note: Add all corresponding methods to `frontend/typescript/pixi_canvas/pixi_canvas.ts`
|
||||
#[wasm_bindgen(module = "/typescript/bundles/pixi_canvas.js")]
|
||||
|
@ -145,11 +147,19 @@ mod js_bridge {
|
|||
|
||||
// -- FastWave-specific --
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn set_var_format(this: &PixiController, index: usize, var_format: JsValue);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn remove_var(this: &PixiController, index: usize);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn push_var(this: &PixiController, signal_ref_index: usize, timeline: JsValue);
|
||||
pub fn push_var(
|
||||
this: &PixiController,
|
||||
signal_ref_index: usize,
|
||||
timeline: JsValue,
|
||||
var_format: JsValue,
|
||||
);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn pop_var(this: &PixiController);
|
||||
|
|
Reference in a new issue