Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Bevy Cosmic Edit
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Microhacks
Bevy Forks
Bevy Cosmic Edit
Commits
b0b789fa
"src/tree.rs" did not exist on "43344419bc997897ef228a4b0b5f14051095a594"
Commit
b0b789fa
authored
1 year ago
by
sam edelsten
Browse files
Options
Downloads
Patches
Plain Diff
fix docs links
parent
e261ec4c
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/buffer.rs
+11
-11
11 additions, 11 deletions
src/buffer.rs
src/cosmic_edit.rs
+44
-56
44 additions, 56 deletions
src/cosmic_edit.rs
src/events.rs
+1
-1
1 addition, 1 deletion
src/events.rs
with
56 additions
and
68 deletions
src/buffer.rs
+
11
−
11
View file @
b0b789fa
use
crate
::
*
;
use
bevy
::{
prelude
::
*
,
window
::
PrimaryWindow
};
/// Set of all buffer setup functions. Runs in `First`
/// Set of all buffer setup functions. Runs in
[
`First`
]
#[derive(SystemSet,
Debug,
Clone,
PartialEq,
Eq,
Hash)]
pub
struct
BufferSet
;
...
...
@@ -36,7 +36,7 @@ impl BufferExtras for Buffer {
///
/// # Returns
///
/// A `String` containing the cosmic text content.
/// A
[
`String`
]
containing the cosmic text content.
fn
get_text
(
&
self
)
->
String
{
let
mut
text
=
String
::
new
();
let
line_count
=
self
.lines
.len
();
...
...
@@ -69,7 +69,7 @@ impl<'s, 'r> CosmicBuffer {
}
// Das a lotta boilerplate just to hide the shaping argument
/// Add text to a newly created `CosmicBuffer`
/// Add text to a newly created
[
`CosmicBuffer`
]
pub
fn
with_text
(
mut
self
,
font_system
:
&
mut
FontSystem
,
...
...
@@ -80,9 +80,9 @@ impl<'s, 'r> CosmicBuffer {
self
}
/// Add rich text to a newly created `CosmicBuffer`
/// Add rich text to a newly created
[
`CosmicBuffer`
]
///
/// Rich text is an iterable of `(&'s str, Attrs<'r>)
/// Rich text is an iterable of `(&'s str, Attrs<'r>)
`
pub
fn
with_rich_text
<
I
>
(
mut
self
,
font_system
:
&
mut
FontSystem
,
...
...
@@ -111,7 +111,7 @@ impl<'s, 'r> CosmicBuffer {
/// Replace buffer text with rich text
///
/// Rich text is an iterable of `(&'s str, Attrs<'r>)
/// Rich text is an iterable of `(&'s str, Attrs<'r>)
`
pub
fn
set_rich_text
<
I
>
(
&
mut
self
,
font_system
:
&
mut
FontSystem
,
...
...
@@ -168,7 +168,7 @@ impl<'s, 'r> CosmicBuffer {
}
}
/// Adds a `FontSystem` to a newly created `CosmicBuffer` if one was not provided
/// Adds a
[
`FontSystem`
]
to a newly created
[
`CosmicBuffer`
]
if one was not provided
pub
fn
add_font_system
(
mut
font_system
:
ResMut
<
CosmicFontSystem
>
,
mut
q
:
Query
<&
mut
CosmicBuffer
,
Added
<
CosmicBuffer
>>
,
...
...
@@ -182,7 +182,7 @@ pub fn add_font_system(
}
}
/// Initialises `CosmicBuffer` scale factor
/// Initialises
[
`CosmicBuffer`
]
scale factor
pub
fn
set_initial_scale
(
window_q
:
Query
<&
Window
,
With
<
PrimaryWindow
>>
,
mut
cosmic_query
:
Query
<&
mut
CosmicBuffer
,
Added
<
CosmicBuffer
>>
,
...
...
@@ -196,21 +196,21 @@ pub fn set_initial_scale(
}
}
/// Initialises new `CosmicBuffer` redraw flag to true
/// Initialises new
[
`CosmicBuffer`
]
redraw flag to true
pub
fn
set_redraw
(
mut
q
:
Query
<&
mut
CosmicBuffer
,
Added
<
CosmicBuffer
>>
)
{
for
mut
b
in
q
.iter_mut
()
{
b
.set_redraw
(
true
);
}
}
/// Initialises new `CosmicEditor` redraw flag to true
/// Initialises new
[
`CosmicEditor`
]
redraw flag to true
pub
fn
set_editor_redraw
(
mut
q
:
Query
<&
mut
CosmicEditor
,
Added
<
CosmicEditor
>>
)
{
for
mut
b
in
q
.iter_mut
()
{
b
.set_redraw
(
true
);
}
}
/// Sets image of UI elements to the `CosmicBuffer` output
/// Sets image of UI elements to the
[
`CosmicBuffer`
]
output
pub
fn
swap_target_handle
(
source_q
:
Query
<&
Handle
<
Image
>
,
With
<
CosmicBuffer
>>
,
mut
dest_q
:
Query
<
...
...
This diff is collapsed.
Click to expand it.
src/cosmic_edit.rs
+
44
−
56
View file @
b0b789fa
use
crate
::
*
;
use
bevy
::
prelude
::
*
;
/// Enum representing text wrapping in a cosmic `Buffer`
/// Enum representing text wrapping in a cosmic
[
`Buffer`
]
#[derive(Clone,
Component,
PartialEq,
Default)]
pub
enum
CosmicWrap
{
InfiniteLine
,
...
...
@@ -9,7 +9,7 @@ pub enum CosmicWrap {
Wrap
,
}
/// Enum representing the text alignment in a cosmic `Buffer`
/// Enum representing the text alignment in a cosmic
[
`Buffer`
]
#[derive(Clone,
Component)]
pub
enum
CosmicTextAlign
{
Center
{
padding
:
i32
},
...
...
@@ -23,19 +23,19 @@ impl Default for CosmicTextAlign {
}
}
/// Tag component to disable writing to a `CosmicBuffer`
/// Tag component to disable writing to a
[
`CosmicBuffer`
]
// TODO: Code example
#[derive(Component)]
pub
struct
ReadOnly
;
// tag component
/// Internal value used to decide what section of a `Buffer` to render
/// Internal value used to decide what section of a
[
`Buffer`
]
to render
#[derive(Component,
Debug,
Default)]
pub
struct
XOffset
{
pub
left
:
f32
,
pub
width
:
f32
,
}
/// Default text attributes to be used on a `CosmicBuffer`
/// Default text attributes to be used on a
[
`CosmicBuffer`
]
#[derive(Component,
Deref,
DerefMut)]
pub
struct
DefaultAttrs
(
pub
AttrsOwned
);
...
...
@@ -70,7 +70,7 @@ pub struct MaxLines(pub usize);
#[derive(Component,
Default)]
pub
struct
MaxChars
(
pub
usize
);
/// A pointer to an entity with a `CosmicEditBundle`, used to apply cosmic rendering to a UI
/// A pointer to an entity with a
[
`CosmicEditBundle`
]
, used to apply cosmic rendering to a UI
/// element.
///
///```
...
...
@@ -78,41 +78,37 @@ pub struct MaxChars(pub usize);
/// # use bevy_cosmic_edit::*;
/// #
/// # fn setup(mut commands: Commands) {
///
// Create a new cosmic bundle
///
let cosmic_edit = commands.spawn(CosmicEditBundle::default()).id();
/// // Create a new cosmic bundle
/// let cosmic_edit = commands.spawn(CosmicEditBundle::default()).id();
///
/// // Spawn the target bundle
/// commands
/// .spawn(ButtonBundle {
/// style: Style {
/// width: Val::Percent(100.),
/// height: Val::Percent(100.),
/// ..default()
/// },
/// background_color: BackgroundColor(Color::WHITE),
/// ..default()
/// })
/// // Add the source component to the target element
/// .insert(CosmicSource(cosmic_edit));
/// # }
/// #
/// # fn presetup(mut commands: Commands) {
/// # commands.spawn(Camera2dBundle::default());
/// // Spawn the target bundle
/// commands
/// .spawn(ButtonBundle {
/// style: Style {
/// width: Val::Percent(100.),
/// height: Val::Percent(100.),
/// ..default()
/// },
/// background_color: BackgroundColor(Color::WHITE),
/// ..default()
/// })
/// // Add the source component to the target element
/// .insert(CosmicSource(cosmic_edit));
/// # }
/// #
/// # fn main() {
/// # App::new()
/// # .add_plugins(MinimalPlugins)
/// # .add_plugins(CosmicEditPlugin::default())
/// # .add_systems(Startup,
(pre
setup
, setup)
);
/// # .add_systems(Startup, setup);
/// # }
#[derive(Component)]
pub
struct
CosmicSource
(
pub
Entity
);
/// A bundle containing all the required components for `CosmicBuffer` functionality.
/// A bundle containing all the required components for
[
`CosmicBuffer`
]
functionality.
///
/// Uses an invisible `SpriteBundle` for rendering by default, so should either be paired with another
/// entity with a `CosmicSource` pointing to it's entity, or have the sprite set.
/// Uses an invisible
[
`SpriteBundle`
]
for rendering by default, so should either be paired with another
/// entity with a
[
`CosmicSource`
]
pointing to it's entity, or have the sprite set.
///
/// ### UI mode
///
...
...
@@ -121,33 +117,29 @@ pub struct CosmicSource(pub Entity);
/// # use bevy_cosmic_edit::*;
/// #
/// # fn setup(mut commands: Commands) {
///
// Create a new cosmic bundle
///
let cosmic_edit = commands.spawn(CosmicEditBundle::default()).id();
/// // Create a new cosmic bundle
/// let cosmic_edit = commands.spawn(CosmicEditBundle::default()).id();
///
/// // Spawn the target bundle
/// commands
/// .spawn(ButtonBundle {
/// style: Style {
/// width: Val::Percent(100.),
/// height: Val::Percent(100.),
/// ..default()
/// },
/// background_color: BackgroundColor(Color::WHITE),
/// ..default()
/// })
/// // Add the source component to the target element
/// .insert(CosmicSource(cosmic_edit));
/// # }
/// #
/// # fn presetup(mut commands: Commands) {
/// # commands.spawn(Camera2dBundle::default());
/// // Spawn the target bundle
/// commands
/// .spawn(ButtonBundle {
/// style: Style {
/// width: Val::Percent(100.),
/// height: Val::Percent(100.),
/// ..default()
/// },
/// background_color: BackgroundColor(Color::WHITE),
/// ..default()
/// })
/// // Add the source component to the target element
/// .insert(CosmicSource(cosmic_edit));
/// # }
/// #
/// # fn main() {
/// # App::new()
/// # .add_plugins(MinimalPlugins)
/// # .add_plugins(CosmicEditPlugin::default())
/// # .add_systems(Startup,
(pre
setup
, setup)
);
/// # .add_systems(Startup, setup);
/// # }
/// ```
/// ### Sprite mode
...
...
@@ -169,15 +161,11 @@ pub struct CosmicSource(pub Entity);
/// });
/// # }
/// #
/// # fn presetup(mut commands: Commands) {
/// # commands.spawn(Camera2dBundle::default());
/// # }
/// #
/// # fn main() {
/// # App::new()
/// # .add_plugins(MinimalPlugins)
/// # .add_plugins(CosmicEditPlugin::default())
/// # .add_systems(Startup,
(pre
setup
, setup)
);
/// # .add_systems(Startup, setup);
/// # }
#[derive(Bundle)]
pub
struct
CosmicEditBundle
{
...
...
@@ -229,11 +217,11 @@ impl Default for CosmicEditBundle {
}
}
/// Holds the font system used internally by `cosmic_text`
/// Holds the font system used internally by
[
`cosmic_text`
]
#[derive(Resource,
Deref,
DerefMut)]
pub
struct
CosmicFontSystem
(
pub
FontSystem
);
/// Wrapper component for an `Editor` with a few helpful values for cursor blinking
/// Wrapper component for an
[
`Editor`
]
with a few helpful values for cursor blinking
#[derive(Component,
Deref,
DerefMut)]
pub
struct
CosmicEditor
{
#[deref]
...
...
This diff is collapsed.
Click to expand it.
src/events.rs
+
1
−
1
View file @
b0b789fa
...
...
@@ -13,6 +13,6 @@ impl Plugin for EventsPlugin {
/// 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`
/// Contains the entity on which the text was changed, and the new text as a
[
`String`
]
#[derive(Event,
Debug)]
pub
struct
CosmicTextChanged
(
pub
(
Entity
,
String
));
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment