Cdroid/apps/samples/horzscroll.cc

46 lines
1.7 KiB
C++
Raw Normal View History

2022-01-18 16:21:54 +08:00
#include <cdroid.h>
2021-08-27 18:41:10 +08:00
#include <dirent.h>
#include <fstream>
2022-11-07 07:49:41 +08:00
using namespace Cairo;
2021-08-27 18:41:10 +08:00
int main(int argc,const char*argv[]){
App app(argc,argv);
2023-03-21 18:38:38 +08:00
Window*w=new Window(100,50,1080,600);
2021-08-27 18:41:10 +08:00
HorizontalScrollView* hs=new HorizontalScrollView(1280,400);
LinearLayout*layout=new LinearLayout(1280,100);
layout->setOrientation(LinearLayout::HORIZONTAL);
std::string path="/home/houzh/images";
if(argc>1)path=argv[1];
DIR*dir=opendir(path.c_str());
struct dirent*ent;
int count=0;
2023-03-21 18:38:38 +08:00
hs->setBackgroundColor(0xFFFF0000);
layout->setBackgroundColor(0xFF00FF00);
printf("%s open=%p\n",path.c_str(),dir);
2022-12-17 00:08:21 +08:00
while(dir&&(ent=readdir(dir))){
2021-08-27 18:41:10 +08:00
std::string fullpath=path+"/"+ent->d_name;
2023-03-21 18:38:38 +08:00
//LOGI("img:%s ",fullpath.c_str());
if(ent->d_type==DT_DIR)continue;
std::ifstream fs(fullpath.c_str(),std::ios::binary|std::ios::in);
if(strstr(fullpath.c_str(),".png")==nullptr)continue;
RefPtr<Cairo::ImageSurface>img=ImageSurface::create_from_stream(fs);
2023-03-21 18:38:38 +08:00
//LOGI("img:%s =%p",fullpath.c_str(),img.get());
2021-08-27 18:41:10 +08:00
if(img==nullptr)continue;
ImageView*iv=new ImageView(150,30);
iv->setImageBitmap(img);
iv->setId(++count);
layout->addView(iv,new LinearLayout::LayoutParams(LayoutParams::WRAP_CONTENT,LayoutParams::MATCH_PARENT));
}
hs->setOverScrollMode(View::OVER_SCROLL_ALWAYS);
2023-03-21 18:38:38 +08:00
hs->setHorizontalScrollBarEnabled(true);
hs->setVerticalScrollBarEnabled(true);
hs->addView(layout,new LinearLayout::LayoutParams(LayoutParams::WRAP_CONTENT,LayoutParams::MATCH_PARENT));
2021-08-27 18:41:10 +08:00
//w->addView(layout);
w->addView(hs);
layout->requestLayout();
if(dir)closedir(dir);
w->requestLayout();
app.exec();
}