perfomance changes

This commit is contained in:
2024-11-22 11:29:00 +01:00
parent cc0ea4a9f5
commit 7f1437e779
4 changed files with 18 additions and 9 deletions
+11 -6
View File
@@ -64,12 +64,7 @@ extern "C" fn render_loop(ptr: *mut c_void) -> bool {
}
let args = unsafe { &mut *(ptr as *mut LArgs) };
while args.running {
let (width, height) = get_term_size();
let mut frame: Vec<String> = create_frame(width, height);
render_to_frame(true, width, &mut frame, args.element);
clear();
print!("{}", frame.join(""));
flush();
sleep(1000);
}
false
}
@@ -92,12 +87,14 @@ extern "C" fn event_loop(ptr: *mut c_void) -> *const c_void {
crossterm::event::Event::FocusGained,
&document,
);
document.render();
while args.running {
if ptr.is_null() {
break;
}
event(args.element, crossterm::event::read().unwrap(), &document);
document.render();
}
null() as *const c_void
}
@@ -124,6 +121,14 @@ extern "C" fn cmd_loop(ptr: *mut c_void) -> *const c_void {
})
.unwrap();
}
Command::Render => {
let (width, height) = get_term_size();
let mut frame: Vec<String> = create_frame(width, height);
render_to_frame(true, width, &mut frame, args.element);
clear();
print!("{}", frame.join(""));
flush();
}
}
}
null()
+4
View File
@@ -216,6 +216,7 @@ pub fn convert<T>(widget: &mut Box<dyn ElementWidget>) -> &mut Box<T> {
pub enum Command {
Exit,
Render,
GetElementById(String),
}
@@ -240,4 +241,7 @@ impl Document {
None
}
}
pub fn render(&self) {
self.cmd_sender.send(Command::Render).unwrap();
}
}
+1 -3
View File
@@ -9,13 +9,11 @@ fn main() {
fn app() -> Element {
rsx! { styling: Some(styles()),
button { class: "btn", on_click: Handler::new(|_, _, document| {
if let Some(txt) = document.get_element_by_id::<Text>("txt") {
txt.children.set_text("edited");
}
}), "Hello, World!" }
text { id: "txt", "Some text!" }
text { id: "txt", y: 2, "Some text!" }
}
}
+2
View File
@@ -159,8 +159,10 @@ impl ElementWidget for Button<'_> {
match event {
Event::Key(key) => {
if key.code == KeyCode::Enter {
document.render();
self.state = "clicked";
run_handler!(self.on_click(event, document));
document.render();
sleep(100);
self.state = "";
}