diff options
Diffstat (limited to 'ui/src/components')
-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 |
18 files changed, 309 insertions, 83 deletions
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; + } } #[derive(Debug)] @@ -254,6 +281,7 @@ pub struct Pager { dirty: bool, content: CellBuffer, movement: Option<PageMovement>, + id: ComponentId, } impl fmt::Display for Pager { @@ -524,12 +552,19 @@ impl Component for Pager { map } + + fn id(&self) -> ComponentId { + self.id + } + fn set_id(&mut self, id: ComponentId) { + self.id = id; + } } /// Status bar. #[derive(Debug)] pub struct StatusBar { - container: Entity, + container: Box<Component>, status: String, notifications: VecDeque<String>, ex_buffer: String, @@ -537,6 +572,7 @@ pub struct StatusBar { mode: UIMode, height: usize, dirty: bool, + id: ComponentId, } impl fmt::Display for StatusBar { @@ -547,7 +583,7 @@ impl fmt::Display for StatusBar { } impl StatusBar { - pub fn new(container: Entity) -> Self { + pub fn new(container: Box<Component>) -> Self { StatusBar { container, status: String::with_capacity(256), @@ -557,6 +593,7 @@ impl StatusBar { dirty: true, mode: UIMode::Normal, height: 1, + id: ComponentId::default(), } } fn draw_status_bar(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) { @@ -615,7 +652,7 @@ impl Component for StatusBar { } let height = self.height; - self.container.component.draw( + self.container.draw( grid, ( upper_left, @@ -649,7 +686,7 @@ impl Component for StatusBar { } } fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool { - if self.container.rcv_event(event, context) { + if self.container.process_event(event, context) { return true; } @@ -728,7 +765,7 @@ impl Component for StatusBar { false } fn is_dirty(&self) -> bool { - self.dirty || self.container.component.is_dirty() + self.dirty || self.container.is_dirty() } fn set_dirty(&mut self) { self.dirty = true; @@ -737,33 +774,13 @@ impl Component for StatusBar { fn get_shortcuts(&self, context: &Context) -> ShortcutMap { self.container.get_shortcuts(context) } -} - -// A box with a text content. -#[derive(Debug)] -pub struct TextBox { - _content: String, -} - -impl TextBox { - pub fn new(s: String) -> Self { - TextBox { _content: s } - } -} -impl fmt::Display for TextBox { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - // TODO display info - write!(f, "text box") + fn id(&self) -> ComponentId { + self.id } -} - -impl Component for TextBox { - fn draw(&mut self, _grid: &mut CellBuffer, _area: Area, _context: &mut Context) {} - fn process_event(&mut self, _event: &mut UIEvent, _context: &mut Context) -> bool { - false + fn set_id(&mut self, id: ComponentId) { + self.id = id; } - fn set_dirty(&mut self) {} } #[derive(Debug)] @@ -771,6 +788,7 @@ pub struct Progress { description: String, total_work: usize, finished: usize, + id: ComponentId, } impl Progress { @@ -779,6 +797,7 @@ impl Progress { description: s, total_work, finished: 0, |