chore: ran cargo fmt
This commit is contained in:
@@ -7,11 +7,7 @@ use crate::{
|
||||
paths::EwwPaths,
|
||||
widgets::window::Window,
|
||||
// dynval::DynVal,
|
||||
widgets::{
|
||||
build_widget::build_gtk_widget,
|
||||
build_widget::WidgetInput,
|
||||
widget_definitions::WidgetRegistry,
|
||||
},
|
||||
widgets::{build_widget::build_gtk_widget, build_widget::WidgetInput, widget_definitions::WidgetRegistry},
|
||||
window::{
|
||||
coords::Coords,
|
||||
monitor::MonitorIdentifier,
|
||||
@@ -27,7 +23,7 @@ use ewwii_shared_util::Span;
|
||||
use gdk::Monitor;
|
||||
use glib::ObjectExt;
|
||||
use gtk::{gdk, glib};
|
||||
use iirhai::widgetnode::{WidgetNode, get_id_to_props_map};
|
||||
use iirhai::widgetnode::{get_id_to_props_map, WidgetNode};
|
||||
use itertools::Itertools;
|
||||
use once_cell::sync::Lazy;
|
||||
use rhai::{Dynamic, Scope};
|
||||
@@ -327,13 +323,10 @@ impl<B: DisplayBackend> App<B> {
|
||||
|
||||
/// Holds the id and the props of a widget
|
||||
/// It is crutual for supporting dynamic updates
|
||||
let mut widget_reg_store = WidgetRegistry::new();
|
||||
let mut widget_reg_store = WidgetRegistry::new();
|
||||
// note for future me: ^ this might need cloning.
|
||||
|
||||
let root_widget = build_gtk_widget(
|
||||
WidgetInput::Window(window_def),
|
||||
&mut widget_reg_store
|
||||
)?;
|
||||
let root_widget = build_gtk_widget(WidgetInput::Window(window_def), &mut widget_reg_store)?;
|
||||
|
||||
root_widget.style_context().add_class(window_name);
|
||||
|
||||
@@ -351,7 +344,7 @@ impl<B: DisplayBackend> App<B> {
|
||||
while let Some(var_name) = rx.recv().await {
|
||||
log::debug!("Received update for var: {}", var_name);
|
||||
let vars = store.read().unwrap().clone();
|
||||
|
||||
|
||||
match generate_new_widgetnode(&vars, &config_path).await {
|
||||
Ok(new_widget) => {
|
||||
if let Err(e) = update_sender.send(new_widget) {
|
||||
@@ -559,11 +552,7 @@ fn initialize_window<B: DisplayBackend>(
|
||||
|
||||
window.show_all();
|
||||
|
||||
Ok(EwwiiWindow {
|
||||
name: window_init.name.clone(),
|
||||
gtk_window: window,
|
||||
destroy_event_handler_id: None
|
||||
})
|
||||
Ok(EwwiiWindow { name: window_init.name.clone(), gtk_window: window, destroy_event_handler_id: None })
|
||||
}
|
||||
|
||||
async fn generate_new_widgetnode(all_vars: &HashMap<String, String>, code_path: &Path) -> Result<WidgetNode> {
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
use anyhow::Result;
|
||||
use gtk::{
|
||||
gdk::prelude::Cast,
|
||||
};
|
||||
use gtk::gdk::prelude::Cast;
|
||||
|
||||
use crate::{
|
||||
config::WindowDefinition,
|
||||
widgets::widget_definitions::*,
|
||||
};
|
||||
use crate::{config::WindowDefinition, widgets::widget_definitions::*};
|
||||
|
||||
use iirhai::widgetnode::WidgetNode;
|
||||
|
||||
@@ -30,52 +25,30 @@ pub fn build_gtk_widget(input: WidgetInput, widget_reg: &mut WidgetRegistry) ->
|
||||
fn build_gtk_widget_from_node(root_node: WidgetNode, widget_reg: &mut WidgetRegistry) -> Result<gtk::Widget> {
|
||||
let root_node2 = root_node.clone();
|
||||
let gtk_widget = match root_node {
|
||||
WidgetNode::Box { props, children } =>
|
||||
build_gtk_box(props, children, widget_reg)?.upcast(),
|
||||
WidgetNode::CenterBox { props, children } =>
|
||||
build_center_box(props, children, widget_reg)?.upcast(),
|
||||
WidgetNode::EventBox { props, children } =>
|
||||
build_gtk_event_box(props, children, widget_reg)?.upcast(),
|
||||
WidgetNode::Box { props, children } => build_gtk_box(props, children, widget_reg)?.upcast(),
|
||||
WidgetNode::CenterBox { props, children } => build_center_box(props, children, widget_reg)?.upcast(),
|
||||
WidgetNode::EventBox { props, children } => build_gtk_event_box(props, children, widget_reg)?.upcast(),
|
||||
WidgetNode::ToolTip { children } => build_tooltip(children, widget_reg)?.upcast(),
|
||||
WidgetNode::CircularProgress { props } =>
|
||||
build_circular_progress_bar(props, widget_reg)?.upcast(),
|
||||
WidgetNode::Graph { props } =>
|
||||
build_graph(props, widget_reg)?.upcast(),
|
||||
WidgetNode::Transform { props } =>
|
||||
build_transform(props, widget_reg)?.upcast(),
|
||||
WidgetNode::Slider { props } =>
|
||||
build_gtk_scale(props, widget_reg)?.upcast(),
|
||||
WidgetNode::Progress { props } =>
|
||||
build_gtk_progress(props, widget_reg)?.upcast(),
|
||||
WidgetNode::Image { props } =>
|
||||
build_gtk_image(props, widget_reg)?.upcast(),
|
||||
WidgetNode::Button { props } =>
|
||||
build_gtk_button(props, widget_reg)?.upcast(),
|
||||
WidgetNode::Label { props } =>
|
||||
build_gtk_label(props, widget_reg)?.upcast(),
|
||||
WidgetNode::CircularProgress { props } => build_circular_progress_bar(props, widget_reg)?.upcast(),
|
||||
WidgetNode::Graph { props } => build_graph(props, widget_reg)?.upcast(),
|
||||
WidgetNode::Transform { props } => build_transform(props, widget_reg)?.upcast(),
|
||||
WidgetNode::Slider { props } => build_gtk_scale(props, widget_reg)?.upcast(),
|
||||
WidgetNode::Progress { props } => build_gtk_progress(props, widget_reg)?.upcast(),
|
||||
WidgetNode::Image { props } => build_gtk_image(props, widget_reg)?.upcast(),
|
||||
WidgetNode::Button { props } => build_gtk_button(props, widget_reg)?.upcast(),
|
||||
WidgetNode::Label { props } => build_gtk_label(props, widget_reg)?.upcast(),
|
||||
// WIDGET_NAME_LITERAL => build_gtk_literal(node)?.upcast(),
|
||||
WidgetNode::Input { props } =>
|
||||
build_gtk_input(props, widget_reg)?.upcast(),
|
||||
WidgetNode::Calendar { props } =>
|
||||
build_gtk_calendar(props, widget_reg)?.upcast(),
|
||||
WidgetNode::ColorButton { props } =>
|
||||
build_gtk_color_button(props, widget_reg)?.upcast(),
|
||||
WidgetNode::Expander { props, children } =>
|
||||
build_gtk_expander(props, children, widget_reg)?.upcast(),
|
||||
WidgetNode::ColorChooser { props } =>
|
||||
build_gtk_color_chooser(props, widget_reg)?.upcast(),
|
||||
WidgetNode::ComboBoxText { props } =>
|
||||
build_gtk_combo_box_text(props, widget_reg)?.upcast(),
|
||||
WidgetNode::Checkbox { props } =>
|
||||
build_gtk_checkbox(props, widget_reg)?.upcast(),
|
||||
WidgetNode::Revealer { props, children } =>
|
||||
build_gtk_revealer(props, children, widget_reg)?.upcast(),
|
||||
WidgetNode::Scroll { props, children } =>
|
||||
build_gtk_scrolledwindow(props, children, widget_reg)?.upcast(),
|
||||
WidgetNode::OverLay { children } =>
|
||||
build_gtk_overlay(children, widget_reg)?.upcast(),
|
||||
WidgetNode::Stack { props, children } =>
|
||||
build_gtk_stack(props, children, widget_reg)?.upcast(),
|
||||
WidgetNode::Input { props } => build_gtk_input(props, widget_reg)?.upcast(),
|
||||
WidgetNode::Calendar { props } => build_gtk_calendar(props, widget_reg)?.upcast(),
|
||||
WidgetNode::ColorButton { props } => build_gtk_color_button(props, widget_reg)?.upcast(),
|
||||
WidgetNode::Expander { props, children } => build_gtk_expander(props, children, widget_reg)?.upcast(),
|
||||
WidgetNode::ColorChooser { props } => build_gtk_color_chooser(props, widget_reg)?.upcast(),
|
||||
WidgetNode::ComboBoxText { props } => build_gtk_combo_box_text(props, widget_reg)?.upcast(),
|
||||
WidgetNode::Checkbox { props } => build_gtk_checkbox(props, widget_reg)?.upcast(),
|
||||
WidgetNode::Revealer { props, children } => build_gtk_revealer(props, children, widget_reg)?.upcast(),
|
||||
WidgetNode::Scroll { props, children } => build_gtk_scrolledwindow(props, children, widget_reg)?.upcast(),
|
||||
WidgetNode::OverLay { children } => build_gtk_overlay(children, widget_reg)?.upcast(),
|
||||
WidgetNode::Stack { props, children } => build_gtk_stack(props, children, widget_reg)?.upcast(),
|
||||
// WIDGET_NAME_SYSTRAY => build_systray(node)?.upcast(),
|
||||
unknown => {
|
||||
return Err(anyhow::anyhow!("Cannot build GTK widget from node: {:?}", unknown));
|
||||
|
||||
@@ -8,7 +8,7 @@ use anyhow::{anyhow, bail, Result};
|
||||
use gdk::{ModifierType, NotifyType};
|
||||
use gtk::{self, prelude::*, DestDefaults, TargetEntry, TargetList};
|
||||
use gtk::{gdk, glib, pango};
|
||||
use iirhai::widgetnode::{WidgetNode, hash_props_and_type};
|
||||
use iirhai::widgetnode::{hash_props_and_type, WidgetNode};
|
||||
use once_cell::sync::Lazy;
|
||||
use rhai::Map;
|
||||
|
||||
@@ -16,11 +16,11 @@ use super::widget_definitions_helper::*;
|
||||
use ewwii_shared_util::general_helper::*;
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
collections::HashMap,
|
||||
// cmp::Ordering,
|
||||
collections::HashSet,
|
||||
rc::Rc,
|
||||
time::Duration,
|
||||
collections::HashMap,
|
||||
};
|
||||
|
||||
// custom widgets
|
||||
@@ -63,9 +63,7 @@ pub struct WidgetRegistry {
|
||||
|
||||
impl WidgetRegistry {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
widgets: HashMap::new(),
|
||||
}
|
||||
Self { widgets: HashMap::new() }
|
||||
}
|
||||
|
||||
pub fn update_prop_changes(&self, id_to_props: HashMap<u64, Map>) {
|
||||
@@ -73,8 +71,8 @@ impl WidgetRegistry {
|
||||
if let Some(entry) = self.widgets.get(&id) {
|
||||
(entry.update_fn)(&props);
|
||||
} // else {
|
||||
// println!("Warning: id {} not found in widget_registry", id);
|
||||
// }
|
||||
// println!("Warning: id {} not found in widget_registry", id);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -101,7 +99,7 @@ pub(super) fn build_gtk_box(props: Map, children: Vec<WidgetNode>, widget_regist
|
||||
}
|
||||
|
||||
let gtk_widget_clone = gtk_widget.clone();
|
||||
|
||||
|
||||
let update_fn: UpdateFn = Box::new(move |props: &Map| {
|
||||
if let Some(orientation_str) = props.get("orientation").and_then(|v| v.clone().try_cast::<String>()) {
|
||||
if let Ok(orientation) = parse_orientation(&orientation_str) {
|
||||
@@ -120,10 +118,13 @@ pub(super) fn build_gtk_box(props: Map, children: Vec<WidgetNode>, widget_regist
|
||||
|
||||
let id = hash_props_and_type(&props, "Box");
|
||||
|
||||
widget_registry.widgets.insert(id, WidgetEntry {
|
||||
// widget: gtk_widget.upcast(),
|
||||
update_fn,
|
||||
});
|
||||
widget_registry.widgets.insert(
|
||||
id,
|
||||
WidgetEntry {
|
||||
// widget: gtk_widget.upcast(),
|
||||
update_fn,
|
||||
},
|
||||
);
|
||||
|
||||
Ok(gtk_widget)
|
||||
}
|
||||
@@ -199,9 +200,18 @@ pub(super) fn build_center_box(props: Map, children: Vec<WidgetNode>, widget_reg
|
||||
bail!("centerbox must contain exactly 3 children, but got more");
|
||||
}
|
||||
|
||||
let first = build_gtk_widget(WidgetInput::Node(children.get(0).cloned().ok_or_else(|| anyhow!("missing child 0"))?), widget_registry)?;
|
||||
let center = build_gtk_widget(WidgetInput::Node(children.get(1).cloned().ok_or_else(|| anyhow!("missing child 1"))?), widget_registry)?;
|
||||
let end = build_gtk_widget(WidgetInput::Node(children.get(2).cloned().ok_or_else(|| anyhow!("missing child 2"))?), widget_registry)?;
|
||||
let first = build_gtk_widget(
|
||||
WidgetInput::Node(children.get(0).cloned().ok_or_else(|| anyhow!("missing child 0"))?),
|
||||
widget_registry,
|
||||
)?;
|
||||
let center = build_gtk_widget(
|
||||
WidgetInput::Node(children.get(1).cloned().ok_or_else(|| anyhow!("missing child 1"))?),
|
||||
widget_registry,
|
||||
)?;
|
||||
let end = build_gtk_widget(
|
||||
WidgetInput::Node(children.get(2).cloned().ok_or_else(|| anyhow!("missing child 2"))?),
|
||||
widget_registry,
|
||||
)?;
|
||||
|
||||
let gtk_widget = gtk::Box::new(orientation, 0);
|
||||
gtk_widget.pack_start(&first, true, true, 0);
|
||||
@@ -219,28 +229,30 @@ pub(super) fn build_center_box(props: Map, children: Vec<WidgetNode>, widget_reg
|
||||
.get("orientation")
|
||||
.and_then(|v| v.clone().try_cast::<String>())
|
||||
.map(|s| parse_orientation(&s))
|
||||
.transpose() {
|
||||
Ok(opt) => opt.unwrap_or(gtk::Orientation::Horizontal),
|
||||
Err(e) => {
|
||||
eprintln!("Error parsing orientation: {:?}", e);
|
||||
gtk::Orientation::Horizontal
|
||||
}
|
||||
};
|
||||
.transpose()
|
||||
{
|
||||
Ok(opt) => opt.unwrap_or(gtk::Orientation::Horizontal),
|
||||
Err(e) => {
|
||||
eprintln!("Error parsing orientation: {:?}", e);
|
||||
gtk::Orientation::Horizontal
|
||||
}
|
||||
};
|
||||
|
||||
gtk_widget_clone.set_orientation(orientation);
|
||||
});
|
||||
|
||||
|
||||
let id = hash_props_and_type(&props, "CenterBox");
|
||||
|
||||
widget_registry.widgets.insert(id, WidgetEntry {
|
||||
update_fn
|
||||
});
|
||||
widget_registry.widgets.insert(id, WidgetEntry { update_fn });
|
||||
|
||||
Ok(gtk_widget)
|
||||
}
|
||||
|
||||
pub(super) fn build_gtk_event_box(props: Map, children: Vec<WidgetNode>, widget_registry: &mut WidgetRegistry) -> Result<gtk::EventBox> {
|
||||
pub(super) fn build_gtk_event_box(
|
||||
props: Map,
|
||||
children: Vec<WidgetNode>,
|
||||
widget_registry: &mut WidgetRegistry,
|
||||
) -> Result<gtk::EventBox> {
|
||||
let gtk_widget = gtk::EventBox::new();
|
||||
|
||||
// Support :hover selector
|
||||
@@ -918,14 +930,11 @@ pub(super) fn build_gtk_label(props: Map, widget_registry: &mut WidgetRegistry)
|
||||
|
||||
let id = hash_props_and_type(&props, "Label");
|
||||
|
||||
widget_registry.widgets.insert(id, WidgetEntry {
|
||||
update_fn,
|
||||
});
|
||||
widget_registry.widgets.insert(id, WidgetEntry { update_fn });
|
||||
|
||||
Ok(gtk_widget)
|
||||
}
|
||||
|
||||
|
||||
pub(super) fn build_gtk_input(props: Map, widget_registry: &mut WidgetRegistry) -> Result<gtk::Entry> {
|
||||
let gtk_widget = gtk::Entry::new();
|
||||
|
||||
@@ -1048,7 +1057,11 @@ pub(super) fn build_gtk_combo_box_text(props: Map, widget_registry: &mut WidgetR
|
||||
Ok(gtk_widget)
|
||||
}
|
||||
|
||||
pub(super) fn build_gtk_expander(props: Map, children: Vec<WidgetNode>, widget_registry: &mut WidgetRegistry) -> Result<gtk::Expander> {
|
||||
pub(super) fn build_gtk_expander(
|
||||
props: Map,
|
||||
children: Vec<WidgetNode>,
|
||||
widget_registry: &mut WidgetRegistry,
|
||||
) -> Result<gtk::Expander> {
|
||||
let gtk_widget = gtk::Expander::new(None);
|
||||
|
||||
let count = children.len();
|
||||
@@ -1077,7 +1090,11 @@ pub(super) fn build_gtk_expander(props: Map, children: Vec<WidgetNode>, widget_r
|
||||
Ok(gtk_widget)
|
||||
}
|
||||
|
||||
pub(super) fn build_gtk_revealer(props: Map, children: Vec<WidgetNode>, widget_registry: &mut WidgetRegistry) -> Result<gtk::Revealer> {
|
||||
pub(super) fn build_gtk_revealer(
|
||||
props: Map,
|
||||
children: Vec<WidgetNode>,
|
||||
widget_registry: &mut WidgetRegistry,
|
||||
) -> Result<gtk::Revealer> {
|
||||
let gtk_widget = gtk::Revealer::new();
|
||||
|
||||
let transition = get_string_prop(&props, "transition", Some("crossfade"))?;
|
||||
@@ -1181,14 +1198,8 @@ pub(super) fn build_gtk_color_chooser(props: Map, widget_registry: &mut WidgetRe
|
||||
Ok(gtk_widget)
|
||||
}
|
||||
|
||||
pub(super) fn build_gtk_scale(
|
||||
props: Map,
|
||||
widget_registry: &mut WidgetRegistry,
|
||||
) -> Result<gtk::Scale> {
|
||||
let gtk_widget = gtk::Scale::new(
|
||||
gtk::Orientation::Horizontal,
|
||||
Some(>k::Adjustment::new(0.0, 0.0, 100.0, 1.0, 1.0, 1.0)),
|
||||
);
|
||||
pub(super) fn build_gtk_scale(props: Map, widget_registry: &mut WidgetRegistry) -> Result<gtk::Scale> {
|
||||
let gtk_widget = gtk::Scale::new(gtk::Orientation::Horizontal, Some(>k::Adjustment::new(0.0, 0.0, 100.0, 1.0, 1.0, 1.0)));
|
||||
|
||||
// Reusable closure for applying props
|
||||
let apply_props = |props: &Map, widget: >k::Scale| -> Result<()> {
|
||||
@@ -1226,7 +1237,11 @@ pub(super) fn build_gtk_scale(
|
||||
Ok(gtk_widget)
|
||||
}
|
||||
|
||||
pub(super) fn build_gtk_scrolledwindow(props: Map, children: Vec<WidgetNode>, widget_registry: &mut WidgetRegistry) -> Result<gtk::ScrolledWindow> {
|
||||
pub(super) fn build_gtk_scrolledwindow(
|
||||
props: Map,
|
||||
children: Vec<WidgetNode>,
|
||||
widget_registry: &mut WidgetRegistry,
|
||||
) -> Result<gtk::ScrolledWindow> {
|
||||
// I don't have single idea of what those two generics are supposed to be, but this works.
|
||||
let gtk_widget = gtk::ScrolledWindow::new(None::<>k::Adjustment>, None::<>k::Adjustment>);
|
||||
|
||||
|
||||
@@ -62,7 +62,6 @@ pub fn get_i32_prop(props: &Map, key: &str, default: Option<i32>) -> Result<i32>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn get_vec_string_prop(props: &Map, key: &str, default: Option<Vec<String>>) -> Result<Vec<String>> {
|
||||
if let Some(value) = props.get(key) {
|
||||
let array = value.clone().try_cast::<Vec<Dynamic>>().ok_or_else(|| anyhow!("Expected property `{}` to be a vec", key))?;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
pub mod builtins;
|
||||
pub mod error;
|
||||
pub mod helper;
|
||||
pub mod module_resolver;
|
||||
pub mod parser;
|
||||
pub mod providers;
|
||||
pub mod updates;
|
||||
pub mod widgetnode;
|
||||
pub mod module_resolver;
|
||||
@@ -1,8 +1,6 @@
|
||||
use rhai::{
|
||||
Engine, Module, ModuleResolver, Scope, AST, Position, EvalAltResult,
|
||||
};
|
||||
use rhai::{Engine, EvalAltResult, Module, ModuleResolver, Position, Scope, AST};
|
||||
use std::fs;
|
||||
use std::path::{PathBuf};
|
||||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct SimpleFileResolver;
|
||||
@@ -22,30 +20,22 @@ impl ModuleResolver for SimpleFileResolver {
|
||||
}
|
||||
|
||||
let base_dir = if let Some(src) = source_path {
|
||||
PathBuf::from(src)
|
||||
.parent()
|
||||
.map(|p| p.to_path_buf())
|
||||
.unwrap_or(std::env::current_dir().map_err(|e| {
|
||||
EvalAltResult::ErrorSystem("getting current_dir".into(), e.into())
|
||||
})?)
|
||||
PathBuf::from(src).parent().map(|p| p.to_path_buf()).unwrap_or(
|
||||
std::env::current_dir().map_err(|e| EvalAltResult::ErrorSystem("getting current_dir".into(), e.into()))?,
|
||||
)
|
||||
} else {
|
||||
std::env::current_dir().map_err(|e| {
|
||||
EvalAltResult::ErrorSystem("getting current_dir".into(), e.into())
|
||||
})?
|
||||
std::env::current_dir().map_err(|e| EvalAltResult::ErrorSystem("getting current_dir".into(), e.into()))?
|
||||
};
|
||||
|
||||
|
||||
if !file_path.is_absolute() {
|
||||
file_path = base_dir.join(file_path);
|
||||
}
|
||||
|
||||
let full_path = file_path.canonicalize().map_err(|e| {
|
||||
EvalAltResult::ErrorSystem(format!("resolving path: {path}"), e.into())
|
||||
})?;
|
||||
let full_path =
|
||||
file_path.canonicalize().map_err(|e| EvalAltResult::ErrorSystem(format!("resolving path: {path}"), e.into()))?;
|
||||
|
||||
let script = fs::read_to_string(&full_path).map_err(|e| {
|
||||
EvalAltResult::ErrorSystem(format!("reading file: {full_path:?}"), e.into())
|
||||
})?;
|
||||
let script = fs::read_to_string(&full_path)
|
||||
.map_err(|e| EvalAltResult::ErrorSystem(format!("reading file: {full_path:?}"), e.into()))?;
|
||||
|
||||
let ast: AST = engine.compile(&script)?;
|
||||
let scope = Scope::new();
|
||||
@@ -93,8 +83,6 @@ impl<R1: ModuleResolver, R2: ModuleResolver> ModuleResolver for ChainedResolver<
|
||||
path: &str,
|
||||
pos: Position,
|
||||
) -> Result<Rc<Module>, Box<EvalAltResult>> {
|
||||
self.first
|
||||
.resolve(engine, source_path, path, pos)
|
||||
.or_else(|_| self.second.resolve(engine, source_path, path, pos))
|
||||
self.first.resolve(engine, source_path, path, pos).or_else(|_| self.second.resolve(engine, source_path, path, pos))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use crate::{
|
||||
builtins::register_all_widgets, error::format_rhai_error, helper::extract_poll_and_listen_vars,
|
||||
providers::register_all_providers, widgetnode::WidgetNode,
|
||||
module_resolver::SimpleFileResolver,
|
||||
module_resolver::SimpleFileResolver, providers::register_all_providers, widgetnode::WidgetNode,
|
||||
};
|
||||
use anyhow::{anyhow, Result};
|
||||
use rhai::{Dynamic, Engine, Scope, AST};
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
pub mod env;
|
||||
pub mod text;
|
||||
|
||||
use crate::module_resolver::{ChainedResolver, SimpleFileResolver};
|
||||
use rhai::module_resolvers::StaticModuleResolver;
|
||||
use rhai::{exported_module, Engine};
|
||||
use crate::module_resolver::{SimpleFileResolver, ChainedResolver};
|
||||
|
||||
pub fn register_stdlib(engine: &mut Engine) {
|
||||
use crate::providers::stdlib::{env::env, text::text};
|
||||
|
||||
let mut resolver = StaticModuleResolver::new();
|
||||
|
||||
let chained = ChainedResolver {
|
||||
first: SimpleFileResolver,
|
||||
second: resolver.clone(),
|
||||
};
|
||||
let chained = ChainedResolver { first: SimpleFileResolver, second: resolver.clone() };
|
||||
|
||||
// adding modules
|
||||
let text_mod = exported_module!(text);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use rhai::{Dynamic, Map, Array};
|
||||
use anyhow::{Result, bail};
|
||||
use ahash::AHasher;
|
||||
use std::hash::{Hasher, Hash};
|
||||
use anyhow::{bail, Result};
|
||||
use rhai::{Array, Dynamic, Map};
|
||||
use std::collections::HashMap;
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum WidgetNode {
|
||||
@@ -46,92 +46,90 @@ pub fn get_id_to_props_map(root_node: &WidgetNode, id_to_props: &mut HashMap<u64
|
||||
for child in children {
|
||||
get_id_to_props_map(child, id_to_props)?;
|
||||
}
|
||||
},
|
||||
}
|
||||
WidgetNode::CenterBox { props, children } => {
|
||||
insert_props(props, "CenterBox", id_to_props)?;
|
||||
for child in children {
|
||||
get_id_to_props_map(child, id_to_props)?;
|
||||
}
|
||||
},
|
||||
}
|
||||
WidgetNode::EventBox { props, children } => {
|
||||
insert_props(props, "EventBox", id_to_props)?;
|
||||
for child in children {
|
||||
get_id_to_props_map(child, id_to_props)?;
|
||||
}
|
||||
},
|
||||
}
|
||||
WidgetNode::CircularProgress { props } => {
|
||||
insert_props(props, "CircularProgress", id_to_props)?;
|
||||
},
|
||||
}
|
||||
WidgetNode::Graph { props } => {
|
||||
insert_props(props, "Graph", id_to_props)?;
|
||||
},
|
||||
}
|
||||
WidgetNode::Transform { props } => {
|
||||
insert_props(props, "Transform", id_to_props)?;
|
||||
},
|
||||
}
|
||||
WidgetNode::Slider { props } => {
|
||||
insert_props(props, "Slider", id_to_props)?;
|
||||
},
|
||||
}
|
||||
WidgetNode::Progress { props } => {
|
||||
insert_props(props, "Progress", id_to_props)?;
|
||||
},
|
||||
}
|
||||
WidgetNode::Image { props } => {
|
||||
insert_props(props, "Image", id_to_props)?;
|
||||
},
|
||||
}
|
||||
WidgetNode::Button { props } => {
|
||||
insert_props(props, "Button", id_to_props)?;
|
||||
},
|
||||
}
|
||||
WidgetNode::Label { props } => {
|
||||
insert_props(props, "Label", id_to_props)?;
|
||||
},
|
||||
}
|
||||
WidgetNode::Input { props } => {
|
||||
insert_props(props, "Input", id_to_props)?;
|
||||
},
|
||||
}
|
||||
WidgetNode::Calendar { props } => {
|
||||
insert_props(props, "Calendar", id_to_props)?;
|
||||
},
|
||||
}
|
||||
WidgetNode::ColorButton { props } => {
|
||||
insert_props(props, "ColorButton", id_to_props)?;
|
||||
},
|
||||
}
|
||||
WidgetNode::Expander { props, children } => {
|
||||
insert_props(props, "Expander", id_to_props)?;
|
||||
for child in children {
|
||||
get_id_to_props_map(child, id_to_props)?;
|
||||
}
|
||||
},
|
||||
}
|
||||
WidgetNode::ToolTip { children } => {
|
||||
for child in children {
|
||||
get_id_to_props_map(child, id_to_props)?;
|
||||
}
|
||||
},
|
||||
}
|
||||
WidgetNode::ColorChooser { props } => {
|
||||
insert_props(props, "ColorChooser", id_to_props)?;
|
||||
},
|
||||
}
|
||||
WidgetNode::ComboBoxText { props } => {
|
||||
insert_props(props, "ComboBoxText", id_to_props)?;
|
||||
},
|
||||
}
|
||||
WidgetNode::Checkbox { props } => {
|
||||
insert_props(props, "Checkbox", id_to_props)?;
|
||||
},
|
||||
}
|
||||
WidgetNode::Revealer { props, children } => {
|
||||
insert_props(props, "Revealer", id_to_props)?;
|
||||
for child in children {
|
||||
get_id_to_props_map(child, id_to_props)?;
|
||||
}
|
||||
},
|
||||
WidgetNode::Scroll { props, children } => {
|
||||
insert_props(props, "Scroll", id_to_props)?
|
||||
},
|
||||
}
|
||||
WidgetNode::Scroll { props, children } => insert_props(props, "Scroll", id_to_props)?,
|
||||
WidgetNode::OverLay { children } => {
|
||||
for child in children {
|
||||
get_id_to_props_map(child, id_to_props)?;
|
||||
}
|
||||
},
|
||||
}
|
||||
WidgetNode::Stack { props, children } => {
|
||||
insert_props(props, "Stack", id_to_props)?;
|
||||
for child in children {
|
||||
get_id_to_props_map(child, id_to_props)?;
|
||||
}
|
||||
},
|
||||
}
|
||||
_ => {
|
||||
// do nothing for now ig?
|
||||
}
|
||||
@@ -164,7 +162,7 @@ pub fn hash_props_and_type(props: &Map, widget_type_str: &str) -> u64 {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use rhai::{Map, Dynamic};
|
||||
use rhai::{Dynamic, Map};
|
||||
|
||||
#[test]
|
||||
fn test_hash_props_and_type_consistency() {
|
||||
|
||||
Reference in New Issue
Block a user