Prepare room rendering
This commit is contained in:
parent
1543940fbc
commit
3efca6a6d1
2 changed files with 44 additions and 6 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
mod input;
|
mod input;
|
||||||
mod layout;
|
mod layout;
|
||||||
mod overlays;
|
mod overlays;
|
||||||
|
mod room;
|
||||||
mod rooms;
|
mod rooms;
|
||||||
mod textline;
|
mod textline;
|
||||||
|
|
||||||
|
|
@ -24,6 +25,7 @@ use crate::ui::overlays::OverlayReaction;
|
||||||
|
|
||||||
use self::input::EventHandler;
|
use self::input::EventHandler;
|
||||||
use self::overlays::{JoinRoom, JoinRoomState};
|
use self::overlays::{JoinRoom, JoinRoomState};
|
||||||
|
use self::room::RoomInfo;
|
||||||
use self::rooms::{Rooms, RoomsState};
|
use self::rooms::{Rooms, RoomsState};
|
||||||
|
|
||||||
pub type Backend = CrosstermBackend<Stdout>;
|
pub type Backend = CrosstermBackend<Stdout>;
|
||||||
|
|
@ -48,6 +50,7 @@ pub struct Ui {
|
||||||
event_tx: UnboundedSender<UiEvent>,
|
event_tx: UnboundedSender<UiEvent>,
|
||||||
rooms: HashMap<String, Arc<Mutex<Room>>>,
|
rooms: HashMap<String, Arc<Mutex<Room>>>,
|
||||||
rooms_state: RoomsState,
|
rooms_state: RoomsState,
|
||||||
|
room: Option<RoomInfo>,
|
||||||
overlay: Option<Overlay>,
|
overlay: Option<Overlay>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -58,6 +61,7 @@ impl Ui {
|
||||||
event_tx,
|
event_tx,
|
||||||
rooms: HashMap::new(),
|
rooms: HashMap::new(),
|
||||||
rooms_state: RoomsState::default(),
|
rooms_state: RoomsState::default(),
|
||||||
|
room: None,
|
||||||
overlay: None,
|
overlay: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -225,13 +229,16 @@ impl Ui {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn switch_to_room(&mut self, name: String) {
|
async fn switch_to_room(&mut self, name: String) {
|
||||||
match self.rooms.entry(name.clone()) {
|
let room = match self.rooms.entry(name.clone()) {
|
||||||
Entry::Occupied(_) => {}
|
Entry::Occupied(entry) => entry.get().clone(),
|
||||||
Entry::Vacant(entry) => {
|
Entry::Vacant(entry) => {
|
||||||
entry.insert(
|
let identity = self.config.cove_identity.clone();
|
||||||
Room::new(name, self.config.cove_identity.clone(), None, self.config).await,
|
let room = Room::new(name.clone(), identity, None, self.config).await;
|
||||||
);
|
entry.insert(room.clone());
|
||||||
|
room
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
self.room = Some(RoomInfo::new(name, room))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
31
cove-tui/src/ui/room.rs
Normal file
31
cove-tui/src/ui/room.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use tokio::sync::Mutex;
|
||||||
|
use tui::backend::Backend;
|
||||||
|
use tui::layout::Rect;
|
||||||
|
use tui::Frame;
|
||||||
|
|
||||||
|
use crate::room::Room;
|
||||||
|
|
||||||
|
pub struct RoomInfo {
|
||||||
|
name: String,
|
||||||
|
room: Arc<Mutex<Room>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RoomInfo {
|
||||||
|
pub fn new(name: String, room: Arc<Mutex<Room>>) -> Self {
|
||||||
|
Self { name, room }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn name(&self) -> &str {
|
||||||
|
&self.name
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn render_messages<B: Backend>(&mut self, frame: &mut Frame<'_, B>, area: Rect) {
|
||||||
|
// TODO Implement
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn render_users<B: Backend>(&mut self, frame: &mut Frame<'_, B>, area: Rect) {
|
||||||
|
// TODO Implement
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue