• <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  評(píng)論-2670  文章-0  trackbacks-0
                GacUI發(fā)布了一個(gè)新的Demo。這個(gè)Demo是關(guān)于多選框和單選框的。跟Windows一樣,直接創(chuàng)建出來(lái)的單選框其實(shí)是不會(huì)互斥的,除非你把他們放進(jìn)同一個(gè)group里面。界面是左右各一個(gè)group box,使用table來(lái)保證兩邊的尺寸都一樣大。每一個(gè)group box里面放三個(gè)按鈕,而且每一個(gè)group box的最小尺寸都取決于兩邊所有6按鈕中最長(zhǎng)的那個(gè)按鈕。每一邊的三個(gè)按鈕使用stack來(lái)排列成像一個(gè)列表一樣。左邊是多選框,右邊是單選框。現(xiàn)在先上圖:

                第一張是剛打開(kāi)的時(shí)候,窗口的尺寸自動(dòng)變化到能顯示所有內(nèi)容的最小的尺寸。盡管因?yàn)槲淖值年P(guān)系,左邊的按鈕比右邊的短,但是table可以控制兩個(gè)group box一樣大,并且共享最小尺寸。



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



                大家已經(jīng)看了前面的三個(gè)demo,所以有些東西其實(shí)已經(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ù),用來(lái)構(gòu)造單選按鈕的時(shí)候,穿進(jìn)去的最后一個(gè)參數(shù)。GuiSelectableButton::GroupController類(lèi)是一個(gè)虛類(lèi),用來(lái)控制選中狀況。而預(yù)定義的MutexGroupController則可以控制連接到的所有GuiSelectionButton并保證他們互斥。如果需要更加復(fù)雜的情況,譬如說(shuō)“最多只能選中N個(gè)按鈕”這樣的,則自己集成一個(gè)group controller就可以了。在創(chuàng)建了一個(gè)group controller,要調(diào)用GuiWindow::AddComponent保持他的生命周期,然后使用GuiSelectableButton::SetGroupController來(lái)幫頂一個(gè)按鈕和一個(gè)group controller。

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

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

              回復(fù)  更多評(píng)論
              
            # re: GacUI Demo:多選框和單選框[未登錄](méi) 2012-04-27 20:41 | Koobin
            不知道有沒(méi)有開(kāi)發(fā)ui的ide呀?  回復(fù)  更多評(píng)論
              
            # re: GacUI Demo:多選框和單選框[未登錄](méi) 2012-04-28 00:15 | fox
            天生不支持xp,這是基于什么考慮呢  回復(fù)  更多評(píng)論
              
            # re: GacUI Demo:多選框和單選框 2012-04-28 04:47 | qqdy
            @陳梓瀚(vczh) 或者考慮采用類(lèi)似 lua 那種 table 結(jié)構(gòu)如何?
              回復(fù)  更多評(píng)論
              
            # re: GacUI Demo:多選框和單選框 2012-04-28 05:21 | 陳梓瀚(vczh)
            @fox
            我有GDI啊,怎么能說(shuō)天生不支持xp呢,只是xp沒(méi)有顯卡加速而已。  回復(fù)  更多評(píng)論
              
            # re: GacUI Demo:多選框和單選框 2012-04-28 05:22 | 陳梓瀚(vczh)
            @qqdy
            lua的table做GUI不好用。  回復(fù)  更多評(píng)論
              
            # re: GacUI Demo:多選框和單選框 2012-04-28 05:48 | 陳梓瀚(vczh)
            @Pear
            我應(yīng)該會(huì)做出blend那種樣子,而不是CSS那種樣子的。  回復(fù)  更多評(píng)論
              
            # re: GacUI Demo:多選框和單選框 2012-04-29 04:24 | qqdy
            @陳梓瀚(vczh) table 支持 key-value ,而且 value 也可以是任意類(lèi)型,可以很輕松滴構(gòu)建出像樹(shù)這種結(jié)構(gòu)。個(gè)人感覺(jué) xml 能夠包含的信息,table 也能包含,而且類(lèi)似 table / json 這種結(jié)構(gòu)視覺(jué)上看起來(lái)可讀性高點(diǎn)哇?  回復(fù)  更多評(píng)論
              
            # re: GacUI Demo:多選框和單選框 2012-04-29 05:39 | 陳梓瀚(vczh)
            @qqdy
            這是C++?。∧M一個(gè)“value”出來(lái)你知道有多困難嗎= =雖然要做當(dāng)然是可以做,不劃算啊,C++就要有C++的樣子。  回復(fù)  更多評(píng)論
              
            # re: GacUI Demo:多選框和單選框 2012-04-29 08:19 | qqdy
            @陳梓瀚(vczh)
            value 類(lèi)型為 void* 如何。。。哎,我只是隨便說(shuō)說(shuō)。。。  回復(fù)  更多評(píng)論
              
            # re: GacUI Demo:多選框和單選框 2012-04-29 08:57 | qqdy
            @陳梓瀚(vczh)
            我的意思是“采用 table / json 這種形式的配置組織格式”,并不是說(shuō)要用C++硬整一個(gè)萬(wàn)能類(lèi)型的 value 出來(lái)哈。提這個(gè)純粹是因?yàn)閭€(gè)人感覺(jué)這種配置格式看起來(lái)比XML更清爽。。。  回復(fù)  更多評(píng)論
              
            # re: GacUI Demo:多選框和單選框 2012-04-29 09:19 | Scan
            @qqdy
            可以用boost::any。以std::map<std::string, boost::any>部分模擬lua的table(key還不是動(dòng)態(tài)類(lèi)型的)。
            C++中什么都可以辦到,問(wèn)題是,一旦語(yǔ)法糖裹厚了,那個(gè)編譯時(shí)間不是可以忍受的。
            我個(gè)人以為,陳子涵老大個(gè)人的C++庫(kù)傾向于.Net風(fēng)格,雖然它不同于stl和boost,但它很實(shí)用。
            往C++中移植其他語(yǔ)言的特性,往往會(huì)付出編譯時(shí)間等代價(jià)。用C++就因?yàn)樗目?,沒(méi)有必要過(guò)度追求語(yǔ)法上的便利性。  回復(fù)  更多評(píng)論
              
            # re: GacUI Demo:多選框和單選框 2012-04-29 17:46 | ooseven
            @陳梓瀚(vczh)
            為啥說(shuō)xp下無(wú)法支持顯卡硬加速?  回復(fù)  更多評(píng)論
              
            # re: GacUI Demo:多選框和單選框 2012-05-01 03:59 | qqdy
            @Scan
            哎,C++的編譯速度向來(lái)被人所詬病啊,加了模板后更是變本加厲的慢。。。  回復(fù)  更多評(píng)論
              
            # re: GacUI Demo:多選框和單選框 2012-05-01 05:04 | 陳梓瀚(vczh)
            @qqdy
            這個(gè)時(shí)候就要看程序員的功力了,boost的spirit編譯一次一個(gè)多小時(shí),我的parser combinator,一樣是模板,編譯一次就5秒鐘。完成的功能幾乎是一樣的,性能也沒(méi)差多少。  回復(fù)  更多評(píng)論
              
            # re: GacUI Demo:多選框和單選框 2012-05-03 05:58 | 裝配腦袋
            復(fù)選框和單選鈕的樣子怪怪的。。  回復(fù)  更多評(píng)論
              
            青青青青久久精品国产h| 久久se精品一区二区影院| 久久综合视频网站| 国产精品熟女福利久久AV| 99久久国产热无码精品免费 | 久久精品www人人爽人人| 香蕉久久久久久狠狠色| 色综合久久88色综合天天 | 久久成人永久免费播放| 久久久久亚洲AV无码专区网站 | 久久国产美女免费观看精品| 日本一区精品久久久久影院| 色噜噜狠狠先锋影音久久| 久久综合九色综合精品| 88久久精品无码一区二区毛片 | 久久久久无码精品| 香蕉aa三级久久毛片| 国产精品亚洲综合久久| 精品久久久无码21p发布| 精品永久久福利一区二区| 伊人色综合久久| 久久毛片免费看一区二区三区| 欧美伊人久久大香线蕉综合69 | 2021精品国产综合久久| 久久精品国产91久久麻豆自制| 热久久这里只有精品| 欧美国产精品久久高清| 精品久久久无码21p发布| 国内精品九九久久久精品| 久久播电影网| 婷婷伊人久久大香线蕉AV| 99久久精品国产一区二区三区| 久久无码国产| 99精品国产综合久久久久五月天| AAA级久久久精品无码片| 久久久久亚洲?V成人无码| 亚洲国产欧洲综合997久久| 久久久久四虎国产精品| 久久亚洲sm情趣捆绑调教| 久久精品www| 亚洲va久久久噜噜噜久久狠狠|