pub fn rui(view: impl View + 'static) {
    let setup = block_on(setup("rui"));
    let window = setup.window;
    let surface = setup.surface;
    let device = setup.device;
    let size = setup.size;
    let adapter = setup.adapter;
    let queue = setup.queue;

    let mut config = wgpu::SurfaceConfiguration {
        usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
        format: surface.get_preferred_format(&adapter).unwrap(),
        width: size.width,
        height: size.height,
        present_mode: wgpu::PresentMode::Mailbox,
    };
    surface.configure(&device, &config);

    let mut vger = VGER::new(&device, wgpu::TextureFormat::Bgra8UnormSrgb);
    let mut cx = Context::new();
    let mut mouse_position = LocalPoint::zero();

    setup.event_loop.run(move |event, _, control_flow| {
        // ControlFlow::Poll continuously runs the event loop, even if the OS hasn't
        // dispatched any events. This is ideal for games and similar applications.
        // *control_flow = ControlFlow::Poll;

        // ControlFlow::Wait pauses the event loop if no events are available to process.
        // This is ideal for non-game applications that only update in response to user
        // input, and uses significantly less power/CPU time than ControlFlow::Poll.
        *control_flow = ControlFlow::Wait;

        match event {
            winit::event::Event::WindowEvent {
                event: WindowEvent::CloseRequested,
                ..
            } => {
                println!("The close button was pressed; stopping");
                *control_flow = ControlFlow::Exit
            }
            winit::event::Event::WindowEvent {
                event:
                    WindowEvent::Resized(size)
                    | WindowEvent::ScaleFactorChanged {
                        new_inner_size: &mut size,
                        ..
                    },
                ..
            } => {
                println!("Resizing to {:?}", size);
                config.width = size.width.max(1);
                config.height = size.height.max(1);
                surface.configure(&device, &config);
            }
            winit::event::Event::MainEventsCleared => {
                // Application update code.

                // Queue a RedrawRequested event.
                //
                // You only need to call this if you've determined that you need to redraw, in
                // applications which do not always need to. Applications that redraw continuously
                // can just render here instead.
                window.request_redraw();
            }
            winit::event::Event::RedrawRequested(_) => {
                // Redraw the application.
                //
                // It's preferable for applications that do not render continuously to render in
                // this event rather than in MainEventsCleared, since rendering in here allows
                // the program to gracefully handle redraws requested by the OS.

                // println!("RedrawRequested");

                let frame = match surface.get_current_texture() {
                    Ok(frame) => frame,
                    Err(_) => {
                        surface.configure(&device, &config);
                        surface
                            .get_current_texture()
                            .expect("Failed to acquire next surface texture!")
                    }
                };

                let window_size = window.inner_size();
                let scale = window.scale_factor() as f32;
                // println!("window_size: {:?}", window_size);
                let width = window_size.width as f32 / scale;
                let height = window_size.height as f32 / scale;

                vger.begin(width, height, scale);

                view.layout(cx.root_id, [width, height].into(), &mut cx, &mut vger);
                view.draw(cx.root_id, &mut cx, &mut vger);

                let texture_view = frame
                    .texture
                    .create_view(&wgpu::TextureViewDescriptor::default());

                let desc = wgpu::RenderPassDescriptor {
                    label: None,
                    color_attachments: &[wgpu::RenderPassColorAttachment {
                        view: &texture_view,
                        resolve_target: None,
                        ops: wgpu::Operations {
                            load: wgpu::LoadOp::Clear(wgpu::Color::BLACK),
                            store: true,
                        },
                    }],
                    depth_stencil_attachment: None,
                };

                vger.encode(&device, &desc, &queue);

                frame.present();
            }
            winit::event::Event::WindowEvent {
                event: WindowEvent::MouseInput { state, .. },
                ..
            } => {
                let event = match state {
                    ElementState::Pressed => Event {
                        kind: EventKind::TouchBegin { id: 0 },
                        position: mouse_position,
                    },
                    ElementState::Released => Event {
                        kind: EventKind::TouchEnd { id: 0 },
                        position: mouse_position,
                    },
                };
                view.process(&event, cx.root_id, &mut cx, &mut vger)
            }
            winit::event::Event::WindowEvent {
                event: WindowEvent::CursorMoved { position, .. },
                ..
            } => {
                let scale = window.scale_factor() as f32;
                mouse_position = [
                    position.x as f32 / scale,
                    (config.height as f32 - position.y as f32) / scale,
                ]
                .into();
                let event = Event {
                    kind: EventKind::TouchMove { id: 0 },
                    position: mouse_position,
                };
                view.process(&event, cx.root_id, &mut cx, &mut vger)
            }
            _ => (),
        }
    });
}
/// Call this function to describe your UI.
Call this function to describe your UI.
Call this function to describe your UI .
pub fn rui(view: impl View + 'static) {
    let setup = block_on(setup("rui"));
    let window = setup.window;
    let surface = setup.surface;
    let device = setup.device;
    let size = setup.size;
    let adapter = setup.adapter;
    let queue = setup.queue;
    let mut config = wgpu::SurfaceConfiguration {
        usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
        format: surface.get_preferred_format(&adapter).unwrap(),
        width: size.width,
        height: size.height,
        present_mode: wgpu::PresentMode::Mailbox,
    };
    surface.configure(&device, &config);
    let mut vger = VGER::new(&device, wgpu::TextureFormat::Bgra8UnormSrgb);
    let mut cx = Context::new();
    let mut mouse_position = LocalPoint::zero();
    setup.event_loop.run(move |event, _, control_flow| {
        // ControlFlow::Poll continuously runs the event loop, even if the OS hasn't
        // dispatched any events. This is ideal for games and similar applications.
        // *control_flow = ControlFlow::Poll;
        // ControlFlow::Wait pauses the event loop if no events are available to process.
        // This is ideal for non-game applications that only update in response to user
        // input, and uses significantly less power/CPU time than ControlFlow::Poll.
        *control_flow = ControlFlow::Wait;
        match event {
            winit::event::Event::WindowEvent {
                event: WindowEvent::CloseRequested,
                ..
            } => {
                println!("The close button was pressed; stopping");
                *control_flow = ControlFlow::Exit
            }
            winit::event::Event::WindowEvent {
                event:
                    WindowEvent::Resized(size)
                    | WindowEvent::ScaleFactorChanged {
                        new_inner_size: &mut size,
                        ..
                    },
                ..
            } => {
                println!("Resizing to {:?}", size);
                config.width = size.width.max(1);
                config.height = size.height.max(1);
                surface.configure(&device, &config);
            }
            winit::event::Event::MainEventsCleared => {
                // Application update code.
                // Queue a RedrawRequested event.
                //
                // You only need to call this if you've determined that you need to redraw, in
                // applications which do not always need to. Applications that redraw continuously
                // can just render here instead.
                window.request_redraw();
            }
            winit::event::Event::RedrawRequested(_) => {
                // Redraw the application.
                //
                // It's preferable for applications that do not render continuously to render in
                // this event rather than in MainEventsCleared, since rendering in here allows
                // the program to gracefully handle redraws requested by the OS.
                // println!("RedrawRequested");
                let frame = match surface.get_current_texture() {
                    Ok(frame) => frame,
                    Err(_) => {
                        surface.configure(&device, &config);
                        surface
                            .get_current_texture()
                            .expect("Failed to acquire next surface texture!")
                    }
                };
                let window_size = window.inner_size();
                let scale = window.scale_factor() as f32;
                // println!("window_size: {:?}", window_size);
                let width = window_size.width as f32 / scale;
                let height = window_size.height as f32 / scale;
                vger.begin(width, height, scale);
                view.layout(cx.root_id, [width, height].into(), &mut cx, &mut vger);
                view.draw(cx.root_id, &mut cx, &mut vger);
                let texture_view = frame
                    .texture
                    .create_view(&wgpu::TextureViewDescriptor::default());
                let desc = wgpu::RenderPassDescriptor {
                    label: None,
                    color_attachments: &[wgpu::RenderPassColorAttachment {
                        view: &texture_view,
                        resolve_target: None,
                        ops: wgpu::Operations {
                            load: wgpu::LoadOp::Clear(wgpu::Color::BLACK),
                            store: true,
                        },
                    }],
                    depth_stencil_attachment: None,
                };
                vger.encode(&device, &desc, &queue);
                frame.present();
            }
            winit::event::Event::WindowEvent {
                event: WindowEvent::MouseInput { state, .. },
                ..
            } => {
                let event = match state {
                    ElementState::Pressed => Event {
                        kind: EventKind::TouchBegin { id: 0 },
                        position: mouse_position,
                    },
                    ElementState::Released => Event {
                        kind: EventKind::TouchEnd { id: 0 },
                        position: mouse_position,
                    },
                };
                view.process(&event, cx.root_id, &mut cx, &mut vger)
            }
            winit::event::Event::WindowEvent {
                event: WindowEvent::CursorMoved { position, .. },
                ..
            } => {
                let scale = window.scale_factor() as f32;
                mouse_position = [
                    position.x as f32 / scale,
                    (config.height as f32 - position.y as f32) / scale,
                ]
                .into();
                let event = Event {
                    kind: EventKind::TouchMove { id: 0 },
                    position: mouse_position,
                };
                view.process(&event, cx.root_id, &mut cx, &mut vger)
            }
            _ => (),
        }
    });
}
pub fn rui ( view : impl View + ' static ) { let setup = block_on ( setup ( " " ) ) ; let window = setup . window ; let surface = setup . surface ; let device = setup . device ; let size = setup . size ; let adapter = setup . adapter ; let queue = setup . queue ; let mut config = wgpu :: SurfaceConfiguration { usage : wgpu :: TextureUsages :: RENDER_ATTACHMENT , format : surface . get_preferred_format ( & adapter ) . unwrap ( ) , width : size . width , height : size . height , present_mode : wgpu :: PresentMode :: Mailbox , } ; surface . configure ( & device , & config ) ; let mut vger = VGER :: new ( & device , wgpu :: TextureFormat :: Bgra8UnormSrgb ) ; let mut cx = Context :: new ( ) ; let mut mouse_position = LocalPoint :: zero ( ) ; setup . event_loop . run ( move | event , _ , control_flow | { // ControlFlow::Poll continuously runs the event loop, even if the OS hasn't // dispatched any events. This is ideal for games and similar applications. // *control_flow = ControlFlow::Poll; // ControlFlow::Wait pauses the event loop if no events are available to process. // This is ideal for non-game applications that only update in response to user // input, and uses significantly less power/CPU time than ControlFlow::Poll. * control_flow = ControlFlow :: Wait ; match event { winit :: event :: Event :: WindowEvent { event : WindowEvent :: CloseRequested , .. } => { println ! ( " " ) ; * control_flow = ControlFlow :: Exit } winit :: event :: Event :: WindowEvent { event : WindowEvent :: Resized ( size ) | WindowEvent :: ScaleFactorChanged { new_inner_size : & mut size , .. } , .. } => { println ! ( " " size ) ; config . width = size . width . max ( 1 ) ; config . height = size . height . max ( 1 ) ; surface . configure ( & device , & config ) ; } winit :: event :: Event :: MainEventsCleared => { // Application update code. // Queue a RedrawRequested event. // // You only need to call this if you've determined that you need to redraw, in // applications which do not always need to. Applications that redraw continuously // can just render here instead. window . request_redraw ( ) ; } winit :: event :: Event :: RedrawRequested ( _ ) => { // Redraw the application. // // It's preferable for applications that do not render continuously to render in // this event rather than in MainEventsCleared, since rendering in here allows // the program to gracefully handle redraws requested by the OS. // println!("RedrawRequested"); let frame = match surface . get_current_texture ( ) { Ok ( frame ) => frame , Err ( _ ) => { surface . configure ( & device , & config ) ; surface . get_current_texture ( ) . expect ( " " ) } } ; let window_size = window . inner_size ( ) ; let scale = window . scale_factor ( ) as f32 ; // println!("window_size: {:?}", window_size); let width = window_size . width as f32 / scale ; let height = window_size . height as f32 / scale ; vger . begin ( width , height , scale ) ; view . layout ( cx . root_id , [ width , height ] . into ( ) , & mut cx , & mut vger ) ; view . draw ( cx . root_id , & mut cx , & mut vger ) ; let texture_view = frame . texture . create_view ( & wgpu :: TextureViewDescriptor :: default ( ) ) ; let desc = wgpu :: RenderPassDescriptor { label : None , color_attachments : & [ wgpu :: RenderPassColorAttachment { view : & texture_view , resolve_target : None , ops : wgpu :: Operations { load : wgpu :: LoadOp :: Clear ( wgpu :: Color :: BLACK ) , store : true , } , } ] , depth_stencil_attachment : None , } ; vger . encode ( & device , & desc , & queue ) ; frame . present ( ) ; } winit :: event :: Event :: WindowEvent { event : WindowEvent :: MouseInput { state , .. } , .. } => { let event = match state { ElementState :: Pressed => Event { kind : EventKind :: TouchBegin { id : 0 } , position : mouse_position , } , ElementState :: Released => Event { kind : EventKind :: TouchEnd { id : 0 } , position : mouse_position , } , } ; view . process ( & event , cx . root_id , & mut cx , & mut vger ) } winit :: event :: Event :: WindowEvent { event : WindowEvent :: CursorMoved { position , .. } , .. } => { let scale = window . scale_factor ( ) as f32 ; mouse_position = [ position . x as f32 / scale , ( config . height as f32 - position . y as f32 ) / scale , ] . into ( ) ; let event = Event { kind : EventKind :: TouchMove { id : 0 } , position : mouse_position , } ; view . process ( & event , cx . root_id , & mut cx , & mut vger ) } _ => ( ) , } } ) ; }
Call this function to describe your UI.
Call this function to describe your UI .
view
impl View + 'static
view
impl View + 'static