diff --git a/src/ui/euph/room.rs b/src/ui/euph/room.rs index d64c3c5..161bd9c 100644 --- a/src/ui/euph/room.rs +++ b/src/ui/euph/room.rs @@ -19,6 +19,7 @@ use crate::ui::chat::{ChatState, Reaction}; use crate::ui::input::{key, InputEvent, KeyBindingsList, KeyEvent}; use crate::ui::widgets::background::Background; use crate::ui::widgets::border::Border; +use crate::ui::widgets::cursor::Cursor; use crate::ui::widgets::editor::EditorState; use crate::ui::widgets::empty::Empty; use crate::ui::widgets::join::{HJoin, Segment, VJoin}; @@ -193,7 +194,7 @@ impl EuphRoom { match &self.state { State::Normal => {} - State::Auth(editor) => layers.push(Self::auth_widget(editor)), + State::Auth(_) => layers.push(Self::auth_widget()), State::Nick(editor) => layers.push(Self::nick_widget(editor)), } @@ -204,11 +205,17 @@ impl EuphRoom { Layer::new(layers).into() } - fn auth_widget(editor: &EditorState) -> BoxedWidget { - Popup::new(Padding::new(editor.widget()).left(1)) - .title("Enter password") - .inner_padding(false) - .build() + fn auth_widget() -> BoxedWidget { + Popup::new( + Padding::new(Cursor::new(Text::new(( + "", + ContentStyle::default().grey().italic(), + )))) + .left(1), + ) + .title("Enter password") + .inner_padding(false) + .build() } fn nick_widget(editor: &EditorState) -> BoxedWidget { diff --git a/src/ui/widgets.rs b/src/ui/widgets.rs index e98f62b..f9ebba1 100644 --- a/src/ui/widgets.rs +++ b/src/ui/widgets.rs @@ -5,6 +5,7 @@ pub mod background; pub mod border; +pub mod cursor; pub mod editor; pub mod empty; pub mod float; diff --git a/src/ui/widgets/cursor.rs b/src/ui/widgets/cursor.rs new file mode 100644 index 0000000..205c5c1 --- /dev/null +++ b/src/ui/widgets/cursor.rs @@ -0,0 +1,39 @@ +use async_trait::async_trait; +use toss::frame::{Frame, Pos, Size}; + +use super::{BoxedWidget, Widget}; + +pub struct Cursor { + inner: BoxedWidget, + pos: Pos, +} + +impl Cursor { + pub fn new>(inner: W) -> Self { + Self { + inner: inner.into(), + pos: Pos::ZERO, + } + } + + pub fn at(mut self, pos: Pos) -> Self { + self.pos = pos; + self + } + + pub fn at_xy(self, x: i32, y: i32) -> Self { + self.at(Pos::new(x, y)) + } +} + +#[async_trait] +impl Widget for Cursor { + fn size(&self, frame: &mut Frame, max_width: Option, max_height: Option) -> Size { + self.inner.size(frame, max_width, max_height) + } + + async fn render(self: Box, frame: &mut Frame) { + self.inner.render(frame).await; + frame.set_cursor(Some(self.pos)); + } +}