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