• <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。這個Demo用了幾個按鈕(之所以不用菜單是因為不想讓Demo一下子包含太多新東西)來實現剪貼板操作、只讀控制和行跳轉等功能。在剪貼板里面的內容是文字的時候,Paste按鈕會被Enable。這個過程是自動的,也就是說,你在畫圖里面復制了一個圖片,這個按鈕也會變灰。Cut和Copy按鈕僅在文本框有文字被選中的時候可用,因此相應了文本框的SelectionChanged來處理這件事情。如果文本框的內容太多的話,{VS, Explorer} X {Debug, Release}這四種運行方法里面,只有在Debug模式下掛了VS這種情況會感覺有點卡,其他的打開方法都是很流暢的。先來看圖:



                代碼還是比較簡單的。先用一個Table分成三行,前兩行讓行高縮短到最短,最后一行則利用了剩余空間的100%撐開。前兩行里面的按鈕用Stack來對它們進行排版。單行文本框沒有最小高度,所以依靠Stack和Table,它的高度會保持跟按鈕一致。代碼如下:

              1 #include "..\..\Public\Source\GacUIIncludes.h"
              2 #include <Windows.h>
              3 
              4 int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int CmdShow)
              5 {
              6     return SetupWindowsDirect2DRenderer();
              7 }
              8 
              9 class TextBoxEditorWindow : public GuiWindow
             10 {
             11 private:
             12     GuiButton*                        buttonCut;
             13     GuiButton*                        buttonCopy;
             14     GuiButton*                        buttonPaste;
             15     GuiButton*                        buttonSelectAll;
             16     GuiSelectableButton*            checkReadonly;
             17     GuiSinglelineTextBox*            textGoto;
             18     GuiButton*                        buttonGoto;
             19     GuiMultilineTextBox*            textDocument;
             20 
             21     void UpdateEditButtonState()
             22     {
             23         buttonCut->SetEnabled(textDocument->CanCut());
             24         buttonCopy->SetEnabled(textDocument->CanCopy());
             25         buttonPaste->SetEnabled(textDocument->CanPaste());
             26     }
             27 
             28     // ensure that the buttonGoto is enabled only when textGoto's content is a positive number
             29     void UpdateGotoButtonState()
             30     {
             31         buttonGoto->SetEnabled(utow(wtou(textGoto->GetText()))==textGoto->GetText() && wtou(textGoto->GetText())!=0);
             32     }
             33 
             34     // cut text box selection
             35     void buttonCut_OnClicked(GuiGraphicsComposition* sender, GuiEventArgs& arguments)
             36     {
             37         textDocument->Cut();
             38         textDocument->SetFocus();
             39     }
             40 
             41     // copy text box selection
             42     void buttonCopy_OnClicked(GuiGraphicsComposition* sender, GuiEventArgs& arguments)
             43     {
             44         textDocument->Copy();
             45         textDocument->SetFocus();
             46     }
             47 
             48     // paste text from clipboard
             49     void buttonPaste_OnClicked(GuiGraphicsComposition* sender, GuiEventArgs& arguments)
             50     {
             51         textDocument->Paste();
             52         textDocument->SetFocus();
             53     }
             54 
             55     // select all text
             56     void buttonSelectAll_OnClicked(GuiGraphicsComposition* sender, GuiEventArgs& arguments)
             57     {
             58         textDocument->SelectAll();
             59         textDocument->SetFocus();
             60     }
             61 
             62     // go to the specified line
             63     void buttonGoto_OnClicked(GuiGraphicsComposition* sender, GuiEventArgs& arguments)
             64     {
             65         int line=wtoi(textGoto->GetText())-1;
             66         textDocument->Select(TextPos(line, 0), TextPos(line, 0));
             67         textDocument->SetFocus();
             68     }
             69 
             70     // make the textbox readonly or not readonly
             71     void checkReadonly_OnSelectedChanged(GuiGraphicsComposition* sender, GuiEventArgs& arguments)
             72     {
             73         textDocument->SetReadonly(checkReadonly->GetSelected());
             74         UpdateEditButtonState();
             75     }
             76 
             77     // when textGoto changed, disable buttonGoto if the text in the textGoto is failed to pass the validation
             78     void textGoto_TextChanged(GuiGraphicsComposition* sender, GuiEventArgs& arguments)
             79     {
             80         UpdateGotoButtonState();
             81     }
             82 
             83     // update the edit buttons when selection changed
             84     void textDocument_SelectionChanged(GuiGraphicsComposition* sender, GuiEventArgs& arguments)
             85     {
             86         UpdateEditButtonState();
             87     }
             88     
             89     // update the edit buttons when clipboard changed changed
             90     void window_OnClipboardUpdated(GuiGraphicsComposition* sender, GuiEventArgs& arguments)
             91     {
             92         UpdateEditButtonState();
             93     }
             94 public:
             95     TextBoxEditorWindow()
             96         :GuiWindow(GetCurrentTheme()->CreateWindowStyle())
             97     {
             98         this->SetText(L"Controls.TextBox.Editor");
             99         this->GetContainerComposition()->SetMinSizeLimitation(GuiGraphicsComposition::LimitToElementAndChildren);
            100         this->ClipboardUpdated.AttachMethod(this&TextBoxEditorWindow::window_OnClipboardUpdated);
            101 
            102         GuiTableComposition* table=new GuiTableComposition;
            103         table->SetAlignmentToParent(Margin(0000));
            104         table->SetCellPadding(2);
            105         table->SetRowsAndColumns(31);
            106         table->SetRowOption(0, GuiCellOption::MinSizeOption());
            107         table->SetRowOption(1, GuiCellOption::MinSizeOption());
            108         table->SetRowOption(2, GuiCellOption::PercentageOption(1.0));
            109         table->SetColumnOption(0, GuiCellOption::PercentageOption(1.0));
            110         this->GetContainerComposition()->AddChild(table);
            111         
            112         {
            113             GuiCellComposition* cell=new GuiCellComposition;
            114             table->AddChild(cell);
            115             cell->SetSite(0011);
            116 
            117             GuiStackComposition* stack=new GuiStackComposition;
            118             stack->SetMinSizeLimitation(GuiGraphicsComposition::LimitToElementAndChildren);
            119             stack->SetPadding(2);
            120             stack->SetAlignmentToParent(Margin(0000));
            121             cell->AddChild(stack);
            122 
            123             {
            124                 GuiStackItemComposition* item=new GuiStackItemComposition;
            125                 stack->AddChild(item);
            126 
            127                 buttonCut=g::NewButton();
            128                 buttonCut->SetText(L"Cut");
            129                 buttonCut->GetBoundsComposition()->SetAlignmentToParent(Margin(0000));
            130                 buttonCut->Clicked.AttachMethod(this&TextBoxEditorWindow::buttonCut_OnClicked);
            131                 item->AddChild(buttonCut->GetBoundsComposition());
            132             }
            133             {
            134                 GuiStackItemComposition* item=new GuiStackItemComposition;
            135                 stack->AddChild(item);
            136 
            137                 buttonCopy=g::NewButton();
            138                 buttonCopy->SetText(L"Copy");
            139                 buttonCopy->GetBoundsComposition()->SetAlignmentToParent(Margin(0000));
            140                 buttonCopy->Clicked.AttachMethod(this&TextBoxEditorWindow::buttonCopy_OnClicked);
            141                 item->AddChild(buttonCopy->GetBoundsComposition());
            142             }
            143             {
            144                 GuiStackItemComposition* item=new GuiStackItemComposition;
            145                 stack->AddChild(item);
            146 
            147                 buttonPaste=g::NewButton();
            148                 buttonPaste->SetText(L"Paste");
            149                 buttonPaste->GetBoundsComposition()->SetAlignmentToParent(Margin(0000));
            150                 buttonPaste->Clicked.AttachMethod(this&TextBoxEditorWindow::buttonPaste_OnClicked);
            151                 item->AddChild(buttonPaste->GetBoundsComposition());
            152             }
            153             {
            154                 GuiStackItemComposition* item=new GuiStackItemComposition;
            155                 stack->AddChild(item);
            156 
            157                 buttonSelectAll=g::NewButton();
            158                 buttonSelectAll->SetText(L"Select All");
            159                 buttonSelectAll->GetBoundsComposition()->SetAlignmentToParent(Margin(0000));
            160                 buttonSelectAll->Clicked.AttachMethod(this&TextBoxEditorWindow::buttonSelectAll_OnClicked);
            161                 item->AddChild(buttonSelectAll->GetBoundsComposition());
            162             }
            163             {
            164                 GuiStackItemComposition* item=new GuiStackItemComposition;
            165                 stack->AddChild(item);
            166 
            167                 checkReadonly=g::NewCheckBox();
            168                 checkReadonly->SetText(L"Readonly");
            169                 checkReadonly->GetBoundsComposition()->SetAlignmentToParent(Margin(0000));
            170                 checkReadonly->SelectedChanged.AttachMethod(this&TextBoxEditorWindow::checkReadonly_OnSelectedChanged);
            171                 item->AddChild(checkReadonly->GetBoundsComposition());
            172             }
            173         }
            174         {
            175             GuiCellComposition* cell=new GuiCellComposition;
            176             table->AddChild(cell);
            177             cell->SetSite(1011);
            178 
            179             GuiStackComposition* stack=new GuiStackComposition;
            180             stack->SetMinSizeLimitation(GuiGraphicsComposition::LimitToElementAndChildren);
            181             stack->SetPadding(2);
            182             stack->SetAlignmentToParent(Margin(0000));
            183             cell->AddChild(stack);
            184 
            185             {
            186                 GuiStackItemComposition* item=new GuiStackItemComposition;
            187                 stack->AddChild(item);
            188 
            189                 textGoto=g::NewTextBox();
            190                 textGoto->GetBoundsComposition()->SetBounds(Rect(Point(00), Size(1800)));
            191                 textGoto->GetBoundsComposition()->SetAlignmentToParent(Margin(0000));
            192                 textGoto->TextChanged.AttachMethod(this&TextBoxEditorWindow::textGoto_TextChanged);
            193                 item->AddChild(textGoto->GetBoundsComposition());
            194             }
            195             {
            196                 GuiStackItemComposition* item=new GuiStackItemComposition;
            197                 stack->AddChild(item);
            198 
            199                 buttonGoto=g::NewButton();
            200                 buttonGoto->SetText(L"Go to this line");
            201                 buttonGoto->GetBoundsComposition()->SetAlignmentToParent(Margin(0000));
            202                 buttonGoto->Clicked.AttachMethod(this&TextBoxEditorWindow::buttonGoto_OnClicked);
            203                 item->AddChild(buttonGoto->GetBoundsComposition());
            204             }
            205         }
            206         {
            207             GuiCellComposition* cell=new GuiCellComposition;
            208             table->AddChild(cell);
            209             cell->SetSite(2011);
            210 
            211             textDocument=g::NewMultilineTextBox();
            212             textDocument->GetBoundsComposition()->SetAlignmentToParent(Margin(0000));
            213             textDocument->SelectionChanged.AttachMethod(this&TextBoxEditorWindow::textDocument_SelectionChanged);
            214             cell->AddChild(textDocument->GetBoundsComposition());
            215         }
            216 
            217         // make some buttons enabled or disabled appropiately
            218         UpdateEditButtonState();
            219         UpdateGotoButtonState();
            220         // set the preferred minimum client size
            221         this->GetBoundsComposition()->SetPreferredMinSize(Size(640480));
            222         // call this to calculate the size immediately if any indirect content in the table changes
            223         // so that the window can calcaulte its correct size before calling the MoveToScreenCenter()
            224         this->ForceCalculateSizeImmediately();
            225         // move to the screen center
            226         this->MoveToScreenCenter();
            227     }
            228 
            229     ~TextBoxEditorWindow()
            230     {
            231     }
            232 };
            233 
            234 void GuiMain()
            235 {
            236     GuiWindow* window=new TextBoxEditorWindow();
            237     GetApplication()->Run(window);
            238     delete window;
            239 }

                GacUI將提供兩個文本框的Demo,這是第一個。GacUI的文本框從一開始就具備了讓每一個字符的顏色可以不同的功能,下一個Demo將展示如何利用使用正則表達式構建的詞法分析器(見這里這里),讓文本框在編輯的時候,跟所有的代碼編輯器一樣,可以根據情況把不同的字符串染成不同的顏色。
            posted on 2012-05-05 02:37 陳梓瀚(vczh) 閱讀(5300) 評論(5)  編輯 收藏 引用 所屬分類: GacUI

            評論:
            # re: GacUI Demo:文本框基本應用 2012-05-05 08:24 | 空明流轉
            基本成型了。。。  回復  更多評論
              
            # re: GacUI Demo:文本框基本應用[未登錄] 2012-05-06 02:10 | me
            你太厲害了!別太累哦!  回復  更多評論
              
            # re: GacUI Demo:文本框基本應用 2012-05-06 05:28 | Zblc(邱震鈺)
            不容易瓦  回復  更多評論
              
            # re: GacUI Demo:文本框基本應用 2012-05-07 00:14 | vczh
            公司發(fā)winphone7.5手機了滅哈哈。  回復  更多評論
              
            # re: GacUI Demo:文本框基本應用[未登錄] 2012-05-07 16:37 | me
            哇哇哇!!!  回復  更多評論
              
            欧美一区二区三区久久综合| 99久久婷婷国产一区二区| 久久久久亚洲精品中文字幕| 久久九九有精品国产23百花影院| 亚洲国产精品无码久久久蜜芽 | 女同久久| 色婷婷久久综合中文久久一本| 国内精品久久久久国产盗摄| 久久精品无码免费不卡| 青青青青久久精品国产h久久精品五福影院1421 | 久久免费高清视频| 久久国产精品-久久精品| 久久99热精品| 欧美久久亚洲精品| 久久无码高潮喷水| 麻豆成人久久精品二区三区免费| 99999久久久久久亚洲| 91久久精品国产成人久久| 久久久久亚洲精品无码网址| 无码人妻久久一区二区三区| a高清免费毛片久久| 久久久久综合国产欧美一区二区| 久久天天躁狠狠躁夜夜躁2014| 久久亚洲私人国产精品| 999久久久国产精品| 久久久久久综合网天天| 国产91色综合久久免费| 久久精品国产一区二区电影| 久久天天躁狠狠躁夜夜avapp| 国产精品久久久久无码av| 久久一区二区三区99| 狠狠色婷婷久久一区二区三区| 久久久久亚洲av成人无码电影| 久久久一本精品99久久精品88| 久久青草国产精品一区| 久久国产欧美日韩精品免费| 久久精品亚洲一区二区三区浴池| 久久国产精品国语对白| 久久精品亚洲日本波多野结衣| 久久久中文字幕日本| 国产精品一区二区久久|