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 {
|
async fn widget(&mut self) -> BoxedWidget {
|
||||||
let widget = match self.mode {
|
let widget = match self.mode {
|
||||||
Mode::Main => self.rooms.widget().await,
|
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 {
|
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
|
&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 {
|
match self.mode {
|
||||||
Mode::Tree => Chat::Tree(self.tree.widget(nick)),
|
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::text::Text;
|
||||||
use crate::ui::widgets::BoxedWidget;
|
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();
|
let mut list = state.widget();
|
||||||
render_rows(&mut list, joined);
|
render_rows(&mut list, joined);
|
||||||
list.into()
|
list.into()
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,12 @@ use super::links::{self, LinksState};
|
||||||
use super::popup::RoomPopup;
|
use super::popup::RoomPopup;
|
||||||
use super::{auth, inspect, nick, nick_list};
|
use super::{auth, inspect, nick, nick_list};
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
|
enum Focus {
|
||||||
|
Chat,
|
||||||
|
NickList,
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(clippy::large_enum_variant)]
|
#[allow(clippy::large_enum_variant)]
|
||||||
enum State {
|
enum State {
|
||||||
Normal,
|
Normal,
|
||||||
|
|
@ -67,6 +73,7 @@ pub struct EuphRoom {
|
||||||
vault: EuphRoomVault,
|
vault: EuphRoomVault,
|
||||||
room: Option<euph::Room>,
|
room: Option<euph::Room>,
|
||||||
|
|
||||||
|
focus: Focus,
|
||||||
state: State,
|
state: State,
|
||||||
popups: VecDeque<RoomPopup>,
|
popups: VecDeque<RoomPopup>,
|
||||||
|
|
||||||
|
|
@ -87,6 +94,7 @@ impl EuphRoom {
|
||||||
ui_event_tx,
|
ui_event_tx,
|
||||||
vault: vault.clone(),
|
vault: vault.clone(),
|
||||||
room: None,
|
room: None,
|
||||||
|
focus: Focus::Chat,
|
||||||
state: State::Normal,
|
state: State::Normal,
|
||||||
popups: VecDeque::new(),
|
popups: VecDeque::new(),
|
||||||
chat: ChatState::new(vault),
|
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) {
|
fn stabilize_state(&mut self, status: &RoomStatus) {
|
||||||
match &mut self.state {
|
match &mut self.state {
|
||||||
State::Auth(_)
|
State::Auth(_)
|
||||||
|
|
@ -205,6 +220,7 @@ impl EuphRoom {
|
||||||
|
|
||||||
async fn stabilize(&mut self, status: &RoomStatus) {
|
async fn stabilize(&mut self, status: &RoomStatus) {
|
||||||
self.stabilize_pseudo_msg().await;
|
self.stabilize_pseudo_msg().await;
|
||||||
|
self.stabilize_focus(status);
|
||||||
self.stabilize_state(status);
|
self.stabilize_state(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -242,7 +258,7 @@ impl EuphRoom {
|
||||||
Padding::new(self.status_widget(status).await).horizontal(1),
|
Padding::new(self.status_widget(status).await).horizontal(1),
|
||||||
)),
|
)),
|
||||||
// TODO Use last known nick?
|
// 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()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
@ -253,11 +269,20 @@ impl EuphRoom {
|
||||||
Segment::new(Border::new(
|
Segment::new(Border::new(
|
||||||
Padding::new(self.status_widget(status).await).horizontal(1),
|
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),
|
.expanding(true),
|
||||||
Segment::new(Border::new(
|
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()
|
.into()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue