<p class="figure">Figure: Push button</p> \r
<p align="center"><img alt="Push button" src="../../images/push_button.png"/></p> \r
\r
-<p>By default, a push button emits a <span style="font-family: Courier New,Courier,monospace;">Button::PressedSignal()</span> signal when the button is pressed, a <span style="font-family: Courier New,Courier,monospace;">Button::ClickedSignal()</span> signal when clicked, and a <span style="font-family: Courier New,Courier,monospace;">Button::ReleasedSignal()</span> signal when released, or of the touch point leaves the boundary of the button. The following is a basic example of implementing a push button:</p>\r
+<p>A push button emits a <span style="font-family: Courier New,Courier,monospace;">Button::PressedSignal()</span> signal when the button is pressed, a <span style="font-family: Courier New,Courier,monospace;">Button::ClickedSignal()</span> signal when clicked, and a <span style="font-family: Courier New,Courier,monospace;">Button::ReleasedSignal()</span> signal when released, or of the touch point leaves the boundary of the button. A basic push button example is as follows:</p>\r
\r
-<pre class="prettyprint">class ButtonsController: public ConnectionTracker\r
+<pre class="prettyprint">\r
+class ButtonController : public ConnectionTracker\r
{\r
- ButtonsController(Application& application)\r
- : mApplication(application)\r
- {\r
- mApplication.InitSignal().Connect(this, &ButtonsController::Create);\r
- }\r
-\r
- void Create(Application& application)\r
- {\r
- Stage stage = Stage::GetCurrent();\r
-\r
- PushButton button = PushButton::New();\r
- button.SetLabel("Select");\r
- button.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension:;ALL_DIMENSIONS);\r
- button.SetSelectedImage(Dali::ResourceImage::New("pressedImage.png"));\r
- button.SetDisabledImage(Dali::ResourceImage::New("disabledImage.png"));\r
- button.SetButtonImage(Dali::ResourceImage::New("buttonImage.png"));\r
-\r
- button.ClickedSignal().Connect(this, &ButtonsController::OnButtonClicked);\r
-\r
- stage.Add(button);\r
- }\r
-\r
- bool OnButtonClicked(Toolkit::Button button)\r
- {\r
- // Application developer code\r
- return true;\r
- }\r
-\r
- Application& mApplication;\r
-}</pre>\r
+public:\r
+ ButtonController( Application& application ): mApplication( application )\r
+ {\r
+ mApplication.InitSignal().Connect( this, &ButtonController::Create );\r
+ }\r
+ void Create( Application& application )\r
+ {\r
+ PushButton button = PushButton::New();\r
+ button.SetLabel( "Select" );\r
+ button.SetParentOrigin( ParentOrigin::CENTER );\r
+ button.ClickedSignal().Connect( this, &ButtonController::OnButtonClicked );\r
+ Stage::GetCurrent().Add( button );\r
+ }\r
+ bool OnButtonClicked( Toolkit::Button button )\r
+ {\r
+ cout << "OnButtonClicked" << endl;\r
+ return true;\r
+ }\r
+private:\r
+ Application& mApplication;\r
+};\r
+\r
+int main( int argc, char **argv )\r
+{\r
+ Application application = Application::New( &argc, &argv );\r
+ ButtonController test( application );\r
+ application.MainLoop();\r
+ return 0;\r
+}\r
+</pre>\r
\r
<h2 id="CheckBoxButton" name="CheckBoxButton">CheckBox Button</h2>\r
\r
<p class="figure">Figure: Checkbox button</p> \r
<p align="center"><img alt="Checkbox button" src="../../images/checkbox_button.png"/></p> \r
\r
-<p>By default, a checkbox button emits a <span style="font-family: Courier New,Courier,monospace;">Button::ClickedSignal()</span> signal when the button changes its state to selected or unselected. The following is a basic example of implementing a checkbox button:</p>\r
-\r
-<pre class="prettyprint">class ButtonsController: public ConnectionTracker\r
-{\r
- ButtonsController(Application& application)\r
- : mApplication(application)\r
- {\r
- mApplication.InitSignal().Connect(this, &ButtonsController::Create);\r
- }\r
-\r
- void Create(Application& application)\r
- {\r
- Stage stage = Stage::GetCurrent();\r
-\r
- Actor checkBoxBackground = Actor::New();\r
- stage.Add(checkBoxBackground);\r
- checkBoxBackground.SetParentOrigin(ParentOrigin::TOP_LEFT);\r
- checkBoxBackground.SetAnchorPoint(ParentOrigin::TOP_LEFT);\r
- checkBoxBackground.SetPosition(0.0f, 0.0f);\r
- checkBoxBackground.SetSize(400.0f, 400.0);\r
-\r
- Dali::Image unselected = Dali::ResourceImage::New("UnSelectedImage.png");\r
- Dali::Image selected = Dali::ResourceImage::New("SelectedImage.png");\r
-\r
- {\r
- Toolkit::CheckBoxButton checkBox = Toolkit::CheckBoxButton::New();\r
- checkBox.SetName("checkbox1");\r
- checkBox.SetBackgroundImage(unselected);\r
- checkBox.SetSelectedImage(selected);\r
- checkBox.SetLabel("CheckBox1 is unselected");\r
- checkBox.StateChangedSignal().Connect(this, &ButtonsController::OnCheckBoxesSelected);\r
-\r
- checkBoxBackground.Add(checkBox);\r
- }\r
-\r
- {\r
- Toolkit::CheckBoxButton checkBox = Toolkit::CheckBoxButton::New();\r
- checkBox.SetName("checkbox2");\r
- checkBox.SetBackgroundImage(unselected);\r
- checkBox.SetSelectedImage(selected);\r
- checkBox.SetLabel("CheckBox2 is selected");\r
- checkBox.SetSelected(true);\r
- checkBox.StateChangedSignal().Connect(this, &ButtonsController::OnCheckBoxesSelected);\r
-\r
- checkBoxBackground.Add(checkBox);\r
- }\r
- }\r
-\r
- bool OnCheckBoxesSelected(Toolkit::Button button)\r
- {\r
- if(button.GetName() == "checkbox1")\r
- {\r
- if(button.IsSelected())\r
- {\r
- button.SetLabel("CheckBox1 is selected");\r
- }\r
- else\r
- {\r
- button.SetLabel("CheckBox1 is unselected");\r
- }\r
- }\r
-\r
- if(button.GetName() == "checkbox2")\r
- {\r
- if(button.IsSelected())\r
- {\r
- button.SetLabel("CheckBox2 is selected");\r
- }\r
- else\r
- {\r
- button.SetLabel("CheckBox2 is unselected");\r
- }\r
- }\r
- return true;\r
- }\r
-\r
- Application& mApplication;\r
-}</pre>\r
+<p>A checkbox button emits all of four button input sinals, but usually you can just use <span style="font-family: Courier New,Courier,monospace;">Button::StateChangedSignal()</span> signal to check the button changes its state to selected or unselected. A basic checkbox button example is as follows:</p>\r
+\r
+<pre class="prettyprint">\r
+// ... same to the push button example\r
+ void Create( Application& application )\r
+ {\r
+ CheckBoxButton button = CheckBoxButton::New();\r
+ button.SetLabel( "Select" );\r
+ button.SetSize( 100,40 );\r
+ button.SetBackgroundColor( Vector4( 1,0,0,1 ) );\r
+ button.SetParentOrigin( ParentOrigin::CENTER );\r
+ button.StateChangedSignal().Connect( this, &ButtonController::OnButtonStateChanged );\r
+ Stage::GetCurrent().Add( button );\r
+ }\r
+ bool OnButtonStateChanged( Toolkit::Button button )\r
+ {\r
+ cout << "OnButtonStateChanged " << button.IsSelected() << endl;\r
+ return true;\r
+ }\r
+// ... same to the push button example\r
+</pre>\r
\r
<h2 id="RadioButton" name="RadioButton">Radio Button</h2>\r
\r
<p class="figure">Figure: Radio button</p> \r
<p align="center"><img alt="Radio button" src="../../images/radio_button.png"/></p> \r
\r
-<p>Radio buttons can be grouped. 2 or more radio buttons are in the same group when they have the same parent. In each group, only 1 radio button can be selected at a given time. The following is a basic example of implementing a radio button:</p>\r
-\r
-<pre class="prettyprint">class ButtonsController: public ConnectionTracker\r
-{\r
- ButtonsController(Application& application)\r
- : mApplication(application)\r
- {\r
- mApplication.InitSignal().Connect(this, &ButtonsController::Create);\r
- }\r
-\r
- void Create(Application& application)\r
- {\r
- Stage stage = Stage::GetCurrent();\r
- Actor radioGroup = Actor::New();\r
- stage.Add(redioGroup);\r
- radioGroup.SetParentOrigin(ParentOrigin::TOP_LEFT);\r
- radioGroup.SetAnchorPoint(ParentOrigin::TOP_LEFT);\r
- radioGroup.SetPosition(0.0f, 0.0f);\r
- radioGroup.SetSize(400.0f, 400.0);\r
-\r
- RadioButton radioButton1 = RadioButton::New("label");\r
- radioButton1.SetParentOrigin(ParentOrigin::TOP_LEFT);\r
- radioButton1.SetAnchorPoint(ParentOrigin::TOP_LEFT);\r
- radioButton1.SetPosition(0.0f, 0.0f);\r
-\r
- RadioButton radioButton2 = RadioButton::New("label");\r
- radioButton2.SetParentOrigin(ParentOrigin::TOP_LEFT);\r
- radioButton2.SetAnchorPoint(ParentOrigin::TOP_LEFT);\r
- radioButton2.SetPosition(0.0f, 40.0f);\r
-\r
- radioButton1.StateChangedSignal().Connect(this, &ButtonsController::EnableSelectButton);\r
-\r
- radioGroup.Add(radioButton1);\r
- radioGroup.Add(radioButton2);\r
- }\r
-\r
- Application& mApplication;\r
-}</pre>\r
+<p>Usually, radio buttons are grouped. Two or more radio buttons are in the same group when they have the same parent. In each group, only 1 radio button can be selected at a given time. You can use <span style="font-family: Courier New,Courier,monospace;">Button::StateChangedSignal()</span> signal to check which radio button is selected. A basic checkbox button example is as follows:</p>\r
+\r
+<pre class="prettyprint">\r
+// ... same to the push button example\r
+ void Create( Application& application )\r
+ {\r
+ Actor radioGroup = Actor::New();\r
+ radioGroup.SetParentOrigin( ParentOrigin::CENTER );\r
+ Stage::GetCurrent().Add(radioGroup);\r
+\r
+ RadioButton button1 = RadioButton::New();\r
+ button1.SetLabel( "button1" );\r
+ button1.SetBackgroundColor( Vector4(1,0,0,1) );\r
+ button1.SetPosition( 0, -40 );\r
+ radioGroup.Add( button1 );\r
+\r
+ RadioButton button2 = RadioButton::New();\r
+ button2.SetLabel( "button2" );\r
+ button2.SetBackgroundColor( Vector4(0,0,1,1) );\r
+ button2.SetPosition( 0, 40 );\r
+ radioGroup.Add( button2 );\r
+\r
+ button1.StateChangedSignal().Connect( this, &ButtonController::OnButtonStateChanged );\r
+ button2.StateChangedSignal().Connect( this, &ButtonController::OnButtonStateChanged );\r
+ }\r
+ bool OnButtonStateChanged( Toolkit::Button button )\r
+ {\r
+ cout << "OnButtonStateChanged " << button.GetLabel() << " " << button.IsSelected() << endl;\r
+ return true;\r
+ }\r
+// ... same to the push button example\r
+</pre>\r
\r
\r
<script type="text/javascript" src="../../scripts/jquery.zclip.min.js"></script>\r