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
5a610baa
Commit
5a610baa
authored
1 year ago
by
sam edelsten
Browse files
Options
Downloads
Patches
Plain Diff
further clean up `lib.rs`
parent
ac95acd8
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/cosmic_edit.rs
+21
-0
21 additions, 0 deletions
src/cosmic_edit.rs
src/events.rs
+14
-0
14 additions, 0 deletions
src/events.rs
src/lib.rs
+5
-39
5 additions, 39 deletions
src/lib.rs
src/util.rs
+13
-0
13 additions, 0 deletions
src/util.rs
with
53 additions
and
39 deletions
src/cosmic_edit.rs
+
21
−
0
View file @
5a610baa
...
...
@@ -110,3 +110,24 @@ impl Default for CosmicEditBundle {
}
}
}
#[derive(Resource,
Deref,
DerefMut)]
pub
struct
CosmicFontSystem
(
pub
FontSystem
);
#[derive(Component,
Deref,
DerefMut)]
pub
struct
CosmicEditor
{
#[deref]
pub
editor
:
Editor
<
'static
>
,
pub
cursor_visible
:
bool
,
pub
cursor_timer
:
Timer
,
}
impl
CosmicEditor
{
pub
fn
new
(
editor
:
Editor
<
'static
>
)
->
Self
{
Self
{
editor
,
cursor_visible
:
true
,
cursor_timer
:
Timer
::
new
(
Duration
::
from_millis
(
530
),
TimerMode
::
Repeating
),
}
}
}
This diff is collapsed.
Click to expand it.
src/events.rs
0 → 100644
+
14
−
0
View file @
5a610baa
// File for all events, meant for easy documentation
use
bevy
::
prelude
::
*
;
pub
struct
EventsPlugin
;
impl
Plugin
for
EventsPlugin
{
fn
build
(
&
self
,
app
:
&
mut
App
)
{
app
.add_event
::
<
CosmicTextChanged
>
();
}
}
#[derive(Event,
Debug)]
pub
struct
CosmicTextChanged
(
pub
(
Entity
,
String
));
This diff is collapsed.
Click to expand it.
src/lib.rs
+
5
−
39
View file @
5a610baa
...
...
@@ -3,6 +3,7 @@
mod
buffer
;
mod
cosmic_edit
;
mod
cursor
;
mod
events
;
mod
focus
;
mod
input
;
mod
password
;
...
...
@@ -22,6 +23,7 @@ pub use cosmic_text::{
FontSystem
,
Metrics
,
Shaping
,
Style
as
FontStyle
,
Weight
as
FontWeight
,
};
pub
use
cursor
::
*
;
pub
use
events
::
*
;
pub
use
focus
::
*
;
pub
use
input
::
*
;
pub
use
password
::
*
;
...
...
@@ -29,6 +31,7 @@ pub use placeholder::*;
pub
use
render
::
*
;
pub
use
util
::
*
;
pub
use
widget
::
*
;
/// Plugin struct that adds systems and initializes resources related to cosmic edit functionality.
#[derive(Default)]
pub
struct
CosmicEditPlugin
{
...
...
@@ -51,9 +54,9 @@ impl Plugin for CosmicEditPlugin {
},
PlaceholderPlugin
,
PasswordPlugin
,
EventsPlugin
,
))
.insert_resource
(
CosmicFontSystem
(
font_system
))
.add_event
::
<
CosmicTextChanged
>
();
.insert_resource
(
CosmicFontSystem
(
font_system
));
#[cfg(target_arch
=
"wasm32"
)]
{
...
...
@@ -76,30 +79,6 @@ pub enum CursorConfig {
None
,
}
#[derive(Event,
Debug)]
pub
struct
CosmicTextChanged
(
pub
(
Entity
,
String
));
#[derive(Resource,
Deref,
DerefMut)]
pub
struct
CosmicFontSystem
(
pub
FontSystem
);
#[derive(Component,
Deref,
DerefMut)]
pub
struct
CosmicEditor
{
#[deref]
pub
editor
:
Editor
<
'static
>
,
pub
cursor_visible
:
bool
,
pub
cursor_timer
:
Timer
,
}
impl
CosmicEditor
{
fn
new
(
editor
:
Editor
<
'static
>
)
->
Self
{
Self
{
editor
,
cursor_visible
:
true
,
cursor_timer
:
Timer
::
new
(
Duration
::
from_millis
(
530
),
TimerMode
::
Repeating
),
}
}
}
/// Resource struct that holds configuration options for cosmic fonts.
#[derive(Resource,
Clone)]
pub
struct
CosmicFontConfig
{
...
...
@@ -136,19 +115,6 @@ fn create_cosmic_font_system(cosmic_font_config: CosmicFontConfig) -> FontSystem
cosmic_text
::
FontSystem
::
new_with_locale_and_db
(
locale
,
db
)
}
#[cfg(target_arch
=
"wasm32"
)]
pub
fn
get_timestamp
()
->
f64
{
js_sys
::
Date
::
now
()
}
#[cfg(not(target_arch
=
"wasm32"
))]
pub
fn
get_timestamp
()
->
f64
{
use
std
::
time
::
SystemTime
;
use
std
::
time
::
UNIX_EPOCH
;
let
duration
=
SystemTime
::
now
()
.duration_since
(
UNIX_EPOCH
)
.unwrap
();
duration
.as_millis
()
as
f64
}
#[cfg(test)]
mod
tests
{
use
crate
::
*
;
...
...
This diff is collapsed.
Click to expand it.
src/util.rs
+
13
−
0
View file @
5a610baa
...
...
@@ -118,3 +118,16 @@ pub fn bevy_color_to_cosmic(color: bevy::prelude::Color) -> CosmicColor {
(
color
.a
()
*
255.
)
as
u8
,
)
}
#[cfg(target_arch
=
"wasm32"
)]
pub
fn
get_timestamp
()
->
f64
{
js_sys
::
Date
::
now
()
}
#[cfg(not(target_arch
=
"wasm32"
))]
pub
fn
get_timestamp
()
->
f64
{
use
std
::
time
::
SystemTime
;
use
std
::
time
::
UNIX_EPOCH
;
let
duration
=
SystemTime
::
now
()
.duration_since
(
UNIX_EPOCH
)
.unwrap
();
duration
.as_millis
()
as
f64
}
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