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
e48b3aec
Commit
e48b3aec
authored
1 year ago
by
sam edelsten
Browse files
Options
Downloads
Patches
Plain Diff
set scale factor to login
parent
5f83124d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/login.rs
+11
-32
11 additions, 32 deletions
examples/login.rs
with
11 additions
and
32 deletions
examples/login.rs
+
11
−
32
View file @
e48b3aec
use
bevy
::{
prelude
::
*
,
window
::
PrimaryWindow
};
use
bevy
::{
prelude
::
*
,
window
::
PrimaryWindow
};
use
bevy_cosmic_edit
::
*
;
use
bevy_cosmic_edit
::
*
;
fn
setup
(
mut
commands
:
Commands
)
{
fn
setup
(
mut
commands
:
Commands
,
window
:
Query
<&
Window
,
With
<
PrimaryWindow
>>
)
{
let
window
=
window
.single
();
commands
.spawn
(
Camera2dBundle
::
default
());
commands
.spawn
(
Camera2dBundle
::
default
());
commands
commands
...
@@ -16,6 +18,10 @@ fn setup(mut commands: Commands) {
...
@@ -16,6 +18,10 @@ fn setup(mut commands: Commands) {
.with_children
(|
root
|
{
.with_children
(|
root
|
{
root
.spawn
(
CosmicEditBundle
{
root
.spawn
(
CosmicEditBundle
{
max_lines
:
CosmicMaxLines
(
1
),
max_lines
:
CosmicMaxLines
(
1
),
metrics
:
CosmicMetrics
{
scale_factor
:
window
.scale_factor
()
as
f32
,
..
default
()
},
..
default
()
..
default
()
})
})
.insert
(
ButtonBundle
{
.insert
(
ButtonBundle
{
...
@@ -38,6 +44,10 @@ fn setup(mut commands: Commands) {
...
@@ -38,6 +44,10 @@ fn setup(mut commands: Commands) {
root
.spawn
(
CosmicEditBundle
{
root
.spawn
(
CosmicEditBundle
{
max_lines
:
CosmicMaxLines
(
1
),
max_lines
:
CosmicMaxLines
(
1
),
metrics
:
CosmicMetrics
{
scale_factor
:
window
.scale_factor
()
as
f32
,
..
default
()
},
..
default
()
..
default
()
})
})
.insert
(
ButtonBundle
{
.insert
(
ButtonBundle
{
...
@@ -87,36 +97,6 @@ fn change_active_editor_ui(
...
@@ -87,36 +97,6 @@ fn change_active_editor_ui(
}
}
}
}
fn
change_active_editor_sprite
(
mut
commands
:
Commands
,
windows
:
Query
<&
Window
,
With
<
PrimaryWindow
>>
,
buttons
:
Res
<
Input
<
MouseButton
>>
,
mut
cosmic_edit_query
:
Query
<
(
&
mut
Sprite
,
&
GlobalTransform
,
Entity
),
(
With
<
CosmicEditor
>
,
Without
<
ReadOnly
>
),
>
,
camera_q
:
Query
<
(
&
Camera
,
&
GlobalTransform
)
>
,
)
{
let
window
=
windows
.single
();
let
(
camera
,
camera_transform
)
=
camera_q
.single
();
if
buttons
.just_pressed
(
MouseButton
::
Left
)
{
for
(
sprite
,
node_transform
,
entity
)
in
&
mut
cosmic_edit_query
.iter_mut
()
{
let
size
=
sprite
.custom_size
.unwrap_or
(
Vec2
::
new
(
1.
,
1.
));
let
x_min
=
node_transform
.affine
()
.translation.x
-
size
.x
/
2.
;
let
y_min
=
node_transform
.affine
()
.translation.y
-
size
.y
/
2.
;
let
x_max
=
node_transform
.affine
()
.translation.x
+
size
.x
/
2.
;
let
y_max
=
node_transform
.affine
()
.translation.y
+
size
.y
/
2.
;
if
let
Some
(
pos
)
=
window
.cursor_position
()
{
if
let
Some
(
pos
)
=
camera
.viewport_to_world_2d
(
camera_transform
,
pos
)
{
if
x_min
<
pos
.x
&&
pos
.x
<
x_max
&&
y_min
<
pos
.y
&&
pos
.y
<
y_max
{
commands
.insert_resource
(
Focus
(
Some
(
entity
)))
};
}
};
}
}
}
fn
print_changed_input
(
mut
evr_type
:
EventReader
<
CosmicTextChanged
>
)
{
fn
print_changed_input
(
mut
evr_type
:
EventReader
<
CosmicTextChanged
>
)
{
for
ev
in
evr_type
.iter
()
{
for
ev
in
evr_type
.iter
()
{
println!
(
"Changed: {}"
,
ev
.0
.1
);
println!
(
"Changed: {}"
,
ev
.0
.1
);
...
@@ -132,7 +112,6 @@ fn main() {
...
@@ -132,7 +112,6 @@ fn main() {
})
})
.add_systems
(
Startup
,
setup
)
.add_systems
(
Startup
,
setup
)
.add_systems
(
Update
,
change_active_editor_ui
)
.add_systems
(
Update
,
change_active_editor_ui
)
.add_systems
(
Update
,
change_active_editor_sprite
)
.add_systems
(
Update
,
print_changed_input
)
.add_systems
(
Update
,
print_changed_input
)
.run
();
.run
();
}
}
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