Wt examples  4.0.0
DragExample.C
Go to the documentation of this file.
1 #include "DragExample.h"
2 #include "Character.h"
3 #include <Wt/WEnvironment.h>
4 #include <Wt/WImage.h>
5 #include <Wt/WApplication.h>
6 
11 
17 WImage *createDragImage(const char *url, const char *smallurl,
18  const char *mimeType,
20 {
21  WImage *result = p->addWidget(cpp14::make_unique<WImage>(url));
22  WImage *dragImage = p->addWidget(cpp14::make_unique<WImage>(smallurl));
23  dragImage->setMargin(-15, Side::Left | Side::Top);
24 
25  /*
26  * Set the image to be draggable, showing the other image (dragImage)
27  * to be used as the widget that is visually dragged.
28  */
29  result->setDraggable(mimeType, dragImage, true);
30 
31  return result;
32 }
33 
36 {
37  this->addWidget(cpp14::make_unique<WText>("<p>Help these people with their decision by dragging one of "
38  "the pills.</p>"));
39 
40  if (!wApp->environment().javaScript()) {
41  this->addWidget(cpp14::make_unique<WText>("<i>This examples requires that javascript support is "
42  "enabled.</i>"));
43  }
44 
45  WContainerWidget *pills = this->addWidget(cpp14::make_unique<WContainerWidget>());
46  pills->setContentAlignment(AlignmentFlag::Center);
47 
48  createDragImage("icons/blue-pill.jpg",
49  "icons/blue-pill-small.png",
50  "blue-pill", pills);
51  createDragImage("icons/red-pill.jpg",
52  "icons/red-pill-small.png",
53  "red-pill", pills);
54 
55  WContainerWidget *dropSites = this->addWidget(cpp14::make_unique<WContainerWidget>());
56 
57  dropSites->addWidget(cpp14::make_unique<Character>("Neo"));
58  dropSites->addWidget(cpp14::make_unique<Character>("Morpheus"));
59  dropSites->addWidget(cpp14::make_unique<Character>("Trinity"));
60 
61 }
62 
void setContentAlignment(WFlags< AlignmentFlag > contentAlignment)
WImage * createDragImage(const char *url, const char *smallurl, const char *mimeType, WContainerWidget *p)
Create an image which can be dragged.
Definition: DragExample.C:17
virtual void addWidget(std::unique_ptr< WWidget > widget)

Generated on Mon Sep 4 2017 for the C++ Web Toolkit (Wt) by doxygen 1.8.11