Commit graph

85 commits

Author SHA1 Message Date
Olivier Goffart
ab08502c77 Move the GraphicsWindow to the graphics backend 2021-01-14 08:53:13 +01:00
Olivier Goffart
80380c4cc7 Remove dependencies between window and winit 2021-01-14 08:53:13 +01:00
Olivier Goffart
9050c29305 Don't use the window through the eventloop module 2021-01-14 08:53:13 +01:00
Olivier Goffart
e2ac322be0 Move the ComponentWindow in its own module 2021-01-14 08:52:22 +01:00
Olivier Goffart
b0fd400cd1 Fix panic: 'already borrowed: BorrowMutError', graphics.rs:702
Both with_platform_window and set_scale_factor borrow the backend.
2021-01-14 08:52:22 +01:00
Simon Hausmann
769ad146e7 Preparation for text handling
Ensure the dpi on the canvas is up-to-date before/after rendering, as
measure_text etc. rely on it and it's otherwise initialized to 1 by
default. Unfortunately this requires jumping through some hoops, but
that can be fixed later in the canvas.
2021-01-14 08:52:22 +01:00
Olivier Goffart
f6d60c2662 Update winit 2020-12-11 16:17:45 +01:00
Olivier Goffart
e75f617125 Fix event loop being blocked because it wouldn't notice that animation is still running
The active_animation was set to false, but if the animation tick did not change, the animation tick
was not maked dirty, and we wouldn't then re-evaluate animated property that would set the
active_animation to true again
2020-12-09 17:28:14 +01:00
Olivier Goffart
852eeb1c11 WIP popup 2020-11-30 15:20:51 +01:00
Olivier Goffart
0c97b4f296 More use of the ItemRc 2020-11-24 13:42:34 +01:00
Olivier Goffart
124eec9960 Introfuce ItemRc and ItemWeak
Wrapper around ComponentRc and index
2020-11-24 13:42:34 +01:00
Simon Hausmann
89e0b57627 Rework and simplify the focus handling
Instead of determining the focus item through item tree traversal and
pointer comparison and storing the intermediate indices in the
components in the tree, remember the focus item by a pair of
VWeak<ComponentVTable, Dyn> and item_index: usize.

This speeds up determining the focus item as well as delivering events,
which can now be done directly after retrieving an ItemRef with
get_item_ref.

This also fixes the duplicate line edit focus in the 7gui cells
test case.
2020-11-20 15:33:15 +01:00
Simon Hausmann
7a5113ece1 Free graphics resources without item tree traversal 2020-11-18 08:49:57 +01:00
Simon Hausmann
54ee7b3556 Cpp: Give each generated component a ComponentWindow
That's a counted reference to the window in the run-time and avoids the need to do the parent->parent->window dance.
2020-11-16 16:59:57 +01:00
Simon Hausmann
c258a907f0 Simplify event loop start-up
Move the layout constraint tracker into the window where we can apply
the constraints right before drawing, instead of doing that from within
the event loop. This allows to remove the component parameter from the
run function.
2020-11-12 15:04:48 +01:00
Simon Hausmann
05ba16f1d6 Remove the component parameter from GenericWindow::set_focus 2020-11-11 19:18:53 +01:00
Simon Hausmann
a2dadf8fe8 Remove the component parameter from GenericWindow::process_key_input 2020-11-11 19:16:26 +01:00
Simon Hausmann
516680ad5d Fix wasm build 2020-11-11 19:09:56 +01:00
Simon Hausmann
3f0c9c97b7 Remove some component parameters from GenericWindow 2020-11-11 19:06:07 +01:00
Simon Hausmann
64b92df87e Initialize the component in the Window at component creation time
This will allow getting rid of the component as parameter to run()
2020-11-11 19:03:04 +01:00
Simon Hausmann
a09355c634 Begin associating a Window with a component in the run-time 2020-11-11 18:31:52 +01:00
Simon Hausmann
5d744c86c2 Begin passing the VRC<ComponentVTable, Dyn> into the run-time library
First by changing the signature of run() and by adding a self_weak
to the C++ struct.
2020-11-11 18:31:51 +01:00
Simon Hausmann
02904c4014 Simplify signature of Component::run
We don't need to pass the root item anymore since ComponentVTable
has now get_item_ref.
2020-11-11 15:55:03 +01:00
Olivier Goffart
d6a440aa4a Change C++ API to use the ComponentHandle 2020-11-10 19:28:34 +01:00
Olivier Goffart
a4b476bdf3 implement Component::layout_info in C++ 2020-10-29 19:08:52 +01:00
Olivier Goffart
f855b18fb0 Implement min/max size restriction on the window
(Implemented in the interpreter only for now)
2020-10-29 19:08:52 +01:00
Olivier Goffart
5face45c51 Rename Component::compute_layout to apply_layout
And pass the expected rectangle.
This is currently not used yet but will be needed when we can have
repeated elements within a box layout
2020-10-29 19:08:52 +01:00
Simon Hausmann
fa982b9380 Fix calculation of native group box padding
Setting the value of the native_padding_{left, right, top, bottom}
properties *during* the layout_info() call is too late, as the calling
compute_layout implementation has already queried for those properties.

