Skip to content

Commit

Permalink
try to fix borrow issue with custom paint
Browse files Browse the repository at this point in the history
  • Loading branch information
msparkles committed Apr 10, 2024
1 parent 615ff7a commit b4df755
Show file tree
Hide file tree
Showing 5 changed files with 301 additions and 235 deletions.
4 changes: 3 additions & 1 deletion crates/yakui-app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ impl Graphics {

let clear = encoder.finish();

let paint_yak = self.renderer.paint(yak, &self.device, &self.queue, surface);
let paint_yak =
self.renderer
.paint::<(), ()>(yak, &self.device, &self.queue, surface, &mut ());

self.queue.submit([clear, paint_yak]);
output.present();
Expand Down
4 changes: 2 additions & 2 deletions crates/yakui-core/src/paint/layers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{any::Any, ops::Deref};
use std::ops::Deref;

use super::PaintCall;

Expand All @@ -7,7 +7,7 @@ use super::PaintCall;
#[non_exhaustive]
pub struct PaintLayer {
/// The draw calls that can be used to paint this layer.
pub calls: Vec<PaintCall<dyn Any, dyn Any>>,
pub calls: Vec<PaintCall>,
}

impl PaintLayer {
Expand Down
11 changes: 6 additions & 5 deletions crates/yakui-core/src/paint/primitives.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::any::Any;

use glam::{Vec2, Vec4};

use crate::geometry::Rect;
Expand Down Expand Up @@ -31,16 +33,15 @@ where

#[derive(Debug)]
#[allow(missing_docs)]
pub enum PaintCall<S: ?Sized, D: ?Sized> {
pub enum PaintCall {
Yakui(YakuiPaintCall),
Custom(CustomPaintCall<S, D>),
Custom(CustomPaintCall),
}

#[derive(Debug)]
#[allow(missing_docs)]
pub struct CustomPaintCall<S: ?Sized, D: ?Sized> {
pub setup: Box<S>,
pub draw: Box<D>,
pub struct CustomPaintCall {
pub callback: Box<dyn Any>,
}

#[derive(Debug)]
Expand Down
7 changes: 5 additions & 2 deletions crates/yakui-to-image/src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl Graphics {
pub fn paint(
&self,
yak: &mut yakui_core::Yakui,
yak_renderer: &mut yakui_wgpu::YakuiWgpu,
yak_renderer: &mut yakui_wgpu::YakuiWgpu<()>,
) -> RgbaImage {
let viewport = yak.layout_dom().unscaled_viewport();
let size = wgpu::Extent3d {
Expand Down Expand Up @@ -103,8 +103,11 @@ impl Graphics {
sample_count: 1,
color_attachment: &view,
resolve_target: None,
depth_format: None,
depth_attachment: None,
depth_load_op: None,
};
let paint_yak = yak_renderer.paint(yak, &self.device, &self.queue, surface);
let paint_yak = yak_renderer.paint(yak, &self.device, &self.queue, surface, ());

let mut encoder = self
.device
Expand Down
Loading

0 comments on commit b4df755

Please sign in to comment.