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
74b06651
Commit
74b06651
authored
1 year ago
by
sam edelsten
Browse files
Options
Downloads
Patches
Plain Diff
tidy up
parent
b6d22da1
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
assets/fonts/FiraMono-Regular.ttf
+0
-0
0 additions, 0 deletions
assets/fonts/FiraMono-Regular.ttf
examples/login.rs
+90
-28
90 additions, 28 deletions
examples/login.rs
src/lib.rs
+3
-3
3 additions, 3 deletions
src/lib.rs
src/render.rs
+7
-8
7 additions, 8 deletions
src/render.rs
with
100 additions
and
39 deletions
assets/fonts/FiraMono-Regular.ttf
deleted
100644 → 0
+
0
−
0
View file @
b6d22da1
File deleted
This diff is collapsed.
Click to expand it.
examples/login.rs
+
90
−
28
View file @
74b06651
use
bevy
::{
prelude
::
*
,
window
::
PrimaryWindow
};
use
bevy
::{
prelude
::
*
,
window
::{
PrimaryWindow
,
WindowResolution
},
};
use
bevy_cosmic_edit
::
*
;
fn
setup
(
mut
commands
:
Commands
,
window
:
Query
<&
Window
,
With
<
PrimaryWindow
>>
)
{
let
window
=
window
.single
();
#[derive(Component)]
struct
SubmitButton
;
#[derive(Component)]
struct
UsernameTag
;
#[derive(Component)]
struct
PasswordTag
;
#[derive(Component)]
struct
DisplayTag
;
fn
setup
(
mut
commands
:
Commands
,
mut
window
:
Query
<&
mut
Window
,
With
<
PrimaryWindow
>>
)
{
let
mut
window
=
window
.single_mut
();
window
.resolution
=
WindowResolution
::
new
(
330.0
,
480.0
);
commands
.spawn
(
Camera2dBundle
::
default
());
...
...
@@ -10,7 +27,10 @@ fn setup(mut commands: Commands, window: Query<&Window, With<PrimaryWindow>>) {
.spawn
(
NodeBundle
{
style
:
Style
{
flex_direction
:
FlexDirection
::
Column
,
width
:
Val
::
Px
(
300.0
),
align_items
:
AlignItems
::
Center
,
padding
:
UiRect
::
all
(
Val
::
Px
(
15.0
)),
width
:
Val
::
Px
(
330.0
),
..
default
()
},
..
default
()
...
...
@@ -40,7 +60,8 @@ fn setup(mut commands: Commands, window: Query<&Window, With<PrimaryWindow>>) {
attrs
:
PlaceholderAttrs
(
AttrsOwned
::
new
(
Attrs
::
new
()
.color
(
bevy_color_to_cosmic
(
Color
::
rgb_u8
(
128
,
128
,
128
))),
)),
});
})
.insert
(
UsernameTag
);
root
.spawn
(
CosmicEditBundle
{
max_lines
:
CosmicMaxLines
(
1
),
...
...
@@ -62,42 +83,47 @@ fn setup(mut commands: Commands, window: Query<&Window, With<PrimaryWindow>>) {
..
default
()
})
.insert
(
CosmicEditPlaceholderBundle
{
text_setter
:
PlaceholderText
(
CosmicText
::
OneStyle
(
"Password
●
"
.into
())),
text_setter
:
PlaceholderText
(
CosmicText
::
OneStyle
(
"Password"
.into
())),
attrs
:
PlaceholderAttrs
(
AttrsOwned
::
new
(
Attrs
::
new
()
.color
(
bevy_color_to_cosmic
(
Color
::
rgb_u8
(
128
,
128
,
128
))),
)),
})
.insert
(
PasswordInput
(
'●'
));
.insert
(
PasswordTag
)
.insert
(
PasswordInput
::
default
());
root
.spawn
(
CosmicEditBundle
{
max_lines
:
CosmicMaxLines
(
1
),
metrics
:
CosmicMetrics
{
font_size
:
25.0
,
line_height
:
25.0
,
scale_factor
:
window
.scale_factor
()
as
f32
,
..
default
()
},
attrs
:
CosmicAttrs
(
AttrsOwned
::
new
(
Attrs
::
new
()
.color
(
bevy_color_to_cosmic
(
Color
::
WHITE
)),
)),
text_setter
:
CosmicText
::
OneStyle
(
"Submit"
.into
()),
fill_color
:
FillColor
(
Color
::
GREEN
),
..
default
()
})
.insert
(
ButtonBundle
{
style
:
Style
{
// Size and position of text box
width
:
Val
::
Px
(
30
0.
),
width
:
Val
::
Px
(
15
0.
),
height
:
Val
::
Px
(
50.
),
margin
:
UiRect
::
all
(
Val
::
Px
(
15.0
)),
border
:
UiRect
::
all
(
Val
::
Px
(
3.0
)),
..
default
()
},
background_color
:
BackgroundColor
(
Color
::
WHITE
),
border_color
:
Color
::
DARK_GREEN
.into
(),
..
default
()
})
.insert
(
CosmicEditPlaceholderBundle
{
text_setter
:
PlaceholderText
(
CosmicText
::
OneStyle
(
"Password 🙊"
.into
())),
attrs
:
PlaceholderAttrs
(
AttrsOwned
::
new
(
Attrs
::
new
()
.color
(
bevy_color_to_cosmic
(
Color
::
rgb_u8
(
128
,
128
,
128
))),
)),
})
.insert
(
PasswordInput
(
'🙊'
));
.insert
(
SubmitButton
)
.insert
(
ReadOnly
);
root
.spawn
(
CosmicEditBundle
{
max_lines
:
CosmicMaxLines
(
1
),
metrics
:
CosmicMetrics
{
scale_factor
:
window
.scale_factor
()
as
f32
,
..
default
()
...
...
@@ -108,7 +134,7 @@ fn setup(mut commands: Commands, window: Query<&Window, With<PrimaryWindow>>) {
style
:
Style
{
// Size and position of text box
width
:
Val
::
Px
(
300.
),
height
:
Val
::
Px
(
5
0.
),
height
:
Val
::
Px
(
10
0.
),
margin
:
UiRect
::
all
(
Val
::
Px
(
15.0
)),
..
default
()
},
...
...
@@ -116,12 +142,12 @@ fn setup(mut commands: Commands, window: Query<&Window, With<PrimaryWindow>>) {
..
default
()
})
.insert
(
CosmicEditPlaceholderBundle
{
text_setter
:
PlaceholderText
(
CosmicText
::
OneStyle
(
"
Password -
"
.into
())),
text_setter
:
PlaceholderText
(
CosmicText
::
OneStyle
(
"
Output
"
.into
())),
attrs
:
PlaceholderAttrs
(
AttrsOwned
::
new
(
Attrs
::
new
()
.color
(
bevy_color_to_cosmic
(
Color
::
rgb_u8
(
128
,
128
,
128
))),
)),
})
.insert
(
PasswordInput
(
'-'
));
.insert
(
(
ReadOnly
,
DisplayTag
));
});
}
...
...
@@ -157,23 +183,59 @@ fn print_changed_input(mut evr_type: EventReader<CosmicTextChanged>) {
}
}
fn
main
()
{
let
font_bytes
:
&
[
u8
]
=
include_bytes!
(
"../assets/fonts/FiraMono-Regular.ttf"
);
let
font_config
=
CosmicFontConfig
{
fonts_dir_path
:
None
,
font_bytes
:
Some
(
vec!
[
font_bytes
]),
load_system_fonts
:
true
,
};
fn
submit_button
(
button_q
:
Query
<&
Interaction
,
With
<
SubmitButton
>>
,
username_q
:
Query
<
&
CosmicEditor
,
(
With
<
UsernameTag
>
,
Without
<
PasswordTag
>
,
Without
<
DisplayTag
>
),
>
,
password_q
:
Query
<
&
CosmicEditor
,
(
With
<
PasswordTag
>
,
Without
<
UsernameTag
>
,
Without
<
DisplayTag
>
),
>
,
mut
display_q
:
Query
<
(
&
mut
CosmicEditor
,
&
CosmicAttrs
),
(
With
<
DisplayTag
>
,
Without
<
UsernameTag
>
,
Without
<
PasswordTag
>
),
>
,
mut
font_system
:
ResMut
<
CosmicFontSystem
>
,
mut
window
:
Query
<&
mut
Window
,
With
<
PrimaryWindow
>>
,
)
{
for
interaction
in
button_q
.iter
()
{
match
interaction
{
Interaction
::
None
=>
{}
Interaction
::
Pressed
=>
{
let
u
=
username_q
.single
();
let
p
=
password_q
.single
();
let
(
mut
d
,
attrs
)
=
display_q
.single_mut
();
let
text
=
format!
(
"Submitted!
\n
Username: {}
\n
Password: {}
\n
"
,
u
.get_text
(),
p
.get_text
()
);
d
.set_text
(
CosmicText
::
OneStyle
(
text
),
attrs
.0
.clone
(),
&
mut
font_system
.0
,
);
}
Interaction
::
Hovered
=>
{
window
.single_mut
()
.cursor.icon
=
CursorIcon
::
Hand
;
}
}
}
}
fn
main
()
{
App
::
new
()
.add_plugins
(
DefaultPlugins
)
.add_plugins
(
CosmicEditPlugin
{
change_cursor
:
CursorConfig
::
Default
,
font_config
,
..
default
()
})
.add_systems
(
Startup
,
setup
)
.add_systems
(
Update
,
change_active_editor_ui
)
.add_systems
(
Update
,
print_changed_input
)
.add_systems
(
Update
,
(
print_changed_input
,
submit_button
)
)
.run
();
}
This diff is collapsed.
Click to expand it.
src/lib.rs
+
3
−
3
View file @
74b06651
...
...
@@ -22,7 +22,7 @@ use input::{poll_wasm_paste, WasmPaste, WasmPasteAsyncChannel};
use
render
::{
blink_cursor
,
cosmic_edit_redraw_buffer
,
freeze_cursor_blink
,
hide_inactive_or_readonly_cursor
,
hide_password_text
,
on_scale_factor_change
,
restore_password_text
,
set_initial_scale
,
CursorBlinkTimer
,
CursorVisibility
,
Password
Stat
es
,
SwashCacheState
,
CursorBlinkTimer
,
CursorVisibility
,
Password
Valu
es
,
SwashCacheState
,
};
#[cfg(feature
=
"multicam"
)]
...
...
@@ -106,7 +106,7 @@ struct XOffset(Option<(f32, f32)>);
pub
struct
CosmicEditor
(
pub
Editor
);
impl
CosmicEditor
{
fn
set_text
(
pub
fn
set_text
(
&
mut
self
,
text
:
CosmicText
,
attrs
:
AttrsOwned
,
...
...
@@ -341,7 +341,7 @@ impl Plugin for CosmicEditPlugin {
),
)
.init_resource
::
<
Focus
>
()
.init_resource
::
<
Password
Stat
es
>
()
.init_resource
::
<
Password
Valu
es
>
()
.insert_resource
(
CursorBlinkTimer
(
Timer
::
from_seconds
(
0.53
,
TimerMode
::
Repeating
,
...
...
This diff is collapsed.
Click to expand it.
src/render.rs
+
7
−
8
View file @
74b06651
...
...
@@ -28,6 +28,9 @@ pub(crate) struct CursorBlinkTimer(pub Timer);
#[derive(Resource)]
pub
(
crate
)
struct
CursorVisibility
(
pub
bool
);
#[derive(Resource,
Default)]
pub
(
crate
)
struct
PasswordValues
(
pub
HashMap
<
Entity
,
(
String
,
usize
)
>
);
pub
(
crate
)
fn
cosmic_edit_redraw_buffer
(
windows
:
Query
<&
Window
,
With
<
PrimaryWindow
>>
,
mut
images
:
ResMut
<
Assets
<
Image
>>
,
...
...
@@ -413,7 +416,7 @@ pub(crate) fn hide_inactive_or_readonly_cursor(
let
editor
=
&
mut
editor
.0
;
let
mut
cursor
=
editor
.0
.cursor
();
if
cursor
.color
==
Some
(
cosmic_text
::
Color
::
rgba
(
0
,
0
,
0
,
0
))
{
return
;
continue
;
}
cursor
.color
=
Some
(
cosmic_text
::
Color
::
rgba
(
0
,
0
,
0
,
0
));
editor
.0
.set_cursor
(
cursor
);
...
...
@@ -425,7 +428,7 @@ pub(crate) fn hide_inactive_or_readonly_cursor(
if
active_editor
.is_none
()
||
e
!=
active_editor
.0
.unwrap
()
{
let
mut
cursor
=
editor
.0
.cursor
();
if
cursor
.color
==
Some
(
cosmic_text
::
Color
::
rgba
(
0
,
0
,
0
,
0
))
{
return
;
continue
;
}
cursor
.color
=
Some
(
cosmic_text
::
Color
::
rgba
(
0
,
0
,
0
,
0
));
editor
.0
.set_cursor
(
cursor
);
...
...
@@ -499,13 +502,10 @@ pub(crate) fn update_handle_sprite(
}
}
#[derive(Resource,
Default)]
pub
(
crate
)
struct
PasswordStates
(
pub
HashMap
<
Entity
,
(
String
,
usize
)
>
);
pub
(
crate
)
fn
hide_password_text
(
mut
editor_q
:
Query
<
(
Entity
,
&
mut
CosmicEditor
,
&
CosmicAttrs
,
&
PasswordInput
)
>
,
mut
font_system
:
ResMut
<
CosmicFontSystem
>
,
mut
password_input_states
:
ResMut
<
Password
Stat
es
>
,
mut
password_input_states
:
ResMut
<
Password
Valu
es
>
,
active_editor
:
Res
<
Focus
>
,
)
{
for
(
entity
,
mut
cosmic_editor
,
attrs
,
password
)
in
editor_q
.iter_mut
()
{
...
...
@@ -562,11 +562,10 @@ pub(crate) fn hide_password_text(
pub
(
crate
)
fn
restore_password_text
(
mut
editor_q
:
Query
<
(
Entity
,
&
mut
CosmicEditor
,
&
CosmicAttrs
,
&
PasswordInput
)
>
,
mut
font_system
:
ResMut
<
CosmicFontSystem
>
,
password_input_states
:
Res
<
Password
Stat
es
>
,
password_input_states
:
Res
<
Password
Valu
es
>
,
)
{
for
(
entity
,
mut
cosmic_editor
,
attrs
,
password
)
in
editor_q
.iter_mut
()
{
if
let
Some
((
text
,
_glyph_idx
))
=
password_input_states
.0
.get
(
&
entity
)
{
// reset intercepted text
if
!
text
.is_empty
()
{
let
char_len
=
password
.0
.len_utf8
();
...
...
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