Rename "join room" to "switch room"
This commit is contained in:
parent
c06a598a86
commit
f7a319f875
3 changed files with 21 additions and 21 deletions
|
|
@ -26,7 +26,7 @@ use crate::room::Room;
|
|||
use crate::ui::overlays::OverlayReaction;
|
||||
|
||||
use self::input::EventHandler;
|
||||
use self::overlays::{JoinRoom, JoinRoomState};
|
||||
use self::overlays::{Overlay, SwitchRoom, SwitchRoomState};
|
||||
use self::pane::PaneInfo;
|
||||
use self::room::RoomInfo;
|
||||
use self::rooms::Rooms;
|
||||
|
|
@ -44,10 +44,6 @@ enum EventHandleResult {
|
|||
Stop,
|
||||
}
|
||||
|
||||
enum Overlay {
|
||||
JoinRoom(JoinRoomState),
|
||||
}
|
||||
|
||||
pub struct Ui {
|
||||
config: &'static Config,
|
||||
event_tx: UnboundedSender<UiEvent>,
|
||||
|
|
@ -155,7 +151,7 @@ impl Ui {
|
|||
// Overlay
|
||||
if let Some(overlay) = &mut self.overlay {
|
||||
let reaction = match overlay {
|
||||
Overlay::JoinRoom(state) => state.handle_key(event),
|
||||
Overlay::SwitchRoom(state) => state.handle_key(event),
|
||||
};
|
||||
if let Some(reaction) = reaction {
|
||||
self.handle_overlay_reaction(reaction).await;
|
||||
|
|
@ -169,8 +165,8 @@ impl Ui {
|
|||
// Otherwise, global bindings
|
||||
match event.code {
|
||||
KeyCode::Char('q') => STOP,
|
||||
KeyCode::Char('c') => {
|
||||
self.overlay = Some(Overlay::JoinRoom(JoinRoomState::default()));
|
||||
KeyCode::Char('s') => {
|
||||
self.overlay = Some(Overlay::SwitchRoom(SwitchRoomState::default()));
|
||||
CONTINUE
|
||||
}
|
||||
_ => CONTINUE,
|
||||
|
|
@ -181,7 +177,7 @@ impl Ui {
|
|||
match reaction {
|
||||
OverlayReaction::Handled => {}
|
||||
OverlayReaction::Close => self.overlay = None,
|
||||
OverlayReaction::JoinRoom(name) => {
|
||||
OverlayReaction::SwitchRoom(name) => {
|
||||
let name = name.trim();
|
||||
if !name.is_empty() {
|
||||
self.overlay = None;
|
||||
|
|
@ -260,8 +256,8 @@ impl Ui {
|
|||
// Overlay
|
||||
if let Some(overlay) = &mut self.overlay {
|
||||
match overlay {
|
||||
Overlay::JoinRoom(state) => {
|
||||
frame.render_stateful_widget(JoinRoom, entire_area, state);
|
||||
Overlay::SwitchRoom(state) => {
|
||||
frame.render_stateful_widget(SwitchRoom, entire_area, state);
|
||||
let (x, y) = state.last_cursor_pos();
|
||||
frame.set_cursor(x, y);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,13 @@
|
|||
mod join_room;
|
||||
mod switch_room;
|
||||
|
||||
pub use join_room::*;
|
||||
pub use switch_room::*;
|
||||
|
||||
pub enum Overlay {
|
||||
SwitchRoom(SwitchRoomState),
|
||||
}
|
||||
|
||||
pub enum OverlayReaction {
|
||||
Handled,
|
||||
Close,
|
||||
JoinRoom(String),
|
||||
SwitchRoom(String),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@ use crate::ui::textline::{TextLine, TextLineReaction, TextLineState};
|
|||
|
||||
use super::OverlayReaction;
|
||||
|
||||
pub struct JoinRoom;
|
||||
pub struct SwitchRoom;
|
||||
|
||||
impl StatefulWidget for JoinRoom {
|
||||
type State = JoinRoomState;
|
||||
impl StatefulWidget for SwitchRoom {
|
||||
type State = SwitchRoomState;
|
||||
|
||||
fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) {
|
||||
let area = layout::centered(50, 3, area);
|
||||
|
|
@ -27,16 +27,16 @@ impl StatefulWidget for JoinRoom {
|
|||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct JoinRoomState {
|
||||
pub struct SwitchRoomState {
|
||||
room: TextLineState,
|
||||
}
|
||||
|
||||
impl EventHandler for JoinRoomState {
|
||||
impl EventHandler for SwitchRoomState {
|
||||
type Reaction = OverlayReaction;
|
||||
|
||||
fn handle_key(&mut self, event: KeyEvent) -> Option<Self::Reaction> {
|
||||
if event.code == KeyCode::Enter {
|
||||
return Some(Self::Reaction::JoinRoom(self.room.content()));
|
||||
return Some(Self::Reaction::SwitchRoom(self.room.content()));
|
||||
}
|
||||
|
||||
self.room.handle_key(event).map(|r| match r {
|
||||
|
|
@ -46,7 +46,7 @@ impl EventHandler for JoinRoomState {
|
|||
}
|
||||
}
|
||||
|
||||
impl JoinRoomState {
|
||||
impl SwitchRoomState {
|
||||
pub fn last_cursor_pos(&self) -> (u16, u16) {
|
||||
self.room.last_cursor_pos()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue