staffengineer / bevy_cosmic_edit Goto Github PK
View Code? Open in Web Editor NEWLicense: Apache License 2.0
License: Apache License 2.0
It's hardcoded currently:
Line 1029 in 3123ef0
Instead of ActiveEditor resource let's use Focus
component (or any other better named marker component).
Atm the FillColor
attribute still blends alpha/opacity, so it's impossible to have opaque text on a transparent background.
Not sure how to get access to the window scale from inside the impl Default for CosmicMetrics
block.
Could set the default to something stupid like 0.69696969
and have a system checking if that scale is set on anything, then set the scale to window scale.
Very open to suggestions here
On other text inputs holding a key will send one input, then wait a time, then repeat inputs for that key with a delay between inputs.
This applies to every input I can find, including paste, backspace, directions, return, delete.
Key repeat respects held modifiers like shift
and cmd
/ctrl
Might be smarter to implement a separate key repeat system that passes data to the input system, but that will introduce a 1 frame delay between input and action, and text input should be as immediate as possible to feel smooth.
winit
has an is_repeat
field on KeyEvent
, may be able to hook that somehow.
winit
has the ability to distinguish repeat keys in 0.29.X-beta
, which will obsolete a fix once released and picked up by bevy.
Add option to enable inner shadow
(see https://github.com/StaffEngineer/velo/blob/main/assets/shaders/shadows.wgsl for inspiration)
Will lead to cleaner system ordering, and let user fns run between or after internal stages.
If set_text
called with text length smaller than the current buffer cosmic-text panics due to cursor being out of bounds. Panic thrown in let text = self.text.split_off(index);
on cosmic-text side.
Steps to reproduce:
CosmicText
component.Action::Insert)
.Wasm can be done using https://rustwasm.github.io/wasm-bindgen/api/web_sys/struct.Clipboard.html with async API, ideally may be upstreamed to arboard
.
1-mouse-click: place cursor (already implemented by cosmic-text)
2-clicks: select word
3-clicks: select paragraph
(mimic behaviour of google translate text selection on mouse clicking)
Currently VictorMono is bundled, and has a fair footprint. Ideally the font should be as small as reasonably possible, as it will be included in all builds and downloads.
Currently text that can't fit into buffer becoming invisible and can be scrolled in buffer. Let's add feature for automatic buffer height adjustment based on content, so all buffer's content is always visible.
buffer.width = user_defined_width
image_width = user_defined_width
image_height = calc_buffer_height (one or more lines),
all visible (unless max height specified I guess)
Could be a key repeat (#63) issue
Per-input cursor granularity allows for creating styled "buttons" with cosmic text, without always having an I-beam cursor.
Selectability should be toggleable too, for the button use case at least.
I beam cursor when hovered, revert when not.
Line 286 in 5157cb3
(set_text is a bit weirdly looking, would be cool to implement syncing and rename it to text)
Something like https://github.com/johanhelsing/bevy_web_asset/blob/main/src/web_asset_io.rs#L26
This will allow to use emoji fonts on wasm without bloating the binary size.
Inputs [SHIFT][A][Backspace]
leaves the A, a second backspace removes it.
Inputs [SHIFT][A](unshift)[b]
deletes the b and the A only needs one backspace to delete.
Shifting while capslocked has the same effect on lowercase letters.
Caps Lock then backspace deletes correctly.
Seems to happen if the last character typed was shifted.
cosmic-text throws layout not found
, linked to this upstream TODO
May be trying to move underlying cursor to out of bounds position
DOWN and UP arrows also panic
PGDOWN and PGUP also panic, but only after the widget has had text and then it has been deleted.
Original comment:
#84 (comment)
Use Sprites for all rendering, have a Node component on "UI" bundles for positioning.
Will simplify the codebase and allow for use of sprite-specific bevy features, such as shaders.
Think I remember reading about UI Sprites somewhere in the bevy repo, will edit with a link if I can find it.
On my machine Sprites look a bit fuzzier than UI Images, this will need to be addressed. Probably a Z positioning thing or something.
would replace bevy_color_to_cosmic
and make code prettier :)
may also solve selections appearing from previous cursor position on editor focus
When using CosmicEditPlugin
alongside systems which attempt to lock the cursor, the cursor flickers when moved around, instead of staying hidden and locked.
Might be an optional component, replacing every character going in to the buffer with •
.
Obscured input should not be copy or cuttable, but should accept paste.
Option to turn obscuring off via an event would be desirable, like the eye symbols on the web. This suggests a struct such as pub struct PasswordInput { pub hidden: bool }
.
editor.get_text()
should return the unobscured string, so the buffer must hold the actual text, only drawing an amount of • equal to the length of the buffer.
Hopefully displaying and holding different values doesn't mess up the click functions.
One approach is to re-export cosmic-text
types.
With bevy_color_to_cosmic
in userland, should the click handlers follow? Conversely should the color converter be in utils.rs
?
History seems to count first two inputs as item 0
Occasionally, the following line (src/input.rs:583
) will crash, as when undo_redo
is called, no entities which satisfy editor_q
's query are in the World:
let (mut editor, attrs, mut edit_history) = editor_q.get_mut(entity).unwrap();
This can be fixed by replacing .unwrap() with a match statement, essentially exiting the function if the query has no items. This is what I do on my fork, and it doesn't seem to break anything, but I'm not 100% sure.
On some runs, cannot delete characters in a buffer with backspace.
Some runs it works as expected.
WASM seems to work fine consistently (sample size of 10 refreshes, two builds)
https://github.com/StaffEngineer/bevy_cosmic_edit/actions/runs/6220242769/job/16879866636?pr=40
Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/s/systemd/libudev-dev_249.11-0ubuntu3.9_amd64.deb 404 Not Found [IP: 52.252.75.106 80]
Will make #17 simpler as single line inputs will be a common use-case, and adds ways for such limits to extend to other use cases (e.g. username length limits)
Hi,
I recently encountered a bug where when leaving the focus of the app, to open spotlight search on mac, I lose the focus of the response window even after switching back to the app. This does not occur on other platforms, nor when switching between windows.
Thanks in advance!
Needs a refactor, I'm going to give it a shot.
@StaffEngineer Do you think putting input in a separate file like cursor.rs
is a good idea?
max_lines
doesn't work properly with long lines since line wrapping. Let's give a plugin user option to disable text wrapping.
The following code disables it:
let mut buffer = Buffer::new(
&mut font_system.0,
Metrics::new(metrics.font_size, metrics.line_height).scale(metrics.scale_factor),
);
buffer.set_wrap(&mut font_system.0, cosmic_text::Wrap::None);
let mut editor = Editor::new(buffer);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.