Add welcome mat

This commit is contained in:
mars 2022-05-26 01:49:22 -06:00
parent 42b0070985
commit 7744cfe66a
2 changed files with 74 additions and 47 deletions

6
src/logo.txt Normal file
View File

@ -0,0 +1,6 @@
__ __ ____ _ _
| \/ | __ _ _ __ ___ / ___| |__ __ _| |_
| |\/| |/ _` | '__/ __| | | '_ \ / _` | __|
| | | | (_| | | \__ \ |___| | | | (_| | |_
|_| |_|\__,_|_| |___/\____|_| |_|\__,_|\__|

View File

@ -46,7 +46,7 @@ impl Tui {
}
pub fn run(&mut self) {
Self::edit_identity(&mut self.cursive);
/*Self::edit_identity(&mut self.cursive);
self.cursive.run();
while let Ok(edit) = self.edit_receiver.try_recv() {
@ -58,54 +58,23 @@ impl Tui {
}
Self::show_main(&mut self.cursive);
self.cursive.run();*/
Self::show_welcome_mat(&mut self.cursive);
self.cursive.run();
}
pub fn show_main(siv: &mut Cursive) {
let list = ListView::new()
.child("message_0000", TextView::new("Hello, world!"))
.with_name("messages_list")
.scrollable()
.full_height();
let message_edit = EditView::new()
.on_submit(|siv, text| {
siv.call_on_name("message_edit", |message: &mut EditView| {
message.set_content("");
});
siv.call_on_name("messages_list", |list: &mut ListView| {
list.add_child("new_message", TextView::new(text));
});
})
.with_name("message_edit")
.full_width();
let chat = LinearLayout::vertical().child(list).child(message_edit);
let mut rooms = SelectView::<&'static str>::new().on_submit(|siv, room: &str| {
let dialog = Dialog::info(format!("Selected room: {}", room));
siv.add_layer(dialog);
});
rooms.add_item("Room 1", "room_id_1");
rooms.add_item("Room 2", "room_id_2");
rooms.add_item("Room 3", "room_id_3");
let rooms = Dialog::around(rooms)
.title("Rooms")
.title_position(HAlign::Left);
let mut connections = SelectView::new();
connections.add_item("Connection 1", "connection_1");
let connections = Dialog::around(connections)
.title("Connections")
.title_position(HAlign::Left);
let sidebar = LinearLayout::vertical().child(rooms).child(connections);
let layout = LinearLayout::horizontal().child(sidebar).child(chat);
siv.add_fullscreen_layer(layout);
pub fn show_welcome_mat(siv: &mut Cursive) {
let logo = TextView::new(include_str!("logo.txt")).center();
let labels = TextView::new("Identity:");
let values = Button::new_raw("<none>", |siv| Self::edit_identity(siv));
let config = LinearLayout::horizontal().child(labels).child(values);
let layout = LinearLayout::vertical().child(logo).child(config);
let dialog = Dialog::around(layout)
.title("Welcome User!")
.button("Link start!", |siv| Self::show_main(siv))
.button("Quit", Cursive::quit);
siv.add_layer(dialog);
}
pub fn edit_identity(siv: &mut Cursive) {
@ -128,7 +97,7 @@ impl Tui {
sender.send(EditEvent::Name(name)).unwrap();
sender.send(EditEvent::About(about)).unwrap();
});
siv.quit();
siv.pop_layer();
});
siv.add_layer(dialog);
@ -218,6 +187,58 @@ impl Tui {
siv.add_layer(dialog);
}
pub fn show_main(siv: &mut Cursive) {
let list = ListView::new()
.child("message_0000", TextView::new("Hello, world!"))
.with_name("messages_list")
.scrollable()
.full_height();
let message_edit = EditView::new()
.on_submit(|siv, text| {
siv.call_on_name("message_edit", |message: &mut EditView| {
message.set_content("");
});
siv.call_on_name("messages_list", |list: &mut ListView| {
list.add_child("new_message", TextView::new(text));
});
})
.with_name("message_edit")
.full_width();
let chat = LinearLayout::vertical().child(list).child(message_edit);
let mut rooms = SelectView::<&'static str>::new().on_submit(|siv, room: &str| {
let dialog = Dialog::info(format!("Selected room: {}", room));
siv.add_layer(dialog);
});
rooms.add_item("Room 1", "room_id_1");
rooms.add_item("Room 2", "room_id_2");
rooms.add_item("Room 3", "room_id_3");
let rooms = Dialog::around(rooms)
.button("Create...", |siv| {
siv.add_layer(Dialog::info("Room creation dialog goes here"))
})
.title("Rooms")
.title_position(HAlign::Left)
.with_name("room_select");
let mut connections = SelectView::new();
connections.add_item("Connection 1", "connection_1");
let connections = Dialog::around(connections)
.title("Connections")
.title_position(HAlign::Left)
.with_name("connection_s");
let sidebar = LinearLayout::vertical().child(rooms).child(connections);
let layout = LinearLayout::horizontal().child(sidebar).child(chat);
siv.add_fullscreen_layer(layout);
}
}
pub struct Identity {