Phase 1.2-1.6: replace variables HashMap<String,String> with HashMap<String,Value>, rewrite str_to_dyn/dyn_to_str -> value_to_dynamic/dynamic_to_value, update resolve_string/evaluate_condition/is_truthy for Value
This commit is contained in:
14
src/app.rs
14
src/app.rs
@@ -1,7 +1,7 @@
|
||||
use iced::widget::{column, container};
|
||||
use iced::{Length, Theme};
|
||||
|
||||
use crate::interpreter::{Document, Element, Interpreter, RheiContext};
|
||||
use crate::interpreter::{Document, Element, Interpreter, RheiContext, Value};
|
||||
use crate::renderer::render_element;
|
||||
use crate::Message;
|
||||
|
||||
@@ -19,7 +19,7 @@ impl GlintApp {
|
||||
pub fn update(&mut self, message: Message) -> iced::Task<Message> {
|
||||
match message {
|
||||
Message::WindowScrolled(y) => {
|
||||
self.doc.variables.insert("__scroll_y".to_string(), y.to_string());
|
||||
self.doc.variables.insert("__scroll_y".to_string(), Value::Float(y as f64));
|
||||
}
|
||||
Message::EventTriggered(script) => {
|
||||
if !script.is_empty() {
|
||||
@@ -27,15 +27,15 @@ impl GlintApp {
|
||||
}
|
||||
}
|
||||
Message::InputChanged(Some(var), val) => {
|
||||
self.doc.variables.insert(var, val);
|
||||
self.doc.variables.insert(var, Value::from(val));
|
||||
}
|
||||
Message::ToggleChanged(Some(var), val) => {
|
||||
self.doc.variables.insert(var, val.to_string());
|
||||
self.doc.variables.insert(var, Value::Bool(val));
|
||||
}
|
||||
Message::SliderChanged(Some(var), val) => {
|
||||
self.doc.variables.insert(var.clone(), format!("{:.1}", val));
|
||||
self.doc.variables.insert(var.clone(), Value::Float(val));
|
||||
if var == "volume_level" {
|
||||
self.doc.variables.insert("age".to_string(), val.to_string());
|
||||
self.doc.variables.insert("age".to_string(), Value::Float(val));
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
@@ -63,7 +63,7 @@ impl GlintApp {
|
||||
let mut global_sticky_layers = Vec::new();
|
||||
|
||||
let _scroll_y = self.doc.variables.get("__scroll_y")
|
||||
.and_then(|v| v.parse::<f32>().ok())
|
||||
.and_then(|v| if let Value::Float(f) = v { Some(*f as f32) } else { None })
|
||||
.unwrap_or(0.0);
|
||||
|
||||
for root in &self.vdom_roots {
|
||||
|
||||
Reference in New Issue
Block a user