Upgrade to Rust 1.99 and edition 2024

dc1e5b1e2efb0267bc357dcf580bc43caf57a2c3
Alexis Sellier committed ago 1 parent d291896c
Cargo.toml +1 -1
8 8
default-members = [
9 9
  "reve",
10 10
  "ombre",
11 11
  "syntaxe",
12 12
]
13 -
resolver = "2"
13 +
resolver = "3"
14 14
15 15
[workspace.dependencies]
16 16
lexopt = { version = "0.3.0" }
17 17
popol = { version = "3.0.1" }
18 18
ombre-derive/Cargo.toml +1 -1
1 1
[package]
2 2
name = "ombre-derive"
3 3
version = "0.1.0"
4 -
edition = "2021"
4 +
edition = "2024"
5 5
6 6
[dependencies]
7 7
syn = { version = "1.0" }
8 8
quote = { version = "1.0" }
9 9
ombre-derive/src/lib.rs +8 -8
1 1
//! Derive macros for the ombre crate.
2 2
use proc_macro::TokenStream;
3 3
use quote::quote;
4 -
use syn::{parse_macro_input, Data, DeriveInput, Error, Fields};
4 +
use syn::{Data, DeriveInput, Error, Fields, parse_macro_input};
5 5
6 6
/// Derives the `VertexAttributes` trait for structs.
7 7
///
8 8
/// Fields can be renamed in the shader using `#[attrib(name = "...")]`.
9 9
#[proc_macro_derive(VertexAttributes, attributes(attrib))]
19 19
                return syn::Error::new_spanned(
20 20
                    name,
21 21
                    "`VertexAttributes` can only be derived for structs with named fields",
22 22
                )
23 23
                .to_compile_error()
24 -
                .into()
24 +
                .into();
25 25
            }
26 26
        },
27 27
        _ => {
28 28
            return syn::Error::new_spanned(
29 29
                name,
30 30
                "`VertexAttributes` can only be derived for structs",
31 31
            )
32 32
            .to_compile_error()
33 -
            .into()
33 +
            .into();
34 34
        }
35 35
    };
36 36
37 37
    // Generate attribute descriptors for each field
38 38
    let attrs = fields.iter().map(|field| {
95 95
                return Error::new_spanned(
96 96
                    name,
97 97
                    "`UniformBlock` can only be derived for structs with named fields",
98 98
                )
99 99
                .to_compile_error()
100 -
                .into()
100 +
                .into();
101 101
            }
102 102
        },
103 103
        _ => {
104 104
            return Error::new_spanned(name, "`UniformBlock` can only be derived for structs")
105 105
                .to_compile_error()
106 -
                .into()
106 +
                .into();
107 107
        }
108 108
    };
109 109
110 110
    // Generate uniform descriptors for each field.
111 111
    let descriptors = fields.iter().map(|field| {
178 178
                return Error::new_spanned(
179 179
                    name,
180 180
                    "`Lenses` can only be derived for structs with named fields",
181 181
                )
182 182
                .to_compile_error()
183 -
                .into()
183 +
                .into();
184 184
            }
185 185
        },
186 186
        _ => {
187 187
            return Error::new_spanned(name, "`Lenses` can only be derived for structs")
188 188
                .to_compile_error()
189 -
                .into()
189 +
                .into();
190 190
        }
191 191
    };
192 192
193 193
    // Generate lens implementations for fields with #[lens] attribute
