控件拖拽使用的是gui::dragger
操作方法是
dragger dg;
dg.trigger(*this);
dg.target(*this);
*this是控件
如果控件有好多,一个dragger无法操作多个控件,原因是一个dragger只记录了一个控件的拖拽状态。
所以可以在控件的类里增加一个dragger成员,这样每新建一个控件,就会伴随新建一个dragger。
#ifndef BLOCK_H
#define BLOCK_H
#include <nana/gui.hpp>
#include <nana/gui/widgets/button.hpp>
#include <nana/gui/dragger.hpp>
#include <string>
#include <vector>
using namespace nana;
using namespace std;
struct BlockInfo
{
string name;
string otype;
vector<string> itype;
};
class Block:public button
{
public:
int id;
string name;
string itype;
string otype;
string getName();
BlockInfo info;
dragger dg;
void setName(string s);
string getFileName();
bool isEmpty();
Block(window f,int i,string s,int x,int y,int w,int h);
virtual ~Block();
protected:
private:
};
#endif // BLOCK_H
在构造函数中把这个dragger指向自己
Block::Block(window f,int i,string s,int x,int y,int w,int h)
{
name=s;
id=i;
create(f, rectangle(x, y, w, h));
caption(s);
dg.trigger(*this);
dg.target(*this);
}