Commit graph

218 commits

Author SHA1 Message Date
Simon Hausmann
727c9a19f7 Add basic text item support
This needs more work, but gets something onto the screen at least.
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
c7ff67d0fc Move the ItemRenderer to the item_rendering 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
Simon Hausmann
5906f39a47 Silence some warnings 2021-01-14 08:52:22 +01:00
Simon Hausmann
c74c8592a0 Minor simplification of new_renderer trait function
It's not necesary to pass the window dimensions when the renderer owns
the window.
2021-01-14 08:52:22 +01:00
Simon Hausmann
de4194c9ba Make ItemRenderer take &mut again
It's cleaner and indeed possible
2021-01-14 08:52:22 +01:00
Simon Hausmann
43127cb059 Implement releasing of textures when items are destroyed
This means going back to an immutable renderer reference and interior
mutability for the canvas and the gpu cache. This is because while
traversing the item tree for rendering we may end up destroying
other items due to the lazyness of the models.
2021-01-14 08:52:22 +01:00
Simon Hausmann
e334efbcc5 Fix borrow error panic
Don't try to borrow the backend mutably when destroying items.
2021-01-14 08:52:22 +01:00
Simon Hausmann
d159a3b523 Implement caching of images
Don't re-load/decode the image every frame (and leak it), just load it
once per source change.
2021-01-14 08:52:22 +01:00
Simon Hausmann
d92fe445d5 Remove the old GL renderer
and try to stub in the hooks to trigger the new one
2021-01-14 08:52:22 +01:00
Simon Hausmann
607fecdb18 Simplify rendering interface
Instead of passing through a generic transformation matrix, let's just
pass through what we actually use: a translation point
2021-01-14 08:52:22 +01:00
Simon Hausmann
d4f603246c WIP: Start a femtovg backend 2021-01-14 08:52:22 +01:00
Olivier Goffart
b42c16851a Use the color property of the window as a background 2020-12-18 16:54:19 +01:00
Olivier Goffart
61399e566a Add a title to the Window
also add a color, but not yet implemented
2020-12-18 16:47:14 +01:00
Olivier Goffart
16f5a03c14 Run cargo fmt 2020-12-18 10:29:15 +01:00
Olivier Goffart
dfa25b96f7 Rename SharedArray to SharedVector 2020-12-18 10:26:07 +01:00
Olivier Goffart
0d2d48be4f Rename "signal" to "callback" 2020-12-18 09:51:01 +01:00
Simon Hausmann
ca1fb8ab0d Fix GPU primitive vs. rendering variable division for Rectangle
Changing the border radius or border width does not require uploading a new geometry.
Therefore these can become rendering variables.
2020-12-15 18:08:33 +01:00
Olivier Goffart
2b5213c408 Refactor the rendering variables in a enum instead of an array
And finish the ImageFit::contain implementation
2020-12-15 12:16:44 +01:00
Simon Hausmann
625978fe1a WIP: Add an image-fit property to Image/ClippedImage 2020-12-15 10:26:54 +01:00
Olivier Goffart
395e11a558 Change the default window title 2020-12-10 10:52:33 +01:00
Olivier Goffart
198a1e17c1 Close the combobox on click 2020-12-07 17:08:48 +01:00
Simon Hausmann
1e683de64d Simplify Rust Timer API
Don't require the caller to Box the closure. With the assumption that
the majority of callers *want* the closure to be boxed (i.e. it's not
already boxed), the API becomes easier to use.
2020-12-04 10:57:19 +01:00
Olivier Goffart
7bfa998f00 Popup positioning 2020-11-30 18:39:41 +01:00
Olivier Goffart
b0a9d65f55 More Popup WIP 2020-11-30 18:39:41 +01:00
Olivier Goffart
852eeb1c11 WIP popup 2020-11-30 15:20:51 +01:00
Olivier Goffart
3ae7c6e0b5 Hover effect 2020-11-24 18:09:32 +01:00
Olivier Goffart
845627c6b4 Implement the mouse_input in a generic way so we can remove the one in the component 2020-11-24 15:40:41 +01:00
Olivier Goffart
124eec9960 Introfuce ItemRc and ItemWeak
Wrapper around ComponentRc and index
2020-11-24 13:42:34 +01:00
Simon Hausmann
f0289192b7 More font handling cleanup
Group all fields we need to determine a physical font into one FontRequest
structure and use that throughout.

That way adding more fields will require less changes.
2020-11-24 09:00:07 +01:00
Simon Hausmann
3d85e45ec3 Add support for source clipping to the Image element
This allows rendering only a sub-rectangle of the original image, which
we can use right away in the sliding puzzle demo.
2020-11-23 15:46:59 +01:00
Olivier Goffart
596b740b62 Rename ARGBColor to RgbaColor 2020-11-23 11:47:47 +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
78fae068dd Use ComponentRc during item tree traversal
This is in preparation for allowing the run-time / items to clone VRc's
of the component.

ComponentVTable functions like visit_children_item contine to take a
ComponentRefPin as "self" parameter type, as a VRc would not be
supported by rust right now. That means the implementation then uses
self_weak to obtain a strong self-reference.
2020-11-19 17:04:01 +01:00
Simon Hausmann
7a5113ece1 Free graphics resources without item tree traversal 2020-11-18 08:49: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
3f0c9c97b7 Remove some component parameters from GenericWindow 2020-11-11 19:06:07 +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
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
Simon Hausmann
842339f620 Avoid an unusable window due to invalid constraints
With manually placed maximum-width and minimum-width bindings it's
possible to create a layout where the minimum is greater than the maximum.

In the unlikely event of that happening, swap min/max so that the window
is resizeable. Otherwise at least on macOS the window manager tries to
apply both and the window funnily jumps.
2020-10-30 14:23:53 +01:00
Simon Hausmann
178d83b305 Fix wrong initial window size on macOS/Windows and endless repaints
Setting the size will trigger a repaint, even if it didn't change.
2020-10-30 14:23:24 +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
a98da9ecc9 Draw rounded rectangles with anti-aliasing
Draw rounded rectangles using a distance function. This removes the need
to use lyon to tesselate the rounded corners and as a bonus it gives
anti-aliased borders.
2020-10-21 09:35:35 +02:00
Simon Hausmann
1887b37af7 Remove premultiply_alpha from ARGBColor again
It's not safe to use with ARGBColor<u8> because of overflows, so instead let's
use it in the place where we need it and where the precision is given.
2020-10-19 18:45:33 +02:00
Simon Hausmann
6dd08b2109 Fix color blending when using the alpha channel
Given choice of ONE_MINUS_SRC_ALPHA blending function, we assume not
only that textures are pre-multiplied with their alpha (see commit
bf396ad578), the same applies also to
flat colors.

This fixes blending such as this:

    App := Window {
        Text {
            text: "Hello World";
        }
        Rectangle {
            color: #ff335588;
            width: 100%;
            height: 100%;
        }
    }
2020-10-19 17:21:03 +02:00