Instead, this patch moves the padding calculation into a shared property
binding that's queried from bindings to the individual native_padding_*
properties and layout_info() just uses the properties, too.
2020-10-12 16:49:44 +02:00
Simon Hausmann
51f9fc0e61 Refresh the window when loading of an HTML image completed 2020-10-09 10:44:15 +02:00
Simon Hausmann
9ad8968529 Add support for the initial_focus synthetic property
Setting it will translate to a set_focus_item call in the constructor.

This implements parts of #55
2020-09-30 15:11:01 +02:00
Simon Hausmann
ec91e4c933 Make ComponentWindow::set_focus_item ffi friendly
Take a Pin<VRef<ItemVTable>>, which is easier to map from C++ than a generic method...
2020-09-28 15:59:29 +02:00
Simon Hausmann
e5dfb3a4c0 Implement basic focus handling
Similar to the mouse_grabber, we use a VisitChildrenResult field to
track the focus item within a component. Unlike the mouse grabber
however, it is set/cleared using dedicated focus events.

The key event now routes the key event directly to the focus item.

The focus can be requested via set_focus_item on a window, which the
TextItem does.
2020-09-25 10:43:47 +02:00
Simon Hausmann
7ca66d62b9 Fix crash in TextInput when deleting a left-directed selection
When selecting to the left, the anchor remains to the right of the cursor.
When deleting such a selection, we fetch the cursor and anchor using a helper
method, which ensures that the anchor is to the left of the cursor.
Finally when setting the cursor then to the anchor, we need to also
set the anchor, since both were swapped.

This also add an automated test for this scenario.
2020-09-23 17:33:09 +02:00
Simon Hausmann
8f63c0dc53 Fix character input handling with modifiers
For a sequence of pressing and releasing Ctrl+C, winit sends up press, character input
and release.
We're not interested in
processing the character input when control, alt or logo are pressed.
2020-09-23 11:31:13 +02:00
Simon Hausmann
bb81c99ddb Add support for keyboard modifiers in the internal key event 2020-09-21 14:30:16 +02:00
Simon Hausmann
6bcbf082ff Fix backspace handling
On macOS at least, backspace triggers a character input event as well as
key down/release -- the key_* handlers trigger as well as
doCommandBySelector. We're not interested in backspace as an input
character though. More generally, let's exclude control characters. This
could be extended in the future to more categories.
2020-09-18 18:03:16 +02:00
Simon Hausmann
0d751e6627 Render a text cursor for TextInput items
It doesn't look quite perfect yet, but it's a start.
2020-09-18 17:58:14 +02:00
Simon Hausmann
3f438ec3f6 Fix wasm build 2020-09-18 16:29:32 +02:00
Simon Hausmann
39fabdee9e Pass a window reference to Item::key_event
Similar to the input_event.
2020-09-18 16:22:00 +02:00
Simon Hausmann
7053aee0c8 Pass the ComponentWindow to ItemVTable::input_event 2020-09-18 16:18:48 +02:00
Simon Hausmann
79ba5d9de8 Provide a window reference in various ItemVTable functions
Access to the window, in particular the scale factor, will be needed in a few places.
2020-09-15 15:55:47 +02:00
Simon Hausmann
546818ee55 Add key event data structures and event function boiler plate 2020-09-15 11:16:55 +02:00
Simon Hausmann
3c2172d043 Use new-style intra-crate rust-doc links instead of relying on .html links 2020-09-09 18:53:59 +02:00
Simon Hausmann
0bc2e40e28 Add remaining docs for the eventloop crate.
The particularly relevant bit here is the GenericWindow trait since that
heavily relates to the implementation in the graphics module.
2020-08-31 14:34:42 +02:00
Olivier Goffart
e7210d8d6c wasm: send an Exit event when the cursor leave the canvas
We do not get move or release event when the cursor is outside of the canvas
as a result, we would have no way of detecting that the mouse has been released
outside and we would be in a inconsistant state.

Fixes #19
2020-08-29 11:11:16 +02:00
Olivier Goffart
58cdaeb8dd Update license header to mention that commertial option are available 2020-08-26 13:23:42 +02:00
Simon Hausmann
2823f32692 Apply license headers to all non-binary/non-json sources 2020-08-17 17:55:20 +02:00
Simon Hausmann
d650cadc02 Release graphics resources of items when deleting components in C++ 2020-08-13 13:31:52 +02:00
Simon Hausmann
b96b627a4f Release graphics resources of items when destroying components
This is only implemented for Rust at the moment.
2020-08-13 13:31:29 +02:00
Simon Hausmann
89953e1957 Replace GenericWindow::window_handle() that returns a Ref with a callback
The std::cell::Ref<> exposes the way a refcell is used in a way that
makes it harder to change.
2020-08-13 11:33:34 +02:00