pub struct SelectableText { /* private fields */ }Expand description
Plain text that participates in the window-scoped TextSelection.
Use Self::new for an independent run, or Self::with_handle when
several elements form one selectable document.
Applications must render one crate::TextSelectionLayer above their
content and call crate::init during startup. Selection and copy then
work without depending on gpui-component.
Implementations§
Source§impl SelectableText
impl SelectableText
Sourcepub fn new(id: impl Into<ElementId>, text: impl Into<SharedString>) -> Self
pub fn new(id: impl Into<ElementId>, text: impl Into<SharedString>) -> Self
Creates a run that owns its own selection.
Sourcepub fn with_handle(
id: impl Into<ElementId>,
handle: TextSelectionHandle,
text: impl Into<SharedString>,
) -> Self
pub fn with_handle( id: impl Into<ElementId>, handle: TextSelectionHandle, text: impl Into<SharedString>, ) -> Self
Creates a run that joins the document handle belongs to.
Sourcepub fn document_order(self, order: u64) -> Self
pub fn document_order(self, order: u64) -> Self
Places this run in reading order among the others sharing its handle.
Sourcepub fn text_style(self, style: TextStyleRefinement) -> Self
pub fn text_style(self, style: TextStyleRefinement) -> Self
Sets the text style the run is laid out and painted with.
Sourcepub fn highlights(
self,
highlights: impl IntoIterator<Item = (Range<usize>, HighlightStyle)>,
) -> Self
pub fn highlights( self, highlights: impl IntoIterator<Item = (Range<usize>, HighlightStyle)>, ) -> Self
Styles ranges of the text, such as the matches of a search, as
StyledText::with_highlights does. The ranges are UTF-8 offsets, in
order and without overlap.
Sourcepub fn selection_color(self, color: Hsla) -> Self
pub fn selection_color(self, color: Hsla) -> Self
Overrides the selection background, which defaults to the theme’s
colors.selection token.
Sourcepub fn reveal_range(self, range: Range<usize>) -> Self
pub fn reveal_range(self, range: Range<usize>) -> Self
Request that the visual line containing the start of this UTF-8 byte
range scroll into view. The line is revealed once when the range is
first supplied or changes, matching TextViewState::reveal_range, so
the user can scroll away afterwards. Invalid ranges are ignored.
Trait Implementations§
Source§impl Element for SelectableText
impl Element for SelectableText
Source§type RequestLayoutState = TextSelectionHandle
type RequestLayoutState = TextSelectionHandle
Element::request_layout. A mutable reference to this state is subsequently
provided to Element::prepaint and Element::paint.Source§type PrepaintState = Hitbox
type PrepaintState = Hitbox
Element::prepaint. A mutable reference to this state is subsequently
provided to Element::paint.Source§fn id(&self) -> Option<ElementId>
fn id(&self) -> Option<ElementId>
Source§fn source_location(&self) -> Option<&'static Location<'static>>
fn source_location(&self) -> Option<&'static Location<'static>>
Source§fn request_layout(
&mut self,
global_id: Option<&GlobalElementId>,
inspector_id: Option<&InspectorElementId>,
window: &mut Window,
cx: &mut App,
) -> (LayoutId, Self::RequestLayoutState)
fn request_layout( &mut self, global_id: Option<&GlobalElementId>, inspector_id: Option<&InspectorElementId>, window: &mut Window, cx: &mut App, ) -> (LayoutId, Self::RequestLayoutState)
Source§fn prepaint(
&mut self,
global_id: Option<&GlobalElementId>,
inspector_id: Option<&InspectorElementId>,
bounds: Bounds<Pixels>,
handle: &mut Self::RequestLayoutState,
window: &mut Window,
cx: &mut App,
) -> Self::PrepaintState
fn prepaint( &mut self, global_id: Option<&GlobalElementId>, inspector_id: Option<&InspectorElementId>, bounds: Bounds<Pixels>, handle: &mut Self::RequestLayoutState, window: &mut Window, cx: &mut App, ) -> Self::PrepaintState
Element::request_layout().Source§fn paint(
&mut self,
global_id: Option<&GlobalElementId>,
inspector_id: Option<&InspectorElementId>,
bounds: Bounds<Pixels>,
handle: &mut Self::RequestLayoutState,
_: &mut Self::PrepaintState,
window: &mut Window,
cx: &mut App,
)
fn paint( &mut self, global_id: Option<&GlobalElementId>, inspector_id: Option<&InspectorElementId>, bounds: Bounds<Pixels>, handle: &mut Self::RequestLayoutState, _: &mut Self::PrepaintState, window: &mut Window, cx: &mut App, )
Element::request_layout().Source§fn a11y_role(&self) -> Option<Role>
fn a11y_role(&self) -> Option<Role>
None are not included in the accessibility tree. Read moreSource§fn write_a11y_info(&self, _node: &mut Node)
fn write_a11y_info(&self, _node: &mut Node)
a11y_role() returns Some. Read moreSource§fn a11y_synthetic_children(
&mut self,
_prepaint: &mut Self::PrepaintState,
_builder: &mut A11ySubtreeBuilder<'_>,
)
fn a11y_synthetic_children( &mut self, _prepaint: &mut Self::PrepaintState, _builder: &mut A11ySubtreeBuilder<'_>, )
Source§fn into_any(self) -> AnyElement
fn into_any(self) -> AnyElement
AnyElement.Auto Trait Implementations§
impl !RefUnwindSafe for SelectableText
impl !Send for SelectableText
impl !Sync for SelectableText
impl !UnwindSafe for SelectableText
impl Forget for SelectableText
impl Freeze for SelectableTextwhere
NonZero<u32>: Freeze,
&'static str: Freeze,
*const ArcInner<str> is !null: Freeze,
PhantomData<ArcInner<str>>: Freeze,
*const ArcInner<Path> is !null: Freeze,
PhantomData<ArcInner<Path>>: Freeze,
*const str is !null: Freeze,
PhantomData<&'static str>: Freeze,
*const ArcInner<ElementId> is !null: Freeze,
PhantomData<ArcInner<ElementId>>: Freeze,
*const (): Freeze,
*const ArcInner<RwLock<RawRwLock, EntityRefCounts>> is !null: Freeze,
PhantomData<fn(SelectableTextState) -> SelectableTextState>: Freeze,
*const u8 is !null: Freeze,
PhantomData<TextRun>: Freeze,
PhantomData<(Range<usize>, HighlightStyle)>: Freeze,
PhantomData<(Range<usize>, SharedString)>: Freeze,
*const RcInner<RefCell<Option<TextLayoutInner>>> is !null: Freeze,
PhantomData<RcInner<RefCell<Option<TextLayoutInner>>>>: Freeze,
*const ArcInner<Vec<(String, u32)>> is !null: Freeze,
PhantomData<ArcInner<Vec<(String, u32)>>>: Freeze,
*const ArcInner<Vec<String>> is !null: Freeze,
PhantomData<ArcInner<Vec<String>>>: Freeze,
*const dyn Fn(Bounds<Pixels>, &mut Window, &mut App) is !null: Freeze,
PhantomData<dyn Fn(Bounds<Pixels>, &mut Window, &mut App)>: Freeze,
impl Move for SelectableText
impl Unpin for SelectableTextwhere
NonZero<u32>: Unpin,
&'static str: Unpin,
Arc<str>: Unpin,
Arc<Path>: Unpin,
*const str is !null: Unpin,
Arc<ElementId>: Unpin,
*const (): Unpin,
*const ArcInner<RwLock<RawRwLock, EntityRefCounts>> is !null: Unpin,
*const u8 is !null: Unpin,
Arc<Vec<(String, u32)>>: Unpin,
Arc<Vec<String>>: Unpin,
Rc<RefCell<Option<TextLayoutInner>>>: Unpin,
Box<dyn Fn(Bounds<Pixels>, &mut Window, &mut App)>: Unpin,
impl UnsafeUnpin for SelectableTextwhere
NonZeroU32Inner: UnsafeUnpin,
&'static str: UnsafeUnpin,
*const ArcInner<str> is !null: UnsafeUnpin,
PhantomData<ArcInner<str>>: UnsafeUnpin,
*const ArcInner<Path> is !null: UnsafeUnpin,
PhantomData<ArcInner<Path>>: UnsafeUnpin,
*const str is !null: UnsafeUnpin,
PhantomData<&'static str>: UnsafeUnpin,
*const ArcInner<ElementId> is !null: UnsafeUnpin,
PhantomData<ArcInner<ElementId>>: UnsafeUnpin,
*const (): UnsafeUnpin,
*const ArcInner<RwLock<RawRwLock, EntityRefCounts>> is !null: UnsafeUnpin,
PhantomData<fn(SelectableTextState) -> SelectableTextState>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<TextRun>: UnsafeUnpin,
PhantomData<(Range<usize>, HighlightStyle)>: UnsafeUnpin,
PhantomData<(Range<usize>, SharedString)>: UnsafeUnpin,
*const RcInner<RefCell<Option<TextLayoutInner>>> is !null: UnsafeUnpin,
PhantomData<RcInner<RefCell<Option<TextLayoutInner>>>>: UnsafeUnpin,
*const ArcInner<Vec<(String, u32)>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Vec<(String, u32)>>>: UnsafeUnpin,
*const ArcInner<Vec<String>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Vec<String>>>: UnsafeUnpin,
*const dyn Fn(Bounds<Pixels>, &mut Window, &mut App) is !null: UnsafeUnpin,
PhantomData<dyn Fn(Bounds<Pixels>, &mut Window, &mut App)>: UnsafeUnpin,
Blanket Implementations§
Source§impl<E> AnimationExt for Ewhere
E: IntoElement + 'static,
impl<E> AnimationExt for Ewhere
E: IntoElement + 'static,
Source§fn with_animation(
self,
id: impl Into<ElementId>,
animation: Animation,
animator: impl Fn(Self, f32) -> Self + 'static,
) -> AnimationElement<Self>where
Self: Sized,
fn with_animation(
self,
id: impl Into<ElementId>,
animation: Animation,
animator: impl Fn(Self, f32) -> Self + 'static,
) -> AnimationElement<Self>where
Self: Sized,
Source§fn with_animations(
self,
id: impl Into<ElementId>,
animations: Vec<Animation>,
animator: impl Fn(Self, usize, f32) -> Self + 'static,
) -> AnimationElement<Self>where
Self: Sized,
fn with_animations(
self,
id: impl Into<ElementId>,
animations: Vec<Animation>,
animator: impl Fn(Self, usize, f32) -> Self + 'static,
) -> AnimationElement<Self>where
Self: Sized,
Source§fn with_spring<T>(
self,
id: impl Into<ElementId>,
animation: SpringAnimation<T>,
animator: impl FnOnce(Self, <T as SpringTarget>::Output) -> Self + 'static,
) -> SpringAnimationElement<Self>
fn with_spring<T>( self, id: impl Into<ElementId>, animation: SpringAnimation<T>, animator: impl FnOnce(Self, <T as SpringTarget>::Output) -> Self + 'static, ) -> SpringAnimationElement<Self>
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> FluentBuilder for Twhere
T: IntoElement,
impl<T> FluentBuilder for Twhere
T: IntoElement,
Source§fn map<U>(self, f: impl FnOnce(Self) -> U) -> Uwhere
Self: Sized,
fn map<U>(self, f: impl FnOnce(Self) -> U) -> Uwhere
Self: Sized,
Source§fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Selfwhere
Self: Sized,
fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Selfwhere
Self: Sized,
Source§fn when_else(
self,
condition: bool,
then: impl FnOnce(Self) -> Self,
else_fn: impl FnOnce(Self) -> Self,
) -> Selfwhere
Self: Sized,
fn when_else(
self,
condition: bool,
then: impl FnOnce(Self) -> Self,
else_fn: impl FnOnce(Self) -> Self,
) -> Selfwhere
Self: Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoElement for Twhere
T: Element,
impl<T> IntoElement for Twhere
T: Element,
Source§type Element = T
type Element = T
Source§fn into_element(self) -> <T as IntoElement>::Element
fn into_element(self) -> <T as IntoElement>::Element
Element.Source§fn into_any_element(self) -> AnyElement
fn into_any_element(self) -> AnyElement
AnyElement.Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<E> TestTextExt for Ewhere
E: IntoElement,
impl<E> TestTextExt for Ewhere
E: IntoElement,
Source§fn test_text(
self,
text: impl Into<SharedString>,
) -> ObservedTextElement<Self::Element>
fn test_text( self, text: impl Into<SharedString>, ) -> ObservedTextElement<Self::Element>
test-support, records text each time the element paints.
Otherwise returns the element it builds.Source§fn test_alt_text(
self,
text: impl Into<SharedString>,
) -> ObservedTextElement<Self::Element>
fn test_alt_text( self, text: impl Into<SharedString>, ) -> ObservedTextElement<Self::Element>
Self::test_text for an image’s alternative text, which
stands in for what the element draws.