This commit is contained in:
Martin Kavík 2024-06-17 11:36:00 +02:00
parent e59d10d23a
commit d078f3a470
3 changed files with 41 additions and 32 deletions

View file

@ -1,4 +1,4 @@
use crate::{Layout, Filename}; use crate::{Filename, Layout};
use std::cell::Cell; use std::cell::Cell;
use std::mem; use std::mem;
use std::ops::Not; use std::ops::Not;

View file

@ -1,6 +1,6 @@
use zoon::*; use crate::{platform, script_bridge, Filename, Layout};
use crate::{platform, script_bridge, Layout, Filename};
use std::rc::Rc; use std::rc::Rc;
use zoon::*;
pub struct HeaderPanel { pub struct HeaderPanel {
hierarchy: Mutable<Option<Rc<wellen::Hierarchy>>>, hierarchy: Mutable<Option<Rc<wellen::Hierarchy>>>,
@ -32,7 +32,7 @@ impl HeaderPanel {
.s(Padding::new().top(5)) .s(Padding::new().top(5))
.s(Gap::both(15)) .s(Gap::both(15))
.item(self.load_button()) .item(self.load_button())
.item(self.layout_switcher()) .item(self.layout_switcher()),
) )
.item(self.command_panel()) .item(self.command_panel())
} }
@ -192,7 +192,7 @@ impl HeaderPanel {
.s(Gap::new().x(15)) .s(Gap::new().x(15))
.s(Padding::new().x(5)) .s(Padding::new().x(5))
.item(El::new().child("Javascript commands")) .item(El::new().child("Javascript commands"))
.item(El::new().s(Align::new().right()).child("Shift + Enter")) .item(El::new().s(Align::new().right()).child("Shift + Enter")),
) )
.item(self.command_editor(command_result)) .item(self.command_editor(command_result))
} }
@ -209,11 +209,20 @@ impl HeaderPanel {
.s(RoundedCorners::all(15)) .s(RoundedCorners::all(15))
.s(Height::default().min(50)) .s(Height::default().min(50))
.s(Width::default().min(300)) .s(Width::default().min(300))
.s(Font::new().tracking(1).weight(FontWeight::Medium).color(color!("White")).family([FontFamily::new("Courier New"), FontFamily::Monospace])) .s(Font::new()
.s(Shadows::new([Shadow::new().inner().color(color!("DarkSlateBlue")).blur(4)])) .tracking(1)
.weight(FontWeight::Medium)
.color(color!("White"))
.family([FontFamily::new("Courier New"), FontFamily::Monospace]))
.s(Shadows::new([Shadow::new()
.inner()
.color(color!("DarkSlateBlue"))
.blur(4)]))
// @TODO to MZ API? (together with autocomplete and others?) // @TODO to MZ API? (together with autocomplete and others?)
.update_raw_el(|raw_el| raw_el.attr("spellcheck", "false")) .update_raw_el(|raw_el| raw_el.attr("spellcheck", "false"))
.placeholder(Placeholder::new("FW.say_hello()").s(Font::new().color(color!("LightBlue")))) .placeholder(
Placeholder::new("FW.say_hello()").s(Font::new().color(color!("LightBlue"))),
)
.label_hidden("command editor panel") .label_hidden("command editor panel")
.text_signal(script_signal) .text_signal(script_signal)
.on_change(clone!((script, command_result) move |text| { .on_change(clone!((script, command_result) move |text| {
@ -242,10 +251,7 @@ impl HeaderPanel {
.s(Align::new().top()) .s(Align::new().top())
.s(Scrollbars::both()) .s(Scrollbars::both())
.s(Padding::new().x(5)) .s(Padding::new().x(5))
.item( .item(El::new().child("Command result"))
El::new()
.child("Command result")
)
.item(self.command_result_el(command_result)) .item(self.command_result_el(command_result))
} }
@ -254,27 +260,29 @@ impl HeaderPanel {
command_result: ReadOnlyMutable<Option<Result<JsValue, JsValue>>>, command_result: ReadOnlyMutable<Option<Result<JsValue, JsValue>>>,
) -> impl Element { ) -> impl Element {
El::new() El::new()
.s(Font::new().tracking(1).weight(FontWeight::Medium).color(color!("White")).family([FontFamily::new("Courier New"), FontFamily::Monospace])) .s(Font::new()
.tracking(1)
.weight(FontWeight::Medium)
.color(color!("White"))
.family([FontFamily::new("Courier New"), FontFamily::Monospace]))
.s(Scrollbars::both()) .s(Scrollbars::both())
.s(Height::default().max(100)) .s(Height::default().max(100))
.child_signal( .child_signal(command_result.signal_ref(|result| match result {
command_result.signal_ref(|result| match result { Some(Ok(js_value)) => {
Some(Ok(js_value)) => { if let Some(string_value) = js_value.as_string() {
if let Some(string_value) = js_value.as_string() { string_value
string_value } else if let Some(number_value) = js_value.as_f64() {
} else if let Some(number_value) = js_value.as_f64() { number_value.to_string()
number_value.to_string() } else if let Some(bool_value) = js_value.as_bool() {
} else if let Some(bool_value) = js_value.as_bool() { bool_value.to_string()
bool_value.to_string() } else {
} else { format!("{js_value:?}")
format!("{js_value:?}")
}
} }
Some(Err(js_value)) => { }
format!("Error: {js_value:?}") Some(Err(js_value)) => {
} format!("Error: {js_value:?}")
None => "-".to_owned() }
}), None => "-".to_owned(),
) }))
} }
} }

View file

@ -89,7 +89,8 @@ 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_with_options(EventOptions::new().preventable(), raw_el.event_handler_with_options(
EventOptions::new().preventable(),
clone!((controller) move |event: events_extra::WheelEvent| { clone!((controller) move |event: events_extra::WheelEvent| {
event.prevent_default(); event.prevent_default();
if let Some(controller) = controller.lock_ref().as_ref() { if let Some(controller) = controller.lock_ref().as_ref() {