Wt examples  4.0.2
Classes | Functions
Drag and Drop example

Classes

class  Character
 A Matrix character that takes red and/or blue pills. More...
 

Functions

WImagecreateDragImage (const char *url, const char *smallurl, const char *mimeType, WContainerWidget *p)
 Create an image which can be dragged. More...
 
 DragExample::DragExample ()
 

Detailed Description

Function Documentation

WImage* createDragImage ( const char *  url,
const char *  smallurl,
const char *  mimeType,
WContainerWidget p 
)

Create an image which can be dragged.

The image to be displayed when dragging is given by smallurl, and configured with the given mime type

Definition at line 17 of file DragExample.C.

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 }
void setDraggable(const std::string &mimeType, WWidget *dragWidget=nullptr, bool isDragWidgetOnly=false, WObject *sourceWidget=nullptr)
virtual void setMargin(const WLength &margin, WFlags< Side > sides=AllSides) override
virtual void addWidget(std::unique_ptr< WWidget > widget)
DragExample::DragExample ( )

Definition at line 34 of file DragExample.C.

34  :
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 }
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 Fri Nov 24 2017 for the C++ Web Toolkit (Wt) by doxygen 1.8.11