Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/crates/bevy_text/src/cursor.rs
30635 views
1
use bevy_color::{
2
palettes::tailwind::{SKY_300, SKY_400, SLATE_700},
3
Color,
4
};
5
use 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(Component, Clone, Copy, Debug, PartialEq)]
14
pub 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
/// Corner radius of selection highlight rectangles, normalized relative to the selection height.
27
///
28
/// Values are clamped between `0.0` and `0.5`.
29
pub selection_radius: f32,
30
}
31
32
impl Default for TextCursorStyle {
33
fn default() -> Self {
34
Self {
35
color: Color::from(SLATE_700),
36
selection_color: Color::from(SKY_300),
37
unfocused_selection_color: Color::from(SKY_400),
38
selected_text_color: None,
39
selection_radius: 0.,
40
}
41
}
42
}
43
44