Restructure and prepare for cove room UI

This commit is contained in:
Joscha 2022-03-05 15:43:28 +01:00
parent 619e04c42a
commit e81900caac
4 changed files with 20 additions and 14 deletions

View file

@ -1,3 +1,4 @@
mod cove;
mod input;
mod layout;
mod overlays;
@ -18,10 +19,9 @@ use tui::layout::{Constraint, Direction, Layout, Rect};
use tui::{Frame, Terminal};
use crate::config::Config;
use crate::cove;
use crate::cove::room::CoveRoom;
use crate::ui::overlays::OverlayReaction;
use self::cove::CoveUi;
use self::input::EventHandler;
use self::overlays::{Overlay, SwitchRoom, SwitchRoomState};
use self::pane::PaneInfo;
@ -35,8 +35,8 @@ pub enum UiEvent {
Redraw,
}
impl From<cove::conn::Event> for UiEvent {
fn from(_: cove::conn::Event) -> Self {
impl From<crate::cove::conn::Event> for UiEvent {
fn from(_: crate::cove::conn::Event) -> Self {
Self::Redraw
}
}
@ -49,7 +49,8 @@ enum EventHandleResult {
pub struct Ui {
config: &'static Config,
event_tx: UnboundedSender<UiEvent>,
cove_rooms: HashMap<String, CoveRoom>,
cove_rooms: HashMap<String, CoveUi>,
rooms_pane: PaneInfo,
users_pane: PaneInfo,

7
cove-tui/src/ui/cove.rs Normal file
View file

@ -0,0 +1,7 @@
mod users;
use crate::cove::room::CoveRoom;
pub struct CoveUi {
room: CoveRoom,
}

View file

@ -18,18 +18,18 @@ struct UserInfo {
impl From<&Session> for UserInfo {
fn from(s: &Session) -> Self {
UserInfo {
Self {
nick: s.nick.clone(),
identity: s.identity,
}
}
}
pub struct Users {
pub struct CoveUsers {
users: Vec<UserInfo>,
}
impl Users {
impl CoveUsers {
pub fn new(present: &Present) -> Self {
let mut users: Vec<UserInfo> = iter::once(&present.session)
.chain(present.others.values())
@ -40,7 +40,7 @@ impl Users {
}
}
impl Widget for Users {
impl Widget for CoveUsers {
fn render(self, area: Rect, buf: &mut Buffer) {
let sessions = self.users.len();
let identities = self

View file

@ -1,13 +1,11 @@
use std::collections::HashMap;
use std::sync::Arc;
use tui::buffer::Buffer;
use tui::layout::Rect;
use tui::text::{Span, Spans};
use tui::widgets::{Paragraph, Widget};
use crate::cove::room::CoveRoom;
use super::cove::CoveUi;
use super::styles;
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
@ -21,10 +19,10 @@ pub struct Rooms {
}
impl Rooms {
pub fn new(cove_rooms: &HashMap<String, CoveRoom>) -> Self {
pub fn new(cove_rooms: &HashMap<String, CoveUi>) -> Self {
let mut rooms = cove_rooms
.iter()
.map(|(name, _room)| RoomInfo { name: name.clone() })
.map(|(name, _)| RoomInfo { name: name.clone() })
.collect::<Vec<_>>();
rooms.sort();
Self {