Skip to content
This repository has been archived by the owner on Dec 28, 2021. It is now read-only.

Commit

Permalink
Apply cargo fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelMauderer committed Oct 26, 2021
1 parent 13ab59b commit 7a6440c
Show file tree
Hide file tree
Showing 427 changed files with 35,871 additions and 29,924 deletions.
29 changes: 15 additions & 14 deletions src/rust/build/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
#![feature(trait_alias)]

use std::path;
use std::io::ErrorKind;
use std::fmt::Display;
use std::io::ErrorKind;
use std::path;

/// Types that can yield a reference to std::path::Path.
pub trait PathRef = AsRef<path::Path>;

/// A structure describing a concrete release package on GitHub.
pub struct GithubRelease<T> {
pub project_url : T,
pub version : T,
pub filename : T,
pub project_url: T,
pub version: T,
pub filename: T,
}

impl<T:AsRef<str>+Display> GithubRelease<T> {
impl<T: AsRef<str> + Display> GithubRelease<T> {
/// Download the release package from GitHub if the target file was missing. Returns true if
/// the file was downloaded or false if it already existed.
///
/// The project_url should be a project's main page on GitHub.
pub fn download(&self, destination_dir:&path::Path) {
let url = format!("{}/releases/download/{}/{}",self.project_url,self.version,self.filename);
pub fn download(&self, destination_dir: &path::Path) {
let url =
format!("{}/releases/download/{}/{}", self.project_url, self.version, self.filename);
let destination_file = destination_dir.join(self.filename.as_ref());
Self::remove_old_file(&destination_file);
let mut resp = reqwest::blocking::get(&url).expect("Download failed.");
let mut out = std::fs::File::create(destination_file).expect("Failed to create file.");
let mut out = std::fs::File::create(destination_file).expect("Failed to create file.");
std::io::copy(&mut resp, &mut out).expect("Failed to copy file content.");
}

fn remove_old_file(file:&path::Path) {
let result = std::fs::remove_file(&file);
let error = result.err();
fn remove_old_file(file: &path::Path) {
let result = std::fs::remove_file(&file);
let error = result.err();
let fatal_error = error.filter(|err| err.kind() != ErrorKind::NotFound);
assert!(fatal_error.is_none());
}
Expand All @@ -48,10 +49,10 @@ pub fn absolute_path(path: impl PathRef) -> std::io::Result<path::PathBuf> {
}

/// Get the environment variable or panic if not available.
pub fn env_var_or_panic(var_name:&str) -> String {
pub fn env_var_or_panic(var_name: &str) -> String {
match std::env::var(var_name) {
Ok(var) => var,
Err(e) => panic!("Failed to read environment variable {}: {}.", var_name, e),
Err(e) => panic!("Failed to read environment variable {}: {}.", var_name, e),
}
}

Expand Down
38 changes: 21 additions & 17 deletions src/rust/ensogl/build.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
use std::{path, env};
use std::env;
use std::path;

/// A module with functions generating huge chunk of texts for text component benchmarks.
mod huge_text_generator {
use std::collections::hash_map::DefaultHasher;
use std::fs::File;
use std::hash::{Hash,Hasher};
use std::hash::Hash;
use std::hash::Hasher;
use std::io::Write;
use std::path::Path;

const MANY : usize = 100000;
const NOT_SO_MANY : usize = 100;
const MANY: usize = 100000;
const NOT_SO_MANY: usize = 100;

/// Create a file with many lines.
pub fn make_long_text_file(name:&Path) {
pub fn make_long_text_file(name: &Path) {
let mut file = File::create(name).unwrap();
for i in (1..MANY).rev() {
write_verse(&mut file, i);
Expand All @@ -21,40 +23,42 @@ mod huge_text_generator {
}

/// Create a file with not so many long lines
pub fn make_wide_text_file(name:&Path) {
let mut file = File::create(name).unwrap();
let verses_in_line = MANY/NOT_SO_MANY;
pub fn make_wide_text_file(name: &Path) {
let mut file = File::create(name).unwrap();
let verses_in_line = MANY / NOT_SO_MANY;
for i in (1..MANY).rev() {
write_verse(&mut file, i);
if i % verses_in_line == 0 {
let line_index = i / verses_in_line;
let offset = hash_from(line_index) % 32;
let prefix = (0..offset).map(|_| '|').collect::<String>();
let offset = hash_from(line_index) % 32;
let prefix = (0..offset).map(|_| '|').collect::<String>();
writeln!(file).unwrap();
write!(file,"{}",prefix).unwrap();
write!(file, "{}", prefix).unwrap();
}
}
}

fn hash_from(i:usize) -> u64 {
fn hash_from(i: usize) -> u64 {
let mut hasher = DefaultHasher::new();
i.hash(&mut hasher);
hasher.finish()
}

fn write_verse(file:&mut File, i:usize) {
write!(file,
fn write_verse(file: &mut File, i: usize) {
write!(
file,
"{i} bottles of beer on the wall, {i} bottles of beer.\
Take one down and pass it around, {j} bottles of beer on the wall. ",
i = i,
j = i-1
).unwrap();
j = i - 1
)
.unwrap();
}
}


fn main() {
let out = env::var("OUT_DIR").unwrap();
let out = env::var("OUT_DIR").unwrap();
let out_dir = path::Path::new(&out);
huge_text_generator::make_long_text_file(out_dir.join("long.txt").as_path());
huge_text_generator::make_wide_text_file(out_dir.join("wide.txt").as_path());
Expand Down
5 changes: 2 additions & 3 deletions src/rust/ensogl/example/src/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
use crate::prelude::*;

use ensogl_core::system::web;
use ensogl_core::application::Application;
use ensogl_core::system::web;
use ensogl_core::DEPRECATED_Animation;
use ensogl_text_msdf_sys::run_once_initialized;
use logger::TraceLogger as Logger;
Expand Down Expand Up @@ -34,8 +34,7 @@ pub fn entry_point_animation() {
// ========================

fn init() {

let logger : Logger = Logger::new("AnimationTest");
let logger: Logger = Logger::new("AnimationTest");
let network = enso_frp::Network::new("test");
let animation = DEPRECATED_Animation::<f32>::new(&network);
animation.set_target_value(-259_830.0);
Expand Down
128 changes: 65 additions & 63 deletions src/rust/ensogl/example/src/complex_shape_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
use ensogl_core::prelude::*;

use ensogl_core::data::color;
use ensogl_core::display::navigation::navigator::Navigator;
use ensogl_core::system::web;
use wasm_bindgen::prelude::*;
use ensogl_core::display::object::ObjectOps;
use ensogl_core::display::world::*;
use ensogl_core::display::scene;
use ensogl_core::display::shape::*;
use ensogl_core::data::color;
use ensogl_core::display::style::theme;
use ensogl_core::display::world::*;
use ensogl_core::system::web;
use wasm_bindgen::prelude::*;



Expand Down Expand Up @@ -58,30 +58,30 @@ pub fn entry_point_complex_shape_system() {
web::forward_panic_hook_to_console();
web::set_stack_trace_limit();

let world = World::new(&web::get_html_element_by_id("root").unwrap());
let scene = world.scene();
let camera = scene.camera().clone_ref();
let navigator = Navigator::new(scene,&camera);
let logger = Logger::new("ShapeView");
let world = World::new(&web::get_html_element_by_id("root").unwrap());
let scene = world.scene();
let camera = scene.camera().clone_ref();
let navigator = Navigator::new(scene, &camera);
let logger = Logger::new("ShapeView");

let theme_manager = theme::Manager::from(&scene.style_sheet);

let theme1 = theme::Theme::new();
theme1.set("base_color", color::Rgba::new(0.0,0.0,1.0,1.0));
theme1.set("base_color", color::Rgba::new(0.0, 0.0, 1.0, 1.0));
theme1.set("animation.duration", 0.5);
theme1.set("graph.node.shadow.color", 5.0);
theme1.set("graph.node.shadow.size", 5.0);
theme1.set("mouse.pointer.color", color::Rgba::new(0.3,0.3,0.3,1.0));
theme1.set("mouse.pointer.color", color::Rgba::new(0.3, 0.3, 0.3, 1.0));

let theme2 = theme::Theme::new();
theme2.set("base_color", color::Rgba::new(0.0,1.0,0.0,1.0));
theme2.set("base_color", color::Rgba::new(0.0, 1.0, 0.0, 1.0));
theme2.set("animation.duration", 0.7);
theme2.set("graph.node.shadow.color", 5.0);
theme2.set("graph.node.shadow.size", 5.0);
theme2.set("mouse.pointer.color", color::Rgba::new(0.3,0.3,0.3,1.0));
theme2.set("mouse.pointer.color", color::Rgba::new(0.3, 0.3, 0.3, 1.0));

theme_manager.register("theme1",theme1);
theme_manager.register("theme2",theme2);
theme_manager.register("theme1", theme1);
theme_manager.register("theme2", theme2);

theme_manager.set_enabled(&["theme1".to_string()]);

Expand All @@ -97,7 +97,8 @@ pub fn entry_point_complex_shape_system() {
mask.size.set(Vector2::new(300.0, 300.0));
mask.mod_position(|t| *t = Vector3::new(-50.0, 0.0, 0.0));

let scissor_box = scene::layer::ScissorBox::new_with_position_and_size(default(),Vector2(600,600));
let scissor_box =
scene::layer::ScissorBox::new_with_position_and_size(default(), Vector2(600, 600));
scene.layers.main.set_scissor_box(Some(&scissor_box));

let view2 = shape::View::new(&logger);
Expand All @@ -111,51 +112,52 @@ pub fn entry_point_complex_shape_system() {
let scene = world.scene().clone_ref();

let mut frame = 0;
world.on_frame(move |_time| {
mask.set_position_x(((frame as f32)/30.0).sin()*100.0);

let _keep_alive = &navigator;
let _keep_alive = &style_watch;
let _keep_alive = &theme_manager;
if frame == 50 {
// These comments are left for easy debugging in the future.
// DEBUG!("---------------");
// DEBUG!("{scene.layers.node_searcher:#?}");
// DEBUG!("{scene.layers.main:#?}");
// DEBUG!("{scene.layers.mask:#?}");
// DEBUG!("{scene.layers.node_searcher_mask:#?}");
// DEBUG!("{scene.layers.viz:#?}");
}
if frame == 100 {
DEBUG!("Adding previously hidden element.");
scene.add_child(&view2);
// These comments are left for easy debugging in the future.
// DEBUG!("---------------");
// DEBUG!("{scene.layers.node_searcher:#?}");
// DEBUG!("{scene.layers.main:#?}");
// DEBUG!("{scene.layers.mask:#?}");
// DEBUG!("{scene.layers.node_searcher_mask:#?}");
// DEBUG!("{scene.layers.viz:#?}");
}
if frame == 150 {
DEBUG!("Enabling masking.");
// These comments are left for easy debugging in the future.
// DEBUG!("---------------");
// DEBUG!("{scene.layers.node_searcher:#?}");
// DEBUG!("{scene.layers.main:#?}");
// DEBUG!("{scene.layers.mask:#?}");
// DEBUG!("{scene.layers.node_searcher_mask:#?}");
// DEBUG!("{scene.layers.viz:#?}");

scene.layers.node_searcher.add_exclusive(&view1);
scene.layers.node_searcher.add_exclusive(&view2);
scene.layers.node_searcher_mask.add_exclusive(&mask);
}
if frame == 200 {
DEBUG!("Changing the theme.");
theme_manager.set_enabled(&["theme2".to_string()]);
}
frame += 1;
}).forget();

world
.on_frame(move |_time| {
mask.set_position_x(((frame as f32) / 30.0).sin() * 100.0);

let _keep_alive = &navigator;
let _keep_alive = &style_watch;
let _keep_alive = &theme_manager;
if frame == 50 {
// These comments are left for easy debugging in the future.
// DEBUG!("---------------");
// DEBUG!("{scene.layers.node_searcher:#?}");
// DEBUG!("{scene.layers.main:#?}");
// DEBUG!("{scene.layers.mask:#?}");
// DEBUG!("{scene.layers.node_searcher_mask:#?}");
// DEBUG!("{scene.layers.viz:#?}");
}
if frame == 100 {
DEBUG!("Adding previously hidden element.");
scene.add_child(&view2);
// These comments are left for easy debugging in the future.
// DEBUG!("---------------");
// DEBUG!("{scene.layers.node_searcher:#?}");
// DEBUG!("{scene.layers.main:#?}");
// DEBUG!("{scene.layers.mask:#?}");
// DEBUG!("{scene.layers.node_searcher_mask:#?}");
// DEBUG!("{scene.layers.viz:#?}");
}
if frame == 150 {
DEBUG!("Enabling masking.");
// These comments are left for easy debugging in the future.
// DEBUG!("---------------");
// DEBUG!("{scene.layers.node_searcher:#?}");
// DEBUG!("{scene.layers.main:#?}");
// DEBUG!("{scene.layers.mask:#?}");
// DEBUG!("{scene.layers.node_searcher_mask:#?}");
// DEBUG!("{scene.layers.viz:#?}");

scene.layers.node_searcher.add_exclusive(&view1);
scene.layers.node_searcher.add_exclusive(&view2);
scene.layers.node_searcher_mask.add_exclusive(&mask);
}
if frame == 200 {
DEBUG!("Changing the theme.");
theme_manager.set_enabled(&["theme2".to_string()]);
}
frame += 1;
})
.forget();
}
Loading

0 comments on commit 7a6440c

Please sign in to comment.