Added focus cursor in input

This commit is contained in:
2025-08-08 23:51:15 +02:00
parent d3861909e7
commit c8ebe36d78
5 changed files with 17 additions and 15 deletions
+7 -5
View File
@@ -14,14 +14,16 @@ impl Element for Input {
fn render(
&mut self,
scope: &mut crate::prelude::RenderScope,
_: &crate::render_scope::RenderContext,
render_context: &crate::render_scope::RenderContext,
) {
let s = self.state.get();
scope.draw_text(0, 0, &s);
if let Some(c) = s.chars().nth(self.cursor) {
scope.draw_text_inverted(self.cursor as u16, 0, &c.to_string());
} else {
scope.draw_text_inverted(s.len() as u16, 0, " ");
if render_context.is_focused() {
if let Some(c) = s.chars().nth(self.cursor) {
scope.draw_text_inverted(self.cursor as u16, 0, &c.to_string());
} else {
scope.draw_text_inverted(s.len() as u16, 0, " ");
}
}
}