Wt examples  3.7.1
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 (Wt::WContainerWidget *parent)
 

Detailed Description

Function Documentation

◆ createDragImage()

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 19 of file DragExample.C.

22 {
23  WImage *result = new WImage(url, p);
24  WImage *dragImage = new WImage(smallurl, p);
25  dragImage->setMargin(-15, Left | Top);
26 
27  /*
28  * Set the image to be draggable, showing the other image (dragImage)
29  * to be used as the widget that is visually dragged.
30  */
31  result->setDraggable(mimeType, dragImage, true);
32 
33  return result;
34 }
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

◆ DragExample()

DragExample::DragExample ( Wt::WContainerWidget parent)

Definition at line 36 of file DragExample.C.

36  :
37  WContainerWidget(parent)
38 {
39  new WText("<p>Help these people with their decision by dragging one of "
40  "the pills.</p>", this);
41 
42  if (!wApp->environment().javaScript()) {
43  new WText("<i>This examples requires that javascript support is "
44  "enabled.</i>", this);
45  }
46 
47  WContainerWidget *pills = new WContainerWidget(this);
48  pills->setContentAlignment(AlignCenter);
49 
50  createDragImage("icons/blue-pill.jpg",
51  "icons/blue-pill-small.png",
52  "blue-pill", pills);
53  createDragImage("icons/red-pill.jpg",
54  "icons/red-pill-small.png",
55  "red-pill", pills);
56 
57  WContainerWidget *dropSites = new WContainerWidget(this);
58 
59  new Character("Neo", dropSites);
60  new Character("Morpheus", dropSites);
61  new Character("Trinity", dropSites);
62 
63 }
A Matrix character that takes red and/or blue pills.
Definition: Character.h:24
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:19

Generated on Tue Dec 15 2020 for the C++ Web Toolkit (Wt) by doxygen 1.8.13