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:
Glint Dev
2026-07-21 20:32:29 +03:00
parent 5597f07787
commit 30cf2e5e26
7 changed files with 542 additions and 53 deletions

View File

@@ -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 {