on master help sign in
Add some function documentations (#5360)
75dfaffPascal Sommer
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.
2// Q: how does this work with popups?
2// Q: how does this work with popups?
3// cursive does compositor.screen_mut().add_layer_at(pos::absolute(x, y), <component>)
3// cursive does compositor.screen_mut().add_layer_at(pos::absolute(x, y), <component>)
4use helix_core::Position;
4use helix_core::Position;
@@ -97,6 +97,7 @@ impl Compositor {
97 self.area = area;
97 self.area = area;
98 }
98 }
99
99
100+ /// Add a layer to be rendered in front of all existing layers.
100 pub fn push(&mut self, mut layer: Box<dyn Component>) {
101 pub fn push(&mut self, mut layer: Box<dyn Component>) {
101 let size = self.size();
102 let size = self.size();
102 // trigger required_size on init
103 // trigger required_size on init
@@ -136,7 +137,8 @@ impl Compositor {
136 let mut consumed = false;
137 let mut consumed = false;
137
138
138 // propagate events through the layers until we either find a layer that consumes it or we
139 // 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.
140 for layer in self.layers.iter_mut().rev() {
142 for layer in self.layers.iter_mut().rev() {
141 match layer.handle_event(event, cx) {
143 match layer.handle_event(event, cx) {
142 EventResult::Consumed(Some(callback)) => {
144 EventResult::Consumed(Some(callback)) => {
helix-term/src/ui/popup.rs+10
@@ -42,6 +42,10 @@ impl<T: Component> Popup<T> {
42 }
42 }
43 }
43 }
44
44
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.
45 pub fn position(mut self, pos: Option<Position>) -> Self {
49 pub fn position(mut self, pos: Option<Position>) -> Self {
46 self.position = pos;
50 self.position = pos;
47 self
51 self
@@ -51,6 +55,10 @@ impl<T: Component> Popup<T> {
51 self.position
55 self.position
52 }
56 }
53
57
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.
54 pub fn position_bias(mut self, bias: Open) -> Self {
62 pub fn position_bias(mut self, bias: Open) -> Self {
55 self.position_bias = bias;
63 self.position_bias = bias;
56 self
64 self
@@ -78,6 +86,8 @@ impl<T: Component> Popup<T> {
78 self
86 self
79 }
87 }
80
88
89+ /// Calculate the position where the popup should be rendered and return the coordinates of the
90+ /// top left corner.
81 pub fn get_rel_position(&mut self, viewport: Rect, cx: &Context) -> (u16, u16) {
91 pub fn get_rel_position(&mut self, viewport: Rect, cx: &Context) -> (u16, u16) {
82 let position = self
92 let position = self
83 .position
93 .position
helix-view/src/editor.rs+2
@@ -1341,6 +1341,8 @@ impl Editor {
1341 .find(|doc| doc.path().map(|p| p == path.as_ref()).unwrap_or(false))
1341 .find(|doc| doc.path().map(|p| p == path.as_ref()).unwrap_or(false))
1342 }
1342 }
1343
1343
1344+ /// Gets the primary cursor position in screen coordinates,
1345+ /// or `None` if the primary cursor is not visible on screen.
1344 pub fn cursor(&self) -> (Option<Position>, CursorKind) {
1346 pub fn cursor(&self) -> (Option<Position>, CursorKind) {
1345 let config = self.config();
1347 let config = self.config();
1346 let (view, doc) = current_ref!(self);
1348 let (view, doc) = current_ref!(self);