Commit graph

1059 commits

Author SHA1 Message Date
Olivier Goffart
4f1eacd6d8 LineEdit is now able to scroll to keep the cursor visible 2021-09-02 17:20:44 +02:00
Simon Hausmann
5ae6d308be Minor cleanup in Window::draw_contents
The component rendering closure can be FnOnce, it doesn't have to be
FnMut.
2021-09-02 12:16:35 +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
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
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
Olivier Goffart
e1be599bc0 Print an warning in stderr when modifying read-only model
... and improve the documentation of Model
2021-08-31 10:36:22 +02:00
Simon Hausmann
f50ba4a40f Fix doc build with nightly
The lack of docs for the debug_log macro produces a warning now (and
an error for us). Add some basic docs as remedy.
2021-08-30 18:36:07 +02:00
Simon Hausmann
dbc8b34494 Internal cleanup
Simplify if condition for entering the branch in the item graphics cache that
may update an existing entry.
2021-08-27 15:10:27 +02:00
Simon Hausmann
88af441321 Fix panic in the GL backend when text has complex bindings to sizes
Avoid borrowing the rendering cache while evaluating property bindings.

Fixes #410
2021-08-27 15:10:27 +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
Olivier Goffart
76ca2eed6b Fix intra-doc links
It should be ``[`...`]``, not `` `[...]` ``
2021-08-19 09:17:30 +02:00
Tobias Hunger
d26707e41e Janitor: Fix clippy::bool_assert_comparison 2021-08-18 00:24:51 +02:00
Olivier Goffart
a2966bdafa Fix warning generating internal docs
references to non-existing items
2021-08-16 18:27:35 +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
073447a47d Fix the clippy error about comparing address of virtual table
Fix one vtable_address_comparisons clippy link.
It is fine to only compare the data pointer.
Two different model with the same data pointer in a Rc could only be obtained
with tricks like transmute because each model is allocated on a different Rc.
2021-08-16 10:53:28 +02:00
Olivier Goffart
ec529f088b Fix the native style drawn from the GL backend
Femtovg wants RGBA, not ARGB
2021-08-13 18:12:18 +02:00
Simon Hausmann
386d61d648 Simplify Rust’s SharedVector::clear() when the vector is shared
Co-authored-by: Olivier Goffart <ogoffart@sixtyfps.io>
2021-08-12 13:41:08 +02:00
Simon Hausmann
d65af654d7 Changed Rust's SharedVector::clear() to not preserve capacity when shared 2021-08-12 13:41:08 +02:00
Simon Hausmann
856a049627 Implement SharedVector::clear() for Rust 2021-08-12 13:41:08 +02:00
Simon Hausmann
e5c2a4f996 Avoid hardcoding the rgb crate version for rustdoc builds 2021-08-11 08:46:55 +02:00
Simon Hausmann
ea663955bd Fix links to rgb crate in the sixtyfps.io hosted online docs
Use the external docs rustdoc feature to link to the rgb docs on docs.rs.
2021-08-10 22:30:37 +02:00
Simon Hausmann
e23dcc336f Fix doc build
Amends commit 0852a7661b
2021-08-10 16:53:37 +02:00
Simon Hausmann
0852a7661b Fix mutable slice API
* Change SharedVector::as_mut_slice() to SharedVector::make_mut_slice()
* SharedPixelBuffer::as_mut_slice and SharedPixelBuffer::make_mut_slice()
* SharedPixelBuffer::as_bytes_mut() to SharedPixelBuffer::make_mut_bytes()

This is consistent with Rc::make_mut() and is supposed to emphasize
that, unlike the usual as_* operations, it is not a free operation but
may involve work (detaching the data by cloning it).

Amends commit 7384ebdc32
2021-08-10 16:37:34 +02:00
Simon Hausmann
1fca971fa8 Rename RGB(A)8Pixel to Rgb(a)8Pixel
That's consistent casing with RgbaColor.
2021-08-10 15:56:01 +02:00
Simon Hausmann
4e9b2725a7 doc fix: Remove mention of SharedVector in SharedPixelBuffer
It's an implementation detail
2021-08-10 15:56:01 +02:00
Simon Hausmann
a0f06e35d7 Fix rustdoc link
Co-authored-by: Olivier Goffart <ogoffart@sixtyfps.io>
2021-08-10 15:56:01 +02:00
Simon Hausmann
0d3c38899f minor doc fix: capitalize Rust 2021-08-10 15:56:01 +02:00
Simon Hausmann
d023475f1c Rename Image::new_rgb*() to Image::from_rgb* 2021-08-10 15:56:01 +02:00
Simon Hausmann
76041684c0 Simplify scenario description in Image docs
It doesn't have to be an external crate that renders images, just Rust code generally.

Co-authored-by: Olivier Goffart <ogoffart@sixtyfps.io>
2021-08-10 15:56:01 +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
cfb6caca01 Fix calling Image::size() on default or pixel-buffer constructed images
For such images we do not need a backend and can avoid the panic.
2021-08-10 15:56:01 +02:00
Simon Hausmann
6016007c6f Avoid the need for SharedPixelBuffer users to depend on rgb
Re-export the two typical pixel types, for convenience. Of course other
types can be used, too, if the user depends on rgb directly.
2021-08-10 15:56:01 +02:00
Simon Hausmann
c18b289e62 Provide convenience as_bytes(_mut) for SharedPixelBuffer
This avoids the need for users of the API to import the ComponentBytes trait from rgb.
2021-08-10 15:56:01 +02:00
Simon Hausmann
8b62564a4b Fix incorrect self parameter in SharedPixelBuffer
We don't need a mutable reference for `as_slice()`
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
12916e7488 Fix C++ build after Image API changes
Export missing types
2021-08-10 15:56:01 +02:00
Simon Hausmann
2e9e818691 Mark SharedPixelBuffer as repr(C)
For use in the ffi later
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
7384ebdc32 Deprecated SharedVector::as_slice_mut() in favor of SharedVector::as_mut_slice()
The standard library uses the latter name.
2021-08-09 14:51:09 +02:00
Tobias Hunger
c3ce321429 Janitor: Fix clippy::ptr_arg 2021-08-09 13:19:34 +02:00
Tobias Hunger
cbdea7c9c7 Janitor: Fix clippy::missing_safety_doc 2021-08-09 13:19:34 +02:00
Tobias Hunger
bac4d895ce Janitor: Fix clippy::while_let_on_iterator 2021-08-09 13:19:34 +02:00
Simon Hausmann
b4ba77dba7 Fix SharedVector creation from iterators with default size hints
* In capacity_for_grow, don't compare the number of elements
  (current_cap) with the size of an element in bytes, but
  with the required capacity instead (to detect that we don't need
  to grow). Not all call sites check for that (i.e. push), so there's
  a new test for that.

* When re-allocating due to growth and copying elements from the old
  inner to the new inner, make sure to copy all old elements from the beginning,
  not only the last element repeatedly.
2021-08-06 16:18:33 +02:00
Tobias Hunger
ff76aa8953 Janitor: Fix clippy::blocks_in_if_conditions 2021-08-05 23:41:56 +02:00
Simon Hausmann
acb10caea3 internal cleanup: don't bother with Cargo.toml files
Crates names just create noise
2021-08-05 13:54:17 +02:00