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
db074eb6
Commit
db074eb6
authored
1 year ago
by
sam edelsten
Browse files
Options
Downloads
Patches
Plain Diff
refactor readonly example to new API
also noticed some more broken things, made a TODO to track them
parent
92e60fe0
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
TODO
+8
-0
8 additions, 0 deletions
TODO
examples/readonly.rs
+38
-27
38 additions, 27 deletions
examples/readonly.rs
src/lib.rs
+22
-22
22 additions, 22 deletions
src/lib.rs
with
68 additions
and
49 deletions
TODO
0 → 100644
+
8
−
0
View file @
db074eb6
[ ] Friendly get/set text fns on CosmicEditor impl
BUGS INTRODUCED:
[ ] Font size has been changed somehow
[ ] No cursor on readonly
[ ] Window resizing broken
\ No newline at end of file
This diff is collapsed.
Click to expand it.
examples/readonly.rs
+
38
−
27
View file @
db074eb6
use
bevy
::{
prelude
::
*
,
window
::
PrimaryWindow
};
use
bevy
::{
prelude
::
*
,
window
::
PrimaryWindow
};
use
bevy_cosmic_edit
::{
use
bevy_cosmic_edit
::{
c
reate_cosmic_font_system
,
spawn_c
osmic_edit
,
ActiveEditor
,
Cosmic
EditMeta
,
CosmicEditPlugin
,
cosmic_edi
t_set_tex
t
,
ActiveEditor
,
Cosmic
Attrs
,
CosmicEditPlugin
,
CosmicEditUiBundle
,
CosmicFont
,
CosmicFont
Config
,
CosmicMetrics
,
CosmicNode
,
CosmicText
,
CosmicTextPos
,
CosmicFont
Config
,
CosmicFont
System
,
CosmicMetrics
,
CosmicText
,
CosmicTextPos
ition
,
ReadOnly
,
};
};
use
cosmic_text
::
AttrsOwned
;
use
cosmic_text
::
AttrsOwned
;
fn
setup
(
fn
setup
(
mut
commands
:
Commands
,
mut
commands
:
Commands
,
windows
:
Query
<&
Window
,
With
<
PrimaryWindow
>>
,
windows
:
Query
<&
Window
,
With
<
PrimaryWindow
>>
,
mut
cosmic_fonts
:
ResMut
<
Assets
<
CosmicFont
>
>
,
mut
font_system
:
ResMut
<
CosmicFont
System
>
,
)
{
)
{
let
primary_window
=
windows
.single
();
let
primary_window
=
windows
.single
();
commands
.spawn
(
Camera2dBundle
::
default
());
commands
.spawn
(
Camera2dBundle
::
default
());
...
@@ -23,45 +23,56 @@ fn setup(
...
@@ -23,45 +23,56 @@ fn setup(
..
default
()
..
default
()
})
})
.id
();
.id
();
let
font_bytes
:
&
[
u8
]
=
include_bytes!
(
"../assets/fonts/VictorMono-Regular.ttf"
);
let
cosmic_font_config
=
CosmicFontConfig
{
fonts_dir_path
:
None
,
font_bytes
:
Some
(
vec!
[
font_bytes
]),
load_system_fonts
:
true
,
};
let
font_system
=
create_cosmic_font_system
(
cosmic_font_config
);
let
font_system_handle
=
cosmic_fonts
.add
(
CosmicFont
(
font_system
));
let
mut
attrs
=
cosmic_text
::
Attrs
::
new
();
let
mut
attrs
=
cosmic_text
::
Attrs
::
new
();
attrs
=
attrs
.family
(
cosmic_text
::
Family
::
Name
(
"Victor Mono"
));
attrs
=
attrs
.family
(
cosmic_text
::
Family
::
Name
(
"Victor Mono"
));
attrs
=
attrs
.color
(
cosmic_text
::
Color
::
rgb
(
0x94
,
0x00
,
0xD3
));
attrs
=
attrs
.color
(
cosmic_text
::
Color
::
rgb
(
0x94
,
0x00
,
0xD3
));
let
cosmic_edit_meta
=
CosmicEditMeta
{
text
:
CosmicText
::
OneStyle
(
"😀😀😀 x => y
\n
Read only widget"
.to_string
()),
//
attrs
:
AttrsOwned
::
new
(
attrs
),
let
mut
cosmic_edit
=
CosmicEditUiBundle
{
text_pos
:
CosmicTextPos
::
Center
,
style
:
Style
{
bg
:
Color
::
WHITE
,
width
:
Val
::
Percent
(
100.
),
metrics
:
CosmicMetrics
{
height
:
Val
::
Percent
(
100.
),
..
default
()
},
cosmic_attrs
:
CosmicAttrs
(
AttrsOwned
::
new
(
attrs
)),
text_position
:
CosmicTextPosition
::
Center
,
background_color
:
BackgroundColor
(
Color
::
WHITE
),
cosmic_metrics
:
CosmicMetrics
{
font_size
:
14.
,
font_size
:
14.
,
line_height
:
18.
,
line_height
:
18.
,
scale_factor
:
primary_window
.scale_factor
()
as
f32
,
scale_factor
:
primary_window
.scale_factor
()
as
f32
,
},
},
font_system_handle
,
..
default
()
node
:
CosmicNode
::
Ui
,
size
:
None
,
readonly
:
true
,
bg_image
:
None
,
};
};
let
cosmic_edit
=
spawn_cosmic_edit
(
&
mut
commands
,
&
mut
cosmic_fonts
,
cosmic_edit_meta
);
commands
.entity
(
root
)
.add_child
(
cosmic_edit
);
cosmic_edit_set_text
(
commands
.insert_resource
(
ActiveEditor
{
CosmicText
::
OneStyle
(
"😀😀😀 x => y
\n
Read only widget"
.to_string
()),
entity
:
Some
(
cosmic_edit
),
AttrsOwned
::
new
(
attrs
),
&
mut
cosmic_edit
.editor
.0
,
&
mut
font_system
.0
,
);
//
let
mut
id
=
None
;
commands
.entity
(
root
)
.with_children
(|
parent
|
{
id
=
Some
(
parent
.spawn
(
cosmic_edit
)
.insert
(
ReadOnly
)
.id
());
});
});
commands
.insert_resource
(
ActiveEditor
{
entity
:
id
});
}
}
fn
main
()
{
fn
main
()
{
let
font_bytes
:
&
[
u8
]
=
include_bytes!
(
"../assets/fonts/VictorMono-Regular.ttf"
);
let
font_config
=
CosmicFontConfig
{
fonts_dir_path
:
None
,
font_bytes
:
Some
(
vec!
[
font_bytes
]),
load_system_fonts
:
true
,
};
App
::
new
()
App
::
new
()
.add_plugins
(
DefaultPlugins
)
.add_plugins
(
DefaultPlugins
)
.add_plugins
(
CosmicEditPlugin
)
.add_plugins
(
CosmicEditPlugin
{
font_config
}
)
.add_systems
(
Startup
,
setup
)
.add_systems
(
Startup
,
setup
)
.run
();
.run
();
}
}
This diff is collapsed.
Click to expand it.
src/lib.rs
+
22
−
22
View file @
db074eb6
...
@@ -19,20 +19,6 @@ use cosmic_text::{
...
@@ -19,20 +19,6 @@ use cosmic_text::{
};
};
use
image
::{
imageops
::
FilterType
,
GenericImageView
};
use
image
::{
imageops
::
FilterType
,
GenericImageView
};
#[derive(Clone)]
pub
struct
CosmicEditUi
;
#[derive(Clone)]
pub
struct
CosmicEditSprite
{
pub
transform
:
Transform
,
}
#[derive(Clone)]
pub
enum
CosmicNode
{
Ui
,
Sprite
(
CosmicEditSprite
),
}
#[derive(Clone)]
#[derive(Clone)]
pub
enum
CosmicText
{
pub
enum
CosmicText
{
OneStyle
(
String
),
OneStyle
(
String
),
...
@@ -66,7 +52,7 @@ impl Default for CosmicMetrics {
...
@@ -66,7 +52,7 @@ impl Default for CosmicMetrics {
}
}
#[derive(Resource)]
#[derive(Resource)]
pub
struct
CosmicFontSystem
(
FontSystem
);
pub
struct
CosmicFontSystem
(
pub
FontSystem
);
#[derive(Component)]
#[derive(Component)]
pub
struct
ReadOnly
;
// tag component
pub
struct
ReadOnly
;
// tag component
...
@@ -85,18 +71,27 @@ impl Default for CosmicEditor {
...
@@ -85,18 +71,27 @@ impl Default for CosmicEditor {
/// Adds the font system to each editor when added
/// Adds the font system to each editor when added
fn
cosmic_editor_builder
(
fn
cosmic_editor_builder
(
mut
added_editors
:
Query
<&
mut
CosmicEditor
,
Added
<
CosmicEditor
>>
,
mut
added_editors
:
Query
<
(
&
mut
CosmicEditor
,
&
CosmicAttrs
),
Added
<
CosmicEditor
>>
,
mut
font_system
:
ResMut
<
CosmicFontSystem
>
,
mut
font_system
:
ResMut
<
CosmicFontSystem
>
,
)
{
)
{
for
mut
editor
in
added_editors
.iter_mut
()
{
for
(
mut
editor
,
attrs
)
in
added_editors
.iter_mut
()
{
editor
// keep old text if set
.0
let
mut
text
=
get_cosmic_text
(
editor
.0
.buffer
());
.buffer_mut
()
.set_text
(
&
mut
font_system
.0
,
""
,
Attrs
::
new
(),
Shaping
::
Advanced
);
if
text
.is_empty
()
{
text
=
""
.into
();
}
editor
.0
.buffer_mut
()
.set_text
(
&
mut
font_system
.0
,
text
.as_str
(),
attrs
.0
.as_attrs
(),
Shaping
::
Advanced
,
);
editor
editor
.0
.0
.buffer_mut
()
.buffer_mut
()
// TODO size here????
.set_size
(
&
mut
font_system
.0
,
100.
,
100.
)
.set_size
(
&
mut
font_system
.0
,
100.
,
100.
)
}
}
}
}
...
@@ -410,9 +405,12 @@ pub fn cosmic_edit_set_text(
...
@@ -410,9 +405,12 @@ pub fn cosmic_edit_set_text(
editor
:
&
mut
Editor
,
editor
:
&
mut
Editor
,
font_system
:
&
mut
FontSystem
,
font_system
:
&
mut
FontSystem
,
)
{
)
{
println!
(
"SETTING TEXT"
);
editor
.buffer_mut
()
.lines
.clear
();
editor
.buffer_mut
()
.lines
.clear
();
match
text
{
match
text
{
CosmicText
::
OneStyle
(
text
)
=>
{
CosmicText
::
OneStyle
(
text
)
=>
{
println!
(
"ONESTYLE {:?}, {:?}"
,
text
,
attrs
);
editor
.buffer_mut
()
.set_text
(
editor
.buffer_mut
()
.set_text
(
font_system
,
font_system
,
text
.as_str
(),
text
.as_str
(),
...
@@ -421,6 +419,8 @@ pub fn cosmic_edit_set_text(
...
@@ -421,6 +419,8 @@ pub fn cosmic_edit_set_text(
);
);
}
}
CosmicText
::
MultiStyle
(
lines
)
=>
{
CosmicText
::
MultiStyle
(
lines
)
=>
{
println!
(
"M-M-M-M-MULTI-STYLE"
);
for
line
in
lines
{
for
line
in
lines
{
let
mut
line_text
=
String
::
new
();
let
mut
line_text
=
String
::
new
();
let
mut
attrs_list
=
AttrsList
::
new
(
attrs
.as_attrs
());
let
mut
attrs_list
=
AttrsList
::
new
(
attrs
.as_attrs
());
...
...
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