Skip to main content

bevy_text/
cursor.rs

1use bevy_color::{
2    palettes::tailwind::{SKY_300, SKY_400, SLATE_700},
3    Color,
4};
5use bevy_ecs::component::Component;
6
7/// Controls text cursor appearance.
8///
9/// When this component on the same entity as an [`EditableText`](`crate::EditableText`) ,
10/// and the [`UiRenderPlugin`](https://docs.rs/bevy/latest/bevy/ui_render/struct.UiRenderPlugin.html)
11/// is active, a simple rectangle will be drawn for the cursor.
12/// This is an optional component, to allow for stylistic cursors.
13#[derive(impl bevy_ecs::component::Component for TextCursorStyle where
    Self: ::core::marker::Send + ::core::marker::Sync + 'static {
    const STORAGE_TYPE: bevy_ecs::component::StorageType =
        bevy_ecs::component::StorageType::Table;
    type Mutability = bevy_ecs::component::Mutable;
    fn register_required_components(_requiree:
            bevy_ecs::component::ComponentId,
        required_components:
            &mut bevy_ecs::component::RequiredComponentsRegistrator) {}
    fn clone_behavior() -> bevy_ecs::component::ComponentCloneBehavior {
        use bevy_ecs::component::{
            DefaultCloneBehaviorBase, DefaultCloneBehaviorViaClone,
        };
        (&&&bevy_ecs::component::DefaultCloneBehaviorSpecialization::<Self>::default()).default_clone_behavior()
    }
    fn relationship_accessor()
        ->
            ::core::option::Option<bevy_ecs::relationship::ComponentRelationshipAccessor<Self>> {
        ::core::option::Option::None
    }
}Component, #[automatically_derived]
impl ::core::clone::Clone for TextCursorStyle {
    #[inline]
    fn clone(&self) -> TextCursorStyle {
        let _: ::core::clone::AssertParamIsClone<Color>;
        let _: ::core::clone::AssertParamIsClone<Option<Color>>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for TextCursorStyle { }Copy, #[automatically_derived]
impl ::core::fmt::Debug for TextCursorStyle {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field4_finish(f,
            "TextCursorStyle", "color", &self.color, "selection_color",
            &self.selection_color, "unfocused_selection_color",
            &self.unfocused_selection_color, "selected_text_color",
            &&self.selected_text_color)
    }
}Debug, #[automatically_derived]
impl ::core::cmp::PartialEq for TextCursorStyle {
    #[inline]
    fn eq(&self, other: &TextCursorStyle) -> bool {
        self.color == other.color &&
                    self.selection_color == other.selection_color &&
                self.unfocused_selection_color ==
                    other.unfocused_selection_color &&
            self.selected_text_color == other.selected_text_color
    }
}PartialEq)]
14pub struct TextCursorStyle {
15    /// Color of the cursor
16    pub color: Color,
17    /// Background color of selected text
18    pub selection_color: Color,
19    /// Background color of unfocused selected text
20    ///
21    /// In many applications, this is completely transparent.
22    /// This reduces visual clutter of de-emphasized text inputs.
23    pub unfocused_selection_color: Color,
24    /// If some, overrides the color of selected text
25    pub selected_text_color: Option<Color>,
26}
27
28impl Default for TextCursorStyle {
29    fn default() -> Self {
30        Self {
31            color: Color::from(SLATE_700),
32            selection_color: Color::from(SKY_300),
33            unfocused_selection_color: Color::from(SKY_400),
34            selected_text_color: None,
35        }
36    }
37}