问题是关于TUI C ++库https://github.com/gansm/finalcut。
我使用最终版本0.3.0。
答案 0 :(得分:0)
在最终剪切git存储库的当前版本中,FListBox小部件能够从STL容器导入数据。您可以通过"延迟转换"直接在插入时或稍后第一次访问时导入数据。你需要的只是一个小帮手功能。
直接导入
#include <final/final.h>
using namespace finalcut;
static FString* temp_str = 0;
// Direct import helper functions
FString& IntToString (std::vector<int>::const_iterator iter)
{
return temp_str->setNumber(*iter);
}
int main (int argc, char* argv[])
{
FApplication app(argc, argv);
FDialog dialog ("List example", &app);
dialog.setGeometry (FPoint(30, 2), FSize(22, 22));
FListBox list (&dialog);
list.setText ("Direct import");
list.setGeometry (FPoint(1, 1), FSize(20, 19));
int n = 0;
temp_str = new FString;
std::vector<int> v(100,0);
std::vector<int>::iterator iter = v.begin();
while ( iter != v.end() )
{
n++;
*iter = n;
++iter;
}
list.insert (v.begin(), v.end(), IntToString);
delete temp_str;
app.setMainWidget(&dialog);
dialog.show();
return app.exec();
}
通过延迟转化导入
#include <final/final.h>
using namespace finalcut;
// Lazy conversion helper functions
void IntToString (FListBoxItem& item, FDataPtr container, int index)
{
std::vector<int>* vec = static_cast<std::vector<int>*>(container);
int n = (*vec)[index];
item.setText (" " + FString().setNumber(n));
}
int main (int argc, char* argv[])
{
FApplication app(argc, argv);
FDialog dialog ("List example", &app);
dialog.setGeometry (FPoint(30, 2), FSize(22, 22));
FListBox list (&dialog);
list.setText ("Lazy conversion");
list.setGeometry (FPoint(1, 1), FSize(20, 19));
int n = 0;
std::vector<int>* v = new std::vector<int>(100,0);
std::vector<int>::iterator iter = v->begin();
while ( iter != v->end() )
{
*iter = n;
(n%2 != 0) ? n++ : n+=3;
++iter;
}
list.insert (v, IntToString);
app.setMainWidget(&dialog);
dialog.show();
int ret = app.exec();
delete v;
return ret;
}