• <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新增了一個Demo。這里模擬了一個簡單到過頭了的編輯程序。界面是一個標(biāo)簽頁,第一頁里面只有一個按鈕:Add Page。點(diǎn)中了他之后,其它頁包含一個用來關(guān)掉自己的按鈕,和一個多行的文本框。

                這個Demo要展示的其中一個問題是,在按下關(guān)閉按鈕的時候,由于那個Page會被移除并刪除,會導(dǎo)致按鈕自己也被刪除。但是事件發(fā)生過后,實(shí)際上還有很多事情要做的。所以這里展示了如何使用GacUI進(jìn)行“延遲執(zhí)行”,在事件結(jié)束之后再刪除自己。為了方便,這個Demo使用了C++11(但是庫的實(shí)現(xiàn)并不依賴與C++11)。先上圖:





                然后我們來看代碼:

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

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

            class TextBoxPage : public GuiTabPage
            {
            private:
                
            static int pageCounter;

                GuiButton
            *                closeButton;
                GuiMultilineTextBox
            *    textBox;

                
            void closeButton_Clicked(GuiGraphicsComposition* sender, GuiEventArgs& arguments)
                {
                    
            // deleteing the tab page will also delete the button, because the button is in the page
                    
            // when an event is processing, the button is not going to be deleted
                    
            // because there are many works to do after this event
                    
            // and maybe someone has already added another event handler to this button
                    
            // so it use GetApplication()->InvokeInMainThread to send a function to the queue
                    
            // so that this function will be executed after this input message (an input message raises multiple events)
                    
            // to the user, this page is closed after cliking this button
                    GetApplication()->InvokeInMainThread([this]()
                    {
                        
            // remove the page and delete it
                        this->GetOwnerTab()->RemovePage(this);
                        delete 
            this;
                    });
                }

                
            void OnPageContainerReady(GuiGraphicsComposition* sender, GuiEventArgs& arguments)
                {
                    
            // create a table to place a button and a text box
                    GuiTableComposition* table=new GuiTableComposition;
                    table
            ->SetRowsAndColumns(21);
                    table
            ->SetRowOption(0, GuiCellOption::MinSizeOption());
                    table
            ->SetRowOption(1, GuiCellOption::PercentageOption(1.0));
                    table
            ->SetColumnOption(0, GuiCellOption::PercentageOption(1.0));
                    table
            ->SetAlignmentToParent(Margin(0000));
                    table
            ->SetCellPadding(2);

                    {
                        GuiCellComposition
            * cell=new GuiCellComposition;
                        table
            ->AddChild(cell);
                        cell
            ->SetSite(0011);
                        
                        closeButton
            =g::NewButton();
                        closeButton
            ->SetText(L"Close Me!");
                        closeButton
            ->Clicked.AttachMethod(this&TextBoxPage::closeButton_Clicked);
                        cell
            ->AddChild(closeButton->GetBoundsComposition());
                    }
                    
                    {
                        GuiCellComposition
            * cell=new GuiCellComposition;
                        table
            ->AddChild(cell);
                        cell
            ->SetSite(1011);
                        
                        textBox
            =g::NewMultilineTextBox();
                        textBox
            ->GetBoundsComposition()->SetAlignmentToParent(Margin(0000));
                        textBox
            ->SetText(L"You can input several lines of text here.\r\nThis is a multiple line text box.");
                        cell
            ->AddChild(textBox->GetBoundsComposition());
                    }

                    
            this->GetContainer()->GetContainerComposition()->AddChild(table);
                }

            public:
                TextBoxPage()
                    :closeButton(
            0)
                    ,textBox(
            0)
                {
                    PageContainerReady.AttachMethod(
            this&TextBoxPage::OnPageContainerReady);
                    
            this->SetText(L"Page "+itow(++pageCounter));
                }

                
            ~TextBoxPage()
                {
                }
            };

            int TextBoxPage::pageCounter=0;

            class TextBoxPageWindow : public GuiWindow
            {
            private:
                GuiTab
            *                        tabControl;
                GuiTabPage
            *                    controlPanelPage;
                GuiButton
            *                    buttonAddPage;

                
            void buttonAddPage_Clicked(GuiGraphicsComposition* sender, GuiEventArgs& arguments)
                {
                    
            // when the button is clicked, it creates a new TextBoxPage and adds it to the tab control
                    TextBoxPage* page=new TextBoxPage;
                    tabControl
            ->CreatePage(page);
                    tabControl
            ->SetSelectedPage(page);
                }
            public:
                TextBoxPageWindow()
                    :GuiWindow(GetCurrentTheme()
            ->CreateWindowStyle())
                {
                    
            this->SetText(L"Controls.Tab.TextBoxPage");
                    
            this->GetBoundsComposition()->SetPreferredMinSize(Size(640480));

                    
            // create a tab control
                    tabControl=g::NewTab();
                    tabControl
            ->GetBoundsComposition()->SetAlignmentToParent(Margin(2222));
                    
            this->AddChild(tabControl);

                    
            // the first page is a control panel
                    controlPanelPage=tabControl->CreatePage();
                    controlPanelPage
            ->SetText(L"Control Panel");

                    
            // add a button to the control panel
                    buttonAddPage=g::NewButton();
                    buttonAddPage
            ->SetText(L"Add a tab page");
                    buttonAddPage
            ->Clicked.AttachMethod(this&TextBoxPageWindow::buttonAddPage_Clicked);
                    controlPanelPage
            ->GetContainer()->GetContainerComposition()->SetInternalMargin(Margin(2222));
                    controlPanelPage
            ->GetContainer()->AddChild(buttonAddPage);

                    
            this->ForceCalculateSizeImmediately();
                    
            this->MoveToScreenCenter();
                }

                
            ~TextBoxPageWindow()
                {
                }
            };

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

                那一大段的注釋,就是在講延遲執(zhí)行的事情??催^C++11的人都知道,lambda expression實(shí)際上就是一個functor。在舊C++里面,調(diào)用InvokeInMainThread的時候,要么可以傳一個void(*)(void*)和void*,要么可以傳一個帶operator()()的struct。在新C++里面,直接把lambda expression寫在里面就好了。

                如果不使用延遲執(zhí)行,在事件發(fā)生的時候把自己刪掉,會導(dǎo)致Access Violation的發(fā)生,因?yàn)榻酉聛硪L問的對象被你刪掉了。如果使用延遲執(zhí)行,就可以在input message處理完之后,執(zhí)行刪除的代碼。這樣一切都是好的。

                下一個Demo就是關(guān)于文本框的操作,再下一個Demo是關(guān)于如何做用來顯示代碼的高亮文本框的事情。敬請期待,啊哈哈哈。
            posted on 2012-04-30 23:28 陳梓瀚(vczh) 閱讀(2027) 評論(2)  編輯 收藏 引用 所屬分類: GacUI

            評論:
            # re: GacUI Demo:標(biāo)簽頁 2012-05-01 06:31 | CY
            AttachMethod如果是只有一個響應(yīng)或者最后一個響應(yīng)里面delete自己,應(yīng)該能僥幸沒事不?  回復(fù)  更多評論
              
            # re: GacUI Demo:標(biāo)簽頁 2012-05-01 09:55 | 陳梓瀚(vczh)
            @CY
            不能  回復(fù)  更多評論
              
            亚洲精品国产成人99久久| 国内精品久久久久久久coent| 久久久噜噜噜久久| 久久久久久精品久久久久| 久久久亚洲裙底偷窥综合| 久久精品亚洲一区二区三区浴池 | 久久久久久国产精品美女 | 精品无码久久久久久国产| 久久笫一福利免费导航| jizzjizz国产精品久久| 国内精品久久久久久中文字幕| 久久久久国产| 91久久精品国产91性色也| 看全色黄大色大片免费久久久| 国产亚洲精久久久久久无码77777| 国产综合久久久久| 国产69精品久久久久观看软件| 乱亲女H秽乱长久久久| 欧美精品丝袜久久久中文字幕| .精品久久久麻豆国产精品| 久久综合九色综合久99| 亚洲综合婷婷久久| 97久久久精品综合88久久| 亚洲中文字幕无码久久2020| 欧美日韩中文字幕久久久不卡 | 色综合久久夜色精品国产| 99久久99久久| 91精品国产色综久久| 97久久婷婷五月综合色d啪蜜芽 | 99国产精品久久| 久久综合香蕉国产蜜臀AV| 久久国产劲爆AV内射—百度| 麻豆久久久9性大片| 香蕉久久AⅤ一区二区三区| 久久久精品国产Sm最大网站| 国产成人香蕉久久久久| 国产日韩久久久精品影院首页| 99久久综合狠狠综合久久止| 国色天香久久久久久久小说| 久久精品二区| 国产香蕉久久精品综合网|