Skip to content

Commit

Permalink
Minor changes in drag_and_drop example
Browse files Browse the repository at this point in the history
The most important change here is clearing the data from the
windowData about types that weren't dropped in the last action, to
avoid mixing dropped data from previous actions and only show the last
dropped data.
  • Loading branch information
dacap committed May 30, 2024
1 parent cb15528 commit 228d555
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion examples/drag_and_drop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,20 @@ class DragTarget : public os::DragTarget {
if (ev.acceptDrop()) {
if (ev.dataProvider()->contains(os::DragDataItemType::Paths))
windowData.paths = ev.dataProvider()->getPaths();
else
windowData.paths.clear();

#if CLIP_ENABLE_IMAGE
if (ev.dataProvider()->contains(os::DragDataItemType::Image))
windowData.image = ev.dataProvider()->getImage();
else
windowData.image.reset();
#endif

if (ev.dataProvider()->contains(os::DragDataItemType::Url))
windowData.url = ev.dataProvider()->getUrl();
else
windowData.url.clear();
}

redraw_window(ev.target());
Expand Down Expand Up @@ -167,7 +175,7 @@ static os::WindowRef create_window(os::DragTarget& dragTarget)

os::WindowRef newWindow = os::instance()->makeWindow(spec);
newWindow->setCursor(os::NativeCursor::Arrow);
newWindow->setTitle("Drag & Drop example");
newWindow->setTitle("Drag & Drop");
newWindow->setDragTarget(&dragTarget);

windowData.dropZone = gfx::Rect(spec.frame().w-64-12, 12, 64, 64);
Expand Down Expand Up @@ -196,6 +204,14 @@ int app_main(int argc, char* argv[])

switch (ev.type()) {

case os::Event::KeyDown:
switch (ev.scancode()) {
case os::kKeyEsc:
running = false;
break;
}
break;

case os::Event::CloseApp:
case os::Event::CloseWindow:
running = false;
Expand Down

0 comments on commit 228d555

Please sign in to comment.