Commit graph

346 commits

Author SHA1 Message Date
Tobias Hunger
7053a21749 live preview: Add a drop marker
Add a drop mark into DropInformation to visualize where an item will get added.

This is the UI side of things and some more preparational work.
2024-04-01 16:27:35 +02: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
543bff941f live preview: Introduce a SelectionRectangle struct 2024-03-19 08:58:34 +01:00
Tobias Hunger
b5a7408774 live preview: Prettyfy selection
Make something that looks a bit closer to
popular web-based design tools.
2024-03-19 08:58:34 +01:00
Tobias Hunger
b4120fe312 live preview Do not handle key events in error case
Only process key events while the preview is in design mode and does
not show an error. So far the only key that actually does something
is the delete key, which deletes elements. Unfortunately we do not
know which text range is covered by the element we want to delete,
so we delete random chunks of text.

So disable that when we ran into an error.

This partially addresses #4872.
2024-03-18 15:10:31 +01:00
Tobias Hunger
33d8832b5f live preview: We seem to have given up on i- prefix
... for element ids. So consistently remove them from
the live preview.
2024-03-18 15:10:31 +01:00
Tobias Hunger
a0c1ba34f9 live preview: Do not scroll errors 2024-03-14 13:42:53 +01:00
Tobias Hunger
1d7ca89fdc preview: Remove experimental flag from design mode 2024-03-06 17:31:26 +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
a4053531ad live-preview: Never start with an 0x0 pixel preview 2024-03-06 14:24:04 +01:00
Tobias Hunger
6ab0a30192 live preview: Disable moving/resizing of selected elements 2024-02-28 22:33:39 +01:00
Tobias Hunger
150b2b0cc4 live preview: Only offer interactive editing while in design mode 2024-02-28 15:53:49 +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
Simon Hausmann
f932f25dea Design mode: Minor polish to the library side bar
- Use "Library" instead of "Assets" as title
- Don't scroll the title when scrolling through the controls/widgets
- Use a bigger font than the category separators
2024-02-26 14:16:51 +01:00
Tobias Hunger
17fbe46342 live preview: Fix select-behind being eaten by drag-area
Fix select-behind being eaten by the drasg area in
the Resizer used to move the selected element.
2024-02-23 09:58:58 +01:00
Olivier Goffart
a53c4c8a71 LSP preview: disable selection handle when not in experimental mode 2024-02-20 19:34:37 +01:00
Tobias Hunger
2c096aa885 live preview: Update selection when size of UI changes
Changing the size of a UI will most likely move elements
around. So reselect the current selection when that happens.

This is not a proper solution: It e.g. ignores animations
changing element sizes, etc. but it does handle one
annoying case.
2024-02-20 12:30:49 +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
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
17149505d8 live preview: Make the UI less ugly and only show it in design mode 2024-02-19 22:27:32 +01:00
Tobias Hunger
dd8fefd6a2 live preview: Polish drag-and-drop UI
* Add the import path into the sheared data so that
  is available when needed.
* Fix drop location, mouse pointers, ...
2024-02-12 15:03:08 +01:00
Simon Hausmann
84a3ffa045 Fix initial rendering of the live-preview
The hack to sets the preview area's width and height through the init callback was run _after_ rendering the component container and during evaluation
of the dirty tracker. The latter sets itself to dirty = false after evaluation, so it's never dirty despite
the width and height having changed.

As a workaround for 1.4.1, move the init callback hack to before render() is called.
2024-02-01 16:30:54 +01:00
Florian Blasius
1933b03ee7
lsp: Use alternate background on drawing rect and set border on resizer (#4446)
Co-authored-by: Tobias Hunger <tobias.hunger@slint.dev>
2024-01-29 08:47:16 +01:00
Tobias Hunger
c29314b2a8 lsp: Fix calculation of drop coordinates over the preview area 2024-01-26 13:19:48 +01:00
Tobias Hunger
0b626ccbb5 lsp: More visual selection
This is a long odyssee :-/

I am back to file-based navigation now: The component-based navigation
felt so very tree-based again.

So you can click anywhere to select the "topmost" rendered element that
is defined in the same file that is getting previewed.

A double-click is again punching through the layers: It goes deeper into
the rendering layers, selecting an item at the same point but covered by
the current selection.

Ctrl makes the selection ignore file boundaries when picking something.

Shift reverses the search direction when double clicking: It will pick
an element in the click position that is rendered after the currently
selected item.
2024-01-25 11:27:39 +01:00
Tobias Hunger
d50373951f lsp: Use a more "visual" element selection for Preview UI
Try a more visual selection approach over the rather technical
tree-based one from earlier.

In this commit, a click selects the element that was rendered at the
click position *last*. I use rendered loosely here: It even takes
elements into account that are invisible but still cover the clicked
location.

A double-click punshes through to the item rendered earlier (behind) the
currently selected item that also covers the clicked position.

A shift-double-click moves towards the later rendered elements again,
usually undoing the last double-click.
2024-01-25 11:27:39 +01:00
Tobias Hunger
e93b307643 lsp: Change selection mode in preview
It is tree based now: Allowing you to visit children, the siblings and
the parent of the current selection.

Advantage: You can actually get to all elements now, even those covered by
other elements.

Disadvantage: You basically need the document outline to make sense of
the navigation:-/

We need a more visual way to select elements! But how can we even tell
which elements are going to be visible in the UI and which are not?

Here is how you navigate in this PR:

 * Click selects an element. If the click hits the currently selected
   element, then it will do nothing. Otherwise it will look whether a
   sibling was hit, working its way up the tree to the root element.
 * Double-click selects a child of the current selection: the "foremost"
   child that covers the click location will be selected.
 * shift-double-click: Takes you to the current selections parent.
 * Ctrl-click: Select a sibling of the current selected element "behind"
   the sibling that covers the current click location.
 * Shift-ctrl-click: Selects a sibling of the current selected element
   in front of the current selection that cover s the click location.
2024-01-25 11:27:39 +01:00
Tobias Hunger
03bed1a4eb lsp: Implement UI side of drag and drop
... the rust side is just qa mock yet.
2024-01-19 09:14:02 +01:00
Tobias Hunger
7754fccdd4 lsp: Add Sidebar showing available Components
Just show what all the components currently available.
2024-01-19 09:14:02 +01:00
Tobias Hunger
bcac170262 lsp: Refactor Preview UI 2024-01-19 09:14:02 +01:00
Tobias Hunger
ad72f5499c lsp: Add experimental feature flag and forward it to preview UI 2024-01-19 09:14:02 +01:00
Tobias Hunger
e7ff4c196e lsp: Fix diagnostics in Preview UI
... when showing the UI around the actual preview.
2024-01-15 14:46:39 +01:00
Olivier Goffart
ba738be0a7 LSP preview: fix some issue related to geometry
- make sure that the initial size is proper by calling show() on the preview ui
   after the factory has been set
 - ensure that there is no recursion if the inner layout info depends on the size
   (Fixes #3989)
 - Ensure that the geometry constraints are respected when previewing a component
   that was already resized
2024-01-02 10:48:12 +01:00
Olivier Goffart
c5be0ec8aa LSP preview: workaround the resize handler not working
If resizing makes the value of is-resizable dirty, we would hit issue #3953
and the handle would be re-created and the drag operation aborted
2024-01-02 09:56:54 +01:00
Tobias Hunger
ca1263c3e5 lsp: Handle selections and highlighting in the LSP
Ask the interpreter for all the necessary information, but handle the
look and feel in the LSP preview UI.
2023-12-20 19:28:35 +01:00
Tobias Hunger
547ba6d998 lsp: Make previewed component resizable 2023-11-28 10:38:46 +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
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
326d0b6414 LSP Preview: add a --fullscreen command arg
Useful to preview on devices
2023-11-10 15:43:02 +01:00
Olivier Goffart
aeb512686e
LSP preview: small UI adjustments
- Add a title and icon to the window
 - remove dead code (Spinner)
 - Make the text of error align to the left and word-wrap
 - With a pointer mouse cursor so the user knows they are clickable
2023-11-08 16:23:49 +01:00
Tobias Hunger
6206504dca lsp: Do not use a spinner and show errors
... as the UI thread is blocked. Print a status text instead.

Also show errors (if any).

Fixes: #3858
2023-11-07 10:57:54 +01:00
Tobias Hunger
fa7fe55faf lsp: Update UI for release
Disable the "Design Mode" button for now as selectionis not great and
add a label before the Style ComboBox.
2023-11-06 13:15:34 +01:00
Tobias Hunger
a19cfd06b2 lsp: Make preview the authorative source for style usage 2023-11-03 22:14:20 +01:00
Tobias Hunger
c3cabc8751 lsp: Build preview UI with Design Mode text and default style 2023-11-03 22:14:20 +01:00
Tobias Hunger
4246168b2a Add style combobox to preview UI
... and remove code supporting style selection from slintpad and vscode.
2023-11-03 22:14:20 +01:00
Tobias Hunger
e5bfddf73f lsp: Improve preview UI
A big thank you to @FloVanGH !
2023-11-03 22:14:20 +01:00