Crate bevy_cosmic_edit
source ·Expand description
§bevy_cosmic_edit
Multiline text editor using cosmic_text
for the bevy
game engine!
This bevy plugin provides multiline text editing for bevy apps, thanks to cosmic_text crate! Emoji, ligatures, and other fancy stuff is supported!
§Usage
Warning: This plugin is currently in early development, and its API is subject to change.
use bevy::prelude::*;
use bevy_cosmic_edit::*;
fn setup(mut commands: Commands, mut font_system: ResMut<CosmicFontSystem>) {
commands.spawn(Camera2dBundle::default());
// Text attributes
let font_size = 16.0;
let line_height = 18.0;
let attrs = Attrs::new()
.family(Family::Monospace)
.color(Color::DARK_GRAY.to_cosmic())
.weight(FontWeight::BOLD);
// Spawning
commands.spawn(CosmicEditBundle {
buffer: CosmicBuffer::new(&mut font_system, Metrics::new(font_size, line_height))
.with_text(&mut font_system, "Hello, Cosmic!", attrs),
sprite_bundle: SpriteBundle {
sprite: Sprite {
custom_size: Some(Vec2::new(300.0, 40.0)),
..default()
},
..default()
},
..default()
});
}
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(CosmicEditPlugin::default())
.add_systems(Startup, setup)
.add_systems(Update, change_active_editor_sprite)
.run();
}
Check the examples folder for much more!
Native:
$ cargo r --example font_per_widget
Wasm:
$ cargo install wasm-server-runner
$ RUSTFLAGS=--cfg=web_sys_unstable_apis cargo r --target wasm32-unknown-unknown --example basic_ui
§Compatibility
bevy | bevy_cosmic_edit |
---|---|
0.13.0 | 0.16 - latest |
0.12.* | 0.15 |
0.11.* | 0.8 - 0.14 |
§Feature flags
multicam
— Enable to avoid panicing when multiple cameras are used in the same world Requires you to addCosmicPrimaryCamera
marker component to the primary camera
§License
MIT or Apache-2.0
Re-exports§
pub use cosmic_text::Action;
pub use cosmic_text::Attrs;
pub use cosmic_text::AttrsOwned;
pub use cosmic_text::Buffer;
pub use cosmic_text::CacheKeyFlags;
pub use cosmic_text::Color as CosmicColor;
pub use cosmic_text::Cursor;
pub use cosmic_text::Edit;
pub use cosmic_text::Editor;
pub use cosmic_text::Family;
pub use cosmic_text::FamilyOwned;
pub use cosmic_text::FontSystem;
pub use cosmic_text::Metrics;
pub use cosmic_text::Shaping;
pub use cosmic_text::Stretch;
pub use cosmic_text::Style as FontStyle;
pub use cosmic_text::Weight as FontWeight;
Structs§
- Set of all buffer setup functions. Runs in
First
- Timer for double / triple clicks
- Color to be used as a buffer’s background
- Image to be used as a buffer’s background
- Component wrapper for
Buffer
- A bundle containing all the required components for
CosmicBuffer
functionality. - Plugin struct that adds systems and initializes resources related to cosmic edit functionality.
- Wrapper component for an
Editor
with a few helpful values for cursor blinking - Resource struct that holds configuration options for cosmic fonts.
- Holds the font system used internally by
cosmic_text
- Wrapper for a
Vec2
describing the horizontal and vertical padding of a widget. This is set programatically, not for user modification. To set a widget’s padding, useCosmicTextAlign
- A pointer to an entity with a
CosmicEditBundle
, used to apply cosmic rendering to a UI element. - Text change events Sent when text is changed in a cosmic buffer Contains the entity on which the text was changed, and the new text as a
String
- Color to be used for the text cursor
- Unit resource whose existence in the world disables the cursor plugin systems.
- System set for mouse cursor systems. Runs in
Update
- Default text attributes to be used on a
CosmicBuffer
- System set for focus systems. Runs in
PostUpdate
- Resource struct that keeps track of the currently active editor entity.
- Maximum number of characters allowed in a buffer
- Maximum number of lines allowed in a buffer
- Component to be added to an entity with a
CosmicEditBundle
to block contents with a password blocker glyph - System set for password blocking systems. Runs in
PostUpdate
- Component to be added to an entity with a
CosmicEditBundle
add placeholder text - Tag component to disable writing to a
CosmicBuffer
- System set for cosmic text rendering systems. Runs in
PostUpdate
- Buffer does not respond to scroll events
- Color to be used for the selected text
- Color to be used as the selected text background
- For use with custom cursor control Event is emitted when cursor enters a text widget Event contains the cursor from the buffer’s
HoverCursor
- For use with custom cursor control Event is emitted when cursor leaves a text widget
- Tag component to disable user selection Like CSS
user-select: none
https://developer.mozilla.org/en-US/docs/Web/CSS/user-select - Crossbeam channel struct for Wasm clipboard data
- Async channel for receiving from the clipboard in Wasm
- System set for cosmic text layout systems. Runs in
PostUpdate
- Internal value used to decide what section of a
Buffer
to render
Enums§
- Enum representing the text alignment in a cosmic
Buffer
- Enum representing text wrapping in a cosmic
Buffer
Traits§
- Trait for adding color conversion from
bevy::prelude::Color
tocosmic_text::Color
Functions§
- Adds a
FontSystem
to a newly createdCosmicBuffer
if one was not provided - System to allow focus on click for sprite widgets
- System to allow focus on click for UI widgets
- System to unfocus editors when [Esc] is pressed
- Function to find the location of the mouse cursor in a cosmic widget
- Utility function to get the current unix timestamp
- System to print editor text content on change
- Initialises new
CosmicEditor
redraw flag to true - Initialises
CosmicBuffer
scale factor - Initialises new
CosmicBuffer
redraw flag to true - Sets image of UI elements to the
CosmicBuffer
output