Commit graph

255 commits

Author SHA1 Message Date
Simon Hausmann
79b7e825bb Minor cleanup of font cache handling
Store the font family as a SharedString, as that allows us to make a
lookup without a string copy.
2020-11-23 18:23:22 +01:00
Simon Hausmann
bad7734c21 Avoid leaking cached texture allocations
Let the texture cache hold weak references and drain them each time
the rendering primitives builder finishes.
2020-11-23 16:26:21 +01:00
Simon Hausmann
ad99dc6475 Add support for image loading caching for embedded images
Extend the texture cache in the GL rendering backend to has by either
the path on disk or by the address of the static data.
2020-11-23 15:50:00 +01:00
Simon Hausmann
fdeda0d0ed Add some basic image loading caching for images loaded from the file system
Place them in a HashMap that's indexed by the path. This needs further
tuning, for example to also be applied to embedded images, and the cache
shouldn't hold a strong reference. But it makes the berlin page
playable.
2020-11-23 15:49:57 +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
Simon Hausmann
7583394751 Remove unnecessary image_size field of the Texture low-level primitive
Since our atlas allocator has an alignment of 1, the texture coordinates
(non-normalized) are identical.
2020-11-23 13:53:35 +01:00
Olivier Goffart
2e60afec39 Run cargo fmt 2020-11-23 12:08:23 +01:00
Olivier Goffart
596b740b62 Rename ARGBColor to RgbaColor 2020-11-23 11:47:47 +01:00
Olivier Goffart
62272bd73d Fix canvas size on browser. The size writen in the html is logical 2020-11-13 15:48:26 +01:00
Olivier Goffart
a82c23fc41 Add ability for the native style to export native Globals 2020-11-02 16:13:04 +01:00
Olivier Goffart
608ba95f9e Fix wasm warning 2020-10-31 11:58:10 +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
ccb57114ce Clean up cursor rectangle handling
Generalize this to be called a normalized rectangle and create it by hand.
2020-10-21 08:15:16 +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
Olivier Goffart
b60567d7f2 Qt style: Use an QImage that is backed by a SharedArray
This way we have one copy less of the data
2020-10-19 11:35:57 +02:00
Simon Hausmann
93df708d87 Fix clipping in the wasm demos
Enable the stencil buffer on the WebGL context attributes.
2020-10-15 07:42:33 +02:00
Olivier Goffart
d57ad389e0 Default to the native style in the viewer if it is available 2020-10-14 14:51:47 +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
f4b6eea646 Implement the rest of the dynamic image loading for the online editor
This works except that there's a mechanism missing for refreshing the
canvas when the image was loaded.
2020-10-09 10:10:48 +02:00
Simon Hausmann
785f23f01a Make the tex__image_2d call work
* Set cross origin for the image to "anonymous" to ask the server for permission
* Pass RGBA as internal format
2020-10-09 09:57:45 +02:00
Olivier Goffart
6c9f0691aa WIP: Attempt to get image loading in wasm
Not working
2020-10-09 09:57:45 +02:00
Simon Hausmann
0f07684fcf Clean up GLFrame::render_primitive
Move the main match out into a separate helper function in GLFrame and
keep render_primitive to just be the loop. This will also make it easier
to implement the dynamic primitives later.
2020-10-09 09:56:32 +02:00
Simon Hausmann
88b94a26ea Add support for clip rectangles in the GL rendering backend 2020-09-29 11:42:02 +02:00
Simon Hausmann
1e450abc9c Change layer contents placement policy to reduce visual mess when resizing
This makes window resizing much smoother. Great advice from an anonymous
Norwegian friend ;-)
2020-09-22 14:30:27 +02:00
Simon Hausmann
4f25b0942f Draw text selections 2020-09-21 18:43:59 +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
dd8e487acc Fix discrepancy between Text layout info and rendering
The layout_info() would calculate the text metrics based on a different effective pixel
size compared to the rendering.
2020-09-15 16:15:26 +02:00
Simon Hausmann
c69781ace2 Upgrade glow 2020-09-15 11:14:23 +02:00
Simon Hausmann
19cce012a0 Add ARGBColor<T> to the color API
As discussed in the last API review, this replaces the as_rgba_f32/u8
"accessor" functions by returning a struct with named fields.
2020-09-08 22:11:23 +02:00
Simon Hausmann
220dc2ee47 Fix rendering of rounded rectangles in examples preview
For something like

    Window {
        GridLayout {
            Rectangle {
                border_width: 2lx;
                border_radius: 2lx;
                border_color: black;
            }
        }
    }

