• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆-341  評論-2670  文章-0  trackbacks-0
                GacUI發(fā)布了一個新的Demo。這個Demo是關(guān)于多選框和單選框的。跟Windows一樣,直接創(chuàng)建出來的單選框其實是不會互斥的,除非你把他們放進同一個group里面。界面是左右各一個group box,使用table來保證兩邊的尺寸都一樣大。每一個group box里面放三個按鈕,而且每一個group box的最小尺寸都取決于兩邊所有6按鈕中最長的那個按鈕。每一邊的三個按鈕使用stack來排列成像一個列表一樣。左邊是多選框,右邊是單選框?,F(xiàn)在先上圖:

                第一張是剛打開的時候,窗口的尺寸自動變化到能顯示所有內(nèi)容的最小的尺寸。盡管因為文字的關(guān)系,左邊的按鈕比右邊的短,但是table可以控制兩個group box一樣大,并且共享最小尺寸。



                然后改變窗口的尺寸,按鈕始終靠左上角,兩個group box則保持一樣大。



                大家已經(jīng)看了前面的三個demo,所以有些東西其實已經(jīng)不需要重復(fù)解釋了。先上代碼:

            #include "..\..\Public\Source\GacUIIncludes.h"
            #include 
            <Windows.h>

            int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int CmdShow)
            {
                
            return SetupWindowsDirect2DRenderer();
            }

            class CheckAndRadioWindow : public GuiWindow
            {
            private:

                GuiCellComposition
            * CreateButtons(const WString& groupName, const WString& buttonName, bool checkBox, GuiSelectableButton::GroupController* groupController)
                {
                    GuiCellComposition
            * cell=new GuiCellComposition;

                    GuiControl
            * groupBox=g::NewGroupBox();
                    groupBox
            ->GetBoundsComposition()->SetMinSizeLimitation(GuiGraphicsComposition::LimitToElementAndChildren);
                    groupBox
            ->GetContainerComposition()->SetMinSizeLimitation(GuiGraphicsComposition::LimitToElementAndChildren);
                    
            // all child controls should at least 10 pixels away from the group box
                    groupBox->GetContainerComposition()->SetInternalMargin(Margin(10101010));
                    
            // dock the group box to fill the cell
                    groupBox->GetBoundsComposition()->SetAlignmentToParent(Margin(0000));
                    groupBox
            ->SetText(groupName);
                    
            // add the button to the cell
                    cell->AddChild(groupBox->GetBoundsComposition());

                    
            // create a stack to layout the 3 buttons from top to bottom shown like a list
                    GuiStackComposition* stack=new GuiStackComposition;
                    stack
            ->SetMinSizeLimitation(GuiGraphicsComposition::LimitToElementAndChildren);
                    stack
            ->SetDirection(GuiStackComposition::Vertical);
                    stack
            ->SetAlignmentToParent(Margin(0000));
                    stack
            ->SetPadding(6);
                    groupBox
            ->GetContainerComposition()->AddChild(stack);

                    
            // create buttons
                    for(int i=0;i<3;i++)
                    {
                        GuiSelectableButton
            * button=checkBox?g::NewCheckBox():g::NewRadioButton();
                        button
            ->SetText(buttonName+itow(i+1));
                        button
            ->GetBoundsComposition()->SetAlignmentToParent(Margin(0000));
                        
            if(groupController)
                        {
                            button
            ->SetGroupController(groupController);
                        }

                        GuiStackItemComposition
            * stackItem=new GuiStackItemComposition;
                        stack
            ->AddChild(stackItem);
                        stackItem
            ->AddChild(button->GetBoundsComposition());
                    }

                    
            return cell;
                }
            public:
                CheckAndRadioWindow()
                    :GuiWindow(GetCurrentTheme()
            ->CreateWindowStyle())
                {
                    
            this->SetText(L"Controls.Button.CheckAndRadio");
                    
            // limit the size that the window should always show the whole content without cliping it
                    this->GetContainerComposition()->SetMinSizeLimitation(GuiGraphicsComposition::LimitToElementAndChildren);

                    
            // create a table to layout the 2 group boxes
                    GuiTableComposition* table=new GuiTableComposition;
                    
            // make the table to have 2 rows
                    table->SetRowsAndColumns(12);
                    table
            ->SetRowOption(0, GuiCellOption::MinSizeOption());
                    table
            ->SetColumnOption(0, GuiCellOption::PercentageOption(0.5));
                    table
            ->SetColumnOption(1, GuiCellOption::PercentageOption(0.5));
                    
            // dock the table to fill the window
                    table->SetAlignmentToParent(Margin(4444));
                    table
            ->SetCellPadding(6);
                    
            // add the table to the window;
                    this->GetContainerComposition()->AddChild(table);

                    
            // add group box for check boxes
                    {
                        GuiCellComposition
            * cell=CreateButtons(L"Check Boxes", L"This is a check box "true0);
                        table
            ->AddChild(cell);
                        
            // this cell is the left cell
                        cell->SetSite(0011);
                    }

                    
            // add group box for radio buttons
                    {
                        
            // create a group controller to group those radio buttons together
                        
            // so that select a radio button will unselect the previous one automatically
                        GuiSelectableButton::GroupController* groupController=new GuiSelectableButton::MutexGroupController;
                        
            this->AddComponent(groupController);

                        GuiCellComposition
            * cell=CreateButtons(L"Radio buttons", L"This is a radio button "false, groupController);
                        table
            ->AddChild(cell);
                        
            // this cell is the right cell
                        cell->SetSite(0111);
                    }

                    
            // call this to calculate the size immediately if any indirect content in the table changes
                    
            // so that the window can calcaulte its correct size before calling the MoveToScreenCenter()
                    this->ForceCalculateSizeImmediately();
                    
            // move to the screen center
                    this->MoveToScreenCenter();
                }

                
            ~CheckAndRadioWindow()
                {
                }
            };

            void GuiMain()
            {
                GuiWindow
            * window=new CheckAndRadioWindow();
                GetApplication()
            ->Run(window);
                delete window;
            }

                需要關(guān)心的就是第二次調(diào)用CreateButtons函數(shù),用來構(gòu)造單選按鈕的時候,穿進去的最后一個參數(shù)。GuiSelectableButton::GroupController類是一個虛類,用來控制選中狀況。而預(yù)定義的MutexGroupController則可以控制連接到的所有GuiSelectionButton并保證他們互斥。如果需要更加復(fù)雜的情況,譬如說“最多只能選中N個按鈕”這樣的,則自己集成一個group controller就可以了。在創(chuàng)建了一個group controller,要調(diào)用GuiWindow::AddComponent保持他的生命周期,然后使用GuiSelectableButton::SetGroupController來幫頂一個按鈕和一個group controller。

                這個demo就介紹到這里了,下一個將是關(guān)于tab控件和文本框的demo。
            posted on 2012-04-27 06:02 陳梓瀚(vczh) 閱讀(2255) 評論(25)  編輯 收藏 引用 所屬分類: GacUI

            評論:
            # re: GacUI Demo:多選框和單選框 2012-04-27 06:39 | ccsdu2009
            最好通過類似xml配置文件的形式生成窗體,這樣看上去很復(fù)雜  回復(fù)  更多評論
              
            # re: GacUI Demo:多選框和單選框 2012-04-27 07:06 | 陳梓瀚(vczh)
            @ccsdu2009
            我已經(jīng)有計劃了,等到demo寫完網(wǎng)站做好了我就開始做那個。我暫時覺得比xml要好多了,啊哈哈哈  回復(fù)  更多評論
              
            # re: GacUI Demo:多選框和單選框 2012-04-27 16:24 | Pear
            什么時候能支持樣式表涅?其實我只是想做效果的時候偷懶一點。。  回復(fù)  更多評論
              
            # re: GacUI Demo:多選框和單選框[未登錄] 2012-04-27 19:43 | me
            Excellent !

              回復(fù)  更多評論
              
            # re: GacUI Demo:多選框和單選框[未登錄] 2012-04-27 20:41 | Koobin
            不知道有沒有開發(fā)ui的ide呀?  回復(fù)  更多評論
              
            # re: GacUI Demo:多選框和單選框[未登錄] 2012-04-28 00:15 | fox
            天生不支持xp,這是基于什么考慮呢  回復(fù)  更多評論
              
            # re: GacUI Demo:多選框和單選框 2012-04-28 04:47 | qqdy
            @陳梓瀚(vczh) 或者考慮采用類似 lua 那種 table 結(jié)構(gòu)如何?
              回復(fù)  更多評論
              
            # re: GacUI Demo:多選框和單選框 2012-04-28 05:21 | 陳梓瀚(vczh)
            @fox
            我有GDI啊,怎么能說天生不支持xp呢,只是xp沒有顯卡加速而已。  回復(fù)  更多評論
              
            # re: GacUI Demo:多選框和單選框 2012-04-28 05:22 | 陳梓瀚(vczh)
            @qqdy
            lua的table做GUI不好用。  回復(fù)  更多評論
              
            # re: GacUI Demo:多選框和單選框 2012-04-28 05:48 | 陳梓瀚(vczh)
            @Pear
            我應(yīng)該會做出blend那種樣子,而不是CSS那種樣子的。  回復(fù)  更多評論
              
            # re: GacUI Demo:多選框和單選框 2012-04-29 04:24 | qqdy
            @陳梓瀚(vczh) table 支持 key-value ,而且 value 也可以是任意類型,可以很輕松滴構(gòu)建出像樹這種結(jié)構(gòu)。個人感覺 xml 能夠包含的信息,table 也能包含,而且類似 table / json 這種結(jié)構(gòu)視覺上看起來可讀性高點哇?  回復(fù)  更多評論
              
            # re: GacUI Demo:多選框和單選框 2012-04-29 05:39 | 陳梓瀚(vczh)
            @qqdy
            這是C++啊!模擬一個“value”出來你知道有多困難嗎= =雖然要做當然是可以做,不劃算啊,C++就要有C++的樣子。  回復(fù)  更多評論
              
            # re: GacUI Demo:多選框和單選框 2012-04-29 08:19 | qqdy
            @陳梓瀚(vczh)
            value 類型為 void* 如何。。。哎,我只是隨便說說。。。  回復(fù)  更多評論
              
            # re: GacUI Demo:多選框和單選框 2012-04-29 08:57 | qqdy
            @陳梓瀚(vczh)
            我的意思是“采用 table / json 這種形式的配置組織格式”,并不是說要用C++硬整一個萬能類型的 value 出來哈。提這個純粹是因為個人感覺這種配置格式看起來比XML更清爽。。。  回復(fù)  更多評論
              
            # re: GacUI Demo:多選框和單選框 2012-04-29 09:19 | Scan
            @qqdy
            可以用boost::any。以std::map<std::string, boost::any>部分模擬lua的table(key還不是動態(tài)類型的)。
            C++中什么都可以辦到,問題是,一旦語法糖裹厚了,那個編譯時間不是可以忍受的。
            我個人以為,陳子涵老大個人的C++庫傾向于.Net風格,雖然它不同于stl和boost,但它很實用。
            往C++中移植其他語言的特性,往往會付出編譯時間等代價。用C++就因為它的快,沒有必要過度追求語法上的便利性。  回復(fù)  更多評論
              
            # re: GacUI Demo:多選框和單選框 2012-04-29 17:46 | ooseven
            @陳梓瀚(vczh)
            為啥說xp下無法支持顯卡硬加速?  回復(fù)  更多評論
              
            # re: GacUI Demo:多選框和單選框 2012-05-01 03:59 | qqdy
            @Scan
            哎,C++的編譯速度向來被人所詬病啊,加了模板后更是變本加厲的慢。。。  回復(fù)  更多評論
              
            # re: GacUI Demo:多選框和單選框 2012-05-01 05:04 | 陳梓瀚(vczh)
            @qqdy
            這個時候就要看程序員的功力了,boost的spirit編譯一次一個多小時,我的parser combinator,一樣是模板,編譯一次就5秒鐘。完成的功能幾乎是一樣的,性能也沒差多少。  回復(fù)  更多評論
              
            # re: GacUI Demo:多選框和單選框 2012-05-03 05:58 | 裝配腦袋
            復(fù)選框和單選鈕的樣子怪怪的。。  回復(fù)  更多評論
              
            国内精品久久人妻互换| 精品久久久久久国产牛牛app| 亚洲人成伊人成综合网久久久| 久久人人爽爽爽人久久久| 久久免费视频观看| 一级做a爰片久久毛片毛片| 国内精品久久久久伊人av| 欧美日韩中文字幕久久久不卡| 漂亮人妻被黑人久久精品| 久久久久黑人强伦姧人妻| 91精品国产乱码久久久久久| 久久久久一本毛久久久| www.久久热.com| 亚洲日韩中文无码久久| 一本大道久久东京热无码AV| 91久久精品电影| 潮喷大喷水系列无码久久精品| 欧美激情一区二区久久久| 国产精品美女久久久网AV| 国产欧美久久一区二区| 亚洲va久久久噜噜噜久久男同| 久久人人爽人人精品视频| 97久久精品人人做人人爽| 国产∨亚洲V天堂无码久久久| 国产精品99久久久精品无码| 久久精品国产欧美日韩| 91精品国产乱码久久久久久| 久久国产精品无码一区二区三区| 99久久夜色精品国产网站| 国产精品乱码久久久久久软件 | 久久亚洲AV成人无码| 久久久久久无码国产精品中文字幕 | 国产午夜福利精品久久| 久久99精品国产99久久6男男| 久久夜色精品国产噜噜亚洲AV| 久久精品人人做人人爽电影| 免费一级欧美大片久久网| 无码任你躁久久久久久老妇| 久久天天躁狠狠躁夜夜2020| 亚洲精品高清一二区久久| 2021国产精品久久精品|