Commit graph

143 commits

Author SHA1 Message Date
Tobias Hunger
da78228c56 live-preview: Fix handling of enums
The enum extraction code used to handle values in the
form `EnunName.EnumValue` just fine, but igonred
`EnumValue`. Fix this.
.
2024-12-16 14:31:34 +01:00
Tobias Hunger
4d309f69ba live-preview: Filter in Selection Popup
Add a filter into the Selection popup to filter out
anything not matching.

If all letters are lowercase, then it will do a case-insensitive
match, if there are non-lowercase characters it will do
case-sensitive matching instead.
2024-12-10 18:21:41 +01:00
Tobias Hunger
c44a0f0a1d live-preview: Show popup when preview is outdated
... but keep the old preview visible otherwise.
2024-12-09 13:26:41 +01:00
Tobias Hunger
03e02b5094 live-preview: Have the selection popup highlight locations
Have the selection popup actually highlight the hovered
object in the editor.

We did not have this use case before: We used to either
highlight after an update or never at all. Neither semantic
matches what we are doing in the selection popup, so I added
a highlight-now flag.
2024-11-27 17:26:38 +01:00
szecket
613b2982f1
experiment for highlighting UX (#6837)
* experiment for highlighting UX

this works really well but ideally goes back to what was selected before right click OR the selection actually moves rather than the hover color

* live-preview: Unselect in SelectionPopup again

When un-hovering some item to preview it's selection,
switch selection back to the original selection.

---------

Co-authored-by: Tobias Hunger <tobias.hunger@slint.dev>
2024-11-23 02:57:08 +13:00
Tobias Hunger
9d5b9fb46a live-preview: Implement a selection stack
... that provides a model containing all the elements
at a position sorted from "front" to "back" with extra
information so that we can present the data in a nice UI
in the next step.

The selection code now filters out builtins and ignore nodes
when collecting nodes. So the following filter step does not
need to take those into account anymore.

Whether a selection candidate is actually a part of the root
component or not is now handled by looking at whether the
elements text range is inside the root component's text
range. This is closer to what users expect to happen I think.
2024-11-19 20:20:14 +01:00
szecket
418f279abd
Sub attributes2 (#6749)
* spacing correction

* converted all property value blocks to widgets

* added secondary controls for color and string

* added secondary visuals to make hierarchy more visible

* live-preview: Wire up color widget with the backend

It lets you select colors based on the sliders, but it will
*only* apply the color when you hit enter on the text field
with the color string...

Not nice, but at least it does not keep losing state as it
round-trips the change through the code and compiler and
gets the state reset all the time.

* more dummy data

* cleanup of property sheet based on new controls

* added secondary visuals to make hierarchy more visible

correct extraneous changes

---------

Co-authored-by: Tobias Hunger <tobias.hunger@slint.dev>
2024-11-19 02:55:30 +13:00
Tobias Hunger
10de1e664b live-preview: Default to "native" as expected (if that is available!) 2024-10-22 14:50:41 +02:00
Milian Wolff
0f6c3a4fd7 Use SmolStr in more places of the compiler infrastructure
This removes a lot of allocations and speeds up the compiler step
a bit. Sadly, this patch is very invasive as it touches a lot of
files. That said, each individual hunk is pretty trivial.

For a non-trivial real-world example, the impact is significant,
we get rid of ~29% of all allocations and improve the runtime by
about 4.8% (measured until the viewer loop would start).

Before:
```
Benchmark 1: ./target/release/slint-viewer ../slint-perf/app.slint
  Time (mean ± σ):     664.2 ms ±   6.7 ms    [User: 589.2 ms, System: 74.0 ms]
  Range (min … max):   659.0 ms … 682.4 ms    10 runs

        allocations:            4886888
        temporary allocations:  857508
```

After:
```
Benchmark 1: ./target/release/slint-viewer ../slint-perf/app.slint
  Time (mean ± σ):     639.5 ms ±  17.8 ms    [User: 556.9 ms, System: 76.2 ms]
  Range (min … max):   621.4 ms … 666.5 ms    10 runs

        allocations:            3544318
        temporary allocations:  495685
```
2024-10-17 18:04:58 +02:00
Tobias Hunger
6ed506ab1f live-preview: Sort styles in style combobox
Fixes: #6251
2024-10-07 11:15:54 +02:00
Tobias Hunger
57084a61ec live-preview: Do not consider negative numbers to be complex
... and add some tests ...
2024-09-30 14:54:03 +02:00
Tobias Hunger
d22f202012 live-preview: Filter out properties that make no sense
Filter out properties related to layouts that make no sense
for the current element. These are x/y coordinates and the
grid layout related properties.

It's tricky to do: The properties are looked up in the
context of the unoptimized DocumentCache, so that
(most) properties are visible. The layout information is
not available there though as base types are not resolved yet.

So the layout information is taken from the preview data.
2024-09-30 14:53:01 +02:00
Tobias Hunger
eb3e1dded1 live-preview: Re-ordering of properties in property editor
All other tools have custom widgets for x/y, width/height, etc.,
let's try to come close by at least presenting the properties in
in a logical order that lends itself to data input.

This reorders geometry to show `x`, `y`, `width` and `height` followed by `z`.

It also orders layout as `min-width`, `min-height`, `preferred-width/-height',
and `max-width/height` followed by horizontal and vertical stretch.
2024-09-20 14:49:42 +02:00
Tobias Hunger
3c171f0655 live-preview: Only look at the code when comparing PropertyValues
The rest is derived from code anyway...
2024-09-18 23:22:42 +02:00
Tobias Hunger
9b47b37039 live-preview: Sort properties and split them up into groups
I was stupid this morning: The properties need to be sorted.

So I need to group the properties into groups and I also want
to be able to define in which order the groups will be listed
in the UI. So add a `priority` in addition to the group and use
group name and priority to sort properties into groups.

The test changes since the order changed and it tries to insert
based on previous/later properties.
2024-09-18 23:22:42 +02:00
Olivier Goffart
db5b4686ad property editor: Show the default value from base component when no binding exist
When no bindings exist on the component, the value that is shown in the
property editor should be the default value for that property as defined
in the base component or in the builtin element. Not just the default
value of the type
2024-09-18 18:14:28 +02:00
Tobias Hunger
0e751b1eea livve-preview: Make the color widget editable
... in a bare-bones fashion.
2024-09-18 15:38:45 +02:00
szecket
126ab85366 live-preview: Prettify the property editor 2024-09-17 18:39:37 +02:00
Tobias Hunger
41bdadd960 live-preview: Add a CodeButton component
... and use it in places
2024-09-17 18:39:37 +02:00
Tobias Hunger
ca64212369 live-preview: Less model updates for property editor
Move the model into an extra porperty and move information
irrelevant for the UI behind a callback, so that changing that info
will not invalidate the UI.
2024-09-17 10:29:31 +02:00
Simon Hausmann
5825cb4f46 Use command instead of control for the status text when running on macOS 2024-09-12 12:48:34 +02:00
Tobias Hunger
677838de83 live-preview: Only show style dropdown when importing std-widgets 2024-09-10 16:21:57 +02:00
Tobias Hunger
242ff57d5e live-preview: Add reload preview command to Api
... and make `Ctrl-Shift-R` trigger it in edit mode, in the same broken
way we handle the `Delete` key. It works -- till you hit `Tab` to move
the focus.

We really need #4063 or similar!
2024-09-10 14:19:54 +02:00
Tobias Hunger
cab41c3d0c lsp: Use more TextSize
I got carried away, I replaced `u32` with `TextSize` in one place
because that's what I got and I did not want to convert... and
then I fixed the fallout.

No functional change is intended in any of this.

FIXUP
2024-09-10 13:31:52 +02:00
Tobias Hunger
063d976d28 live-preview: Report @tr properly to property editor
... so that all information for a round-trip into the Property editor
and back is available.
2024-08-30 19:52:55 +02:00
Tobias Hunger
f4c4fed393 live-preview: Always test the property test1
... when testing conversion of properties.
2024-08-30 19:52:55 +02:00
Tobias Hunger
c92960b9d3 live-preview: Remove setters that are not too helpful
We are getting too many setters for properties in our Api IMHO,
so remove two that are easy enough to replicate with `set_code_property`.
2024-08-30 19:52:55 +02:00
Tobias Hunger
64e8330d04 live-preview: Add setter for color property changes 2024-08-30 19:52:55 +02:00
Tobias Hunger
a7c0ae30e8 live-preview: Report property values with units to UI 2024-08-29 17:08:26 +02:00
Tobias Hunger
82fad654a4 live-preview: Parse Color in property data 2024-08-29 17:08:26 +02:00
Tobias Hunger
4bb823830b live-preview: Parse Int32 in property data 2024-08-29 17:08:26 +02:00
Tobias Hunger
fae9b09d86 live-preview: Parse Float32 in property values 2024-08-29 17:08:26 +02:00
Tobias Hunger
e0cf679c0f live-preview: Improve conversion of property info to UI
... and use that in the (still almost unchanged) UI.
2024-08-28 18:02:47 +02:00
Tobias Hunger
7da032ab36 live-preview: Use langtyoe::Type for type info on properties 2024-08-28 18:02:47 +02:00
Tobias Hunger
4a2e2fb2ed live-preview: Pass a element node to ui when converting property info
We need an ElementRcNode (based on the AST from the document cache!),
so that we can look up types in the Document's local type registry.
2024-08-28 11:02:42 +02:00
Tobias Hunger
b5b5f59990 Move AST nodes closer to the simple value extractor 2024-08-28 11:02:11 +02:00
Tobias Hunger
3c1a26ff82 live-preview: Pass a SyntaxNode along with the properties information
Pass the syntax node defining the current property value along with
the other information on properties.

This will allow us to look at the AST nodes and not just the string
value containing the expression.
2024-08-26 14:51:47 +02:00
Tobias Hunger
6d81096ac6 live-preview: Use PathBuf in DeclarationInformation 2024-08-23 18:58:44 +02:00
Tobias Hunger
0f0b76e952 lsp: Clippy fixes 2024-08-23 18:58:44 +02:00
Tobias Hunger
1a306dd155 live-preview: Use TextRange and TextSize in property information
The Properties are no longer sent out straight to the editor, so
we do not need to convert our internal `TextRange` and `TextSize`
to `lsp_types::Range` and `lsp_types::Position`.

We are noweadys turning that straight back into offsets -- which is
just another name for `TextSize` (or pairs of offsets).
2024-08-23 18:58:44 +02:00
Tobias Hunger
1c447db8ca lsp: Build without SourceFileInner::version()
... in preparation to removing that functionality.
2024-08-21 16:55:13 +02:00
Tobias Hunger
092ca597bb live-preview: Remove history navigation
We apparently do not want history-based navigation,
so remove the code supporting that again.
2024-08-14 16:05:24 +02:00
Tobias Hunger
4e68aa1510 lsp: Remove custom commands for property handling
These commands are not needed anymore since we integrated
the property editor into the live preview.

Move the properties code out of `common` and into `preview`
for good measure.
2024-08-08 16:39:37 +02:00
Tobias Hunger
daae440da7 live-preview: Prettify showing of library components in library view 2024-07-19 12:25:10 +02:00
Tobias Hunger
3f41b6f69d live-preview: Make component selection more robust
... by not relying on the component name, which could be used in several
files.
2024-07-17 17:52:12 +02:00
Tobias Hunger
34c9351c31 live-preview: List more components in the components list
* Show all file-local componanets (check is-exported)
* Parse all known files before generating the file list

Keep the document_cache with all the extra documents loaded around,
2024-07-11 18:54:40 +02:00
Tobias Hunger
821d8a893c lsp: Clippy fixes and other small cleanups
... suggested by @ogoffart.
2024-07-10 17:17:33 +02:00
Tobias Hunger
489d6c6a5b live-preview: Update categories displayed in the library
* Show all builtin elements under "Builtin Elements"
 * Show all std-widgets under "Widgets"
 * Show everything else under its file name.
2024-07-10 17:17:17 +02:00
Tobias Hunger
ec87f555e9 live-preview: Use drop-down in property editor for enums 2024-07-10 11:47:06 +02:00
Tobias Hunger
05e0b4dc68 live-preview: Have a simple mode for bools and strings
The property editor built into the live-preview now comes with the
concept of a "simple/complex mode". There is a "K" (for complex, obviously;-)
or a "S" (for simple, just as obvious) beween the property name and property
value. you can click on the letter to switch from simple to complex mode,
but you can only switch back to simple mode if there are no complex expressions
in the line edit.

This implements a "simple" mode for bools.

# Todo

 * [ ] Find icons for simple/complex mode:-)
 * [ ] Figure out how to decide whether other types are "simple"
 * [ ] Define more UIs for simple types

live-preview: Move simple property code into rust

... and handle simple strings in addition to bool.
2024-07-10 11:47:06 +02:00