Commit graph

1488 commits

Author SHA1 Message Date
Olivier Goffart
4e7bbcf2ba
Try to improve rendering (positioning) of signed field distance font. (#6868)
* WIP: swrenderer: use fixed point for the pixmap font coordinate

* swrenderer: signed distance field: move the glyph to the middle

* swrenderer: round the advance instead of truncating it in distance field

* swrenderer: actually align the gplyph on the sub-pixel precision

sub-pixel within the source.

* swrenderer: adapt the threshold for signed distance field

sqrt(2) is the distance to the diagonal, seems like this gives sharper fonts

* Fix bug in the elision, and re-upload the screenshort

the screenshot changed because the afvanced is now rounded intead of
truncated
2024-11-30 23:03:31 +01:00
Tobias Hunger
312d091a1d live-preview: Improve handling of cached files
The idea of the live-preview is that it never causes disk
access itself, the LSP side handles all that for it.

With this in mind:

* Keep source code of invalidated files in the cache. This
  way we will see whether we need to refresh the UI after the
  LSP has read the data back from disk. This avoids quite
  a bit of rerendering just because an unchanged buffer was
  closed in the editor (e.g. because the editor switched buffers!)

* Always return `Some` from our file open fallback so that the
  compiler does not fall back to reading data from disk

* Do not try to render if the main file has no source code yet.
  The LSP will tell us about the sources in time
2024-11-27 16:37:09 +01:00
FloVanGH
712f930897
windows: added skip_taskbar (#6911)
* Update internal/backends/winit/winitwindowadapter.rs

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update internal/backends/winit/winitwindowadapter.rs

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update docs/src/content/docs/reference/window/window.mdx

Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>
2024-11-27 09:55:11 +00:00
Simon Hausmann
0d8b0630c7 Avoid inlining @image-url() expressions that can be expensive due to cache misses
If the `image-url()` expression of an `Image { source: @image-url("large-image.png"); ... }` gets inlined into geometry getters and other places that are called for every frame, then we might end up decoding images every frame, if the image isn't in the 5MB image decoder cache. It's better to rely on the `property <image>` of the `Image` for caching the decoded image, so don't inline those.

This fixes CPU being time being spent constantly on decoding images on the home automation lock screen.
2024-11-27 09:10:26 +01:00
Olivier Goffart
e44f7d7a4c LSP: fix reloading loaded dependencies
The change in https://github.com/slint-ui/slint/pull/6747
invalidated the cache, but it was only reloaded when one of the dependent was reloaded.
We need to reload the cache for all open file so that LSP feature continue to work on
open document even if they get no changes
2024-11-26 14:27:56 +01:00
szecket
ba14285332
Szecket/cupertino colours (#6801)
* creating a lookup table of colors based on the set on apple docs
then selecting from these colors rather than always typing hex
also added an in property for setting selected color (future)

* splitting out method of changing selection colour for later

* forgot to pull CupertinoColors from import

* Squashed commit of the following:

commit 4924aa908d6e039a7bf1f79ede3dc7c26f71007f
Author: szecket <szecket@magrittescow.com>
Date:   Fri Nov 15 17:31:45 2024 -0500

    use  defined Palette for states

commit 80711ee7188f37b1b29ce11855b6a636d7a39306
Author: szecket <szecket@magrittescow.com>
Date:   Fri Nov 15 17:29:51 2024 -0500

    make control colour consistent with style and other controls

commit 1cfd39e6da6643600e8b553dfab2418c8552cdc4
Author: szecket <szecket@magrittescow.com>
Date:   Fri Nov 15 13:58:07 2024 -0500

    selection of controls when focused is not current cupertino style and too strong

commit 4bf4ae6ad385e118687f752362b34e079c03fe22
Author: szecket <szecket@magrittescow.com>
Date:   Fri Nov 15 13:42:58 2024 -0500

    make foreground color contrast when selected

* removing property that is only in cupertino
2024-11-22 08:18:27 +13:00
Olivier Goffart
c0a123b6b9 Callback arguments names is no longer experimental
ChangeLog: named callback arguments
2024-11-21 09:53:17 +01:00
Olivier Goffart
6e91b9bc91 Give name to the builtin element's callback argument 2024-11-21 09:53:17 +01:00
Olivier Goffart
f225f79d49 compiler: Put the argument names in the Type
That simplifies things a bit and will allow to have names for builtin callback and functions
2024-11-21 09:53:17 +01:00
Aurindam Jana
0898a5f641
Tweak Docs (#6834)
---------

Co-authored-by: Nigel Breslaw <nigel.breslaw@slint.dev>
2024-11-20 14:27:37 +01:00
FloVanGH
2200a64471
added min/max support for rem (#6842) 2024-11-20 10:19:28 +00:00
Olivier Goffart
5bd20def0e Experimental support for MenuBar
Introduces `MenuBar{ ... }` that can be put in a Window
2024-11-20 09:25:37 +01:00
Olivier Goffart
73b549a42c bundled translation: Better error reporting
forward the error up the stack instead of panicking while producing the llr
2024-11-19 21:34:42 +01:00
Milian Wolff
f6da161dbb
Reduce SmolStr <-> &str conversions and copies (#6688)
SmolStr has an Arc internally for large strings. This allows
cheap copies of large strings, but we lose that ability
when we convert the SmolStr to a &str and then reconstruct a
SmolStr from that slice.

I was hoping for some larger gains here, considering the impact
of this code change, but it only removes ~50k allocations,
while the impact on the runtime is not noticeable at all.

Still, I believe this is the right thing to do.

Before:
```
        allocations:            2338981

  Time (mean ± σ):     988.3 ms ±  17.9 ms    [User: 690.2 ms, System: 206.4 ms]
  Range (min … max):   956.4 ms … 1016.3 ms    10 runs
```

After:
```
        allocations:            2287723

  Time (mean ± σ):     989.8 ms ±  23.2 ms    [User: 699.2 ms, System: 197.6 ms]
  Range (min … max):   945.3 ms … 1021.4 ms    10 runs
```
2024-11-19 10:07:16 +01:00
Olivier Goffart
d68b84a3f1
Change API to set the language with bundle translation
* Change API to set the language with bundle translation

Part of #6793
2024-11-17 11:40:02 +01:00
FloVanGH
5ea05e18af
std-widgets: added horizontal-alignment to SpinBox (#6778) 2024-11-15 08:05:57 +00:00
Olivier Goffart
5b3ea5cdd5 LSP: record dependencies and invalid all dependents when a dependencies changes
Fixes #5797
2024-11-14 14:35:22 +01:00
Olivier Goffart
cde5133045 compiler: Remember all import in the document with their absolute path
That way we will be able to use that in the LSP to get the dependencies
2024-11-14 14:35:22 +01:00
Olivier Goffart
ed951202e4 compiler: process the import a bit differently
Don't filter type import with the extension. Instead if the import
statement is having braces, always consider it is a slint file, and if
not, consider it as a foreign import
2024-11-14 14:35:22 +01:00
Olivier Goffart
0533fa4acf compiler: don't call resolve_import_path twice
`resolved_import` is only used for non .slint file.
For slint file, `ensure_document_loaded` will call
`resolve_import_path` again.
2024-11-14 14:35:22 +01:00
FloVanGH
9cfe8862f9
embed glyphs: removed duplicated, added missing chars (#6782) 2024-11-14 07:36:25 +00:00
Olivier Goffart
ed372e91a1 Fix wrong optimization trying to merge common properties around assignments
the deduplicate_property_read was bailing out the replacement if one
part of the coinditional branch do assignment. But the other part might
already have partial assignment, so we must continue

Fixes #6616
2024-11-13 22:14:56 +01:00
Olivier Goffart
650fd0eef5 Fix panic when calling expression containing un-called macro
Fixes #6650
2024-11-11 16:08:22 +01:00
FloVanGH
2cb5fb1d99
std-widgets: fixed arrow size of scroll bar button (#6728) 2024-11-11 15:02:39 +00:00
Olivier Goffart
e854e11399 Error when making a for over an empty array
Instead of panicking.

Attempt to fix it in #6765 didn't work for C++.
Code generation might be hard for C++, so I thought it's better to error out.

Fix #6760
2024-11-11 13:23:56 +01:00
FloVanGH
c84af1a8d7
std-widgets: added LayoutSpec global (#6711) 2024-11-06 14:47:04 +00:00
Olivier Goffart
e3ea25f48c LSP: Signature Help 2024-11-06 13:27:29 +01:00
Olivier Goffart
3552e004e1 Fix wrong value or panic in the interpreter when converting struct of struct
The "tmpobj" variable was overwriten because the interpreter (contrary
to rust and C++) don't have scopes for the local variables, and local
variable of the same name would conflict.
(I think this could in theory be a problem in C++ and rust although i
haven't reproduced it)

Other uses of StoreLocalVariable also make the number unique with a
counter

Fixes #6721
2024-11-05 14:06:09 +01:00
Olivier Goffart
929e71e6b0 Widgets: add callback arg names to some callback
The ones that have a comment already.

Tests that the name is consistent accross the styles.
2024-11-04 17:09:57 +01:00
Olivier Goffart
51e4d4562a Do not print the internal struct name in LSP tooltip or error message
just strip the `slint::` or `slint::private_api::`
This is not a 100% match to the slint name (eg, LogicalPosition) but
it is better anyway
2024-11-04 17:09:57 +01:00
Olivier Goffart
b44172be4f Janitor: Remove BuiltinElement::reserved_properties
It was added when support for `font-metrics` was added, but there is no
reason why this can't simply be in the `properties` hash.
2024-11-04 17:09:57 +01:00
Brandon Fowler
6da0f55b05
Associate PopupWindows with an ID for their active popup (#6693)
Popups are stored in a HashMap and are assigned an ID so popup.close(); closes the correct popup and so a single PopupWindow cannot be opened multiple times
2024-11-04 09:17:55 +01:00
Ryan Naddy
908580b951
Added rejected to textedit (#6662) 2024-10-31 16:23:50 +01:00
Olivier Goffart
446bb4a6bf
swrenderer: signed distance field: properly round the x and y glyph coordinate (#6687) 2024-10-30 18:12:52 +01:00
Arnold Loubriat
17207b0508 Make accessible-position-in-set zero-based 2024-10-30 15:54:01 +08:00
Arnold Loubriat
97219c21bf Add the accessible-size-of-set property 2024-10-30 15:54:01 +08:00
Arnold Loubriat
67166fcc2d Add the accessible-position-in-set property 2024-10-30 15:54:01 +08:00
Olivier Goffart
95f5685789
Bundle translations (#6661)
This currently doesn't have public API to enable it yet.

TODO:
 - Error handling in the compiler
 - Public API in the compiler configuration
 - Documentation
2024-10-29 15:07:15 +01:00
Milian Wolff
2f62c60e3c
Optimize resolve_expression to operate on a single scope vector (#6664)
Instead of cloning the vector on every iteration level, pass the
scope in and out of the visitation function and push/pop the element
there as needed. This way we can operate on a single vector that
gets moved around, which removes a few thousand memory allocations.
The speed impact is not measurable, as the code also triggers rowan
API that is much more allocation happy.

Still, I believe this patch is still merge-worthy as it also reduces
the code duplication a bit and is subjectively better, esp. from a
performance pov.
2024-10-29 11:46:04 +01:00
Olivier Goffart
6bb0e6038f
Merge the Callback and Function type
There is no need for two of these
This simplify some code

Amend efdecf0a13
2024-10-28 14:36:30 +01:00
Olivier Goffart
dff19c52da Fix assertion failed: lhs_lookup.is_local_to_component
Fixes #6632
2024-10-28 11:44:25 +01:00
Milian Wolff
89bc023819 Optimize: Filter/map rowan nodes instead of doing multiple lookups
Instead of doing potentially multiple calls in the chained calls,
each of which would allocate in rowan, we now only call the iterator
function once and then leverage `find_map`. This is arguably even
more readable and it removes ~300k allocations and speeds up parsing.

Before:
```
  Time (mean ± σ):     930.7 ms ±  15.1 ms    [User: 678.7 ms, System: 165.5 ms]
  Range (min … max):   906.4 ms … 956.3 ms    10 runs

    allocations: 2339130

```

After:
```
  Time (mean ± σ):     914.6 ms ±  22.7 ms    [User: 649.6 ms, System: 174.5 ms]
  Range (min … max):   874.8 ms … 946.3 ms    10 runs

    allocations: 2017915

```
2024-10-28 09:40:58 +01:00
Milian Wolff
79e1592b9f Intern some more common types
This is just for completeness, we "only" save ~13k allocations
with no measurable speed impact:

Before:
```
  Time (mean ± σ):      1.019 s ±  0.033 s    [User: 0.716 s, System: 0.203 s]
  Range (min … max):    0.957 s …  1.061 s    10 runs

        allocations:            2679001

```

After:
```
  Time (mean ± σ):      1.015 s ±  0.015 s    [User: 0.715 s, System: 0.201 s]
  Range (min … max):    0.997 s …  1.038 s    10 runs

        allocations:            2666889
```
2024-10-28 09:39:54 +01:00
Milian Wolff
df1dd3b6cf Use one central thread_local for builtin function types
Instead of occupying multiple TLS slots, introduce a single type
that stores all the builtin function types in members. Use a macro
to define this struct then, which allows us to use a nice DSL to
define these function types, reducing the boiler plate significantly.

The downside is that we no longer have the ability to easily share
semantically equivalent function types (e.g. for `Round`, `Ceil`
and `Floor` etc.). Doing so would require us to introdue a separate
name for these types, and then use external matching to map the
BuiltinFunctions to the reduced list of types. The performance impact
is minimal though, so this is not done to KISS.
2024-10-28 09:39:54 +01:00
Milian Wolff
6ff8abfb1a Move thread local types from typeregister into BUILTIN
This way we don't need a separate TLS slot for these two types.
2024-10-28 09:39:54 +01:00
Milian Wolff
6e9e66ea7d Refactor typeregister's BUILTIN_ENUMS => BUILTIN.enums
This will allow us to add more buildin types to this thread local
in follow-up patches, to reduce the number of thread local slots.
2024-10-28 09:39:54 +01:00
Milian Wolff
00dec34d34 Cache the reserved properties in a hash map for reserved_property()
The latter accumulates ~2.6% of all CPU cycles, Now, it only takes
1.3% by using the hash map here.
2024-10-28 09:39:54 +01:00
Milian Wolff
0abfb056a1 Also use Rc for langtype::Type::Array
This is rarely used, but using Rc here like elsewhere allows us to
elide a few unneccessary memory allocations when copying such types.
The speed impact is not measurable though. With heaptrack I see that
we get rid of the last ~7600 allocations in my benchmark when cloning
Type.
2024-10-28 09:39:54 +01:00
Milian Wolff
fd0eb01c55 Share common definitions for builtin function types
This way we can reuse a single reference counted type where possible.
2024-10-28 09:39:54 +01:00
Milian Wolff
0fc9f3574a Only allocate the BuiltinFunction::ty() return types once
These are known statically, so let's store them once in thread local
statics and return them from there.

Before:
```
  Time (mean ± σ):      1.034 s ±  0.026 s    [User: 0.733 s, System: 0.201 s]
  Range (min … max):    1.000 s …  1.078 s    10 runs

        allocations:            2917476
```

After:
```
  Time (mean ± σ):     996.9 ms ±  17.7 ms    [User: 708.9 ms, System: 202.9 ms]
  Range (min … max):   977.8 ms … 1033.1 ms    10 runs

        allocations:            2686677
```
2024-10-28 09:39:54 +01:00