nana gui 控件拖拽

控件拖拽使用的是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);
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章