為了測試一下GUI自動排版,照著自己的手機做了一個GUI程序界面。特此發圖以留紀念。

評論
如果詳細講,恐怕不只一篇文章能講得完,在這里僅簡單介紹一下實現原理。
圖中的布局僅使用boxlayout來完成,如果配合space可以完成更多控制。
這個布局控制與QT和WX有所不同,其子窗口由父窗口管理,layout僅具備算法功能,因此理論上可以對窗口任意切換layout。
//代碼原理如下
class xwnd
{
xwnd* first;xwnd* last;xwnd* prev;xwnd*next;
xlayout* layout;
//調用排版功能
void layout()
{
if (_layout)
_layout->layout(this);
for (xwindow* child = _first; child; child = child->_next)
{
child->layout();
}
}
};
class xwindow : xwnd;
class xframe : xwindow;
class xspace : xwindow;不生成實際的窗口,只是一個占位。
//示例如下:
xframe* frame = new xframe(_T("TEST")); //框架
frame->set_layout(xboxlayout(true));//設置HORZ_BOX
new xedit(frame,LAYOUT_FILL,xsize(100,100)); //左面的EDIT窗口
xwindow* right = new xwindow(frame); //右面的窗口做為容器
right->setlayout(xboxlayout(false)); //設置VERT_BOX
new xspace(right,LAYOUT_FILL_Y); //促使OK和CANCEL按鈕置于最下
new xbutton(right,_T("OK"));
new xbutton(right,_T("Cancel"));
frame->create(); //最后生成框架窗口并顯示
回復 更多評論
圖中的布局僅使用boxlayout來完成,如果配合space可以完成更多控制。
這個布局控制與QT和WX有所不同,其子窗口由父窗口管理,layout僅具備算法功能,因此理論上可以對窗口任意切換layout。
//代碼原理如下
class xwnd
{
xwnd* first;xwnd* last;xwnd* prev;xwnd*next;
xlayout* layout;
//調用排版功能
void layout()
{
if (_layout)
_layout->layout(this);
for (xwindow* child = _first; child; child = child->_next)
{
child->layout();
}
}
};
class xwindow : xwnd;
class xframe : xwindow;
class xspace : xwindow;不生成實際的窗口,只是一個占位。
//示例如下:
xframe* frame = new xframe(_T("TEST")); //框架
frame->set_layout(xboxlayout(true));//設置HORZ_BOX
new xedit(frame,LAYOUT_FILL,xsize(100,100)); //左面的EDIT窗口
xwindow* right = new xwindow(frame); //右面的窗口做為容器
right->setlayout(xboxlayout(false)); //設置VERT_BOX
new xspace(right,LAYOUT_FILL_Y); //促使OK和CANCEL按鈕置于最下
new xbutton(right,_T("OK"));
new xbutton(right,_T("Cancel"));
frame->create(); //最后生成框架窗口并顯示
回復 更多評論
只有注冊用戶登錄后才能發表評論。 | ||
【推薦】100%開源!大型工業跨平臺軟件C++源碼提供,建模,組態!
![]() |
||
網站導航:
博客園
IT新聞
BlogJava
博問
Chat2DB
管理
|
||
|