194 194
    let lens_impls = fields.iter().filter_map(|field| {
244 244
    let data = match ast.data {
245 245
        Data::Struct(data) => data,
246 246
        _ => {
247 247
            return Error::new_spanned(&ast, "`Packed` can only be derived for structs")
248 248
                .to_compile_error()
249 -
                .into()
249 +
                .into();
250 250
        }
251 251
    };
252 252
    let field_types = data.fields.iter().map(|f| &f.ty);
253 253
254 254
    quote! {
ombre/Cargo.toml +1 -1
1 1
[package]
2 2
name = "ombre"
3 3
description = "Ombre context creation and graphics library"
4 4
version = "0.6.6"
5 -
edition = "2021"
5 +
edition = "2024"
6 6
keywords = ["graphics", "gamedev", "game"]
7 7
categories = ["graphics", "rendering", "game-development"]
8 8
authors = ["cloudhead <self@cloudhead.io>"]
9 9
10 10
[features]
ombre/examples/fonts.rs +1 -1
3 3
#[path = "common/runtime.rs"]
4 4
mod runtime;
5 5
6 6
use ombre::prelude::*;
7 7
use ombre::ui as gui;
8 -
use ombre::ui::widgets::*;
9 8
use ombre::ui::TextAlign;
9 +
use ombre::ui::widgets::*;
10 10
11 11
pub struct Example<T: RenderBackend> {
12 12
    ui: gui::Interface<Box<dyn Widget<()>>, (), T>,
13 13
    backend: T,
14 14
}
ombre/examples/paint/basic.rs +1 -1
1 1
#![deny(clippy::all)]
2 2
#![allow(clippy::unwrap_used)]
3 3
use std::time::Duration;
4 4
5 -
use ombre::paint::{canvas, shape, Canvas, PaintSurface};
5 +
use ombre::paint::{Canvas, PaintSurface, canvas, shape};
6 6
use ombre::prelude::*;
7 7
use ombre::rng::Rng;
8 8
9 9
pub struct Example<T: RenderBackend> {
10 10
    canvas: Canvas<T>,
ombre/examples/paint/benchmark.rs +3 -3
1 1
#![deny(clippy::all)]
2 2
#![allow(clippy::unwrap_used)]
3 3
use std::time::Duration;
4 4
5 -
use ombre::paint::{canvas, shape, Canvas, PaintSurface};
5 +
use ombre::paint::{Canvas, PaintSurface, canvas, shape};
6 6
use ombre::prelude::*;
7 7
use ombre::rng::Rng;
8 8
use runtime::{RuntimeCtx, Timings};
9 9
10 10
const NUM_SHAPES: usize = 2048;
37 37
            .map(|_| {
38 38
                let position = Point2D::new(
39 39
                    rng.fraction() as f32 * size.width as f32,
40 40
                    rng.fraction() as f32 * size.height as f32,
41 41
                );
42 -
                let velocity = Vector2D::new(rng.gen(-50..50) as f32, rng.gen(-50..50) as f32);
43 -
                let size = rng.gen(SHAPE_SIZE_MIN..SHAPE_SIZE_MAX) as f32;
42 +
                let velocity = Vector2D::new(rng.r#gen(-50..50) as f32, rng.r#gen(-50..50) as f32);
43 +
                let size = rng.r#gen(SHAPE_SIZE_MIN..SHAPE_SIZE_MAX) as f32;
44 44
                let color = Rgba::new(
45 45
                    rng.fraction() as f32,
46 46
                    rng.fraction() as f32,
47 47
                    1.0,
48 48
                    0.7 + 0.3 * rng.fraction() as f32,
ombre/examples/paint/showcase.rs +1 -1
1 1
#![deny(clippy::all)]
2 2
#![allow(clippy::unwrap_used)]
3 3
use ombre::gfx::font::uf2::VENICE;
4 4
use ombre::paint::shape::Circle;
5 -
use ombre::paint::{canvas, Canvas, PaintSurface};
5 +
use ombre::paint::{Canvas, PaintSurface, canvas};
6 6
use ombre::prelude::*;
7 7
use ombre::text::Text;
8 8
9 9
pub struct Example<T: RenderBackend> {
10 10
    canvas: Canvas<T>,
ombre/src/fs.rs +1 -1
1 1
mod watcher;
2 2
3 3
pub use std::fs::*;
4 -
pub use watcher::{watcher, Event, FileWatcher};
4 +
pub use watcher::{Event, FileWatcher, watcher};
ombre/src/fs/watcher.rs +1 -1
5 5
use std::collections::HashMap;
6 6
use std::ffi::CString;
7 7
use std::os::unix::ffi::OsStrExt;
8 8
use std::os::unix::io::RawFd;
9 9
use std::path::{Path, PathBuf};
10 +
use std::sync::Arc;
10 11
use std::sync::mpsc;
11 12
use std::sync::mpsc::{Receiver, Sender};
12 -
use std::sync::Arc;
13 13
use std::{fs, io, mem, thread};
14 14
15 15
/// Constants for `inotify` event masks.
16 16
/// These define the different types of events we can watch for.
17 17
mod inotify {
ombre/src/gfx/gl.rs +105 -91
206 206
            })
207 207
        }
208 208
    }
209 209
210 210
    unsafe fn set_blend(&mut self, blend: BlendState) -> Result<(), Error> {
211 -
        if blend.rgb.is_none() && blend.alpha.is_some() {
212 -
            return Err(Error::AlphaBlendWithoutColor);
213 -
        }
214 -
        if let Some(rgb) = blend.rgb {
215 -
            self.gl.enable(glow::BLEND);
216 -
217 -
            let BlendEquation {
218 -
                op: eq_rgb,
219 -
                sfactor: src_rgb,
220 -
                dfactor: dst_rgb,
221 -
            } = rgb;
222 -
223 -
            if let Some(BlendEquation {
224 -
                op: eq_alpha,
225 -
                sfactor: src_alpha,
226 -
                dfactor: dst_alpha,
227 -
            }) = blend.alpha
228 -
            {
229 -
                self.gl.blend_func_separate(
230 -
                    src_rgb.to_gl(),
231 -
                    dst_rgb.to_gl(),
232 -
                    src_alpha.to_gl(),
233 -
                    dst_alpha.to_gl(),
234 -
                );
235 -
                self.gl.blend_equation_separate(eq_rgb.to_gl(), eq_alpha.to_gl());
211 +
        unsafe {
212 +
            if blend.rgb.is_none() && blend.alpha.is_some() {
213 +
                return Err(Error::AlphaBlendWithoutColor);
214 +
            }
215 +
            if let Some(rgb) = blend.rgb {
216 +
                self.gl.enable(glow::BLEND);
217 +
218 +
                let BlendEquation {
219 +
                    op: eq_rgb,
220 +
                    sfactor: src_rgb,
221 +
                    dfactor: dst_rgb,
222 +
                } = rgb;
223 +
224 +
                if let Some(BlendEquation {
225 +
                    op: eq_alpha,
226 +
                    sfactor: src_alpha,
227 +
                    dfactor: dst_alpha,
228 +
                }) = blend.alpha
229 +
                {
230 +
                    self.gl.blend_func_separate(
231 +
                        src_rgb.to_gl(),
232 +
                        dst_rgb.to_gl(),
233 +
                        src_alpha.to_gl(),
234 +
                        dst_alpha.to_gl(),
235 +
                    );
236 +
                    self.gl.blend_equation_separate(eq_rgb.to_gl(), eq_alpha.to_gl());
237 +
                } else {
238 +
                    self.gl.blend_func(src_rgb.to_gl(), dst_rgb.to_gl());
239 +
                    self.gl.blend_equation_separate(eq_rgb.to_gl(), eq_rgb.to_gl());
240 +
                }
236 241
            } else {
237 -
                self.gl.blend_func(src_rgb.to_gl(), dst_rgb.to_gl());
238 -
                self.gl.blend_equation_separate(eq_rgb.to_gl(), eq_rgb.to_gl());
242 +
                self.gl.disable(glow::BLEND);
239 243
            }
240 -
        } else {
241 -
            self.gl.disable(glow::BLEND);
244 +
            Ok(())
242 245
        }
243 -
        Ok(())
244 246
    }
245 247
246 248
    unsafe fn set_stencil(&mut self, stencil: Option<StencilState>) {
247 -
        if let Some(stencil) = stencil {
248 -
            let front = &stencil.front;
249 -
            let back = &stencil.back;
250 -
251 -
            self.gl.enable(glow::STENCIL_TEST);
252 -
            self.gl.stencil_op_separate(
253 -
                glow::FRONT,
254 -
                front.fail_op.to_gl(),
255 -
                front.depth_fail_op.to_gl(),
256 -
                front.pass_op.to_gl(),
257 -
            );
258 -
            self.gl.stencil_func_separate(
259 -
                glow::FRONT,
260 -
                front.compare.to_gl(),
261 -
                stencil.reference,
262 -
                stencil.read_mask,
263 -
            );
264 -
            self.gl.stencil_mask_separate(glow::FRONT, stencil.write_mask);
265 -
            self.gl.stencil_op_separate(
266 -
                glow::BACK,
267 -
                back.fail_op.to_gl(),
268 -
                back.depth_fail_op.to_gl(),
269 -
                back.pass_op.to_gl(),
270 -
            );
271 -
            self.gl.stencil_func_separate(
272 -
                glow::BACK,
273 -
                back.compare.to_gl(),
274 -
                stencil.reference,
275 -
                stencil.read_mask,
276 -
            );
277 -
            self.gl.stencil_mask_separate(glow::BACK, stencil.write_mask);
278 -
        } else {
279 -
            self.gl.disable(glow::STENCIL_TEST);
249 +
        unsafe {
250 +
            if let Some(stencil) = stencil {
251 +
                let front = &stencil.front;
252 +
                let back = &stencil.back;
253 +
254 +
                self.gl.enable(glow::STENCIL_TEST);
255 +
                self.gl.stencil_op_separate(
256 +
                    glow::FRONT,
257 +
                    front.fail_op.to_gl(),
258 +
                    front.depth_fail_op.to_gl(),
259 +
                    front.pass_op.to_gl(),
260 +
                );
261 +
                self.gl.stencil_func_separate(
262 +
                    glow::FRONT,
263 +
                    front.compare.to_gl(),
264 +
                    stencil.reference,
265 +
                    stencil.read_mask,
266 +
                );
267 +
                self.gl.stencil_mask_separate(glow::FRONT, stencil.write_mask);
268 +
                self.gl.stencil_op_separate(
269 +
                    glow::BACK,
270 +
                    back.fail_op.to_gl(),
271 +
                    back.depth_fail_op.to_gl(),
272 +
                    back.pass_op.to_gl(),
273 +
                );
274 +
                self.gl.stencil_func_separate(
275 +
                    glow::BACK,
276 +
                    back.compare.to_gl(),
277 +
                    stencil.reference,
278 +
                    stencil.read_mask,
279 +
                );
280 +
                self.gl.stencil_mask_separate(glow::BACK, stencil.write_mask);
281 +
            } else {
282 +
                self.gl.disable(glow::STENCIL_TEST);
283 +
            }
280 284
        }
281 285
    }
282 286
283 287
    unsafe fn set_cull_face(&mut self, cull_face: CullMode) {
284 -
        match cull_face {
285 -
            CullMode::Nothing => {
286 -
                self.gl.disable(glow::CULL_FACE);
287 -
            }
288 -
            CullMode::Front => {
289 -
                self.gl.enable(glow::CULL_FACE);
290 -
                self.gl.cull_face(glow::FRONT);
291 -
            }
292 -
            CullMode::Back => {
293 -
                self.gl.enable(glow::CULL_FACE);
294 -
                self.gl.cull_face(glow::BACK);
288 +
        unsafe {
289 +
            match cull_face {
290 +
                CullMode::Nothing => {
291 +
                    self.gl.disable(glow::CULL_FACE);
292 +
                }
293 +
                CullMode::Front => {
294 +
                    self.gl.enable(glow::CULL_FACE);
295 +
                    self.gl.cull_face(glow::FRONT);
296 +
                }
297 +
                CullMode::Back => {
298 +
                    self.gl.enable(glow::CULL_FACE);
299 +
                    self.gl.cull_face(glow::BACK);
300 +
                }
295 301
            }
296 302
        }
297 303
    }
298 304
299 305
    unsafe fn set_color_mask(&mut self, mask: Rgba<bool>) {
300 -
        self.gl.color_mask(mask.r, mask.g, mask.b, mask.a);
306 +
        unsafe {
307 +
            self.gl.color_mask(mask.r, mask.g, mask.b, mask.a);
308 +
        }
301 309
    }
302 310
303 311
    unsafe fn load_shader(
304 312
        &self,
305 313
        kind: ShaderKind,
306 314
        source: &str,
307 315
    ) -> Result<glow::Shader, ShaderError> {
308 -
        let shader = self.gl.create_shader(kind.to_gl()).map_err(ShaderError::Internal)?;
316 +
        unsafe {
317 +
            let shader = self.gl.create_shader(kind.to_gl()).map_err(ShaderError::Internal)?;
309 318
310 -
        self.gl.shader_source(shader, source);
311 -
        self.gl.compile_shader(shader);
319 +
            self.gl.shader_source(shader, source);
320 +
            self.gl.compile_shader(shader);
312 321
313 -
        if !self.gl.get_shader_compile_status(shader) {
314 -
            let message = self.gl.get_shader_info_log(shader);
322 +
            if !self.gl.get_shader_compile_status(shader) {
323 +
                let message = self.gl.get_shader_info_log(shader);
315 324
316 -
            return Err(ShaderError::CompilationError { kind, message });
325 +
                return Err(ShaderError::CompilationError { kind, message });
326 +
            }
327 +
            Ok(shader)
317 328
        }
318 -
        Ok(shader)
319 329
    }
320 330
321 331
    #[cfg(debug_assertions)]
322 332
    unsafe fn validate_program(&self, program: glow::Program) -> Result<(), Error> {
323 -
        self.gl.validate_program(program);
324 -
        if !self.gl.get_program_validate_status(program) {
325 -
            let error = self.gl.get_program_info_log(program);
326 -
            return Err(Error::Shader(ShaderError::ValidationError(error)));
333 +
        unsafe {
334 +
            self.gl.validate_program(program);
335 +
            if !self.gl.get_program_validate_status(program) {
336 +
                let error = self.gl.get_program_info_log(program);
337 +
                return Err(Error::Shader(ShaderError::ValidationError(error)));
338 +
            }
339 +
            Ok(())
327 340
        }
328 -
        Ok(())
329 341
    }
330 342
331 343
    unsafe fn bind_framebuffer(&mut self, framebuffer: Option<glow::Framebuffer>, size: Size<u32>) {
332 -
        self.gl.bind_framebuffer(glow::FRAMEBUFFER, framebuffer);
333 -
        self.gl.viewport(0, 0, size.w as i32, size.h as i32);
334 -
        self.gl.scissor(0, 0, size.w as i32, size.h as i32);
344 +
        unsafe {
345 +
            self.gl.bind_framebuffer(glow::FRAMEBUFFER, framebuffer);
346 +
            self.gl.viewport(0, 0, size.w as i32, size.h as i32);
347 +
            self.gl.scissor(0, 0, size.w as i32, size.h as i32);
348 +
        }
335 349
    }
336 350
}
337 351
338 352
pub struct FrameBuilder<'a> {
339 353
    ctx: &'a mut Context,
511 525
512 526
            offset += size;
513 527
514 528
            unsafe {
515 529
                if let Some(loc) = &uniform.location {
516 -
                    use bytes::align_to;
517 530
                    use UniformKind::*;
531 +
                    use bytes::align_to;
518 532
519 533
                    match uniform.kind {
520 534
                        Float1 => self.ctx.gl.uniform_1_f32_slice(Some(loc), align_to::<f32>(data)),
521 535
                        Float2 => self.ctx.gl.uniform_2_f32_slice(Some(loc), align_to::<f32>(data)),
522 536
                        Float3 => self.ctx.gl.uniform_3_f32_slice(Some(loc), align_to::<f32>(data)),
ombre/src/gfx/image.rs +1 -1
3 3
pub mod float;
4 4
5 5
use std::io;
6 6
use std::sync::Arc;
7 7
8 -
use super::{pixels, Color as _, Point2D, Rect, Rgba8, Size};
8 +
use super::{Color as _, Point2D, Rect, Rgba8, Size, pixels};
9 9
use crate::{
10 10
    bytes::encoding::{Decode, Encode},
11 11
    bytes::{ReadBytes, WriteBytes},
12 12
    math::{Local, Zero},
13 13
};
ombre/src/gfx/traits.rs +1 -1
97 97
98 98
    /// Create a new render pass.
99 99
    fn pass(&mut self, desc: PassDescriptor<'_>) -> Result<PassId, Self::Error>;
100 100
    /// Resize all pass attachments.
101 101
    fn pass_resize_attachments(&mut self, pass: PassId, size: Size<u32>)
102 -
        -> Result<(), Self::Error>;
102 +
    -> Result<(), Self::Error>;
103 103
    /// Read pass color attachment into slice.
104 104
    fn pass_read_color_attachment<T>(
105 105
        &self,
106 106
        pass: PassId,
107 107
        attachment: usize,
ombre/src/lang/evaluator.rs +40 -28
14 14
use crate::gfx::Rgba;
15 15
use crate::lang::dynamic::{Dynamic, IsDynamic};
16 16
use crate::math::{Vector2D, Vector3D, Vector4D};
17 17
18 18
use super::error::{Error, ErrorWithLocation};
19 -
use super::{Parser, Scanner, FILE_EXTENSION};
19 +
use super::{FILE_EXTENSION, Parser, Scanner};
20 20
21 21
/// Result type for all functions.
22 22
pub type Result<T, E = Error> = result::Result<T, E>;
23 23
24 24
/// A symbol is an immutable string.
745 745
}
746 746
747 747
impl PartialEq for Function {
748 748
    fn eq(&self, other: &Self) -> bool {
749 749
        match (self, other) {
750 -
            (Self::Closure(ref a), Self::Closure(ref b)) => Rc::ptr_eq(a, b),
751 -
            (Self::Intrinsic(Intrinsic(ref a)), Self::Intrinsic(Intrinsic(ref b))) => {
752 -
                Rc::ptr_eq(a, b)
753 -
            }
750 +
            (Self::Closure(a), Self::Closure(b)) => Rc::ptr_eq(a, b),
751 +
            (Self::Intrinsic(Intrinsic(a)), Self::Intrinsic(Intrinsic(b))) => Rc::ptr_eq(a, b),
754 752
            _ => false,
755 753
        }
756 754
    }
757 755
}
758 756
777 775
        let mut local = self.env.local.clone();
778 776
        let mut args = args.into_iter();
779 777
780 778
        // Handle positional arguments.
781 779
        for formal in &self.positional {
782 -
            if let Some(arg) = args.next() {
783 -
                local.insert(formal.clone(), arg);
784 -
            } else {
785 -
                return Err(Error::WrongArgumentCount {
786 -
                    expected: self.positional.len(),
787 -
                    actual: local.len(),
788 -
                });
780 +
            match args.next() {
781 +
                Some(arg) => {
782 +
                    local.insert(formal.clone(), arg);
783 +
                }
784 +
                _ => {
785 +
                    return Err(Error::WrongArgumentCount {
786 +
                        expected: self.positional.len(),
787 +
                        actual: local.len(),
788 +
                    });
789 +
                }
789 790
            }
790 791
        }
791 792
792 793
        // Handle named arguments.
793 794
        let mut named_args = HashMap::new();
794 795
        while let Some(arg) = args.next() {
795 796
            if let Expr::Atom(name) = arg {
796 -
                if let Some(value) = args.next() {
797 -
                    named_args.insert(Symbol(name), value);
798 -
                } else {
799 -
                    return Err(Error::ExpectedNamedValue(name));
797 +
                match args.next() {
798 +
                    Some(value) => {
799 +
                        named_args.insert(Symbol(name), value);
800 +
                    }
801 +
                    _ => {
802 +
                        return Err(Error::ExpectedNamedValue(name));
803 +
                    }
800 804
                }
801 805
            } else {
802 806
                return Err(Error::InvalidArgument);
803 807
            }
804 808
        }
1249 1253
            let mut items = tuple.data.into_iter().skip(1).peekable();
1250 1254
            let Some(Expr::Symbol(name)) = items.next() else {
1251 1255
                return Err(Error::ExpectedValue("symbol"));
1252 1256
            };
1253 1257
            // Get optional doc string.
1254 -
            let docstr = if let Some(Expr::Str(ref docstr)) = items.peek().cloned() {
1255 -
                items.next();
1256 -
                Some(docstr.to_owned())
1257 -
            } else {
1258 -
                None
1258 +
            let docstr = match items.peek().cloned() {
1259 +
                Some(Expr::Str(ref docstr)) => {
1260 +
                    items.next();
1261 +
                    Some(docstr.to_owned())
1262 +
                }
1263 +
                _ => None,
1259 1264
            };
1260 1265
            // Create new env for the module. Modules do not capture their environment.
1261 1266
            let mut env = Env::default();
1262 1267
            // Evaluate module body.
1263 1268
            for expr in items {
1773 1778
    /// Set a value under a key in a dictionary.
1774 1779
    pub fn put(args: Vec<Expr>, _env: &Env<'_>) -> Result<Expr> {
1775 1780
        let (dict, key, val) = <(Mut<BTreeMap<Key, Expr>>, Key, Expr)>::try_from_args(args)?;
1776 1781
        let mut d = dict.borrow_mut();
1777 1782
1778 -
        if let Some(old) = d.insert(key, val) {
1779 -
            Ok(old)
1780 -
        } else {
1781 -
            Ok(Expr::Nil)
1783 +
        match d.insert(key, val) {
1784 +
            Some(old) => Ok(old),
1785 +
            _ => Ok(Expr::Nil),
1782 1786
        }
1783 1787
    }
1784 1788
1785 1789
    /// Check if a collection contains a key.
1786 1790
    pub fn contains(args: Vec<Expr>, _env: &Env<'_>) -> Result<Expr> {
1852 1856
        let numbers: Vec<_> = match args.as_slice() {
1853 1857
            [Expr::Integer(end)] => (0..*end).map(Expr::Integer).collect::<Vec<_>>(),
1854 1858
            [Expr::Integer(start), Expr::Integer(end)] => {
1855 1859
                (*start..*end).map(Expr::Integer).collect()
1856 1860
            }
1857 -
            [Expr::Integer(start), Expr::Integer(end), Expr::Integer(step)] if start < end => (0..)
1861 +
            [
1862 +
                Expr::Integer(start),
1863 +
                Expr::Integer(end),
1864 +
                Expr::Integer(step),
1865 +
            ] if start < end => (0..)
1858 1866
                .map(|n| *start + n * *step)
1859 1867
                .take_while(|&x| x < *end)
1860 1868
                .map(Expr::Integer)
1861 1869
                .collect(),
1862 -
            [Expr::Integer(start), Expr::Integer(end), Expr::Integer(step)] if start > end => (0..)
1870 +
            [
1871 +
                Expr::Integer(start),
1872 +
                Expr::Integer(end),
1873 +
                Expr::Integer(step),
1874 +
            ] if start > end => (0..)
1863 1875
                .map(|n| *start + n * *step)
1864 1876
                .take_while(|&x| x > *end)
1865 1877
                .map(Expr::Integer)
1866 1878
                .collect(),
1867 1879
            _ => {
1868 1880
                return Err(Error::WrongArgumentCount {
1869 1881
                    expected: 3,
1870 1882
                    actual: args.len(),
1871 -
                })
1883 +
                });
1872 1884
            }
1873 1885
        };
1874 1886
        Ok(Tuple::new(numbers).into())
1875 1887
    }
1876 1888
ombre/src/lib.rs +2 -2
35 35
pub use derive::*;
36 36
37 37
#[cfg(feature = "paint")]
38 38
pub mod paint;
39 39
#[cfg(feature = "paint")]
40 -
pub use paint::{canvas, Canvas};
40 +
pub use paint::{Canvas, canvas};
41 41
42 42
pub use gfx::color;
43 43
pub use glow;
44 44
45 45
/// Crate prelude.
47 47
    pub use super::array::Array;
48 48
    pub use super::bytes;
49 49
    pub use super::gfx;
50 50
    pub use super::gfx::*;
51 51
    pub use super::math::{
52 -
        coord::*, Point2D, Rect, Size, Transform3D, Vector2D, Vector3D, Zero as _,
52 +
        Point2D, Rect, Size, Transform3D, Vector2D, Vector3D, Zero as _, coord::*,
53 53
    };
54 54
    pub use super::runtime::{Application, ApplicationExt, Simulation, SimulationCtx};
55 55
    pub use super::{logger, platform, runtime};
56 56
}
ombre/src/math/algebra.rs +2 -2
9 9
use std::marker::PhantomData;
10 10
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
11 11
12 12
use super::rect::Rect;
13 13
use super::size::Size;
14 -
use super::transform::{coord::Spherical, Transform2D};
15 -
use super::{traits::*, World};
14 +
use super::transform::{Transform2D, coord::Spherical};
15 +
use super::{World, traits::*};
16 16
17 17
/// View origin.
18 18
#[derive(PartialEq, Eq, Copy, Clone, Debug, Default)]
19 19
pub enum Origin {
20 20
    #[default]
ombre/src/math/macros.rs +2 -2
1 1
//! Some useful macros.
2 2
3 3
/// Assertion macro for [`crate::math::traits::ApproxEq::approx_eq`].
4 4
#[macro_export]
5 5
macro_rules! assert_approx_eq {
6 -
    ($a:expr, $b:expr, $epsilon:expr) => {{
6 +
    ($a:expr_2021, $b:expr_2021, $epsilon:expr_2021) => {{
7 7
        let (a, b, eps) = ($a, $b, $epsilon);
8 8
        assert!(
9 9
            $crate::math::traits::ApproxEq::approx_eq(&a, &b, eps),
10 10
            "\
11 11
assertion `|left - right| <= {eps}` failed
17 17
pub use assert_approx_eq;
18 18
19 19
/// Assertion macro for [`crate::math::traits::ApproxEq::approx_neq`].
20 20
#[macro_export]
21 21
macro_rules! assert_approx_neq {
22 -
    ($a:expr, $b:expr, $epsilon:expr) => {{
22 +
    ($a:expr_2021, $b:expr_2021, $epsilon:expr_2021) => {{
23 23
        let (a, b, eps) = ($a, $b, $epsilon);
24 24
        assert!(
25 25
            $crate::math::traits::ApproxEq::approx_neq(&a, &b, eps),
26 26
            "\
27 27
assertion `|left - right| > {eps}` failed
ombre/src/math/rect.rs +1 -5
271 271
        T: math::Two + Div<Output = T> + PartialOrd + Sub<Output = T>,
272 272
    {
273 273
        let w = self.width();
274 274
        let h = self.height();
275 275
276 -
        if w > h {
277 -
            w / T::TWO
278 -
        } else {
279 -
            h / T::TWO
280 -
        }
276 +
        if w > h { w / T::TWO } else { h / T::TWO }
281 277
    }
282 278
283 279
    /// Check whether the given point is contained in the rectangle.
284 280
    ///
285 281
    /// ```
ombre/src/math/size.rs +1 -1
1 1
use std::fmt;
2 2
use std::ops::{Div, Mul, Sub};
3 3
4 4
use super::Bounded;
5 -
use super::{traits::FloatExt as _, Vector2D, Zero};
5 +
use super::{Vector2D, Zero, traits::FloatExt as _};
6 6
7 7
/// Size.
8 8
#[derive(Debug, Copy, Clone, PartialOrd, Ord, PartialEq, Eq, Default)]
9 9
pub struct Size<T = f32> {
10 10
    /// Width.
ombre/src/math/transform.rs +1 -1
6 6
7 7
//! Matrix transforms.
8 8
use std::marker::PhantomData;
9 9
use std::ops::{Add, Div, Mul, Sub};
10 10
11 +
use super::Size;
11 12
use super::algebra::*;
12 13
use super::traits::*;
13 -
use super::Size;
14 14
15 15
/// Coordinate systems.
16 16
pub mod coord {
17 17
    /// Used as a marker for screen space coordinates.
18 18
    #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord)]
ombre/src/paint.rs +1 -1
6 6
pub mod shape;
7 7
pub mod text;
8 8
pub mod traits;
9 9
10 10
pub use blit::Blit;
11 -
pub use canvas::{canvas, Canvas};
11 +
pub use canvas::{Canvas, canvas};
12 12
pub use shape::{Circle, Geometry, Line, Rectangle, Shape};
13 13
pub use traits::{Brush, PaintOp, PaintSurface};
ombre/src/paint/text.rs +2 -2
1 1
use crate::gfx::Transform2D;
2 2
use crate::math::Rect;
3 -
use crate::{text::rich::TextSpanLayout, text::RichTextLayout, text::TextLayout};
3 +
use crate::{text::RichTextLayout, text::TextLayout, text::rich::TextSpanLayout};
4 4
5 -
use super::traits::Paint;
6 5
use super::PaintOp;
6 +
use super::traits::Paint;
7 7
8 8
struct TextSpanLayoutIter {
9 9
    layout: TextSpanLayout,
10 10
    ix: usize,
11 11
}
ombre/src/rng.rs +9 -9
31 31
pub trait Distribution<T> {
32 32
    /// Generates a random value from this distribution using the given entropy source.
33 33
    fn sample<R: Entropy>(&self, rng: &mut R) -> T;
34 34
}
35 35
36 -
extern "C" {
36 +
unsafe extern "C" {
37 37
    fn getrandom(buf: *mut u8, buflen: usize, flags: u32) -> isize;
38 38
}
39 39
40 40
/// Wrapper around the C `getrandom` function.
41 41
/// Returns `true` if the supplied buffer was filled with random bytes.
99 99
    }
100 100
101 101
    /// Generates a random value of type `T` within the given range.
102 102
    /// Panics if the range is empty.
103 103
    #[inline]
104 -
    pub fn gen<T>(&mut self, range: impl RangeBounds<T>) -> T
104 +
    pub fn r#gen<T>(&mut self, range: impl RangeBounds<T>) -> T
105 105
    where
106 106
        T: Copy + PartialOrd + Sub<Output = T> + Add<Output = T> + Bounded + One + fmt::Debug,
107 107
        Uniform<T>: Distribution<T>,
108 108
    {
109 109
        Uniform::from_range(range).sample(self)
129 129
130 130
    /// Randomly shuffles the elements of the slice in place using Fisher-Yates algorithm.
131 131
    #[inline]
132 132
    pub fn shuffle<T>(&mut self, slice: &mut [T]) {
133 133
        for i in 1..slice.len() {
134 -
            slice.swap(i, self.gen(..=i));
134 +
            slice.swap(i, self.r#gen(..=i));
135 135
        }
136 136
    }
137 137
138 138
    /// Fills a byte slice with random values.
139 139
    pub fn fill(&mut self, slice: &mut [u8]) {
160 160
    #[inline]
161 161
    pub fn choose<'a, T>(&mut self, slice: &'a [T]) -> Option<&'a T> {
162 162
        if slice.is_empty() {
163 163
            None
164 164
        } else {
165 -
            Some(&slice[self.gen(..slice.len())])
165 +
            Some(&slice[self.r#gen(..slice.len())])
166 166
        }
167 167
    }
168 168
169 169
    /// Returns a random mutable reference to an element from the slice, or None if empty.
170 170
    #[inline]
171 171
    pub fn choose_mut<'a, T>(&mut self, slice: &'a mut [T]) -> Option<&'a mut T> {
172 172
        if slice.is_empty() {
173 173
            None
174 174
        } else {
175 -
            let idx = self.gen(0..slice.len());
175 +
            let idx = self.r#gen(0..slice.len());
176 176
            Some(&mut slice[idx])
177 177
        }
178 178
    }
179 179
}
180 180
279 279
    ) {
280 280
        let mut counts = vec![0; buckets];
281 281
        let bucket_size = (range.end - range.start).as_u64() as f64 / buckets as f64;
282 282
283 283
        for _ in 0..samples {
284 -
            let value = rng.gen(range.clone());
284 +
            let value = rng.r#gen(range.clone());
285 285
            let bucket = ((value - range.start).as_u64() as f64 / bucket_size) as usize;
286 286
            counts[bucket.min(buckets - 1)] += 1;
287 287
        }
288 288
289 289
        let expected = samples as f64 / buckets as f64;
320 320
    #[test]
321 321
    fn test_basic_generation() {
322 322
        let mut rng = Rng::new();
323 323
324 324
        // Using gen
325 -
        let _: u64 = rng.gen(..);
325 +
        let _: u64 = rng.r#gen(..);
326 326
        let _: bool = rng.flip();
327 327
328 328
        // Using gen_range
329 -
        let n = rng.gen(1u64..=100);
329 +
        let n = rng.r#gen(1u64..=100);
330 330
        assert!((1..=100).contains(&n));
331 331
332 332
        for _ in 0..10 {
333 -
            let n = rng.gen(0..60);
333 +
            let n = rng.r#gen(0..60);
334 334
            assert!((0..60).contains(&n), "{n}");
335 335
        }
336 336
    }
337 337
338 338
    #[test]
ombre/src/runtime.rs +1 -1
139 139
    /// Change when this is called with [`SimulationCtx::set_tick_rate`].
140 140
    fn tick(&mut self, ctx: &mut SimulationCtx<'_>) -> Result<(), Self::Error>;
141 141
    /// Called when there is a window even, for example when the window is resized or the cursor
142 142
    /// is moved.
143 143
    fn event(&mut self, event: WindowEvent, ctx: &mut SimulationCtx<'_>)
144 -
        -> Result<(), Self::Error>;
144 +
    -> Result<(), Self::Error>;
145 145
    /// Called when the runtime is ready to render a frame to the
146 146
    /// screen. Change when this is called with [`SimulationCtx::set_target_fps`].
147 147
    fn frame(&mut self) -> Result<(), Self::Error>;
148 148
}
149 149
ombre/src/tempdir.rs +1 -1
30 30
    ///
31 31
    pub fn new() -> io::Result<Self> {
32 32
        let mut rng = Rng::new();
33 33
        let pid = process::id();
34 34
        let base = env::temp_dir();
35 -
        let path = base.join(format!("tmp.{pid}.{}", rng.gen::<u32>(..)));
35 +
        let path = base.join(format!("tmp.{pid}.{}", rng.r#gen::<u32>(..)));
36 36
        let _ = fs::create_dir(&path)?;
37 37
38 38
        Ok(TempDir { path })
39 39
    }
40 40
ombre/src/text.rs +10 -8
4 4
use std::borrow::{Borrow, Cow};
5 5
use std::ops::Range;
6 6
use std::rc::Rc;
7 7
8 8
use crate::gfx::{
9 -
    Font, FontMetrics, FontName, FontStyle, Fonts, Image, Rect, Rgba, Size, DEFAULT_FONT,
9 +
    DEFAULT_FONT, Font, FontMetrics, FontName, FontStyle, Fonts, Image, Rect, Rgba, Size,
10 10
};
11 11
use crate::math::{Bounded as _, FloatExt as _, Local};
12 12
13 13
pub use plain::TextLayout;
14 14
pub use rich::{RichTextLayout, RichTextStorage};
159 159
        self
160 160
    }
161 161
162 162
    pub fn build(self, fonts: &Fonts<Image>) -> RichTextLayout {
163 163
        let spans = if self.spans.is_empty() {
164 -
            vec![TextSpan {
165 -
                range: 0..self.body.len(),
166 -
                font: DEFAULT_FONT,
167 -
                style: FontStyle::default(),
168 -
                tint: Rgba::default(),
169 -
            }
170 -
            .load(fonts)]
164 +
            vec![
165 +
                TextSpan {
166 +
                    range: 0..self.body.len(),
167 +
                    font: DEFAULT_FONT,
168 +
                    style: FontStyle::default(),
169 +
                    tint: Rgba::default(),
170 +
                }
171 +
                .load(fonts),
172 +
            ]
171 173
        } else {
172 174
            self.spans.iter().map(|s| s.load(fonts)).collect::<Vec<_>>()
173 175
        };
174 176
        RichTextLayout::build(self.body.borrow(), spans.as_slice(), self.opts, self.area)
175 177
    }
ombre/src/text/plain.rs +2 -2
1 1
//! Plain text layout.
2 2
use super::*;
3 3
use crate::gfx::font::FontMetrics;
4 -
use crate::math::traits::Zero as _;
5 4
use crate::math::Point2D;
5 +
use crate::math::traits::Zero as _;
6 6
7 7
/// Text that has been layed out.
8 8
#[derive(Clone, Debug)]
9 9
pub struct TextLayout {
10 10
    /// Area used for the text layout.
119 119
120 120
#[cfg(test)]
121 121
#[allow(clippy::unwrap_used)]
122 122
mod tests {
123 123
    use super::*;
124 -
    use crate::gfx::font;
125 124
    use crate::gfx::Color as _;
125 +
    use crate::gfx::font;
126 126
127 127
    #[test]
128 128
    fn test_text_layout_basic() {
129 129
        let input = "Sphinx";
130 130
        let font = Rc::new(font::uf2::DEFAULT.decode().unwrap());
ombre/src/ui.rs +3 -3
21 21
22 22
pub use context::*;
23 23
pub use gfx::common::{Align, Align2D, Repaint};
24 24
pub use gfx::cursors::CursorDescriptor;
25 25
pub use gfx::text::{PlainText, RichTextStorage, TextAlign};
26 -
pub use interface::{interface, Config, Error, Interface};
26 +
pub use interface::{Config, Error, Interface, interface};
27 27
pub use lazy::Lazy;
28 28
pub use widgets::*;
29 29
pub use widgets::{Widget, WidgetEvent, WidgetExt};
30 30
31 31
#[cfg(test)]
34 34
/// Bail out of a function with an error.
35 35
/// In debug mode, this panics with the error message.
36 36
/// In release mode, the error is logged and we return from the function early.
37 37
#[macro_export]
38 38
macro_rules! bail {
39 -
    ($fmt:expr, $($arg:tt)*) => {{
39 +
    ($fmt:expr_2021, $($arg:tt)*) => {{
40 40
        #[cfg(debug_assertions)]
41 41
        {
42 42
            panic!($fmt, $($arg)*);
43 43
        }
44 44
        #[cfg(not(debug_assertions))]
45 45
        {
46 46
            log::error!(target: "ui", $fmt, $($arg)*);
47 47
            return;
48 48
        }
49 49
    }};
50 -
    ($fmt:expr) => {{
50 +
    ($fmt:expr_2021) => {{
51 51
        #[cfg(debug_assertions)]
52 52
        {
53 53
            panic!($fmt);
54 54
        }
55 55
        #[cfg(not(debug_assertions))]
ombre/src/ui/context.rs +1 -1
1 1
//! Widget context.
2 2
use std::collections::HashMap;
3 3
use std::ops::Deref;
4 4
5 -
use crate::paint::traits::Paint;
6 5
use crate::paint::PaintOp;
6 +
use crate::paint::traits::Paint;
7 7
use crate::paint::{Brush, Shape};
8 8
use crate::text::Text;
9 9
use crate::ui::gfx::*;
10 10
use crate::ui::math::*;
11 11
ombre/src/ui/gfx.rs +2 -2
6 6
7 7
pub use crate::gfx::font::FontDescriptor;
8 8
pub use crate::gfx::*;
9 9
pub use crate::paint::blit::Blit;
10 10
pub use crate::paint::pipeline::{Uniforms, Vertex};
11 -
pub use crate::paint::shape::{circle, line, rectangle, Circle, Line, Rectangle, Rotation};
12 -
pub use crate::paint::{batch, batch::VertexBatch, pipeline, shape, PaintOp};
11 +
pub use crate::paint::shape::{Circle, Line, Rectangle, Rotation, circle, line, rectangle};
12 +
pub use crate::paint::{PaintOp, batch, batch::VertexBatch, pipeline, shape};
13 13
pub use crate::text::{RichTextLayout, TextAlign, TextLayoutOptions, TextSpan};
14 14
15 15
pub use common::*;
16 16
pub use cursors::CursorDescriptor;
ombre/src/ui/gfx/text.rs +1 -1
1 1
//! Text rendering.
2 2
use std::sync::Arc;
3 3
4 -
use crate::gfx::font::{FontName, Fonts, DEFAULT_FONT};
4 +
use crate::gfx::font::{DEFAULT_FONT, FontName, Fonts};
5 5
use crate::gfx::{Image, Rgba, Size};
6 6
use crate::math::Zero as _;
7 7
8 8
pub use crate::text::*;
9 9
ombre/src/ui/interface.rs +3 -3
5 5
6 6
use crate::canvas;
7 7
use crate::canvas::CanvasBuilder;
8 8
use crate::paint::{Canvas, PaintSurface};
9 9
use crate::prelude::*;
10 +
use crate::ui::Pod;
11 +
use crate::ui::WindowCtx;
10 12
use crate::ui::math::Zero;
11 13
use crate::ui::platform::WindowEvent;
12 14
use crate::ui::widgets;
13 -
use crate::ui::Pod;
14 -
use crate::ui::WindowCtx;
15 -
use crate::ui::{context::Cursors, Context, CursorDescriptor, Widget, WidgetEvent};
15 +
use crate::ui::{Context, CursorDescriptor, Widget, WidgetEvent, context::Cursors};
16 16
17 17
/// Interface error.
18 18
#[derive(Debug)]
19 19
pub enum Error<T: RenderBackend> {
20 20
    /// Canvas error.
ombre/src/ui/lazy.rs +1 -1
53 53
        match self {
54 54
            Self::Init(val) => val,
55 55
            Self::Uninit => {
56 56
                let val = init();
57 57
                *self = Self::Init(val);
58 -
                let Self::Init(ref val) = self else {
58 +
                let &mut Self::Init(ref val) = self else {
59 59
                    todo!();
60 60
                };
61 61
                val
62 62
            }
63 63
        }
ombre/src/ui/widgets/hstack.rs +66 -53
225 225
        ui.paint(&mut widget);
226 226
227 227
        let ops = ui.surface.ops.as_slice();
228 228
        assert_eq!(ops.len(), 3); // One fill operation for each child
229 229
230 -
        if let [PaintOp::Fill {
231 -
            shape: Shape::Rectangle(r1),
232 -
            brush: Brush::Color(c1),
233 -
            transform: t1,
234 -
            ..
235 -
        }, PaintOp::Fill {
236 -
            shape: Shape::Rectangle(r2),
237 -
            brush: Brush::Color(c2),
238 -
            transform: t2,
239 -
            ..
240 -
        }, PaintOp::Fill {
241 -
            shape: Shape::Rectangle(r3),
242 -
            brush: Brush::Color(c3),
243 -
            transform: t3,
244 -
            ..
245 -
        }] = ops
230 +
        if let [
231 +
            PaintOp::Fill {
232 +
                shape: Shape::Rectangle(r1),
233 +
                brush: Brush::Color(c1),
234 +
                transform: t1,
235 +
                ..
236 +
            },
237 +
            PaintOp::Fill {
238 +
                shape: Shape::Rectangle(r2),
239 +
                brush: Brush::Color(c2),
240 +
                transform: t2,
241 +
                ..
242 +
            },
243 +
            PaintOp::Fill {
244 +
                shape: Shape::Rectangle(r3),
245 +
                brush: Brush::Color(c3),
246 +
                transform: t3,
247 +
                ..
248 +
            },
249 +
        ] = ops
246 250
        {
247 251
            assert_eq!(r1.origin, Point2D::ZERO);
248 252
            assert_eq!(t1.translation(), Vector2D::new(0., 0.));
249 253
            assert_eq!(r1.size, Size::new(3., 3.));
250 254
            assert_eq!(c1, &Rgba::RED);
281 285
        ui.paint(&mut widget);
282 286
283 287
        let ops = ui.surface.ops.as_slice();
284 288
        assert_eq!(ops.len(), 4); // One fill operation for each child
285 289
286 -
        if let [PaintOp::Fill {
287 -
            shape: Shape::Rectangle(r1),
288 -
            brush: Brush::Color(c1),
289 -
            transform: t1,
290 -
            ..
291 -
        }, PaintOp::Fill {
292 -
            shape: Shape::Rectangle(r2),
293 -
            brush: Brush::Color(c2),
294 -
            transform: t2,
295 -
            ..
296 -
        }, PaintOp::Fill {
297 -
            shape: Shape::Rectangle(r3),
298 -
            brush: Brush::Color(c3),
299 -
            transform: t3,
300 -
            ..
301 -
        }, PaintOp::Fill {
302 -
            shape: Shape::Rectangle(r4),
303 -
            brush: Brush::Color(c4),
304 -
            transform: t4,
305 -
            ..
306 -
        }] = ops
290 +
        if let [
291 +
            PaintOp::Fill {
292 +
                shape: Shape::Rectangle(r1),
293 +
                brush: Brush::Color(c1),
294 +
                transform: t1,
295 +
                ..
296 +
            },
297 +
            PaintOp::Fill {
298 +
                shape: Shape::Rectangle(r2),
299 +
                brush: Brush::Color(c2),
300 +
                transform: t2,
301 +
                ..
302 +
            },
303 +
            PaintOp::Fill {
304 +
                shape: Shape::Rectangle(r3),
305 +
                brush: Brush::Color(c3),
306 +
                transform: t3,
307 +
                ..
308 +
            },
309 +
            PaintOp::Fill {
310 +
                shape: Shape::Rectangle(r4),
311 +
                brush: Brush::Color(c4),
312 +
                transform: t4,
313 +
                ..
314 +
            },
315 +
        ] = ops
307 316
        {
308 317
            // First row
309 318
            assert_eq!(r1.origin.transform(*t1), Point2D::new(0., 0.));
310 319
            assert_eq!(r1.size, Size::new(3., 3.));
311 320
            assert_eq!(c1, &Rgba::RED);
340 349
        ui.paint(&mut widget);
341 350
342 351
        let ops = ui.surface.ops.as_slice();
343 352
        assert_eq!(ops.len(), 3); // One fill operation for each child
344 353
345 -
        if let [PaintOp::Fill {
346 -
            shape: Shape::Rectangle(r1),
347 -
            brush: Brush::Color(c1),
348 -
            transform: t1,
349 -
            ..
350 -
        }, PaintOp::Fill {
351 -
            shape: Shape::Rectangle(r2),
352 -
            brush: Brush::Color(c2),
353 -
            transform: t2,
354 -
            ..
355 -
        }, PaintOp::Fill {
356 -
            shape: Shape::Rectangle(r3),
357 -
            brush: Brush::Color(c3),
358 -
            transform: t3,
359 -
            ..
360 -
        }] = ops
354 +
        if let [
355 +
            PaintOp::Fill {
356 +
                shape: Shape::Rectangle(r1),
357 +
                brush: Brush::Color(c1),
358 +
                transform: t1,
359 +
                ..
360 +
            },
361 +
            PaintOp::Fill {
362 +
                shape: Shape::Rectangle(r2),
363 +
                brush: Brush::Color(c2),
364 +
                transform: t2,
365 +
                ..
366 +
            },
367 +
            PaintOp::Fill {
368 +
                shape: Shape::Rectangle(r3),
369 +
                brush: Brush::Color(c3),
370 +
                transform: t3,
371 +
                ..
372 +
            },
373 +
        ] = ops
361 374
        {
362 375
            assert_eq!(r1.origin, Point2D::ZERO);
363 376
            assert_eq!(t1.translation(), Vector2D::new(0., 2.));
364 377
            assert_eq!(r1.size, Size::new(2., 2.));
365 378
            assert_eq!(c1, &Rgba::RED);
ombre/src/ui/widgets/image.rs +1 -1
1 1
//! [`Image`] widget.
2 -
use crate::ui::gfx::color::Rgba;
3 2
use crate::ui::gfx::Color;
3 +
use crate::ui::gfx::color::Rgba;
4 4
5 5
use crate::ui::gfx;
6 6
use crate::ui::widgets::*;
7 7
8 8
/// Paints an image on the screen.
ombre/src/ui/widgets/input.rs +2 -2
1 1
//! [`Input`] widget.
2 2
use std::marker::PhantomData;
3 3
4 4
use super::*;
5 -
use crate::gfx::font::{FontName, DEFAULT_FONT};
6 -
use crate::ui::gfx::text::{PlainText, TextStorage};
5 +
use crate::gfx::font::{DEFAULT_FONT, FontName};
7 6
use crate::ui::gfx::Color as _;
8 7
use crate::ui::gfx::TextLayoutOptions;
8 +
use crate::ui::gfx::text::{PlainText, TextStorage};
9 9
use crate::ui::widgets::Label;
10 10
11 11
/// A text input field.
12 12
#[derive(Debug)]
13 13
pub struct Input<T> {
ombre/src/ui/widgets/label.rs +1 -1
1 1
//! [`Label`] widget.
2 2
use super::*;
3 3
use crate::bail;
4 -
use crate::gfx::font::{FontName, DEFAULT_FONT};
4 +
use crate::gfx::font::{DEFAULT_FONT, FontName};
5 5
use crate::ui::gfx::text::{PlainText, TextAlign, TextLayoutOptions, TextValue};
6 6
7 7
/// A text label with wrapping.
8 8
#[derive(Debug)]
9 9
pub struct Label<T> {
ombre/src/ui/widgets/vstack.rs +20 -16
178 178
        ui.paint(&mut widget);
179 179
180 180
        let ops = ui.surface.ops.as_slice();
181 181
        assert_eq!(ops.len(), 3); // One fill operation for each child
182 182
183 -
        if let [PaintOp::Fill {
184 -
            shape: Shape::Rectangle(r1),
185 -
            brush: Brush::Color(c1),
186 -
            transform: t1,
187 -
            ..
188 -
        }, PaintOp::Fill {
189 -
            shape: Shape::Rectangle(r2),
190 -
            brush: Brush::Color(c2),
191 -
            transform: t2,
192 -
            ..
193 -
        }, PaintOp::Fill {
194 -
            shape: Shape::Rectangle(r3),
195 -
            brush: Brush::Color(c3),
196 -
            transform: t3,
197 -
            ..
198 -
        }] = ops
183 +
        if let [
184 +
            PaintOp::Fill {
185 +
                shape: Shape::Rectangle(r1),
186 +
                brush: Brush::Color(c1),
187 +
                transform: t1,
188 +
                ..
189 +
            },
190 +
            PaintOp::Fill {
191 +
                shape: Shape::Rectangle(r2),
192 +
                brush: Brush::Color(c2),
193 +
                transform: t2,
194 +
                ..
195 +
            },
196 +
            PaintOp::Fill {
197 +
                shape: Shape::Rectangle(r3),
198 +
                brush: Brush::Color(c3),
199 +
                transform: t3,
200 +
                ..
201 +
            },
202 +
        ] = ops
199 203
        {
200 204
            assert_eq!(r1.origin.transform(*t1), Point2D::new(0., 0.));
201 205
            assert_eq!(r1.size, Size::new(3., 3.));
202 206
            assert_eq!(c1, &Rgba::RED);
203 207
reve/Cargo.toml +1 -1
2 2
name = "reve"
3 3
description = "Dream in three dimensions"
4 4
keywords = ["graphics", "3d", "modeler"]
5 5
categories = ["graphics", "rendering", "game-development"]
6 6
version = "0.0.0"
7 -
edition = "2021"
7 +
edition = "2024"
8 8
9 9
[dependencies]
10 10
ombre = { version = "0.6", path = "../ombre", features = ["derive"] }
11 11
log = { version = "0.4.20", features = ["std"] }
12 12
reve/src/renderer/scene.rs +1 -5
14 14
        static NEXT: AtomicU32 = AtomicU32::new(1);
15 15
        NodeId(NEXT.fetch_add(1, Ordering::SeqCst))
16 16
    }
17 17
18 18
    pub(super) fn new(n: u32) -> Option<Self> {
19 -
        if n > 0 {
20 -
            Some(Self(n))
21 -
        } else {
22 -
            None
23 -
        }
19 +
        if n > 0 { Some(Self(n)) } else { None }
24 20
    }
25 21
}
26 22
27 23
impl From<NodeId> for u32 {
28 24
    fn from(value: NodeId) -> Self {
rust-toolchain.toml +1 -1
1 1
[toolchain]
2 -
channel = "1.83"
2 +
channel = "1.99.1"
3 3
profile = "default"
4 4
components = ["rust-src"]
syntaxe/Cargo.toml +1 -1
1 1
[package]
2 2
name = "syntaxe"
3 3
description = "Simple, declarative parser combinators"
4 4
documentation = "https://docs.rs/syntaxe"
5 5
version = "0.1.0"
6 -
edition = "2021"
6 +
edition = "2024"
7 7
authors = ["cloudhead <self@cloudhead.io>"]
8 8
license = "MIT"
9 9
10 10
[lints]
11 11
workspace = true
syntaxe/src/parsers.rs +6 -9
365 365
pub fn either<'a, L, R>(left: L, right: R) -> impl Parser<'a, Output = Either<L::Output, R::Output>>
366 366
where
367 367
    L: Parser<'a>,
368 368
    R: Parser<'a>,
369 369
{
370 -
    move |input| {
371 -
        if let Ok((out, rest)) = left.parse_at(input) {
372 -
            Ok((Either::Left(out), rest))
373 -
        } else {
374 -
            match right.parse_at(input) {
375 -
                Ok((out, rest)) => Ok((Either::Right(out), rest)),
376 -
                Err(err) => Err(err),
377 -
            }
378 -
        }
370 +
    move |input| match left.parse_at(input) {
371 +
        Ok((out, rest)) => Ok((Either::Left(out), rest)),
372 +
        _ => match right.parse_at(input) {
373 +
            Ok((out, rest)) => Ok((Either::Right(out), rest)),
374 +
            Err(err) => Err(err),
375 +
        },
379 376
    }
380 377
}
381 378
382 379
/// Parses if the predicate returns `true` on the input's next `char`.
383 380
#[derive(Clone)]
syntaxe/src/prelude.rs +1 -1
1 1
//! Exports all the common parser combinators.
2 2
3 +
pub use crate::parsers::{Either, Parser};
3 4
pub use crate::parsers::{
4 5
    any, backtrack, between, character, choice, digit, either, end, float, letter, linebreaks,
5 6
    many, natural, optional, satisfy, signed, spaces, spaces1, string, symbol, take, take_str,
6 7
    take_until, take_while, take_while1, until, whitespace,
7 8
};
8 -
pub use crate::parsers::{Either, Parser};