mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-29 08:32:27 +03:00
Align tooltip based on the available window space
This commit is contained in:
parent
b3242417b3
commit
238827642a
@ -1619,7 +1619,7 @@ mod tests {
|
|||||||
|
|
||||||
// Don't panic.
|
// Don't panic.
|
||||||
let bounds = RectF::new(Default::default(), size);
|
let bounds = RectF::new(Default::default(), size);
|
||||||
let mut paint_cx = presenter.build_paint_context(&mut scene, cx);
|
let mut paint_cx = presenter.build_paint_context(&mut scene, bounds.size(), cx);
|
||||||
element.paint(bounds, bounds, &mut state, &mut paint_cx);
|
element.paint(bounds, bounds, &mut state, &mut paint_cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,9 +101,16 @@ impl Element for Tooltip {
|
|||||||
self.child.paint(bounds.origin(), visible_bounds, cx);
|
self.child.paint(bounds.origin(), visible_bounds, cx);
|
||||||
if let Some(tooltip) = self.tooltip.as_mut() {
|
if let Some(tooltip) = self.tooltip.as_mut() {
|
||||||
let origin = self.state.read(cx).position.get();
|
let origin = self.state.read(cx).position.get();
|
||||||
let size = tooltip.size();
|
let mut bounds = RectF::new(origin, tooltip.size());
|
||||||
|
if bounds.lower_right().x() > cx.window_size.x() {
|
||||||
|
bounds.set_origin_x(bounds.origin_x() - bounds.width());
|
||||||
|
}
|
||||||
|
if bounds.lower_right().y() > cx.window_size.y() {
|
||||||
|
bounds.set_origin_y(bounds.origin_y() - bounds.height());
|
||||||
|
}
|
||||||
|
|
||||||
cx.scene.push_stacking_context(None);
|
cx.scene.push_stacking_context(None);
|
||||||
tooltip.paint(origin, RectF::new(origin, size), cx);
|
tooltip.paint(bounds.origin(), bounds, cx);
|
||||||
cx.scene.pop_stacking_context();
|
cx.scene.pop_stacking_context();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,7 @@ impl Presenter {
|
|||||||
|
|
||||||
if let Some(root_view_id) = cx.root_view_id(self.window_id) {
|
if let Some(root_view_id) = cx.root_view_id(self.window_id) {
|
||||||
self.layout(window_size, refreshing, cx);
|
self.layout(window_size, refreshing, cx);
|
||||||
let mut paint_cx = self.build_paint_context(&mut scene, cx);
|
let mut paint_cx = self.build_paint_context(&mut scene, window_size, cx);
|
||||||
paint_cx.paint(
|
paint_cx.paint(
|
||||||
root_view_id,
|
root_view_id,
|
||||||
Vector2F::zero(),
|
Vector2F::zero(),
|
||||||
@ -205,10 +205,12 @@ impl Presenter {
|
|||||||
pub fn build_paint_context<'a>(
|
pub fn build_paint_context<'a>(
|
||||||
&'a mut self,
|
&'a mut self,
|
||||||
scene: &'a mut Scene,
|
scene: &'a mut Scene,
|
||||||
|
window_size: Vector2F,
|
||||||
cx: &'a mut MutableAppContext,
|
cx: &'a mut MutableAppContext,
|
||||||
) -> PaintContext {
|
) -> PaintContext {
|
||||||
PaintContext {
|
PaintContext {
|
||||||
scene,
|
scene,
|
||||||
|
window_size,
|
||||||
font_cache: &self.font_cache,
|
font_cache: &self.font_cache,
|
||||||
text_layout_cache: &self.text_layout_cache,
|
text_layout_cache: &self.text_layout_cache,
|
||||||
rendered_views: &mut self.rendered_views,
|
rendered_views: &mut self.rendered_views,
|
||||||
@ -592,6 +594,7 @@ impl<'a> UpgradeViewHandle for LayoutContext<'a> {
|
|||||||
pub struct PaintContext<'a> {
|
pub struct PaintContext<'a> {
|
||||||
rendered_views: &'a mut HashMap<usize, ElementBox>,
|
rendered_views: &'a mut HashMap<usize, ElementBox>,
|
||||||
view_stack: Vec<usize>,
|
view_stack: Vec<usize>,
|
||||||
|
pub window_size: Vector2F,
|
||||||
pub scene: &'a mut Scene,
|
pub scene: &'a mut Scene,
|
||||||
pub font_cache: &'a FontCache,
|
pub font_cache: &'a FontCache,
|
||||||
pub text_layout_cache: &'a TextLayoutCache,
|
pub text_layout_cache: &'a TextLayoutCache,
|
||||||
|
Loading…
Reference in New Issue
Block a user