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

                這個Demo要展示的其中一個問題是,在按下關閉按鈕的時候,由于那個Page會被移除并刪除,會導致按鈕自己也被刪除。但是事件發生過后,實際上還有很多事情要做的。所以這里展示了如何使用GacUI進行“延遲執行”,在事件結束之后再刪除自己。為了方便,這個Demo使用了C++11(但是庫的實現并不依賴與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;
            }

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

                如果不使用延遲執行,在事件發生的時候把自己刪掉,會導致Access Violation的發生,因為接下來要訪問的對象被你刪掉了。如果使用延遲執行,就可以在input message處理完之后,執行刪除的代碼。這樣一切都是好的。

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

            評論:
            # re: GacUI Demo:標簽頁 2012-05-01 06:31 | CY
            AttachMethod如果是只有一個響應或者最后一個響應里面delete自己,應該能僥幸沒事不?  回復  更多評論
              
            # re: GacUI Demo:標簽頁 2012-05-01 09:55 | 陳梓瀚(vczh)
            @CY
            不能  回復  更多評論
              
            韩国三级中文字幕hd久久精品| 久久超碰97人人做人人爱| 国内精品久久久久久久涩爱| 成人午夜精品久久久久久久小说| 久久er国产精品免费观看8| 超级97碰碰碰碰久久久久最新 | 久久久女人与动物群交毛片| 亚洲精品无码久久久久sm| 69久久精品无码一区二区| 国产精品欧美久久久久天天影视| 97精品伊人久久大香线蕉| 久久九九亚洲精品| 亚洲国产一成人久久精品| 国产精品成人99久久久久| 日韩精品久久久肉伦网站| 久久久久国产一区二区| 人妻少妇久久中文字幕一区二区| 久久人人爽人人精品视频| 国产91色综合久久免费| 伊人久久大香线蕉av不卡 | 丁香色欲久久久久久综合网| 夜夜亚洲天天久久| 亚洲av成人无码久久精品| 性做久久久久久久久久久| 国产精品免费久久久久影院| 久久超碰97人人做人人爱| 欧美黑人激情性久久| 亚洲va久久久噜噜噜久久狠狠 | 最新久久免费视频| 麻豆精品久久久一区二区| 久久久国产精华液| 久久久久亚洲精品日久生情| 久久精品亚洲乱码伦伦中文 | 无码久久精品国产亚洲Av影片| 亚洲v国产v天堂a无码久久| 久久99精品久久久久久噜噜| 国内精品久久久久久麻豆| 2020最新久久久视精品爱| 9191精品国产免费久久| 99久久精品国产一区二区三区| 国产成人综合久久久久久|