diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-04-10 22:01:02 +0300 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-06-10 19:40:44 +0300 |
commit | 106744c7ca4e5444d993a04c23bc04d93e2bfa6a (patch) | |
tree | 5aea51551eb5621a339d7066a6db103cb41a1c3f /ui | |
parent | b993375fa0737dcfbd1aca5e765210969a143282 (diff) |
ui: remove Entity
Diffstat (limited to 'ui')
-rw-r--r-- | ui/src/components.rs | 69 | ||||
-rw-r--r-- | ui/src/components/contacts.rs | 15 | ||||
-rw-r--r-- | ui/src/components/contacts/contact_list.rs | 31 | ||||
-rw-r--r-- | ui/src/components/indexer.rs | 9 | ||||
-rw-r--r-- | ui/src/components/indexer/index.rs | 8 | ||||
-rw-r--r-- | ui/src/components/mail.rs | 9 | ||||
-rw-r--r-- | ui/src/components/mail/accounts.rs | 9 | ||||
-rw-r--r-- | ui/src/components/mail/compose.rs | 9 | ||||
-rw-r--r-- | ui/src/components/mail/listing.rs | 15 | ||||
-rw-r--r-- | ui/src/components/mail/listing/compact.rs | 18 | ||||
-rw-r--r-- | ui/src/components/mail/listing/plain.rs | 9 | ||||
-rw-r--r-- | ui/src/components/mail/listing/thread.rs | 9 | ||||
-rw-r--r-- | ui/src/components/mail/view.rs | 9 | ||||
-rw-r--r-- | ui/src/components/mail/view/envelope.rs | 9 | ||||
-rw-r--r-- | ui/src/components/mail/view/html.rs | 17 | ||||
-rw-r--r-- | ui/src/components/mail/view/thread.rs | 8 | ||||
-rw-r--r-- | ui/src/components/notifications.rs | 9 | ||||
-rw-r--r-- | ui/src/components/utilities.rs | 168 | ||||
-rw-r--r-- | ui/src/components/utilities/widgets.rs | 31 | ||||
-rw-r--r-- | ui/src/state.rs | 38 | ||||
-rw-r--r-- | ui/src/types.rs | 2 |
21 files changed, 333 insertions, 168 deletions
diff --git a/ui/src/components.rs b/ui/src/components.rs index 3e90ab94..f5b843d6 100644 --- a/ui/src/components.rs +++ b/ui/src/components.rs @@ -76,69 +76,7 @@ const _DOUBLE_DOWN_AND_LEFT: char = '╗'; const _DOUBLE_UP_AND_LEFT: char = '╝'; const _DOUBLE_UP_AND_RIGHT: char = '╚'; -type EntityId = Uuid; - -/// `Entity` is a container for Components. -#[derive(Debug)] -pub struct Entity { - id: EntityId, - pub component: Box<Component>, // more than one? -} - -impl From<Box<Component>> for Entity { - fn from(mut kind: Box<Component>) -> Entity { - let id = Uuid::new_v4(); - kind.set_id(id); - Entity { - id, - component: kind, - } - } -} - -impl<C: 'static> From<Box<C>> for Entity -where - C: Component, -{ - fn from(mut kind: Box<C>) -> Entity { - let id = Uuid::new_v4(); - kind.set_id(id); - Entity { - id, - component: kind, - } - } -} - -impl Display for Entity { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - Display::fmt(&self.component, f) - } -} - -impl DerefMut for Entity { - fn deref_mut(&mut self) -> &mut Box<Component> { - &mut self.component - } -} - -impl Deref for Entity { - type Target = Box<Component>; - - fn deref(&self) -> &Box<Component> { - &self.component - } -} - -impl Entity { - pub fn id(&self) -> &EntityId { - &self.id - } - /// Pass events to child component. - pub fn rcv_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool { - self.component.process_event(event, context) - } -} +type ComponentId = Uuid; pub type ShortcutMap = FnvHashMap<&'static str, Key>; @@ -155,8 +93,9 @@ pub trait Component: Display + Debug + Send { true } fn set_dirty(&mut self); - fn kill(&mut self, _id: EntityId) {} - fn set_id(&mut self, _id: EntityId) {} + fn kill(&mut self, _id: ComponentId) {} + fn set_id(&mut self, _id: ComponentId) {} + fn id(&self) -> ComponentId; fn get_shortcuts(&self, _context: &Context) -> ShortcutMap { Default::default() diff --git a/ui/src/components/contacts.rs b/ui/src/components/contacts.rs index dddbb0da..592db0b1 100644 --- a/ui/src/components/contacts.rs +++ b/ui/src/components/contacts.rs @@ -36,7 +36,7 @@ enum ViewMode { #[derive(Debug)] pub struct ContactManager { - id: Uuid, + id: ComponentId, pub card: Card, mode: ViewMode, form: FormWidget, @@ -169,13 +169,13 @@ impl Component for ContactManager { }); context.replies.push_back(UIEvent { id: 0, - event_type: UIEventType::EntityKill(self.id), + event_type: UIEventType::ComponentKill(self.id), }); } Some(false) => { context.replies.push_back(UIEvent { id: 0, - event_type: UIEventType::EntityKill(self.id), + event_type: UIEventType::ComponentKill(self.id), }); } } @@ -186,7 +186,7 @@ impl Component for ContactManager { UIEventType::Input(Key::Char('\n')) => { context.replies.push_back(UIEvent { id: 0, - event_type: UIEventType::EntityKill(self.id), + event_type: UIEventType::ComponentKill(self.id), }); return true; }, @@ -206,7 +206,10 @@ impl Component for ContactManager { self.form.set_dirty(); } - fn set_id(&mut self, uuid: Uuid) { - self.id = uuid; + fn id(&self) -> ComponentId { + self.id + } + fn set_id(&mut self, id: ComponentId) { + self.id = id; } } diff --git a/ui/src/components/contacts/contact_list.rs b/ui/src/components/contacts/contact_list.rs index 3554b5b5..e124a2a5 100644 --- a/ui/src/components/contacts/contact_list.rs +++ b/ui/src/components/contacts/contact_list.rs @@ -23,7 +23,8 @@ pub struct ContactList { mode: ViewMode, dirty: bool, - view: Option<Entity>, + view: Option<Box<Component>>, + id: ComponentId, } impl Default for ContactList { @@ -51,6 +52,7 @@ impl ContactList { content, dirty: true, view: None, + id: ComponentId::default(), } } @@ -234,10 +236,10 @@ impl Component for ContactList { UIEventType::Input(ref key) if *key == shortcuts["create_contact"] => { let mut manager = ContactManager::default(); manager.account_pos = self.account_pos; - let entity = Entity::from(Box::new(manager)); + let component = Box::new(manager); - self.mode = ViewMode::View(*entity.id()); - self.view = Some(entity); + self.mode = ViewMode::View(component.id()); + self.view = Some(component); return true; } @@ -249,10 +251,10 @@ impl Component for ContactList { let mut manager = ContactManager::default(); manager.card = card; manager.account_pos = self.account_pos; - let entity = Entity::from(Box::new(manager)); + let component = Box::new(manager); - self.mode = ViewMode::View(*entity.id()); - self.view = Some(entity); + self.mode = ViewMode::View(component.id()); + self.view = Some(component); return true; } @@ -261,9 +263,9 @@ impl Component for ContactList { let mut manager = ContactManager::default(); manager.card = card; manager.account_pos = self.account_pos; - let entity = Entity::from(Box::new(manager)); - self.mode = ViewMode::View(*entity.id()); - self.view = Some(entity); + let component = Box::new(manager); + self.mode = ViewMode::View(component.id()); + self.view = Some(component); return true; } @@ -277,7 +279,7 @@ impl Component for ContactList { self.new_cursor_pos += 1; return true; } - UIEventType::EntityKill(ref kill_id) if self.mode == ViewMode::View(*kill_id) => { + UIEventType::ComponentKill(ref kill_id) if self.mode == ViewMode::View(*kill_id) => { self.mode = ViewMode::List; self.view.take(); self.set_dirty(); @@ -315,4 +317,11 @@ impl Component for ContactList { map } + + fn id(&self) -> ComponentId { + self.id + } + fn set_id(&mut self, id: ComponentId) { + self.id = id; + } } diff --git a/ui/src/components/indexer.rs b/ui/src/components/indexer.rs index 2d1640ea..89a0996d 100644 --- a/ui/src/components/indexer.rs +++ b/ui/src/components/indexer.rs @@ -38,6 +38,7 @@ pub struct Indexer { entries: Vec<MenuEntry>, dirty: bool, cursor: Vec<usize>, + id: ComponentId, } impl fmt::Display for Indexer { @@ -53,6 +54,7 @@ impl Default for Indexer { entries: Vec::with_capacity(8), dirty: true, cursor: Vec::with_capacity(8), + id: ComponentId::default(), } } } @@ -125,4 +127,11 @@ impl Component for Indexer { fn set_dirty(&mut self) { self.dirty = true; } + + fn id(&self) -> ComponentId { + self.id + } + fn set_id(&mut self, id: ComponentId) { + self.id = id; + } } diff --git a/ui/src/components/indexer/index.rs b/ui/src/components/indexer/index.rs index 4794baca..17272d25 100644 --- a/ui/src/components/indexer/index.rs +++ b/ui/src/components/indexer/index.rs @@ -34,6 +34,7 @@ pub struct Index { state: IndexState, content: Box<IndexContent>, + id: ComponentId, } impl Index { @@ -169,6 +170,13 @@ impl Component for Index { fn set_dirty(&mut self) { self.dirty = true; } + + fn id(&self) -> ComponentId { + self.id + } + fn set_id(&mut self, id: ComponentId) { + self.id = id; + } } impl fmt::Display for Index { diff --git a/ui/src/components/mail.rs b/ui/src/components/mail.rs index 503c669b..0eda5942 100644 --- a/ui/src/components/mail.rs +++ b/ui/src/components/mail.rs @@ -48,6 +48,7 @@ pub struct AccountMenu { dirty: bool, visible: bool, cursor: Option<(usize, usize)>, + id: ComponentId, } impl fmt::Display for AccountMenu { @@ -72,6 +73,7 @@ impl AccountMenu { visible: true, dirty: true, cursor: None, + id: ComponentId::default(), } } /* @@ -301,4 +303,11 @@ impl Component for AccountMenu { .cloned() .collect() } + + fn id(&self) -> ComponentId { + self.id + } + fn set_id(&mut self, id: ComponentId) { + self.id = id; + } } diff --git a/ui/src/components/mail/accounts.rs b/ui/src/components/mail/accounts.rs index 42ee3f8d..afd49ee4 100644 --- a/ui/src/components/mail/accounts.rs +++ b/ui/src/components/mail/accounts.rs @@ -27,6 +27,7 @@ pub struct AccountsPanel { cursor: usize, content: CellBuffer, dirty: bool, + id: ComponentId, } impl fmt::Display for AccountsPanel { @@ -84,6 +85,13 @@ impl Component for AccountsPanel { fn set_dirty(&mut self) { self.dirty = true; } + + fn id(&self) -> ComponentId { + self.id + } + fn set_id(&mut self, id: ComponentId) { + self.id = id; + } } impl AccountsPanel { @@ -94,6 +102,7 @@ impl AccountsPanel { cursor: 0, content, dirty: true, + id: ComponentId::default(), } } fn initialize(&mut self, context: &Context) { diff --git a/ui/src/components/mail/compose.rs b/ui/src/components/mail/compose.rs index d38f1355..d449147c 100644 --- a/ui/src/components/mail/compose.rs +++ b/ui/src/components/mail/compose.rs @@ -45,6 +45,7 @@ pub struct Composer { mode: ViewMode, dirty: bool, initialized: bool, + id: ComponentId, } impl Default for Composer { @@ -62,6 +63,7 @@ impl Default for Composer { mode: ViewMode::Edit, dirty: true, initialized: false, + id: ComponentId::default(), } } } @@ -688,6 +690,13 @@ impl Component for Composer { map } + + fn id(&self) -> ComponentId { + self.id + } + fn set_id(&mut self, id: ComponentId) { + self.id = id; + } } fn get_display_name(context: &Context, idx: usize) -> String { diff --git a/ui/src/components/mail/listing.rs b/ui/src/components/mail/listing.rs index 9e2371d7..f108d9f8 100644 --- a/ui/src/components/mail/listing.rs +++ b/ui/src/components/mail/listing.rs @@ -163,6 +163,21 @@ impl Component for Listing { Listing::Threaded(l) => l.get_shortcuts(context), } } + + fn id(&self) -> ComponentId { + match self { + Listing::Compact(l) => l.id(), + Listing::Plain(l) => l.id(), + Listing::Threaded(l) => l.id(), + } + } + fn set_id(&mut self, id: ComponentId) { + match self { + Listing::Compact(l) => l.set_id(id), + Listing::Plain(l) => l.set_id(id), + Listing::Threaded(l) => l.set_id(id), + } + } } impl From<IndexStyle> for Listing { diff --git a/ui/src/components/mail/listing/compact.rs b/ui/src/components/mail/listing/compact.rs index e885cf09..a22942d6 100644 --- a/ui/src/components/mail/listing/compact.rs +++ b/ui/src/components/mail/listing/compact.rs @@ -43,6 +43,7 @@ struct MailboxView { view: ThreadView, movement: Option<PageMovement>, + id: ComponentId, } impl fmt::Display for MailboxView { @@ -87,6 +88,7 @@ impl MailboxView { view: ThreadView::default(), movement: None, + id: ComponentId::default(), } } /// Fill the `self.content` `CellBuffer` with the contents of the account folder the user has @@ -587,6 +589,13 @@ impl Component for MailboxView { map } + + fn id(&self) -> ComponentId { + self.id + } + fn set_id(&mut self, id: ComponentId) { + self.id = id; + } } /// A list of all mail (`Envelope`s) in a `Mailbox`. On `\n` it opens the `Envelope` content in a @@ -597,6 +606,7 @@ pub struct CompactListing { cursor: usize, dirty: bool, populated: bool, + id: ComponentId, } impl ListingTrait for CompactListing { @@ -627,6 +637,7 @@ impl CompactListing { cursor: 0, dirty: true, populated: false, + id: ComponentId::default(), } } } @@ -762,4 +773,11 @@ impl Component for CompactListing { map } + + fn id(&self) -> ComponentId { + self.id + } + fn set_id(&mut self, id: ComponentId) { + self.id = id; + } } diff --git a/ui/src/components/mail/listing/plain.rs b/ui/src/components/mail/listing/plain.rs index 01e1f620..30fae2bb 100644 --- a/ui/src/components/mail/listing/plain.rs +++ b/ui/src/components/mail/listing/plain.rs @@ -41,6 +41,7 @@ pub struct PlainListing { /// If `self.view` exists or not. unfocused: bool, view: Option<MailView>, + id: ComponentId, } impl ListingTrait for PlainListing { @@ -89,6 +90,7 @@ impl PlainListing { dirty: true, unfocused: false, view: None, + id: ComponentId::default(), } } /// Fill the `self.content` `CellBuffer` with the contents of the account folder the user has @@ -561,4 +563,11 @@ impl Component for PlainListing { }; self.dirty = true; } + + fn id(&self) -> ComponentId { + self.id + } + fn set_id(&mut self, id: ComponentId) { + self.id = id; + } } diff --git a/ui/src/components/mail/listing/thread.rs b/ui/src/components/mail/listing/thread.rs index a6ccfccc..95e311ca 100644 --- a/ui/src/components/mail/listing/thread.rs +++ b/ui/src/components/mail/listing/thread.rs @@ -44,6 +44,7 @@ pub struct ThreadListing { unfocused: bool, initialised: bool, view: Option<MailView>, + id: ComponentId, } impl ListingTrait for ThreadListing { @@ -86,6 +87,7 @@ impl ThreadListing { unfocused: false, view: None, initialised: false, + id: ComponentId::default(), } } /// Fill the `self.content` `CellBuffer` with the contents of the account folder the user has @@ -729,4 +731,11 @@ impl Component for ThreadListing { .map(|p| p.get_shortcuts(context)) .unwrap_or_default() } + + fn id(&self) -> ComponentId { + self.id + } + fn set_id(&mut self, id: ComponentId) { + self.id = id; + } } diff --git a/ui/src/components/mail/view.rs b/ui/src/components/mail/view.rs index 0fb3b77a..6ee2160f 100644 --- a/ui/src/components/mail/view.rs +++ b/ui/src/components/mail/view.rs @@ -69,6 +69,7 @@ pub struct MailView { mode: ViewMode, cmd_buf: String, + id: ComponentId, } impl fmt::Display for MailView { @@ -112,6 +113,7 @@ impl MailView { mode: ViewMode::Normal, cmd_buf: String::with_capacity(4), + id: ComponentId::default(), } } @@ -723,4 +725,11 @@ impl Component for MailView { _ => {} } } + + fn id(&self) -> ComponentId { + self.id + } + fn set_id(&mut self, id: ComponentId) { + self.id = id; + } } diff --git a/ui/src/components/mail/view/envelope.rs b/ui/src/components/mail/view/envelope.rs index 51299f12..13217a5f 100644 --- a/ui/src/components/mail/view/envelope.rs +++ b/ui/src/components/mail/view/envelope.rs @@ -55,6 +55,7 @@ pub struct EnvelopeView { account_pos: usize, cmd_buf: String, + id: ComponentId, } impl fmt::Display for EnvelopeView { @@ -79,6 +80,7 @@ impl EnvelopeView { wrapper, account_pos, cmd_buf: String::with_capacity(4), + id: ComponentId::default(), } } @@ -545,4 +547,11 @@ impl Component for EnvelopeView { fn set_dirty(&mut self) { self.dirty = true; } + + fn id(&self) -> ComponentId { + self.id + } + fn set_id(&mut self, id: ComponentId) { + self.id = id; + } } diff --git a/ui/src/components/mail/view/html.rs b/ui/src/components/mail/view/html.rs index b4ca9f55..c5e5cfab 100644 --- a/ui/src/components/mail/view/html.rs +++ b/ui/src/components/mail/view/html.rs @@ -27,10 +27,12 @@ use std::process::{Command, Stdio}; pub struct HtmlView { pager: Pager, bytes: Vec<u8>, + id: ComponentId, } impl HtmlView { pub fn new(bytes: Vec<u8>, context: &mut Context, account_pos: usize) -> Self { + let id = ComponentId::default(); let settings = context.accounts[account_pos].runtime_settings.conf(); if let Some(filter_invocation) = settings.html_filter() { let parts = split_command!(filter_invocation); @@ -57,7 +59,7 @@ impl HtmlView { None, None, ); - HtmlView { pager, bytes } + HtmlView { pager, bytes, id } } else { let mut html_filter = command_obj.unwrap(); html_filter @@ -75,7 +77,7 @@ impl HtmlView { )); let pager = Pager::from_string(display_text, None, None, None); - HtmlView { pager, bytes } + HtmlView { pager, bytes, id } } } else { if let Ok(mut html_filter) = Command::new("w3m") @@ -98,7 +100,7 @@ impl HtmlView { )); let pager = Pager::from_string(display_text, None, None, None); - HtmlView { pager, bytes } + HtmlView { pager, bytes, id } } else { context.replies.push_back(UIEvent { id: 0, @@ -115,7 +117,7 @@ impl HtmlView { None, None, ); - HtmlView { pager, bytes } + HtmlView { pager, bytes, id } } } } @@ -168,4 +170,11 @@ impl Component for HtmlView { fn set_dirty(&mut self) { self.pager.set_dirty(); } + + fn id(&self) -> ComponentId { + self.id + } + fn set_id(&mut self, id: ComponentId) { + self.id = id; + } } diff --git a/ui/src/components/mail/view/thread.rs b/ui/src/components/mail/view/thread.rs index 0a625cd9..d5d2986f 100644 --- a/ui/src/components/mail/view/thread.rs +++ b/ui/src/components/mail/view/thread.rs @@ -51,6 +51,7 @@ pub struct ThreadView { dirty: bool, content: CellBuffer, initiated: bool, + id: ComponentId, } #[derive(Debug)] @@ -985,4 +986,11 @@ impl Component for ThreadView { map } + + fn id(&self) -> ComponentId { + self.id + } + fn set_id(&mut self, id: ComponentId) { + self.id = id; + } } diff --git a/ui/src/components/notifications.rs b/ui/src/components/notifications.rs index f7df74fa..55aabbf7 100644 --- a/ui/src/components/notifications.rs +++ b/ui/src/components/notifications.rs @@ -54,6 +54,11 @@ impl Component for XDGNotifications { false } fn set_dirty(&mut self) {} + + fn id(&self) -> ComponentId { + ComponentId::nil() + } + fn set_id(&mut self, _id: ComponentId) {} } fn escape_str(s: &str) -> String { @@ -133,5 +138,9 @@ impl Component for NotificationFilter { } false } + fn id(&self) -> ComponentId { + ComponentId::nil() + } fn set_dirty(&mut self) {} + fn set_id(&mut self, _id: ComponentId) {} } diff --git a/ui/src/components/utilities.rs b/ui/src/components/utilities.rs index 8f713396..86dc6c54 100644 --- a/ui/src/components/utilities.rs +++ b/ui/src/components/utilities.rs @@ -30,10 +30,11 @@ pub use self::widgets::*; /// A horizontally split in half container. #[derive(Debug)] pub struct HSplit { - top: Entity, - bottom: Entity, + top: Box<Component>, + bottom: Box<Component>, show_divider: bool, ratio: usize, // bottom/whole height * 100 + id: ComponentId, } impl fmt::Display for HSplit { @@ -44,12 +45,18 @@ impl fmt::Display for HSplit { } impl HSplit { - pub fn new(top: Entity, bottom: Entity, ratio: usize, show_divider: bool) -> Self { + pub fn new( + top: Box<Component>, + bottom: Box<Component>, + ratio: usize, + show_divider: bool, + ) -> Self { HSplit { top, bottom, show_divider, ratio, + id: ComponentId::default(), } } } @@ -62,8 +69,8 @@ impl Component for HSplit { let upper_left = upper_left!(area); let bottom_right = bottom_right!(area); let total_rows = get_y(bottom_right) - get_y(upper_left); - let bottom_entity_height = (self.ratio * total_rows) / 100; - let mid = get_y(upper_left) + total_rows - bottom_entity_height; + let bottom_component_height = (self.ratio * total_rows) / 100; + let mid = get_y(upper_left) + total_rows - bottom_component_height; if self.show_divider { for i in get_x(upper_left)..=get_x(bottom_right) { @@ -74,7 +81,7 @@ impl Component for HSplit { .push_back(((get_x(upper_left), mid), (get_x(bottom_right), mid))); } - self.top.component.draw( + self.top.draw( grid, ( upper_left, @@ -82,23 +89,23 @@ impl Component for HSplit { ), context, ); - self.bottom.component.draw( + self.bottom.draw( grid, ((get_x(upper_left), get_y(upper_left) + mid), bottom_right), context, ); } fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool { - self.top.rcv_event(event, context) || self.bottom.rcv_event(event, context) + self.top.process_event(event, context) || self.bottom.process_event(event, context) } fn is_dirty(&self) -> bool { - self.top.component.is_dirty() || self.bottom.component.is_dirty() + self.top.is_dirty() || self.bottom.is_dirty() } fn set_dirty(&mut self) { - self.top.component.set_dirty(); - self.bottom.component.set_dirty(); + self.top.set_dirty(); + self.bottom.set_dirty(); } fn get_shortcuts(&self, context: &Context) -> ShortcutMap { @@ -106,34 +113,48 @@ impl Component for HSplit { top_map.extend(self.bottom.get_shortcuts(context).into_iter()); top_map } + + fn id(&self) -> ComponentId { + self.id + } + fn set_id(&mut self, id: ComponentId) { + self.id = id; + } } /// A vertically split in half container. #[derive(Debug)] pub struct VSplit { - left: Entity, - right: Entity, + left: Box<Component>, + right: Box<Component>, show_divider: bool, prev_visibility: (bool, bool), /// This is the width of the right container to the entire width. ratio: usize, // right/(container width) * 100 + id: ComponentId, } impl fmt::Display for VSplit { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - // TODO display focused entity + // TODO display focused component Display::fmt(&self.right, f) } } impl VSplit { - pub fn new(left: Entity, right: Entity, ratio: usize, show_divider: bool) -> Self { + pub fn new( + left: Box<Component>, + right: Box<Component>, + ratio: usize, + show_divider: bool, + ) -> Self { VSplit { left, right, show_divider, prev_visibility: (true, true), ratio, + id: ComponentId::default(), } } } @@ -151,7 +172,7 @@ impl Component for VSplit { self.set_dirty(); self.prev_visibility = visibility; } - let right_entity_width = match visibility { + let right_component_width = match visibility { (true, true) => (self.ratio * total_cols) / 100, (false, true) => total_cols, (true, false) => 0, @@ -161,7 +182,7 @@ impl Component for VSplit { } }; - let mid = get_x(bottom_right) - right_entity_width; + let mid = get_x(bottom_right) - right_component_width; if get_y(upper_left) > 1 { let c = grid @@ -193,12 +214,12 @@ impl Component for VSplit { .push_back(((mid, get_y(upper_left)), (mid, get_y(bottom_right)))); } - if right_entity_width == total_cols { - self.right.component.draw(grid, area, context); - } else if right_entity_width == 0 { - self.left.component.draw(grid, area, context); + if right_component_width == total_cols { + self.right.draw(grid, area, context); + } else if right_component_width == 0 { + self.left.draw(grid, area, context); } else { - self.left.component.draw( + self.left.draw( grid, ( upper_left, @@ -210,22 +231,21 @@ impl Component for VSplit { context, ); self.right - .component .draw(grid, (set_x(upper_left, mid + 1), bottom_right), context); } } fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool { - (self.left.rcv_event(event, context) || self.right.rcv_event(event, context)) + (self.left.process_event(event, context) || self.right.process_event(event, context)) } fn is_dirty(&self) -> bool { - self.left.component.is_dirty() || self.right.component.is_dirty() + self.left.is_dirty() || self.right.is_dirty() } fn set_dirty(&mut self) { - self.left.component.set_dirty(); - self.right.component.set_dirty(); + self.left.set_dirty(); + self.right.set_dirty(); } fn get_shortcuts(&self, context: &Context) -> ShortcutMap { @@ -233,6 +253,13 @@ impl Component for VSplit { right_map.extend(self.left.get_shortcuts(context).into_iter()); right_map } + + fn id(&self) -> ComponentId { + self.id + } + fn set_id(&mut self, id: ComponentId) { + self.id = id; + } |