diff --git a/packages/canvas-babylon/package.json b/packages/canvas-babylon/package.json index b9168bb39..1136694d3 100644 --- a/packages/canvas-babylon/package.json +++ b/packages/canvas-babylon/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/canvas-babylon", - "version": "2.0.0-alpha.35", + "version": "2.0.0-alpha.36", "description": "", "main": "index", "typings": "index.d.ts", diff --git a/packages/canvas-chartjs/package.json b/packages/canvas-chartjs/package.json index 000ab82c6..264e40a7c 100644 --- a/packages/canvas-chartjs/package.json +++ b/packages/canvas-chartjs/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/canvas-chartjs", - "version": "2.0.0-alpha.35", + "version": "2.0.0-alpha.36", "description": "ChartJS", "main": "index", "typings": "index.d.ts", diff --git a/packages/canvas-media/package.json b/packages/canvas-media/package.json index 673e4c6f9..cb05203ed 100644 --- a/packages/canvas-media/package.json +++ b/packages/canvas-media/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/canvas-media", - "version": "2.0.0-alpha.35", + "version": "2.0.0-alpha.36", "description": "Canvas media", "main": "index", "typings": "index.d.ts", diff --git a/packages/canvas-phaser-ce/package.json b/packages/canvas-phaser-ce/package.json index 06b6e266a..cf6eed69d 100644 --- a/packages/canvas-phaser-ce/package.json +++ b/packages/canvas-phaser-ce/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/canvas-phaser-ce", - "version": "2.0.0-alpha.35", + "version": "2.0.0-alpha.36", "description": "Tools for using Phaser-ce to build native 2D games in NativeScript 👾", "main": "index", "typings": "index.d.ts", diff --git a/packages/canvas-phaser/package.json b/packages/canvas-phaser/package.json index 33c443a79..1194c8469 100644 --- a/packages/canvas-phaser/package.json +++ b/packages/canvas-phaser/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/canvas-phaser", - "version": "2.0.0-alpha.35", + "version": "2.0.0-alpha.36", "description": "Build awesome 2D games with Phaser.js and NativeScript", "main": "index", "typings": "index.d.ts", diff --git a/packages/canvas-pixi/package.json b/packages/canvas-pixi/package.json index 7cd0311c9..6832ebff5 100644 --- a/packages/canvas-pixi/package.json +++ b/packages/canvas-pixi/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/canvas-pixi", - "version": "2.0.0-alpha.35", + "version": "2.0.0-alpha.36", "description": "Plugin for using pixi.js in NativeScript", "main": "index", "typings": "index.d.ts", diff --git a/packages/canvas-polyfill/package.json b/packages/canvas-polyfill/package.json index f2fa40a28..419f498d4 100644 --- a/packages/canvas-polyfill/package.json +++ b/packages/canvas-polyfill/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/canvas-polyfill", - "version": "2.0.0-alpha.35", + "version": "2.0.0-alpha.36", "description": "Polyfill for making NativeScript compatible with web libs like pixi.js, three.js, phaser.js, babylon.js, etc....", "main": "index", "typings": "index.d.ts", diff --git a/packages/canvas-three/package.json b/packages/canvas-three/package.json index 5d7b9e92e..6be0347f1 100644 --- a/packages/canvas-three/package.json +++ b/packages/canvas-three/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/canvas-three", - "version": "2.0.0-alpha.35", + "version": "2.0.0-alpha.36", "description": "Utilities for using THREE.js on NativeScript", "main": "index", "typings": "index.d.ts", diff --git a/packages/canvas/package.json b/packages/canvas/package.json index e6ef126c2..5de4e7576 100644 --- a/packages/canvas/package.json +++ b/packages/canvas/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/canvas", - "version": "2.0.0-alpha.35", + "version": "2.0.0-alpha.36", "description": "DOM Canvas API for NativeScript", "main": "index", "typings": "index.d.ts", diff --git a/packages/canvas/platforms/android/canvas-release.aar b/packages/canvas/platforms/android/canvas-release.aar index 765dd6b5b..e0227c085 100644 Binary files a/packages/canvas/platforms/android/canvas-release.aar and b/packages/canvas/platforms/android/canvas-release.aar differ diff --git a/packages/canvas/platforms/ios/CanvasNative.xcframework/Info.plist b/packages/canvas/platforms/ios/CanvasNative.xcframework/Info.plist index 803c127dd..2552f82e9 100644 --- a/packages/canvas/platforms/ios/CanvasNative.xcframework/Info.plist +++ b/packages/canvas/platforms/ios/CanvasNative.xcframework/Info.plist @@ -8,32 +8,32 @@ DebugSymbolsPath dSYMs LibraryIdentifier - ios-arm64 + ios-arm64_x86_64-simulator LibraryPath CanvasNative.framework SupportedArchitectures arm64 + x86_64 SupportedPlatform ios + SupportedPlatformVariant + simulator DebugSymbolsPath dSYMs LibraryIdentifier - ios-arm64_x86_64-simulator + ios-arm64 LibraryPath CanvasNative.framework SupportedArchitectures arm64 - x86_64 SupportedPlatform ios - SupportedPlatformVariant - simulator CFBundlePackageType diff --git a/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative b/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative index 7686f5a4b..c91dffc95 100755 Binary files a/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative and b/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative differ diff --git a/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative b/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative index cf3a766b0..27892d9db 100644 Binary files a/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative and b/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative differ diff --git a/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/CanvasNative b/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/CanvasNative index c14577e56..1d6b96098 100755 Binary files a/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/CanvasNative and b/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/CanvasNative differ diff --git a/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative b/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative index 4818a9e42..816960e74 100644 Binary files a/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative and b/packages/canvas/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative differ diff --git a/packages/canvas/src-native/canvas-ios/CanvasNative.xcodeproj/project.xcworkspace/xcuserdata/triniwiz.xcuserdatad/UserInterfaceState.xcuserstate b/packages/canvas/src-native/canvas-ios/CanvasNative.xcodeproj/project.xcworkspace/xcuserdata/triniwiz.xcuserdatad/UserInterfaceState.xcuserstate index 3149222ee..65e078037 100644 Binary files a/packages/canvas/src-native/canvas-ios/CanvasNative.xcodeproj/project.xcworkspace/xcuserdata/triniwiz.xcuserdatad/UserInterfaceState.xcuserstate and b/packages/canvas/src-native/canvas-ios/CanvasNative.xcodeproj/project.xcworkspace/xcuserdata/triniwiz.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/Info.plist b/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/Info.plist index 803c127dd..2552f82e9 100644 --- a/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/Info.plist +++ b/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/Info.plist @@ -8,32 +8,32 @@ DebugSymbolsPath dSYMs LibraryIdentifier - ios-arm64 + ios-arm64_x86_64-simulator LibraryPath CanvasNative.framework SupportedArchitectures arm64 + x86_64 SupportedPlatform ios + SupportedPlatformVariant + simulator DebugSymbolsPath dSYMs LibraryIdentifier - ios-arm64_x86_64-simulator + ios-arm64 LibraryPath CanvasNative.framework SupportedArchitectures arm64 - x86_64 SupportedPlatform ios - SupportedPlatformVariant - simulator CFBundlePackageType diff --git a/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative b/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative index 7686f5a4b..c91dffc95 100755 Binary files a/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative and b/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative differ diff --git a/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative b/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative index cf3a766b0..27892d9db 100644 Binary files a/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative and b/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative differ diff --git a/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/CanvasNative b/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/CanvasNative index c14577e56..1d6b96098 100755 Binary files a/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/CanvasNative and b/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/CanvasNative differ diff --git a/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative b/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative index 4818a9e42..816960e74 100644 Binary files a/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative and b/packages/canvas/src-native/canvas-ios/dist/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative differ diff --git a/packages/canvas/src-native/canvas-native/canvas-2d/src/context/drawing_text/mod.rs b/packages/canvas/src-native/canvas-native/canvas-2d/src/context/drawing_text/mod.rs index abffbb878..ab1321b21 100644 --- a/packages/canvas/src-native/canvas-native/canvas-2d/src/context/drawing_text/mod.rs +++ b/packages/canvas/src-native/canvas-native/canvas-2d/src/context/drawing_text/mod.rs @@ -1,14 +1,14 @@ -use log::{log, Level}; -use skia_safe::{Canvas, Paint}; use std::ops::Range; use std::os::raw::c_float; +use skia_safe::{Canvas, Paint}; + +use crate::context::Context; use crate::context::drawing_text::global_fonts::FONT_LIBRARY; use crate::context::drawing_text::text_metrics::TextMetrics; use crate::context::text_styles::text_align::TextAlign; use crate::context::text_styles::text_baseline::TextBaseLine; use crate::context::text_styles::text_direction::TextDirection; -use crate::context::Context; pub(crate) const MAX_TEXT_WIDTH: f32 = 100_000.0; @@ -130,12 +130,18 @@ impl Context { paragraph.layout(100000.); let metrics_vec = paragraph.get_line_metrics(); + + if metrics_vec.is_empty() { + return; + } let line_metrics = &metrics_vec[0]; let font = paragraph.get_font_at(0); let (_, font_metrics) = font.metrics(); + if font_metrics.has_bounds() { } let glyphs = font.str_to_glyphs_vec(text); let glyphs_size = glyphs.len(); + if glyphs_size == 0 { return; } let mut bounds = vec![skia_safe::Rect::default(); glyphs_size]; font.get_bounds(glyphs.as_slice(), bounds.as_mut_slice(), None); let range: Range = 0_usize..glyphs_size; @@ -148,16 +154,19 @@ impl Context { // run.calculateWidth will return 0 if font is rendering as fallback let mut line_width = 0.0; + for tbox in text_box.iter() { + line_width += tbox.rect.width(); + } + + if line_width == 0. { return; } + + let first_char_bounds = bounds[0]; let mut descent = first_char_bounds.bottom; let mut ascent = first_char_bounds.top; let last_char_bounds = bounds[glyphs_size - 1]; let last_char_pos_x = last_char_bounds.x(); - for tbox in text_box.iter() { - line_width += tbox.rect.width(); - } - let until = glyphs_size - 1; for i in 1..=until { let char_bounds = bounds[i]; @@ -314,129 +323,4 @@ impl Context { text_metrics } - - /* - fn draw_text(&mut self, is_fill: bool, text: &str, x: c_float, y: c_float, width: c_float) { - if x.is_infinite() || y.is_infinite() { - return; - } - - if width > 0.0 && width.is_infinite() { - return; - } - let shadow_paint; - let paint; - - if is_fill { - paint = self.state.paint.fill_paint(); - shadow_paint = self.state.paint.fill_shadow_paint( - self.state.shadow_offset, - self.state.shadow_color, - self.state.shadow_blur, - ); - } else { - paint = self.state.paint.stroke_paint(); - shadow_paint = self.state.paint.stroke_shadow_paint( - self.state.shadow_offset, - self.state.shadow_color, - self.state.shadow_blur, - ); - } - let font = &self.state.font; - - let measurement = font.to_skia().measure_str(text, Some(paint)); - let font_width = measurement.0; - let max_width = width; - let width: f32; - let use_max_width = max_width > 0.0 && max_width < font_width; - if use_max_width { - width = max_width - } else { - width = font_width; - } - let (line_spacing, metrics) = font.to_skia().metrics(); - let baseline = get_font_baseline(metrics, self.state.text_baseline); - let mut location: Point = (x, y + baseline).into(); - - match to_real_text_align(self.state.text_align, self.state.direction) { - TextAlign::RIGHT => { - location.x = location.x - width; - } - TextAlign::CENTER => { - location.x = location.x - (width / 2.0); - } - _ => { - // NOOP - } - } - let mut rect: (Point, Size) = ( - ( - location.x - metrics.cap_height / 2.0, - location.y - metrics.ascent - metrics.leading, - ) - .into(), - (width + metrics.cap_height, line_spacing).into(), - ); - - if !is_fill { - inflate_stroke_rect(&mut rect, paint); - } - - if use_max_width { - self.surface.canvas().save(); - self.surface - .canvas() - .translate(Point::new(location.x, location.y)); - let mut scale_x: f32 = 0.0; - if font_width > 0.0 { - scale_x = width / font_width; - } - - // We draw when font_width is 0 so compositing operations (eg, a "copy" op) still work. - self.surface.canvas().scale((scale_x, 1.0)); - } - - let font = font.to_skia(); - if let Some(shadow_paint) = shadow_paint { - self.surface - .canvas() - .draw_str(text, (location.x, location.y), &font, &shadow_paint); - } - - self.surface - .canvas() - .draw_str(text, (location.x, location.y), &font, paint); - - if use_max_width { - self.surface.canvas().restore(); - } - } - - */ - - /* pub fn measure_text(&self, text: &str) -> TextMetrics { - let (width, bounds) = self - .state - .font - .to_skia() - .measure_str(text, Some(self.state.paint.fill_paint())); - let (_, metrics) = self.state.font.to_skia().metrics(); - let ascent = metrics.ascent; - let descent = metrics.descent; - let baseline_y = get_font_baseline(metrics, self.state.text_baseline); - TextMetrics { - width, - actual_bounding_box_left: -bounds.x(), - actual_bounding_box_right: bounds.right(), - font_bounding_box_ascent: (ascent - baseline_y), - font_bounding_box_descent: (descent + baseline_y), - actual_bounding_box_ascent: (-bounds.y() - baseline_y), - actual_bounding_box_descent: (bounds.bottom() + baseline_y), - em_height_ascent: 0.0, - em_height_descent: 0.0, - hanging_baseline: (-0.8 * ascent + baseline_y), - alphabetic_baseline: baseline_y, - ideographic_baseline: (descent + baseline_y), - } - }*/ } diff --git a/packages/canvas/src-native/canvas-native/canvas-core/src/gl/mac.rs b/packages/canvas/src-native/canvas-native/canvas-core/src/gl/mac.rs index ef5cd8423..eab099cac 100644 --- a/packages/canvas/src-native/canvas-native/canvas-core/src/gl/mac.rs +++ b/packages/canvas/src-native/canvas-native/canvas-core/src/gl/mac.rs @@ -611,7 +611,7 @@ impl GLContext { use winit::event_loop::EventLoop; use winit::window::WindowBuilder; - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new().unwrap(); let window_builder = WindowBuilder::new(); let window = window_builder diff --git a/packages/canvas/src-native/canvas-native/playground/Cargo.toml b/packages/canvas/src-native/canvas-native/playground/Cargo.toml index 25484a3fc..79ff3109f 100644 --- a/packages/canvas/src-native/canvas-native/playground/Cargo.toml +++ b/packages/canvas/src-native/canvas-native/playground/Cargo.toml @@ -14,6 +14,6 @@ reqwest = { version = "0.11.14", features = ["blocking"] } chrono = "0.4.23" [target.'cfg(any(target_os = "macos", target_os = "android"))'.dependencies] -glutin = "0.30.4" -winit = "0.28.1" -glutin-winit = "0.3.0" \ No newline at end of file +winit = "0.29.4" +glutin-winit = "0.4.2" +glutin = "0.31.1" \ No newline at end of file diff --git a/packages/canvas/src-native/canvas-native/playground/src/main.rs b/packages/canvas/src-native/canvas-native/playground/src/main.rs index dcde5f178..807762a4a 100644 --- a/packages/canvas/src-native/canvas-native/playground/src/main.rs +++ b/packages/canvas/src-native/canvas-native/playground/src/main.rs @@ -540,7 +540,7 @@ void main() { } fn main() { - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new().unwrap(); let window_builder = WindowBuilder::new(); let mut asset = ImageAsset::new(); @@ -682,13 +682,12 @@ fn main() { value, 0, true, - value, + 0, 0., canvas_2d::context::text_styles::text_direction::TextDirection::LTR, )); - event_loop.run(move |event, target, control_flow| { - control_flow.set_wait(); + event_loop.run(move |event, target| { match event { Event::NewEvents(_) => {} Event::WindowEvent { event, .. } => { @@ -709,100 +708,104 @@ fn main() { // gl_state.swap_buffers(); } WindowEvent::CloseRequested => { - control_flow.set_exit(); + //control_flow.set_exit(); } - _ => {} - } - } - Event::RedrawEventsCleared => { - if !done { - window.request_redraw(); + WindowEvent::RedrawRequested => { + if !done { + window.request_redraw(); - canvas_native_webgl_clear_color(1., 1., 1., 1., &mut gl_state); + canvas_native_webgl_clear_color(1., 1., 1., 1., &mut gl_state); - canvas_native_webgl_clear(16384, &mut gl_state); + canvas_native_webgl_clear(16384, &mut gl_state); - // test(&mut gl_state, &mut gl_state_other, &mut ctx_2d); + // test(&mut gl_state, &mut gl_state_other, &mut ctx_2d); - leaves(&mut gl_state, &mut gl_state_other, &mut ctx_2d); + let mut ctx = ctx_2d.get_context_mut(); - done = true; + ctx.fill_text(" ", 0., 0., None); - gl_state.swap_buffers(); - } + // leaves(&mut gl_state, &mut gl_state_other, &mut ctx_2d); - // rainbow_octopus(&mut ctx_2d, &mut ro); - - // if let (Some(sun), Some(moon), Some(earth)) = (sun.as_ref(), moon.as_ref(), earth.as_ref()) { - // solar(&ctx_2d, earth, moon, sun, fill.clone(), stroke.clone()) - // } - - // { - // clock(&mut ctx_2d); - // } - - //swarm(&mut ctx_2d, &mut particles, particle_count); - - // colorRain(&mut ctx_2d, &mut colors, &mut dots, &mut dots_vel); - - /* - - if let Some(color) = PaintStyle::new_color_str("red") { - { - let mut ctx = ctx_2d.get_context_mut(); - // colorRain(&mut ctx_2d, &mut colors, &mut dots, &mut dots_vel); - let bg = PaintStyle::new_color_str("white").unwrap(); - let black = PaintStyle::new_color_str("black").unwrap(); - ctx.set_fill_style(bg); - let device = *ctx.device(); - ctx.rect(0., 0., device.width, device.height); - ctx.fill(None); - ctx.set_fill_style(black); - - // Create a red line in position 150 - ctx.set_stroke_style(color); - ctx.move_to(150., 20.); - ctx.line_to(150., 170.); - ctx.stroke(None); - - ctx.set_font("15px Arial"); - - // Show the different textAlign values - ctx.set_text_align(TextAlign::START); - ctx.fill_text("textAlign = start", 150., 60., None); - ctx.set_text_align(TextAlign::END); - ctx.fill_text("textAlign = end", 150., 80., None); - ctx.set_text_align(TextAlign::LEFT); - ctx.fill_text("textAlign = left", 150., 100., None); - ctx.set_text_align(TextAlign::CENTER); - ctx.fill_text("textAlign = center", 150., 120., None); - ctx.set_text_align(TextAlign::RIGHT); - ctx.fill_text("textAlign = right", 150., 140., None); - - ctx.flush(); - } + done = true; - // println!("{}", canvas_2d::to_data_url(&mut ctx_2d, "image/jpg", 100)) - } + gl_state.swap_buffers(); + } - */ - // - // ctx_2d.fill_rect_xywh(0., 0., 300., 300.); - // ctx_2d.get_context_mut().flush(); - //ctx_2d.flush(); + // rainbow_octopus(&mut ctx_2d, &mut ro); + + // if let (Some(sun), Some(moon), Some(earth)) = (sun.as_ref(), moon.as_ref(), earth.as_ref()) { + // solar(&ctx_2d, earth, moon, sun, fill.clone(), stroke.clone()) + // } + + // { + // clock(&mut ctx_2d); + // } + + //swarm(&mut ctx_2d, &mut particles, particle_count); + + // colorRain(&mut ctx_2d, &mut colors, &mut dots, &mut dots_vel); + + /* + + if let Some(color) = PaintStyle::new_color_str("red") { + { + let mut ctx = ctx_2d.get_context_mut(); + // colorRain(&mut ctx_2d, &mut colors, &mut dots, &mut dots_vel); + let bg = PaintStyle::new_color_str("white").unwrap(); + let black = PaintStyle::new_color_str("black").unwrap(); + ctx.set_fill_style(bg); + let device = *ctx.device(); + ctx.rect(0., 0., device.width, device.height); + ctx.fill(None); + ctx.set_fill_style(black); + + // Create a red line in position 150 + ctx.set_stroke_style(color); + ctx.move_to(150., 20.); + ctx.line_to(150., 170.); + ctx.stroke(None); + + ctx.set_font("15px Arial"); + + // Show the different textAlign values + ctx.set_text_align(TextAlign::START); + ctx.fill_text("textAlign = start", 150., 60., None); + ctx.set_text_align(TextAlign::END); + ctx.fill_text("textAlign = end", 150., 80., None); + ctx.set_text_align(TextAlign::LEFT); + ctx.fill_text("textAlign = left", 150., 100., None); + ctx.set_text_align(TextAlign::CENTER); + ctx.fill_text("textAlign = center", 150., 120., None); + ctx.set_text_align(TextAlign::RIGHT); + ctx.fill_text("textAlign = right", 150., 140., None); + + ctx.flush(); + } + + // println!("{}", canvas_2d::to_data_url(&mut ctx_2d, "image/jpg", 100)) + } + + */ + // + // ctx_2d.fill_rect_xywh(0., 0., 300., 300.); + // ctx_2d.get_context_mut().flush(); + //ctx_2d.flush(); - // canvas_webgl::webgl::canvas_native_webgl_clear_color(1.0, 1.0, 0.0, 1.0, &mut gl_state); - // - // let start = Instant::now(); - // canvas_webgl::webgl::canvas_native_webgl_clear(canvas_webgl::webgl::COLOR_BUFFER_BIT, &mut gl_state); - // let end = Instant::now() - start; - // - // println!("clear {:?}", end.as_millis()); - // canvas_webgl::webgl::canvas_native_webgl_draw_arrays(canvas_webgl::webgl::TRIANGLES, 0, 3, &mut gl_state); + // canvas_webgl::webgl::canvas_native_webgl_clear_color(1.0, 1.0, 0.0, 1.0, &mut gl_state); + // + // let start = Instant::now(); + // canvas_webgl::webgl::canvas_native_webgl_clear(canvas_webgl::webgl::COLOR_BUFFER_BIT, &mut gl_state); + // let end = Instant::now() - start; + // + // println!("clear {:?}", end.as_millis()); + // canvas_webgl::webgl::canvas_native_webgl_draw_arrays(canvas_webgl::webgl::TRIANGLES, 0, 3, &mut gl_state); - // canvas_webgl::webgl::canvas_native_webgl_draw_arrays(canvas_webgl::webgl::POINTS, 0, 1, &mut gl_state); + // canvas_webgl::webgl::canvas_native_webgl_draw_arrays(canvas_webgl::webgl::POINTS, 0, 1, &mut gl_state); - // gl_state.swap_buffers(); + // gl_state.swap_buffers(); + } + _ => {} + } } Event::Resumed => {} _ => {}