https://github.com/g3th/compose-desktop-drag-and-drop
Drag And Drop operation in Compose Desktop, utilising compositionLocalOf
https://github.com/g3th/compose-desktop-drag-and-drop
compose-desktop drag-and-drop-programming example graphical-user-interface kotlin
Last synced: 20 days ago
JSON representation
Drag And Drop operation in Compose Desktop, utilising compositionLocalOf
- Host: GitHub
- URL: https://github.com/g3th/compose-desktop-drag-and-drop
- Owner: g3th
- Created: 2024-05-09T22:26:11.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-22T21:53:05.000Z (about 2 years ago)
- Last Synced: 2024-05-22T22:45:48.981Z (about 2 years ago)
- Topics: compose-desktop, drag-and-drop-programming, example, graphical-user-interface, kotlin
- Language: Kotlin
- Homepage:
- Size: 93.8 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
Awesome Lists containing this project
README
# Compose Desktop - Drag And Drop Example
## Drag And Drop using the Compose declarative framework
Since some features are missing or currently not supported for Desktop, implementing Drag-And-Drop operations results in more convoluted code than in Android, for instance. The absence of "Modifier.dragAndDropTarget" or "View.OnDragListener" for Desktop makes matters more complicated as implementing a target listener takes more lines of code.
This is an example of how to implement a Drag-and-Drop operation using ```pointerInput```, ```detectDragGestures``` and ```CompositionLocalOf``` to pass data between composable functions, such as current Offsets or Booleans. Although there are probably other ways of implementing such an operation, I have found this was the easiest and most popular
The app also implements:
- ```Modifier.clip``` in order to draw a custom shape using ```PathParser()``` to parse an svg path as a String, originally obtained by using InkScape in Linux.
- ```Modifier.clickable``` so that the custom shape is clickable
- ```Brush.lineargradient``` to generate a gradient once the animal shape is clicked. A function generates random colors each time the shape is clicked.
- A "Debug" feature which displays offsets and DragListener states in real time.
Additional functionality will probably be added in the future, such as more shapes, but this example serves mainly as a reference.
Build with IntelliJ or Android Studio.