Revert "Remove semantic search UI"

This reverts commit c0f042b39a.
This commit is contained in:
Mikayla 2023-08-18 15:59:26 -07:00
parent cb55204e22
commit 48553d7c8f
No known key found for this signature in database
7 changed files with 309 additions and 91 deletions

View file

@ -1,3 +1,5 @@
use std::marker::PhantomData;
use pathfinder_geometry::{rect::RectF, vector::Vector2F};
use crate::{
@ -103,26 +105,22 @@ impl<V: View> Component<V> for ElementAdapter<V> {
}
// Component -> Element
pub struct ComponentAdapter<V: View, E> {
pub struct ComponentAdapter<V, E> {
component: Option<E>,
element: Option<AnyElement<V>>,
#[cfg(debug_assertions)]
_component_name: &'static str,
phantom: PhantomData<V>,
}
impl<E, V: View> ComponentAdapter<V, E> {
impl<E, V> ComponentAdapter<V, E> {
pub fn new(e: E) -> Self {
Self {
component: Some(e),
element: None,
#[cfg(debug_assertions)]
_component_name: std::any::type_name::<E>(),
phantom: PhantomData,
}
}
}
impl<V: View, C: Component<V> + 'static> Element<V> for ComponentAdapter<V, C> {
type LayoutState = ();
type LayoutState = AnyElement<V>;
type PaintState = ();
@ -132,12 +130,10 @@ impl<V: View, C: Component<V> + 'static> Element<V> for ComponentAdapter<V, C> {
view: &mut V,
cx: &mut LayoutContext<V>,
) -> (Vector2F, Self::LayoutState) {
if self.element.is_none() {
let component = self.component.take().unwrap();
self.element = Some(component.render(view, cx.view_context()));
}
let constraint = self.element.as_mut().unwrap().layout(constraint, view, cx);
(constraint, ())
let component = self.component.take().unwrap();
let mut element = component.render(view, cx.view_context());
let constraint = element.layout(constraint, view, cx);
(constraint, element)
}
fn paint(
@ -145,14 +141,11 @@ impl<V: View, C: Component<V> + 'static> Element<V> for ComponentAdapter<V, C> {
scene: &mut SceneBuilder,
bounds: RectF,
visible_bounds: RectF,
_: &mut Self::LayoutState,
layout: &mut Self::LayoutState,
view: &mut V,
cx: &mut PaintContext<V>,
) -> Self::PaintState {
self.element
.as_mut()
.unwrap()
.paint(scene, bounds.origin(), visible_bounds, view, cx)
layout.paint(scene, bounds.origin(), visible_bounds, view, cx)
}
fn rect_for_text_range(
@ -160,35 +153,25 @@ impl<V: View, C: Component<V> + 'static> Element<V> for ComponentAdapter<V, C> {
range_utf16: std::ops::Range<usize>,
_: RectF,
_: RectF,
_: &Self::LayoutState,
element: &Self::LayoutState,
_: &Self::PaintState,
view: &V,
cx: &ViewContext<V>,
) -> Option<RectF> {
self.element
.as_ref()
.unwrap()
.rect_for_text_range(range_utf16, view, cx)
element.rect_for_text_range(range_utf16, view, cx)
}
fn debug(
&self,
_: RectF,
_: &Self::LayoutState,
element: &Self::LayoutState,
_: &Self::PaintState,
view: &V,
cx: &ViewContext<V>,
) -> serde_json::Value {
#[cfg(debug_assertions)]
let component_name = self._component_name;
#[cfg(not(debug_assertions))]
let component_name = "Unknown";
serde_json::json!({
"type": "ComponentAdapter",
"child": self.element.as_ref().unwrap().debug(view, cx),
"component_name": component_name
"child": element.debug(view, cx),
})
}
}