Commit graph

627 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
2f1db396e8 GL backend: Speed up glyph coverage checking
Instead of always mapping the face (from disk), first fan out existing
cached coverage information. Any unchecked scripts are then checked
in the slow code path with `with_face_data` later.
2021-09-21 10:07:21 +02:00
Simon Hausmann
b021152fcc GL backend: Fix internal variable name
The available families is used on all platforms and doesn't need a _ prefix anymore.
2021-09-21 09:20:01 +02:00
Simon Hausmann
d2923d51f6 GL backend: add basic font fallback support for Linux
Use the static (but long) fallback list that we get from fontconfig in the beginning.

This works, but can be optimized to operate on a trimmed and shorter list,
which will speed up the fallback. But for now this makes it work.
2021-09-17 18:58:18 +02:00
Simon Hausmann
cc7ea5b92a GL renderer: fix rendering of Text/TextInput when the text property changes in a way that requires different fonts
Unfortunately the text property was not included in the property dependency chain
for the cached Font.
This is fixed by delaying that with a getter function, but in the mid term
we should be able to remove this again once
femtovg learns lazy font resolution.
2021-09-17 18:27:44 +02:00
Simon Hausmann
db842e1b6b Fix font fallback handling on macOS
Permit processing the entire font cascade list and load fonts from there
lazily by checking their glyph coverage and remembering it.
2021-09-17 18:27:40 +02:00
Simon Hausmann
6130e04e84 Rework the font loading in the GL backend
The basic idea is to use fontdb's load_system_fonts() mechanism, in
conjunction with its built-in mmap support, to get an overview over all
installed fonts on macOS, Windows and Linux.

This isn't quite perfect in terms of discovering systems defaults, but
it's much faster than font-kit's approach of querying the system (good)
but reading the matched files into memory (not using mmap). And we have
the option of perfecting it by using fontconfig directly on Linux (where
the backend is most important).

This also paves the way for better fallback handling, as now we have a
list of all available families and we can use system APIs to query for
fallbacks.
2021-09-17 14:41:14 +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
c142cd61b3 Janitor: bump usvg and resvg once more :) 2021-09-07 08:38:40 +02:00
Simon Hausmann
9a947553b7 Janitor: Bump glow and femtovg versions
femtovg also brings in the same glow version, so no duplicates here
2021-09-07 08:33:37 +02:00
Simon Hausmann
8b5e29534f Upgrade fontdb
The new version splits the mmap feature out of the fs feature.
2021-09-06 15:41:52 +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
Simon Hausmann
71cd4bb3f0 GL backend: clean up of window map state handling
Use std::cell:Ref/RefMut to reduce the indentation and make it easier to
see where the borrow occurs.
2021-09-06 13:15:06 +02:00
Simon Hausmann
192652b78e Fix panic with viewer's --auto-reload feature with the GL backend
Improve the granularity of the borrow of the mapped window, to avoid
that when applying window properties we recurse into a borrow due to
the call for setting the geometry triggering a notify that borrows.
2021-09-06 11:55:22 +02:00
Simon Hausmann
7fb58b9334 Minor cleanup: unify two impl blocks for GraphicsWindow 2021-09-06 11:55:22 +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
Olivier Goffart
b075b40f23 Update resvg version 2021-09-04 10:50:20 +02:00
ogoffart
e54e03148f Bump version number to 0.1.2 2021-09-04 10:08:51 +02:00
Simon Hausmann
5a81976f3b Allow selecting features in the CMake integration
Provide the same features as in the Rust API crate, as CMake
options.
2021-09-03 14:33:55 +02:00
Olivier Goffart
4f1eacd6d8 LineEdit is now able to scroll to keep the cursor visible 2021-09-02 17:20:44 +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
ce62cce266 Internal cleanup: Simplify some Option handling
Replace

   if let Some(Some(Foo)) = bar.map(|some_weak| weak.upgrade())

with

   if let Some(Foo) = bar.and_then(|some_weak| weak.upgrade())
2021-09-01 18:29:32 +02:00
Simon Hausmann
8114e187b0 Unify mouse input event and draw handling between Qt and the GL backend
The unification reduces back-end specific fields for the window and
allows making all the property trackers in the run-time window private.
2021-09-01 18:20:23 +02:00
Simon Hausmann
bcbed23392 Internal cleanup: simplify GraphicsWindow::draw a little bit
Similar to the other window item properties and also similar to how the
Qt backend handles this, fetch the background color in
apply_window_properties().
2021-09-01 18:20:23 +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
60082b84b0 GL backend: remove unnecessary window scale factor refresh call
When the window is mapped, the scale factor is brought up-to-date. Only
after that we can receive a resize event or a window scale factor
changed event.
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
Olivier Goffart
861edf94fd Remove FontMetrics trait
since there is only one function in it, just put that function in the Window
then there is no need to heap alocate a dyn FontMetrics just to call this function.
2021-08-31 13:27:32 +02:00
Olivier Goffart
c1fc242a9a Move the text_input_byte_offset_for_position from the FontMetrics to the Window
In preparation of having mutiple-lines TextInput, we will need to give more
data to this function so it no longer belong in FontMetrics

Also remove the unused FontMetric::line_height()
2021-08-31 13:27:32 +02:00
Simon Hausmann
6db89e3468 Fix key events the control modifier on Windows, X11 and Wayland
Under these windowing systems, we receive a QString text from Qt that
contains a terminal control character (like \u{3} for ctrl+c). We
decided to supply the character for the key (for example 'c' for Ctrl+C)
to the application, so activate the conversion from the key code when
control characters are present.

With winit, we receive first a key down input event with the virtual key
code (for example C for Ctrl+C), followed by a ReceivedCharacter event
with a terminal control character. We choose to ignore that and instead
take the previously received key code and try to use that instead.

Fixes #441
2021-08-30 19:07:32 +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
Tobias Hunger
aea4ecca99 Apply pre-commit hooks to all files 2021-08-17 22:38:16 +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
2a420d7a86 Remove imgref dependency from the public Image API
There's only one place where we need this ourselves and that's also
easily done by hand. Otherwise the `as_bytes(_mut)()` accessor provides the
functionality along with `width()` and `height()`.

Other than that the API is mostly consuming, given that `sixtyfps::Image`
has no way of extracting the data again.
2021-08-10 15:56:01 +02:00
Simon Hausmann
f25f85844d Remove SharedImageBuffer from the public Rust API
and instead fold the constructor functions into Image as `new_rgb8`/`new_rgba8` and `new_rgba8_premultiplied`.
2021-08-10 15:56:01 +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
ogoffart
53f286258c Bump version number to 0.1.1 2021-08-10 08:06:20 +00: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