|
@@ -31,15 +31,12 @@ pub(crate) struct WindowState<WC: WindowComponent> {
|
|
|
window: Rc<winit::window::Window>,
|
|
|
events: Vec<WindowEvent>,
|
|
|
istate: InputState,
|
|
|
- draw_pending: bool,
|
|
|
surface: softbuffer::Surface<Rc<winit::window::Window>, Rc<winit::window::Window>>,
|
|
|
bitmap: RefCell<Option<kahlo::RgbaBitmap>>,
|
|
|
}
|
|
|
|
|
|
impl<WC: WindowComponent> WindowState<WC> {
|
|
|
fn redraw(&mut self, uih: &UIHandle) {
|
|
|
- self.draw_pending = false;
|
|
|
-
|
|
|
let size = self.window.inner_size();
|
|
|
self.surface
|
|
|
.resize(
|
|
@@ -74,9 +71,11 @@ impl<WC: WindowComponent> WindowState<WC> {
|
|
|
kahlo::RgbaBitmap::new(size.width as usize, size.height as usize)
|
|
|
});
|
|
|
|
|
|
- bitmap.fill(uih.theme().background);
|
|
|
layout::recalculate(LayoutNodeAccess::new(&layout));
|
|
|
+ let before = std::time::Instant::now();
|
|
|
self.wc.root_widget().render(uih.theme(), &mut bitmap);
|
|
|
+ let after = std::time::Instant::now();
|
|
|
+ print!("render time: {:?}\r", (after - before));
|
|
|
|
|
|
let mut windowbuffer = kahlo::BitmapMut::<kahlo::formats::Bgr32>::new(
|
|
|
unsafe {
|
|
@@ -106,16 +105,13 @@ impl<WC: WindowComponent> WindowState<WC> {
|
|
|
|
|
|
self.istate.tick();
|
|
|
|
|
|
- if self.draw_pending {
|
|
|
- self.redraw(uih);
|
|
|
- }
|
|
|
-
|
|
|
ret
|
|
|
}
|
|
|
}
|
|
|
|
|
|
pub(crate) trait WindowStateAccess {
|
|
|
fn push_event(&self, we: WindowEvent);
|
|
|
+ fn redraw(&self, uih: &UIHandle);
|
|
|
fn request_redraw(&self);
|
|
|
fn update_mouse_pos(&self, pos: PixelPoint);
|
|
|
fn update_mouse_button(&self, which: MouseButton, to: bool);
|
|
@@ -125,8 +121,11 @@ impl<WC: WindowComponent> WindowStateAccess for RefCell<WindowState<WC>> {
|
|
|
fn push_event(&self, we: WindowEvent) {
|
|
|
self.borrow_mut().events.push(we);
|
|
|
}
|
|
|
+ fn redraw(&self, uih: &UIHandle) {
|
|
|
+ self.borrow_mut().redraw(uih);
|
|
|
+ }
|
|
|
fn request_redraw(&self) {
|
|
|
- self.borrow_mut().draw_pending = true;
|
|
|
+ self.borrow().window.request_redraw();
|
|
|
}
|
|
|
fn update_mouse_pos(&self, pos: PixelPoint) {
|
|
|
self.borrow_mut().istate.mouse.pos = pos;
|
|
@@ -165,7 +164,6 @@ impl<'r, 'l: 'r> WindowBuilder<'r, 'l> {
|
|
|
window,
|
|
|
events: Default::default(),
|
|
|
istate: InputState::default().into(),
|
|
|
- draw_pending: false.into(),
|
|
|
surface: surface.into(),
|
|
|
bitmap: None.into(),
|
|
|
}));
|