Commit graph

395 commits

Author SHA1 Message Date
Simon Hausmann
ac0cc85d33 Simplify font resolution in the GL backend
The font resolution function querying fontdb is fast now, so we can
always call it when rendering text. That way we don't need all the
indirection in the text_size(), etc. functions, we don't need an entry
in the item graphics cache for the font and we can avoid a lot of
property dependencies.
2021-09-21 10:10:45 +02:00
Simon Hausmann
ed3d848d02 Fix native widget rendering when the window is inactive
Set QStyle::State_Active conditional to whether the window is active,
which maps to Qt's active window concept and winit's has-focus (until we
render popups differently).
2021-09-15 15:34:34 +02:00
Simon Hausmann
37464a45c5 Fix rustdoc build in the CI
The nightly has become a bit more picky about seemingly unused variables
:-)
2021-09-13 14:19:17 +02:00
Simon Hausmann
011a9ffb83 GL backend: Prospective fix for panic when trying to create window with AMD GL driver
The srgb workaround from commit a0e827e200
appears to work with the AMD GL driver, without which the GL context
creation works (as tested by the reporter).

So instead of panicing, fall back to the glutin default with possibly an
srgb framebuffer, when trying to create a GL context. If that also
fails, provide a better error message than "called unwrap on an err".

cc #481
2021-09-09 11:53:19 +02:00
Simon Hausmann
df4e06be98 GL backend: render the cursor also for an empty text input if requested 2021-09-07 11:33:28 +02:00
Simon Hausmann
dd043fc51b Fix texture caching for images with the same source but different image-rendering properties
As tests/cases/examples/image_rendering.60 itself demonstrates, the png file
should be loaded into the CPU side image cache once, but the two textures
should be cached independently.

cc #465
2021-09-06 13:47:41 +02:00
Ryan Van Gilder
e7245cd0af cargo fmt and remove uneeded HorizontalLayout import 2021-09-06 10:03:51 +02:00
Ryan Van Gilder
4d1d0e73a4 Rename image-scaling to image-rendering to align with CSS 2021-09-06 10:03:51 +02:00
Ryan Van Gilder
a03a27ae0d Add image-scaling property to Images to control how they are scaled
Like CSS image-rendering it has "smooth" and "pixelated" options.
Only OpenGL has been tested right now, have not tested WASM or Qt.
Right now the first instance of a @image-url() will set the scaling
for that specific image. The same image used from memory on the otherhand
can all have a different scaling property.
2021-09-06 10:03:51 +02:00
Simon Hausmann
baa55e8824 Internal cleanup: Remove canvas dependency from text layout code
We can use the non-canvas bound TextContext and need the canvas only
in the closure when painting.
2021-09-02 11:09:32 +02:00
Simon Hausmann
040775173b Clean up GL backend code
Remove GLRenderer and GLRendererData. Most of the fields fold nicely
into the MappedWindow.
2021-09-02 09:48:04 +02:00
Simon Hausmann
5dff29ef67 Internal cleanup: Centralize code to determine default font properties
If the root item is a Window, then we use the default-font-* properties as the basis
for all unspecified font properties in text rendering.

This patch centralizes the code for retrieving that in the runtime window.

If this becomes a performance bottleneck, then we could cache it in a
box-pinned property in the run-time window.
2021-09-01 18:20:23 +02:00
Simon Hausmann
549fcb049b Internal cleanup: Move the scale factor property into the shared runtime Window 2021-09-01 18:20:23 +02:00
Simon Hausmann
2e8378801d GL backend: internal cleanups
Remove the indirection between the GraphicsWindow and the femtovg renderer.
2021-09-01 18:20:23 +02:00
Olivier Goffart
6e12b4504a A few fixup for the multi-line edit
- Have the cursor at the right place when clicking on end of line
 - make sure not to render new lines if there are some when in single-line mode
 - Enter should make a new line
2021-09-01 16:52:37 +02:00
Olivier Goffart
b2392c25c7 Basic support for Multi-line TextInput 2021-09-01 16:52:37 +02:00
Simon Hausmann
90765a97ce Further clean up item graphics cache handling
The RenderCache (slab and generation) is always in a refcell, so we can
just pass that through. This also eliminates the ItemGraphicsCache
wrapper in the GL backend.

This will allow more fine grained borrowing in the future.
2021-08-26 13:46:37 +02:00
Simon Hausmann
ea07d21560 Internal cleanup
Remove unnecessary wrapper function for the item graphics cache in the GL backend.
2021-08-26 13:31:15 +02:00
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