Commit graph

377 commits

Author SHA1 Message Date
Olivier Goffart
a094ce7a2a Add a warning on the internal crates documentation that we don't follow semver 2021-08-16 18:26:33 +02:00
Olivier Goffart
0b5e87b66b TextInput: Properly align the cursor and selection rect with different vertical alignment 2021-08-11 16:02:25 +02:00
Simon Hausmann
8a3a68a4fa Add API to Rust sixtyfps::Image to enable creation from user supplied image buffers
This adds an ImageBuffer and PixelBuffer type for SharedVector
backed images. The documentation explains how to use this
with low-level rendering functions and the popular image crate.

Fixes #387
2021-08-10 15:56:01 +02:00
Simon Hausmann
9f4fa3599a internal cleanup: make the GL backend cSpell clean 2021-08-05 13:52:55 +02:00
Simon Hausmann
3ec2274365 internal cleanup: rename the eventloop module to event_loop
That's consistent with graphics_window and silences cSpell
2021-08-05 13:46:42 +02:00
Tobias Hunger
24a2021226 Janitor: Fix clippy::needless_borrow 2021-08-04 22:50:35 +02:00
Simon Hausmann
601e93b9f5 Style fixup: Avoid a huge match expression
Instead merging the match with a variable declared later down is easier to read.
2021-08-03 16:47:23 +02:00
Simon Hausmann
25fac2bcd5 GL backend: Avoid run-time opengl errors with clipped zero width or height rectangles
If a Rectangle has a border-radius and clipping, we use an FBO to render
the children and then use femtovg's stencil clipping. If the Rectangle
has a zero width or height, we would end up trying to create a texture
with such dimensions, which produces run-time opengl errors.

We can detect this situation and avoid it early on. The same might happen for shadows.

Fixes #377
2021-08-03 16:47:23 +02:00
Simon Hausmann
d867d7b58a Fix rendering of text selection with combining characters with the GL backend
When the text selection end follows right after a grapheme that uses less
glyphs than characters, then there may not be a matching glyph with the byte
index, therefore we wouldn't set the selection_end_x and draw incorrectly.
Take the visual tail of the last glyph then.
2021-08-01 09:35:19 +02:00
Tobias Hunger
34d461cb2b Janitor: Fix clippy::clone_on_copy 2021-07-30 09:27:48 +02:00
Tobias Hunger
2cdc5848a2 Janitor: Replace float comparison dance with approx_eq from euclid
Sixtyfps uses euclid already, so let's use euclid for float comparisons
as well.

I changed the code to decide whether a number is a positive integer to
make do without a comparison along the way.
2021-07-23 13:48:52 +02:00
Tobias Hunger
27b42687fa Janitor: Fix clippy::redundant_closure 2021-07-23 13:48:52 +02:00
Tobias Hunger
1c21ba89ee Janitor: Fix clippy::if_let_some_result 2021-07-23 13:48:52 +02:00
Tobias Hunger
8d83ce88d7 Janitor: Fix clippy::excessive_precision 2021-07-23 13:48:52 +02:00
Tobias Hunger
aeebbb1d96 Janitor: Fix remaining clippy::option_map_unit_fn 2021-07-21 19:44:57 +02:00
Simon Hausmann
1c285694d7 internal cleanup: Remove the use of ComponentWindow in the interpreter 2021-07-21 17:41:12 +02:00
Simon Hausmann
2553dd1459 Trim the Rust ComponentWindow API and implementation a little bit
* Remove the `new` function from the main impl and use the slightly
  less visible From conversion trait
* Make the inner Rc<Window> pub(crate) instead of pub
* Instead, provide a public as_any() accessor that the Qt backend can use
2021-07-21 17:41:12 +02:00
Tobias Hunger
b105d6add3 Janitor: Do the float comparision dance
I think it is actually makes sense in this case!
2021-07-09 17:00:46 +02:00
Olivier Goffart
13bd828b96 Update license date 2021-07-02 15:55:54 +02:00
Olivier Goffart
bc8bc616ed GL backend: elide Text also when word-wrapping
In this case, the last line will have elipsis on the last line
when no more line can be printed

Note that the behavior is different with the Qt backend
2021-06-30 13:33:19 +02:00
Simon Hausmann
a0e827e200 Work around black window with vmware/glutin/windows10
Glutin's desire to default to srgb mysteriously creates a black window
on Windows 10 under Vmware. I tested this with many glutin apps and examples,
they all exhibit the same: black window,
working when query for srgb is turned off.

This used to work, so I suspect some change underneath on the vmware svga
driver perhaps, or Windows.
2021-06-29 22:53:48 +02:00
Tobias Hunger
13d7f5e7bd Janitor: Fix typos in comments and user-facing strings
Also adapt tests for error messages containing the fixed strings.

No behavior change is intended!
2021-06-28 08:32:25 +02:00
Simon Hausmann
930412d3bb Fix size of default constructed sixtyfps::Image with GL backend
An empty image should have a zero (empty) size, like it does with the
testing and Qt backend.

The datastructures test in the CI revealed this.
2021-06-20 11:18:28 +02:00
Simon Hausmann
0fdb87cc69 Add Image::size()
This requires the image size query to be window independent and go
through the backend instead.

This implies minor changes for the Qt backend and bigger ones for the GL
backend:

* There exists now a thread-local IMAGE_CACHE, which is used by the
  backend's image_size() function as well as by the renderer for
  loading CPU side images.
* The image remain as decoded images in there (including SVG tree)
  and the window now has a texture_cache, which holds CachedImage
  with ImageData::Texture.
* Rendering an image item therefore fetches the CPU side image,
  calls upload_to_gpu() on it, which creates a new Rc<CachedImage>
  and that's stored in the texture_cache.
* The texture cache continues to be pruned when hiding the window.
2021-06-20 11:18:28 +02:00
Olivier Goffart
7f9bb18b9a Fix warning introduced in last commit 2021-06-10 11:18:35 +02:00
Olivier Goffart
9b8efbf5ad GL backend: Properly clip Text that has too many lines for its height
Qt already does that
2021-06-10 10:52:04 +02:00
Simon Hausmann
5b9ce15ae2 GL backend: Implement image_size getter without mapped window
By moving the image cache to the GraphicsWindow we can now decode images
first without a window and later upload to the GPU.

This also allows removing the window_map_pending property hack.
2021-06-01 08:29:39 +02:00
Simon Hausmann
c38696f652 GL backend: Prepare for image cache without window
The HTMLImage only needs the event loop proxy to notify for a repaint, we can repaint all windows.
2021-06-01 08:29:39 +02:00
Simon Hausmann
ad24802fed GL backend: Clean up HTML image loading code
Decouple the Texture from the HTML image loading logic and introduce an
ImageData state that represents just the DOM element.

