From 75dfaff33891d0505e3018a8357fa0619ef1fcc2 Mon Sep 17 00:00:00 2001 From: Pascal Sommer Date: Wed, 11 Jan 2023 03:11:43 +0100 Subject: [PATCH] Add some function documentations (#5360) --- helix-term/src/compositor.rs | 6 ++++-- helix-term/src/ui/popup.rs | 10 ++++++++++ helix-view/src/editor.rs | 2 ++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/helix-term/src/compositor.rs b/helix-term/src/compositor.rs index 9dad36209..2e4a2e20e 100644 --- a/helix-term/src/compositor.rs +++ b/helix-term/src/compositor.rs @@ -1,4 +1,4 @@ -// Each component declares it's own size constraints and gets fitted based on it's parent. +// Each component declares its own size constraints and gets fitted based on its parent. // Q: how does this work with popups? // cursive does compositor.screen_mut().add_layer_at(pos::absolute(x, y), ) use helix_core::Position; @@ -97,6 +97,7 @@ impl Compositor { self.area = area; } + /// Add a layer to be rendered in front of all existing layers. pub fn push(&mut self, mut layer: Box) { let size = self.size(); // trigger required_size on init @@ -136,7 +137,8 @@ impl Compositor { let mut consumed = false; // propagate events through the layers until we either find a layer that consumes it or we - // run out of layers (event bubbling) + // run out of layers (event bubbling), starting at the front layer and then moving to the + // background. for layer in self.layers.iter_mut().rev() { match layer.handle_event(event, cx) { EventResult::Consumed(Some(callback)) => { diff --git a/helix-term/src/ui/popup.rs b/helix-term/src/ui/popup.rs index 62a6785a4..5a95c1bba 100644 --- a/helix-term/src/ui/popup.rs +++ b/helix-term/src/ui/popup.rs @@ -42,6 +42,10 @@ impl Popup { } } + /// Set the anchor position next to which the popup should be drawn. + /// + /// Note that this is not the position of the top-left corner of the rendered popup itself, + /// but rather the screen-space position of the information to which the popup refers. pub fn position(mut self, pos: Option) -> Self { self.position = pos; self @@ -51,6 +55,10 @@ impl Popup { self.position } + /// Set the popup to prefer to render above or below the anchor position. + /// + /// This preference will be ignored if the viewport doesn't have enough space in the + /// chosen direction. pub fn position_bias(mut self, bias: Open) -> Self { self.position_bias = bias; self @@ -78,6 +86,8 @@ impl Popup { self } + /// Calculate the position where the popup should be rendered and return the coordinates of the + /// top left corner. pub fn get_rel_position(&mut self, viewport: Rect, cx: &Context) -> (u16, u16) { let position = self .position diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 3521077ef..547a4ffbd 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -1341,6 +1341,8 @@ impl Editor { .find(|doc| doc.path().map(|p| p == path.as_ref()).unwrap_or(false)) } + /// Gets the primary cursor position in screen coordinates, + /// or `None` if the primary cursor is not visible on screen. pub fn cursor(&self) -> (Option, CursorKind) { let config = self.config(); let (view, doc) = current_ref!(self);