Track focus in room
This commit is contained in:
parent
147c3eaf92
commit
8703a62887
4 changed files with 33 additions and 6 deletions
|
|
@ -188,7 +188,7 @@ impl Ui {
|
|||
async fn widget(&mut self) -> BoxedWidget {
|
||||
let widget = match self.mode {
|
||||
Mode::Main => self.rooms.widget().await,
|
||||
Mode::Log => self.log_chat.widget(String::new()).into(),
|
||||
Mode::Log => self.log_chat.widget(String::new(), true).into(),
|
||||
};
|
||||
|
||||
if let Some(key_bindings_list) = &self.key_bindings_list {
|
||||
|
|
|
|||
|
|
@ -66,7 +66,8 @@ impl<M: Msg, S: MsgStore<M>> ChatState<M, S> {
|
|||
&self.store
|
||||
}
|
||||
|
||||
pub fn widget(&self, nick: String) -> Chat<M, S> {
|
||||
pub fn widget(&self, nick: String, focus: bool) -> Chat<M, S> {
|
||||
// TODO Handle focus
|
||||
match self.mode {
|
||||
Mode::Tree => Chat::Tree(self.tree.widget(nick)),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@ use crate::ui::widgets::list::{List, ListState};
|
|||
use crate::ui::widgets::text::Text;
|
||||
use crate::ui::widgets::BoxedWidget;
|
||||
|
||||
pub fn widget(state: &ListState<String>, joined: &Joined) -> BoxedWidget {
|
||||
pub fn widget(state: &ListState<String>, joined: &Joined, focus: bool) -> BoxedWidget {
|
||||
// TODO Handle focus
|
||||
let mut list = state.widget();
|
||||
render_rows(&mut list, joined);
|
||||
list.into()
|
||||
|
|
|
|||
|
|
@ -31,6 +31,12 @@ use super::links::{self, LinksState};
|
|||
use super::popup::RoomPopup;
|
||||
use super::{auth, inspect, nick, nick_list};
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
enum Focus {
|
||||
Chat,
|
||||
NickList,
|
||||
}
|
||||
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
enum State {
|
||||
Normal,
|
||||
|
|
@ -67,6 +73,7 @@ pub struct EuphRoom {
|
|||
vault: EuphRoomVault,
|
||||
room: Option<euph::Room>,
|
||||
|
||||
focus: Focus,
|
||||
state: State,
|
||||
popups: VecDeque<RoomPopup>,
|
||||
|
||||
|
|
@ -87,6 +94,7 @@ impl EuphRoom {
|
|||
ui_event_tx,
|
||||
vault: vault.clone(),
|
||||
room: None,
|
||||
focus: Focus::Chat,
|
||||
state: State::Normal,
|
||||
popups: VecDeque::new(),
|
||||
chat: ChatState::new(vault),
|
||||
|
|
@ -178,6 +186,13 @@ impl EuphRoom {
|
|||
}
|
||||
}
|
||||
|
||||
fn stabilize_focus(&mut self, status: &RoomStatus) {
|
||||
match status {
|
||||
RoomStatus::Connected(Status::Joined(_)) => {}
|
||||
_ => self.focus = Focus::Chat, // There is no nick list to focus on
|
||||
}
|
||||
}
|
||||
|
||||
fn stabilize_state(&mut self, status: &RoomStatus) {
|
||||
match &mut self.state {
|
||||
State::Auth(_)
|
||||
|
|
@ -205,6 +220,7 @@ impl EuphRoom {
|
|||
|
||||
async fn stabilize(&mut self, status: &RoomStatus) {
|
||||
self.stabilize_pseudo_msg().await;
|
||||
self.stabilize_focus(status);
|
||||
self.stabilize_state(status);
|
||||
}
|
||||
|
||||
|
|
@ -242,7 +258,7 @@ impl EuphRoom {
|
|||
Padding::new(self.status_widget(status).await).horizontal(1),
|
||||
)),
|
||||
// TODO Use last known nick?
|
||||
Segment::new(self.chat.widget(String::new())).expanding(true),
|
||||
Segment::new(self.chat.widget(String::new(), true)).expanding(true),
|
||||
])
|
||||
.into()
|
||||
}
|
||||
|
|
@ -253,11 +269,20 @@ impl EuphRoom {
|
|||
Segment::new(Border::new(
|
||||
Padding::new(self.status_widget(status).await).horizontal(1),
|
||||
)),
|
||||
Segment::new(self.chat.widget(joined.session.name.clone())).expanding(true),
|
||||
Segment::new(
|
||||
self.chat
|
||||
.widget(joined.session.name.clone(), self.focus == Focus::Chat),
|
||||
)
|
||||
.expanding(true),
|
||||
]))
|
||||
.expanding(true),
|
||||
Segment::new(Border::new(
|
||||
Padding::new(nick_list::widget(&self.nick_list, joined)).right(1),
|
||||
Padding::new(nick_list::widget(
|
||||
&self.nick_list,
|
||||
joined,
|
||||
self.focus == Focus::NickList,
|
||||
))
|
||||
.right(1),
|
||||
)),
|
||||
])
|
||||
.into()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue