1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use re_types::ViewClassIdentifier;
use re_ui::UiExt;

use crate::{
    SystemExecutionOutput, ViewClass, ViewClassRegistryError, ViewQuery, ViewSpawnHeuristics,
    ViewState, ViewSystemExecutionError, ViewSystemRegistrator, ViewerContext,
};

/// A placeholder view class that can be used when the actual class is not registered.
#[derive(Default)]
pub struct ViewClassPlaceholder;

impl ViewClass for ViewClassPlaceholder {
    fn identifier() -> ViewClassIdentifier {
        "UnknownViewClass".into()
    }

    fn display_name(&self) -> &'static str {
        "Unknown view class"
    }

    fn icon(&self) -> &'static re_ui::Icon {
        &re_ui::icons::VIEW_UNKNOWN
    }

    fn help_markdown(&self, _egui_ctx: &egui::Context) -> String {
        "Placeholder view for unknown view class".to_owned()
    }

    fn on_register(
        &self,
        _system_registry: &mut ViewSystemRegistrator<'_>,
    ) -> Result<(), ViewClassRegistryError> {
        Ok(())
    }

    fn new_state(&self) -> Box<dyn ViewState> {
        Box::<()>::default()
    }

    fn layout_priority(&self) -> crate::ViewClassLayoutPriority {
        crate::ViewClassLayoutPriority::Low
    }

    fn spawn_heuristics(&self, _ctx: &ViewerContext<'_>) -> ViewSpawnHeuristics {
        ViewSpawnHeuristics::empty()
    }

    fn ui(
        &self,
        _ctx: &ViewerContext<'_>,
        ui: &mut egui::Ui,
        _state: &mut dyn ViewState,
        _query: &ViewQuery<'_>,
        _system_output: SystemExecutionOutput,
    ) -> Result<(), ViewSystemExecutionError> {
        egui::Frame {
            inner_margin: egui::Margin::same(re_ui::DesignTokens::view_padding()),
            ..Default::default()
        }
        .show(ui, |ui| {
            ui.warning_label("Unknown view class");

            ui.markdown_ui(
                "This happens if either the blueprint specifies an invalid view class or \
                this version of the viewer does not know about this type.\n\n\
                \
                **Note**: some views may require a specific Cargo feature to be enabled. In \
                particular, the map view requires the `map_view` feature.",
            );
        });

        Ok(())
    }
}

crate::impl_component_fallback_provider!(ViewClassPlaceholder => []);