on master help sign in
Add some function documentations (#5360)
commit75dfaff33891d0505e3018a8357fa0619ef1fcc2 authorPascal Sommer <Pascal-So@users.noreply.github.com> dateWed 11 Jan 2023, 03:11 (4 years ago) parenta8248c5
3 files changed+16−2
helix-term/src/compositor.rs+4−2 helix-term/src/ui/popup.rs+10 helix-view/src/editor.rs+2
helix-term/src/compositor.rs+4−2
@@ -1,4 +1,4 @@
1−// Each component declares it's own size constraints and gets fitted based on it's parent.
1+// Each component declares its own size constraints and gets fitted based on its parent.
22// Q: how does this work with popups?
33// cursive does compositor.screen_mut().add_layer_at(pos::absolute(x, y), <component>)
44use helix_core::Position;
@@ -97,6 +97,7 @@ impl Compositor {
9797 self.area = area;
9898 }
9999
100+ /// Add a layer to be rendered in front of all existing layers.
100101 pub fn push(&mut self, mut layer: Box<dyn Component>) {
101102 let size = self.size();
102103 // trigger required_size on init
@@ -136,7 +137,8 @@ impl Compositor {
136137 let mut consumed = false;
137138
138139 // propagate events through the layers until we either find a layer that consumes it or we
139− // run out of layers (event bubbling)
140+ // run out of layers (event bubbling), starting at the front layer and then moving to the
141+ // background.
140142 for layer in self.layers.iter_mut().rev() {
141143 match layer.handle_event(event, cx) {
142144 EventResult::Consumed(Some(callback)) => {
helix-term/src/ui/popup.rs+10
@@ -42,6 +42,10 @@ impl<T: Component> Popup<T> {
4242 }
4343 }
4444
45+ /// Set the anchor position next to which the popup should be drawn.
46+ ///
47+ /// Note that this is not the position of the top-left corner of the rendered popup itself,
48+ /// but rather the screen-space position of the information to which the popup refers.
4549 pub fn position(mut self, pos: Option<Position>) -> Self {
4650 self.position = pos;
4751 self
@@ -51,6 +55,10 @@ impl<T: Component> Popup<T> {
5155 self.position
5256 }
5357
58+ /// Set the popup to prefer to render above or below the anchor position.
59+ ///
60+ /// This preference will be ignored if the viewport doesn't have enough space in the
61+ /// chosen direction.
5462 pub fn position_bias(mut self, bias: Open) -> Self {
5563 self.position_bias = bias;
5664 self
@@ -78,6 +86,8 @@ impl<T: Component> Popup<T> {
7886 self
7987 }
8088
89+ /// Calculate the position where the popup should be rendered and return the coordinates of the
90+ /// top left corner.
8191 pub fn get_rel_position(&mut self, viewport: Rect, cx: &Context) -> (u16, u16) {
8292 let position = self
8393 .position
helix-view/src/editor.rs+2
@@ -1341,6 +1341,8 @@ impl Editor {
13411341 .find(|doc| doc.path().map(|p| p == path.as_ref()).unwrap_or(false))
13421342 }
13431343
1344+ /// Gets the primary cursor position in screen coordinates,
1345+ /// or `None` if the primary cursor is not visible on screen.
13441346 pub fn cursor(&self) -> (Option<Position>, CursorKind) {
13451347 let config = self.config();
13461348 let (view, doc) = current_ref!(self);