添加 'tabWidget.h'
This commit is contained in:
parent
d21fe80c13
commit
4793df92d1
|
@ -0,0 +1,125 @@
|
|||
#ifndef __TAB_WIDGET__H
|
||||
#define __TAB_WIDGET__H
|
||||
|
||||
#include "nana/gui/widgets/date_chooser.hpp"
|
||||
#include "nana/gui/widgets/textbox.hpp"
|
||||
#include <nana/gui/place.hpp>
|
||||
#include <nana/gui/widgets/categorize.hpp>
|
||||
#include <nana/gui/widgets/panel.hpp>
|
||||
#include <nana/gui/widgets/tabbar.hpp>
|
||||
#include <nana/gui/widgets/listbox.hpp>
|
||||
#include <nana/gui/widgets/checkbox.hpp>
|
||||
|
||||
|
||||
class tab_page_datechooser : public nana::panel<false> {
|
||||
|
||||
public:
|
||||
tab_page_datechooser(nana::window wd) : nana::panel<false>(wd) {
|
||||
|
||||
date_.create(*this, nana::rectangle(10, 10, 260, 200));
|
||||
textbox_.create(*this, nana::rectangle(280, 10, 170, 23));
|
||||
textbox_.tip_string(("Input a date:"));
|
||||
date_.events().dbl_click([this]() {
|
||||
auto dt = date_.read().read();
|
||||
textbox_.reset(nana::charset(std::to_string(dt.year) + "-" +
|
||||
std::to_string(dt.month) + "-" +
|
||||
std::to_string(dt.day)));
|
||||
});
|
||||
}
|
||||
|
||||
private:
|
||||
nana::date_chooser date_;
|
||||
|
||||
nana::textbox textbox_;
|
||||
};
|
||||
class tab_page_listbox : public nana::panel<false>
|
||||
{
|
||||
public:
|
||||
tab_page_listbox(nana::window wd) : panel<false>(wd) {
|
||||
place_.bind(*this);
|
||||
place_.div("< <list> |30% <check margin=5> >");
|
||||
listbox_.create(*this);
|
||||
listbox_.append_header(("Supported compilers"), 200);
|
||||
auto cat = listbox_.append(("Nana.C++03"));
|
||||
cat.push_back(("GCC 3.4 and later"));
|
||||
cat.push_back(("Visual C++ 2003 and later"));
|
||||
cat = listbox_.append(("Nana.C++11"));
|
||||
cat.push_back(("GCC 4.6 and later"));
|
||||
cat.push_back(("Visual C++ 2012 and later"));
|
||||
checkbox_.create(*this);
|
||||
checkbox_.caption(("Checkable Listbox"));
|
||||
checkbox_.events().click(
|
||||
[this]() { this->listbox_.checkable(this->checkbox_.checked()); });
|
||||
place_.field("list") << listbox_;
|
||||
place_["check"] << checkbox_;
|
||||
}
|
||||
|
||||
private:
|
||||
nana::place place_;
|
||||
nana::listbox listbox_;
|
||||
nana::checkbox checkbox_;
|
||||
};
|
||||
/**
|
||||
* @brief 表格容器
|
||||
*
|
||||
*/
|
||||
class TabWidget : public nana::panel<true> {
|
||||
|
||||
public:
|
||||
TabWidget(nana::window wd, bool visible = true)
|
||||
: nana::panel<true>(wd, visible) {
|
||||
this->create(wd, visible);
|
||||
}
|
||||
~TabWidget() {}
|
||||
bool create(nana::window wd, bool visible = true) {
|
||||
if (!nana::panel<true>::create(wd, visible))
|
||||
return false;
|
||||
|
||||
init_();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
void init_() {
|
||||
place_.bind(*this);
|
||||
place_.div("<vert <weight=30 Tab> | <panel>>");
|
||||
|
||||
// panel1
|
||||
panel1.create(*this);
|
||||
// tabbar1
|
||||
tabbar1.create(*this);
|
||||
place_["Tab"] << tabbar1;
|
||||
tabbar1.typeface(nana::paint::font("", 9, {400, false, true, false}));
|
||||
// categorize1
|
||||
place_.collocate();
|
||||
addWidget();
|
||||
}
|
||||
/**
|
||||
* @brief 添加面板
|
||||
*
|
||||
*/
|
||||
void addWidget() {
|
||||
tabbar1.push_back(("Tab1"));
|
||||
tabpages_.push_back(std::make_shared<tab_page_datechooser>(*this));
|
||||
tabbar1.push_back(("Tab2"));
|
||||
tabpages_.push_back(std::make_shared<tab_page_listbox>(*this));
|
||||
tabbar1.push_back(("Tab3"));
|
||||
tabpages_.push_back(std::make_shared<tab_page_listbox>(*this));
|
||||
tabbar1.push_back(("Tab4"));
|
||||
tabpages_.push_back(std::make_shared<tab_page_listbox>(*this));
|
||||
std::size_t index = 0;
|
||||
for (auto &i : tabpages_) {
|
||||
tabbar1.attach(index++, *i);
|
||||
place_.field("panel").fasten(*i); // Fasten the tab pages
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
nana::place place_;
|
||||
nana::panel<true> panel1;
|
||||
nana::tabbar<std::string> tabbar1;
|
||||
std::vector<std::shared_ptr<panel<false>>> tabpages_;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue