reactive_graph_table_model/types/
entities.rs1use tabled::Table;
2use tabled::Tabled;
3use tabled::settings::Modify;
4use tabled::settings::Style;
5use tabled::settings::Width;
6use tabled::settings::object::Segment;
7
8use crate::container::TableInlineFormat;
9use crate::container::TableInlineFormatSetter;
10use crate::container::TableOptions;
11use crate::types::component::ComponentTypeId;
12use crate::types::component::ComponentTypeIds;
13use crate::types::component::display_component_type_ids_html_inline;
14use crate::types::component::display_component_type_ids_inline_str;
15use crate::types::extension::Extension;
16use crate::types::extension::Extensions;
17use crate::types::extension::display_extensions_html_inline;
18use crate::types::extension::display_extensions_inline_str;
19use crate::types::properties::PropertyType;
20use crate::types::properties::PropertyTypes;
21use crate::types::properties::display_property_types_html_inline;
22use crate::types::properties::display_property_types_inline_str;
23use reactive_graph_graph::NamespacedTypeGetter;
24
25#[derive(Clone, Debug, Tabled)]
26pub struct EntityType {
27 pub namespace: String,
29
30 pub name: String,
32
33 pub description: String,
35
36 #[tabled(display("display_component_type_ids", self))]
38 pub components: Vec<ComponentTypeId>,
39
40 #[tabled(display("display_property_types", self))]
42 pub properties: Vec<PropertyType>,
43
44 #[tabled(display("display_extensions", self))]
46 pub extensions: Vec<Extension>,
47
48 #[tabled(skip)]
49 inline_format: TableInlineFormat,
50}
51
52fn display_component_type_ids(components: &[ComponentTypeId], entity_type: &EntityType) -> String {
53 match entity_type.inline_format {
54 TableInlineFormat::Table => display_component_type_ids_inline_str(components),
55 TableInlineFormat::Html => display_component_type_ids_html_inline(components),
56 }
57}
58
59fn display_property_types(properties: &[PropertyType], entity_type: &EntityType) -> String {
60 match entity_type.inline_format {
61 TableInlineFormat::Table => display_property_types_inline_str(properties),
62 TableInlineFormat::Html => display_property_types_html_inline(properties),
63 }
64}
65
66fn display_extensions(extensions: &[Extension], entity_type: &EntityType) -> String {
67 match entity_type.inline_format {
69 TableInlineFormat::Table => display_extensions_inline_str(extensions),
70 TableInlineFormat::Html => display_extensions_html_inline(extensions),
71 }
72}
73
74impl TableInlineFormatSetter for EntityType {
75 fn set_table_inline_format(&mut self, table_inline_format: TableInlineFormat) {
76 self.inline_format = table_inline_format;
77 }
78}
79
80impl From<reactive_graph_graph::EntityType> for EntityType {
81 fn from(entity_type: reactive_graph_graph::EntityType) -> Self {
82 EntityType {
83 namespace: entity_type.namespace(),
84 name: entity_type.type_name(),
85 description: entity_type.description,
86 components: ComponentTypeIds::from(entity_type.components).0,
87 properties: PropertyTypes::from(entity_type.properties).0,
88 extensions: Extensions::from(entity_type.extensions).0,
89 inline_format: Default::default(),
90 }
91 }
92}
93
94pub struct EntityTypesTableOptions;
95
96impl TableOptions for EntityTypesTableOptions {
97 fn options(table: &mut Table) -> &mut Table {
98 table.with(Style::extended()).with(
99 Modify::new(Segment::new(0.., 0..3))
100 .with(Width::increase(22))
101 .with(Width::increase(22))
102 .with(Width::wrap(40).keep_words(true)),
103 )
104 }
105}