egui-test/src/ui/session.rs

44 lines
1.3 KiB
Rust
Raw Normal View History

2021-10-16 21:50:22 +02:00
use eframe::egui::{self, Sense};
use futures::executor::block_on;
use matrix_sdk::Client;
use super::Id;
/// Logged in application state
#[derive(Debug)]
pub struct App {
client: matrix_sdk::Client,
selected_room: Option<matrix_sdk::ruma::identifiers::RoomId>,
}
impl App {
pub fn with_client(client: Client) -> Self {
Self {
client,
selected_room: None,
}
}
pub fn update(&mut self, ctx: &egui::CtxRef) {
egui::SidePanel::left(Id::RoomPanel)
.max_width(800.0)
.show(ctx, |ui| {
ui.add(egui::Label::new("Joined").strong());
for room in self.client.joined_rooms() {
let response = ui.group(|ui| {
if let Some(name) = room.name() {
ui.label(name.to_string());
}
if let Some(alias) = room.canonical_alias() {
ui.label(alias.to_string());
}
});
let response = response.response.interact(Sense::click());
if response.clicked() {
self.selected_room = Some(room.room_id().clone());
}
}
});
}
}