Commit graph

53 commits

Author SHA1 Message Date
Tobias Hunger
e10e97c944 live-preview: Add placeholder when removing the last eleemnt in a layout
Add a placeholder Rectangle into a layout whenever the last eleemnt is removed.
This makes sure we can drop into the Layout again.

Add infrastructure to find the parent element to ElementRcNode and move more
code into the ElementRcNode.
2024-04-25 10:28:15 +02:00
Tobias Hunger
c1707d52e1 live preview: Insert source code before other elements
... and use that to drop into layouts.
2024-04-23 10:56:55 +02:00
Tobias Hunger
9615fbe4b4 Try an approach where we pass in Yes, No and Maybe for each element
... in the stack of elements at a position and to use that to find which
element to actually drop into.

Make the DropMark work with that apporach
2024-04-23 10:56:55 +02:00
Tobias Hunger
69b8e8d57c live preview: Implement drop marker mapping for elements
... so we know what to do when dropping near tghe border of elements that
accept drops in a layout.
2024-04-23 10:56:55 +02:00
Aurindam Jana
0cfeec1a31
Update Slint Community License (#4994)
Updated the version from 1.1 to 1.2 
Renamed the header to "Slint Royalty-free Desktop, Mobile, and Web Applications License"
Added definition of "Mobile Application" and grant of right
Moved "Limitations" to 3rd section and "License Conditions - Attributions" to 2nd section
Added flexibility to choose between showing "MadeWithSlint" as a dialog/splash screen or on a public webpage
Moved the para on copyright notices to section under "Limitations"
2024-04-15 15:18:55 +02:00
Tobias Hunger
4451d6019a live preview: Add some testing to element selection 2024-03-25 15:42:52 +01:00
Tobias Hunger
21b73769a5 live preview: Provide the kind of layout to the UI
... so we can have a better idea what we need to visualize.

Move the decision on which color to use into the slint file as well:
A designer should make that call, not a developer ;-)
2024-03-22 00:32:55 +01:00
Tobias Hunger
15fb452017 interpreter: Return the ElementRc + index, not just the ElementRc
This way we do not have to check the ElementRc once more to find the node in
its debug data.
2024-03-20 18:47:45 +01:00
Tobias Hunger
9873cfd7c0 janitor: Run cargo clippy --fix
Only the hand-picked sensible things, not all of it ;-)

Also fix a few typos that cspell complained about when I
tried to commit and some formatting changes that cargo fmt
insisted on when commiting.
2024-03-14 13:42:38 +01:00
Tobias Hunger
feb96bb03b preview: Add more data to ComponentInformation
Add `fills_aprent` and `default_properties` to
`ComponentInformation`. The first is a bool showing
whether the Component will fill its parent or not.

The later is a set of properties that the UI will set
when the widget gets dropped.

Refactor the data passing a bit: Keep the data on known
components around. Pass only the component name into
the UI, but pass the entire `ComponentInformation` to
the `drop_location` methods.
2024-03-06 17:31:08 +01:00
Tobias Hunger
d0fc025bc8 live preview: Do not drop on elements that can not have children
Slpit up `lookup_type_for_child_elemnt` (in the compiler) into the
part that looks at the element itself only (called `accepts_child_element`)
and the part that looks at the child.

When deciding whether we can drop something into another element in
the live preview, we know the child type is going to be OK, even when
the `TypeRegister` does not contain it yet (as it is not imported yet).
2024-03-06 12:15:10 +01:00
Tobias Hunger
3ba59dad46 lsp: Use ElementRcNode when handling properties
We recently got better support for inlined elements. Use
The `ElementRcNode` when accessing properties, so that
we can actually have a better idea which SyntaxNode we
need to work on.

This is actually not too critical as the LSP does little
inlining, but I wanted to reuse this on the preview side
as well, which does inlining much more aggressively.

Do NOT access properties in the live preview though:
It is heavily optiomized, so most properties are just
gone there;-)
2024-03-05 13:10:41 +01:00
Tobias Hunger
3ad3a42656 live preview: Do import handling in drop_location
Remove the AddComponent and the AdjustSelection messages
from the communication between LSP and preview.

Also remove the code to delete an element.
2024-03-01 18:54:40 +01:00
Tobias Hunger
a0b862b096 live preview: Delete an element again
* Refactor the code a bit: Move element edit functions
  into the `element_edit` module below `language`
2024-02-28 15:53:49 +01:00
Olivier Goffart
a3c99555a0 LSP: fix compilation without the preview features
Use the format test to test this compilation
2024-02-26 11:14:02 +01:00
Tobias Hunger
08372e5a07 live preview: Implement resizing and moving of selected eleement
Much polish needed, but it is a basis to build upon.
2024-02-19 22:27:32 +01:00
Tobias Hunger
e1aefc6f16 lsp: Notify preview about text edits
Have the LS notify the live preview about changes it initiates, so
the live preview can update its selection.

This is not possible for all edits the LS generates: Many are sent
to the editor which may or may not trigger them later, but the
notification happens when the LS adds changes on top of changes
requested by the live preview (e.g. by adding an import). This
fixes having a newly added element selected once it is rendered.
2024-02-19 22:27:32 +01:00
Tobias Hunger
e4a0a85e2f lsp: Pick one good instance when selecting/highlighting
We need to decorate an Element so we can interact with it. I want
to decorate only *one* instance of a repeated element to avoid
cluttering up the screen. So pick one good candidate for decoration:
Ideally the one the user clicked on, got for the first one
otherwise.

Store this information so we can get it back after re-rendering,
and so that we can actually mark newly added elements for selection
after they get rendered.
2024-02-19 22:27:32 +01:00
Tobias Hunger
67c6f1ba48 live preview: Indent inserted elements (better) 2024-02-13 21:19:25 +01:00
Tobias Hunger
b615baf98d live preview: Implement dropping an Element onto the canvas
... and make it show up in the code/live preview.

Currently layouts are not supported and it will try to drop
onto elements not accepting children.

But it does add the necessary import statement already.
2024-02-13 17:03:58 +01:00
Tobias Hunger
25f0fd116d lsp: Simplify filter_ignore_nodes_in_element to a function
... returning a bool.

Do the iteration where needed instead.
2024-02-12 14:59:04 +01:00
Tobias Hunger
3b4a6a6021 lsp: Allow for empty base URLs when calculating import paths 2024-02-12 13:48:56 +01:00
Tobias Hunger
6dbbc761e4 LSP: Add some getters to common data structs
Just for convenience :-)
2024-02-12 12:44:22 +01:00
Tobias Hunger
b9ae753edd lsp: Make it clearer what is sent to the editor
Move the code that sends to the editor from within the LSP and the live
preview into a module in common.

This makes it clearer what actually happens and allows to remove some
code from the preview that does not really belong there.
2024-02-09 15:24:13 +01:00
Tobias Hunger
8f63417e44 lsp: Fix filter_ignore_nodes_in_element 2024-02-07 18:12:22 +01:00
Tobias Hunger
a329a7312b lsp: Factor out common code to create WorkspaceEdits
Removes some duplication and lends itself for resue in the previewer :-)

Side-effect: We now consitently use versioned text documents, so the
editor will notice when the LSP refactored outdated data.
2024-02-07 14:51:20 +01:00
Tobias Hunger
2cd74463ff lsp: Add a way to ignore nodes
... and use it e.g. for the nodes the preview adds into the code itself.

Now that we mark the preview helper we add into the file as `ignore`, we
can make sure we never try to navigate to it. It was text that got
appended to the actual source code, so the editor tended to jump to the
end of the document when selecting the root element. That was created by
merging the artifical Preview node and the real root node, with the
artificial node being stored first.
2024-01-26 18:11:41 +01:00
Olivier Goffart
804971d5f6 Alsways use a Url in PreviewToLspMessage::ShowDocument
The messages serialized through the LSP should use the LSP's url type.
And keep type information as long as possible.

Otherwise, we'd end up in show_document_request_from_element_callback
with either an URL or a path, depending if the preview is native or not,
and that would fail when re-serializing to an URL to send back to
through the LSP
2024-01-25 18:55:15 +01:00
Olivier Goffart
5b0ee206be LSP: Simplify the lsp to preview messaging
Don't use a trait, but always dispatch through  a LspToPreviewMessage
2024-01-25 18:55:15 +01:00
Tobias Hunger
d05d8fe7da lsp: Test the component_catalog
Fix the component catalog to make the tests pass.
2024-01-19 09:14:02 +01:00
Tobias Hunger
fe0ac9d6e8 FIX: lsp: Improve URL encoding 2024-01-15 14:46:39 +01:00
Tobias Hunger
19cf90a319 lsp: Send document versions from lsp to previewer
We want the previewer to become interactive, so we need to pass on the
document versions so we can detect the editor, lsp and previewer going
out of sync.
2024-01-15 14:46:39 +01:00
Tobias Hunger
f93d1cbe33 lsp: Use new component information functions in code completion 2024-01-15 14:46:39 +01:00
Tobias Hunger
2ae760c8b9 lsp: Add helper functions to extract data on components
Add helper functions into a new `element_catalog` module that extract
information on components used in a piece of Slint code on the LSP side
of the LSP.

Eventually this information will be passed on to the Preview side and
can then be used there to show available components.
2024-01-15 14:46:39 +01:00
Tobias Hunger
9e5806cfe8 lsp: Use lsp_types::Range over lots of usize 2023-12-20 19:28:35 +01:00
Olivier Goffart
184cb5f580 LSP: Simplify the preview config handling
- Put the config in a struct so its easier to pass around
 - respect the command line args as default for the style
 - fix compilation without the preview feature
2023-11-24 14:08:06 +01:00
Olivier Goffart
26e8d308b7 LSP: rename and fix the hide toolbar option
- rename the command line option to --no-toolbar
 - Make it default to not hide the toolbar (so it is visible by default)
2023-11-24 14:08:06 +01:00
Tobias Hunger
548f10be2b lsp: Add option to show/hide preview ui
... and use that option in VSCode configuration.
2023-11-23 20:44:06 +01:00
Olivier Goffart
18a244bb62 LSP preview: make sure that we always update the preview with the latest state
If a preview command is issued while we were compiling, we need to
recompile.
2023-11-08 16:22:56 +01:00
Tobias Hunger
5bf5b7b02d lsp: Clean up PreviewApi
request_state went the wrong way around wrt. communication flow, so
remove and deduplicate it.
2023-11-03 22:14:20 +01:00
Tobias Hunger
b17d566349 lsp: Derive more Debug implementations 2023-11-03 22:14:20 +01:00
Tobias Hunger
d53cebd3e1 lsp: Get signalled by the preview 2023-11-03 22:14:20 +01:00
Tobias Hunger
7d4a73b76c lsp: Make wasm and native previews work
Move code from the native side up into preview.rs as much as possible so
that both previews share as much code as possible.
2023-11-03 22:14:20 +01:00
Tobias Hunger
2aac47b3c6 Change communication of slintpad with Preview
... to route it through the LSP, so that we can have a unified approach
to interact with the Preview UI.
2023-11-03 22:14:20 +01:00
Tobias Hunger
55cc1ae31f lsp: Remove the PostLoadBehavior
We always update if we have a UI and we never update if not. So this
flag does not help.
2023-11-03 22:14:20 +01:00
Tobias Hunger
a0cc85bfb4 LSP: Remove design mode custom commands 2023-11-03 22:14:20 +01:00
Tobias Hunger
97f3046dbd LSP: Simplify the handling of ServerNotifier in the Previewer
The Preview delays starting the event loop as much as possible, simply
because our backends may panic/crash when they are not happy with the
UI configuration state they get started in.

So keep this... but use the `sender` in the Cache as an indicator of "we
have a UI". So explicitly set/reset the sender as the UI comes and goes
and do less implicit setup otherwise.
2023-11-03 22:14:20 +01:00
Tobias Hunger
55d0f5d473 lsp: Make native UI work
The UI is ugly and does not include the Design Mode button yet, but it
is a bit of progress.
2023-11-03 22:14:20 +01:00
J-P Nurmi
c5248c005e Allow specifying paths for @library imports 2023-10-20 16:47:00 +02:00
Tobias Hunger
d5cc147644 lsp: Use one common Error type (where possible) 2023-08-30 10:31:55 +02:00