The border was not fully visible and partly obscured by the window
frame, the canvas element in the case of the preview in the examples.
That looks bad, and this patch fixes it by respecting the border width
in the geometry used to stroke and fill the rectangle.
2020-09-04 14:27:58 +02:00
Simon Hausmann
b50e42a7ba Avoid large empty canvas elements in the html docs
Some of the example code does not include a Window {} element with a
size.  The html says <canvas width=100 height=100> but it turns out that
winit is not interested in these values and any newly created window
with a canvas will get an initial size of 1024x768.

This is not quite the behavior we want, preserving the canvas size may
be more sensible -- it certainly is for our docs. So this patch tries to
preserve that.
2020-09-04 10:12:34 +02:00
Simon Hausmann
570e51eaa9 Improve API of color handling of text
Make the text color a rendering variable, so that it can be passed
through as uniform to the glyph shader and applied to the gray
map of the glyphs. This avoids re-creating the glyph runs when
merely the color changes.

This already "worked" for the glyph cache based text rendering,
but it wasn't used because of the wasm canvas code path. This
patch changes that to render the text into a text using simply black
and then render that texture using our existing glyph shader,
which merely uses the alpha channel anyway.

This reduces also #cfg's.
2020-09-02 11:48:41 +02:00
Olivier Goffart
f1ad78bc25 Qt style support for the rust backend
Need to set the SIXTYFPS_STYLE=native env variable while compiling
2020-09-01 12:25:11 +02:00
Olivier Goffart
6d41b1981d Move the Qt style to a new backend: the Qt backend
Currently the Qt backend still redirect everything to the GL backend,
but the goal is to use QPainter and QWindow

This also adds a "default" backend, whose goal is to select the proper
backend at compile time
2020-08-31 17:26:04 +02:00
Simon Hausmann
07fa020e81 Fix flickering in gallery example when pressing spin box buttons
The path shader uses only one attribute array, while the others use two.
First rendering with say the glyph shader and then the path one may leave
odd artifacts around with GLES, which is fixed by properly disabling the
vertex attribute arrays after use.

Closes: #17
2020-08-28 17:49:45 +02:00
Olivier Goffart
80dd7dcb04 Allow to specify the canvas id when creating a new window with wasm 2020-08-26 17:01:17 +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
a54f222e52 Clean up glyph run creation code
Move more into the glyph cache module
2020-08-13 10:48:27 +02:00
Simon Hausmann
df2620838e Improve RefCell usage
Use a RefCell only where we need it, in the glyph cache. We don't need
it for the platform data.
2020-08-13 10:23:08 +02:00
Simon Hausmann
7807631ba0 Fix leaking texture atlas allocations
When a rendering primitive holding a reference into a texture atlas
allocation is dropped, we should free that area for future re-use.
2020-08-10 17:30:41 +02:00
Simon Hausmann
d6ef7c31a8 Fix rendering artifacts when scaling
The use of the texture atlas may result in pixels from adjacent textures
bleeding into the currently rendered texture. The standard technique appears to be
to add a padding around each image.
2020-08-10 15:53:44 +02:00
Simon Hausmann
ccb2e23cf5 Fix GL texture not freeing its texture id
Similar to the shaders, keep a reference count on the resource itself and
keep the context around for convenient deletion.

Fixes: #3
2020-08-10 11:20:58 +02:00
Simon Hausmann
6faf7439c2 Delete GL shader programs automatically
We already keep the context in an RC, might as well keep another copy :-)

This re-applies commit 9b0dfa14b5 but
replaces the Clone trait on Shader, which would lead to duplicate and
too early program deletion, with an Rc<Shader>.
2020-08-10 11:20:58 +02:00
Simon Hausmann
d9c776eb57 Revert "Delete GL shader programs automatically"
This reverts commit 9b0dfa14b5 as there's
an issue with webgl and everything disappearing.
2020-08-10 09:50:04 +02:00
Simon Hausmann
9b0dfa14b5 Delete GL shader programs automatically
We already keep the context in an RC, might as well keep another copy :-)
2020-08-08 13:31:37 +02:00
Simon Hausmann
f86f8360b2 Fix rendering of text with spaces
Don't waste glyphs and potential pixels from the rasterizer for space --
merely use the advance.
2020-08-07 15:32:59 +02:00
Simon Hausmann
aecf6a8878 Center text in buttons in the demo and gallery
This adds horizontal_alignment/vertical_alignment properties, along with
width/height to Text.

This still uses a hard-coded enumeration in the compiler, which is meant
to go away in favor of general enum support.
2020-08-07 10:02:52 +02:00
Simon Hausmann
b6a5810bdc Fix wasm build 2020-08-05 11:10:39 +02:00
Simon Hausmann
d3c596669c Add larger icons to the printer demo
The icons on the main screen are now nicely large and they scale down on
activation.
2020-08-05 10:04:11 +02:00