Added after render and render on extension with child handlers #26
This commit is contained in:
+7
-10
@@ -33,7 +33,7 @@ use std::sync::{Arc, Mutex};
|
||||
|
||||
use crate::{
|
||||
extensions::{Extension, Handler},
|
||||
prelude::ExtensionContext,
|
||||
prelude::Context,
|
||||
render_scope::RenderScope,
|
||||
widget::{BoxedElement, DynWidget, Element, StaticWidget, Widget, WidgetLoad},
|
||||
};
|
||||
@@ -159,7 +159,7 @@ impl Screen {
|
||||
///
|
||||
/// This method blocks and repeatedly renders the screen at a fixed interval.
|
||||
pub fn run(self: &Arc<Self>) -> std::io::Result<()> {
|
||||
let ctx = ExtensionContext::new(self.clone());
|
||||
let ctx = Context::new(self.clone());
|
||||
|
||||
for ext in self.extensions.lock().unwrap().iter() {
|
||||
ext.lock().unwrap().init(&ctx);
|
||||
@@ -168,7 +168,7 @@ impl Screen {
|
||||
utils::hide_cursor()?;
|
||||
|
||||
while *self.running.lock().unwrap() {
|
||||
self.render()?;
|
||||
self.render(&ctx)?;
|
||||
std::thread::sleep(std::time::Duration::from_millis(28));
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ impl Screen {
|
||||
/// Renders all widgets and applies extensions.
|
||||
///
|
||||
/// This method is called internally by `run`.
|
||||
pub fn render(self: &Arc<Self>) -> std::io::Result<()> {
|
||||
pub fn render(self: &Arc<Self>, ctx: &Context) -> std::io::Result<()> {
|
||||
let mut scope = RenderScope::new();
|
||||
let (w, h) = crossterm::terminal::size().unwrap();
|
||||
scope.set_parent_size(w, h);
|
||||
@@ -186,9 +186,6 @@ impl Screen {
|
||||
utils::clear()?;
|
||||
for elem in self.widgets.lock().unwrap().iter() {
|
||||
if elem.get::<NoRender>().is_some() || elem.get::<NoRenderRoot>().is_some() {
|
||||
for ext in self.extensions.lock().unwrap().iter() {
|
||||
ext.lock().unwrap().render_widget(&mut scope, elem);
|
||||
}
|
||||
elem.auto_refresh();
|
||||
continue;
|
||||
}
|
||||
@@ -206,17 +203,17 @@ impl Screen {
|
||||
}
|
||||
|
||||
for ext in self.extensions.lock().unwrap().iter() {
|
||||
ext.lock().unwrap().render_widget(&mut scope, elem);
|
||||
ext.lock().unwrap().render_widget(ctx, &mut scope, elem);
|
||||
}
|
||||
|
||||
elem.get_elem().render(&mut scope);
|
||||
elem.get_elem().render(&mut scope, ctx);
|
||||
|
||||
if let Some(t) = elem.get() {
|
||||
scope.set_transform(&t);
|
||||
}
|
||||
scope.draw();
|
||||
|
||||
elem.get_elem().after_render(&mut scope);
|
||||
elem.get_elem().after_render(&mut scope, ctx);
|
||||
}
|
||||
|
||||
elem.auto_refresh();
|
||||
|
||||
Reference in New Issue
Block a user