This will make it possible later to also load the images without a canvas.
2021-06-01 08:29:39 +02:00
Simon Hausmann
3ef6f95659 GL backend: minor cleanup
Move the image cache key also into the images module
2021-06-01 08:29:39 +02:00
Simon Hausmann
4a13bba32a Clean up GL resource handling
Make sure that we have a current GL context before deleting textures or other GL resources
2021-06-01 08:29:39 +02:00
Simon Hausmann
6fa6b28661 Simplify GL context handling further
Move the borrow/option business to work around the glutin enum API into
the OpenGLContext type, to simplify its use.
2021-06-01 08:29:39 +02:00
Olivier Goffart
142a8dc185 Rename ImageReference to ImageInner and make Immage.0 private 2021-05-28 17:05:16 +02:00
Olivier Goffart
0b3fecf300 WIP: API to expose image loading from C++ and Rust 2021-05-28 17:05:16 +02:00
Olivier Goffart
4584c40544 Rename items::Image to ImageItem
Because there will be soon a sixtyfps::Image and the names
can't clash
2021-05-28 17:05:16 +02:00
Simon Hausmann
d4385280eb Fix disappearing images or panics when hiding and showing a window with wayland
Properly release GL resource when unmapping a window and detect stale
cache indices using a generation count. This fixes the disappearing
images (GL textures would be invalid and need to be re-created) as well
as the panics when an item's cache index ended up being re-used because
some other item was drawn first and allocated that indices. The latter
is fixed by using a generational counter on the cache that's bumped when
clearing, instead of a single "cache_ok" bool.
2021-05-28 09:16:24 +02:00
Simon Hausmann
9503ba69b3 GL backend: Move all font related code into the fonts module 2021-05-27 18:51:32 +02:00
Simon Hausmann
9b02f2e4a2 GL backend: provide font metrics even when the window is not mapped
Move the item graphics cache into the GraphicsWindow and then, together
with the new femtovg::TextContext, we can provide the metrics and can
stop using the window_map_pending notifier for this query.
2021-05-27 17:00:44 +02:00
Simon Hausmann
61a5859d70 Further encapsulate also the context creation in OpenGLContext 2021-05-27 15:55:38 +02:00
Simon Hausmann
3723aa6f42 Encapsulate the winit WindowContext and wasm winit::Window handling
With wasm there is no current context (can alwasy render) but we own the
winit::Window. With glutin own the ContextWrapper and have to make it
current (and resize). This patch hides all that behind the OpenGLContext
type.
2021-05-27 15:53:33 +02:00
Simon Hausmann
77a064ecab Simplify glutin GL context resizing slightly
Move the resize call into make_current, in preparation for additional
encapsulation in that type.
2021-05-27 15:52:54 +02:00
Simon Hausmann
4a0a9f8a2c Make the font cache thread local 2021-05-27 15:52:54 +02:00
Simon Hausmann
e3264f02d7 Switch to femtovg's TextContext API
This is primarly search & replace for now, slightly simplifying function
signatures.
However this paves the way to a thread-local font cache that can share
fonts across windows (not glyph atlas) and also measure without a canvas.
2021-05-27 15:52:54 +02:00
Simon Hausmann
6d65236813 GL backend: simplify window factory function signature
We can retrieve the event loop window target from anywhere
2021-05-27 15:49:33 +02:00
Simon Hausmann
8d2554ff3b Remove internal event loop proxy clone in the GL renderer
We don't need it since we can send events through the TLS
2021-05-27 15:45:29 +02:00
Olivier Goffart
6540fd48ae GL backend: set the proper size on the rendering context
Otherwise we draw garbage with wayland
2021-05-20 15:19:33 +02:00
Simon Hausmann
a7ce64657c Restore source compatibility for drop-shadow-blur
Let's keep source compatibility and define `drop-shadow-blur` to be a radius.
The CSS spec says that the standard deviation is half of the radius.

We just need to scale again and increase the shadow rect to make sure that no borders are visible.
2021-05-20 12:14:05 +02:00
Simon Hausmann
9a4dc4a8dc Clean up femtovg crate dependencies
Let only the GL backend depend on femtovg, by moving the color functions.
This way it's easier to change the femtovg version in one place.
2021-05-20 08:56:11 +02:00
Simon Hausmann
bb7b301b10 GL backend: new box drop shadow implementation
This replaces the box gradient with a new implementation that
behaves like the HTML Canvas element, by applying a gaussian
blur to the alpha of the rectangle to shadow.

The drop-shadow-blur property is changed to be now just a "level", like
the HTML Canvas shadowBlur property, which is defined to be half of the
standard deviation of the gaussian blur to be applied.
2021-05-20 08:50:02 +02:00
Simon Hausmann
ea358d9b2c Simplify internal image_size API
We don't need a property reference anymore, a plain image reference is fine AFAICS.

Dirtyness of the source is tracked on the caller side of layouting_info()
or in the draw_image_impl anyway.
2021-05-12 19:40:09 +02:00