gui/panels/mod.rs
1//! # UI Panels Module
2//!
3//! This module defines the core panel types and docking tab structures used by the GUI interface.
4//! It exposes the [`Tab`] enum encapsulating various panel components like [`UniversePanel`] and [`TerminalPanel`].
5
6use eframe::egui;
7use common::logging::LogLevel::Error;
8use common::networking::subscription_objects::SubscribeTopic::DMXConfiguration;
9use common::r_log;
10
11/// Module implementing the interactive terminal panel tab.
12pub mod terminal;
13/// Module implementing the visual DMX universe panel tab.
14pub mod universe;
15
16use terminal::TerminalPanel;
17use universe::UniversePanel;
18use crate::controller::UiEvent;
19use crate::UI_EVENT_SENDER;
20
21/// Enum representing all dockable tab types supported in the user interface.
22#[derive(Clone)]
23pub enum Tab {
24 /// Tab displaying a visual DMX universe channel grid.
25 Universe(UniversePanel),
26 /// Tab displaying an interactive terminal command log.
27 Terminal(TerminalPanel),
28}
29
30impl Tab {
31 /// Returns the human-readable display title for this tab header.
32 pub fn title(&self) -> String {
33 match self {
34 Tab::Universe(panel) => format!("Universe {}", panel.selected_universe),
35 Tab::Terminal(_) => "Terminal".to_string(),
36 }
37 }
38
39 /// Returns a unique string identifier for this tab instance used by the dock state.
40 pub fn unique_id(&self) -> String {
41 match self {
42 Tab::Universe(panel) => format!("universe_tab_{}", panel.tab_id),
43 Tab::Terminal(panel) => format!("terminal_tab_{}", panel.tab_id),
44 }
45 }
46
47 /// Renders the content UI for the active tab variant.
48 ///
49 /// # Arguments
50 /// * `ui` - Mutable reference to the `egui::Ui` context.
51 pub fn ui(&mut self, ui: &mut egui::Ui) {
52 match self {
53 Tab::Universe(panel) => panel.ui(ui),
54 Tab::Terminal(panel) => panel.ui(ui),
55 }
56 }
57
58 /// Callback triggered when the application successfully connects and authenticates.
59 ///
60 /// Initiates necessary server subscriptions (such as requesting DMX configuration updates).
61 pub fn on_connect(&mut self) {
62 match self {
63 Tab::Universe(_) => {
64 if let Some(sender) = UI_EVENT_SENDER.read().unwrap().as_ref() {
65 if let Err(e) = sender.send(UiEvent::SubscribeRequest {topic: DMXConfiguration}) {
66 r_log!(Error, "Failed to send UiEvent: {}", e);
67 }
68 }
69 }
70 Tab::Terminal(_) => {}
71 }
72 }
73}