Commit 058b80f9e333611f3bb70517e18710c9c7eb3c75
1 parent
3054c598
Minor text demo tweaks
- Respond to back key
- Start multi-language text at the top
- Scroll to integer positions only
Change-Id: I7595e86ea31f6531683fb4589db009637222ab85
Showing
2 changed files
with
36 additions
and
6 deletions
examples/text/text-label-example.cpp
| @@ -53,6 +53,8 @@ public: | @@ -53,6 +53,8 @@ public: | ||
| 53 | { | 53 | { |
| 54 | Stage stage = Stage::GetCurrent(); | 54 | Stage stage = Stage::GetCurrent(); |
| 55 | 55 | ||
| 56 | + stage.KeyEventSignal().Connect(this, &TextLabelExample::OnKeyEvent); | ||
| 57 | + | ||
| 56 | TextLabel label = TextLabel::New(); | 58 | TextLabel label = TextLabel::New(); |
| 57 | label.SetParentOrigin( ParentOrigin::CENTER ); | 59 | label.SetParentOrigin( ParentOrigin::CENTER ); |
| 58 | stage.Add( label ); | 60 | stage.Add( label ); |
| @@ -66,6 +68,20 @@ public: | @@ -66,6 +68,20 @@ public: | ||
| 66 | //std::cout << "Got text from label: " << labelText.Get< std::string >() << std::endl; | 68 | //std::cout << "Got text from label: " << labelText.Get< std::string >() << std::endl; |
| 67 | } | 69 | } |
| 68 | 70 | ||
| 71 | + /** | ||
| 72 | + * Main key event handler | ||
| 73 | + */ | ||
| 74 | + void OnKeyEvent(const KeyEvent& event) | ||
| 75 | + { | ||
| 76 | + if(event.state == KeyEvent::Down) | ||
| 77 | + { | ||
| 78 | + if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) | ||
| 79 | + { | ||
| 80 | + mApplication.Quit(); | ||
| 81 | + } | ||
| 82 | + } | ||
| 83 | + } | ||
| 84 | + | ||
| 69 | private: | 85 | private: |
| 70 | 86 | ||
| 71 | Application& mApplication; | 87 | Application& mApplication; |
examples/text/text-label-multi-language-example.cpp
| @@ -227,8 +227,11 @@ public: | @@ -227,8 +227,11 @@ public: | ||
| 227 | { | 227 | { |
| 228 | Stage stage = Stage::GetCurrent(); | 228 | Stage stage = Stage::GetCurrent(); |
| 229 | 229 | ||
| 230 | + stage.KeyEventSignal().Connect(this, &TextLabelMultiLanguageExample::OnKeyEvent); | ||
| 231 | + | ||
| 230 | mLayout = VerticalLayout::New(); | 232 | mLayout = VerticalLayout::New(); |
| 231 | - mLayout.SetParentOrigin( ParentOrigin::CENTER ); | 233 | + mLayout.SetParentOrigin( ParentOrigin::TOP_LEFT ); |
| 234 | + mLayout.SetAnchorPoint( AnchorPoint::TOP_LEFT ); | ||
| 232 | 235 | ||
| 233 | stage.Add( mLayout ); | 236 | stage.Add( mLayout ); |
| 234 | 237 | ||
| @@ -259,17 +262,19 @@ public: | @@ -259,17 +262,19 @@ public: | ||
| 259 | if( 1u == event.GetPointCount() ) | 262 | if( 1u == event.GetPointCount() ) |
| 260 | { | 263 | { |
| 261 | const TouchPoint::State state = event.GetPoint(0u).state; | 264 | const TouchPoint::State state = event.GetPoint(0u).state; |
| 265 | + | ||
| 266 | + // Clamp to integer values; this is to reduce flicking due to pixel misalignment | ||
| 267 | + const float localPoint = static_cast<float>( static_cast<int>( event.GetPoint( 0 ).local.y ) ); | ||
| 268 | + | ||
| 262 | if( TouchPoint::Down == state ) | 269 | if( TouchPoint::Down == state ) |
| 263 | { | 270 | { |
| 264 | - mLastPoint = event.GetPoint( 0 ).local.y; | 271 | + mLastPoint = localPoint; |
| 265 | mAnimation = Animation::New( 0.25f ); | 272 | mAnimation = Animation::New( 0.25f ); |
| 266 | - mAnimation.FinishedSignal().Connect( this, &TextLabelMultiLanguageExample::AnimationCompleted ); | ||
| 267 | } | 273 | } |
| 268 | else if( TouchPoint::Motion == state ) | 274 | else if( TouchPoint::Motion == state ) |
| 269 | { | 275 | { |
| 270 | if( mAnimation ) | 276 | if( mAnimation ) |
| 271 | { | 277 | { |
| 272 | - const float localPoint = event.GetPoint( 0 ).local.y; | ||
| 273 | mAnimation.MoveBy( mLayout, Vector3( 0.f, localPoint - mLastPoint, 0.f ), AlphaFunctions::Linear ); | 278 | mAnimation.MoveBy( mLayout, Vector3( 0.f, localPoint - mLastPoint, 0.f ), AlphaFunctions::Linear ); |
| 274 | mAnimation.Play(); | 279 | mAnimation.Play(); |
| 275 | mLastPoint = localPoint; | 280 | mLastPoint = localPoint; |
| @@ -280,9 +285,18 @@ public: | @@ -280,9 +285,18 @@ public: | ||
| 280 | return true; | 285 | return true; |
| 281 | } | 286 | } |
| 282 | 287 | ||
| 283 | - void AnimationCompleted(Animation& source) | 288 | + /** |
| 289 | + * Main key event handler | ||
| 290 | + */ | ||
| 291 | + void OnKeyEvent(const KeyEvent& event) | ||
| 284 | { | 292 | { |
| 285 | - //mAnimation.Reset(); | 293 | + if(event.state == KeyEvent::Down) |
| 294 | + { | ||
| 295 | + if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) | ||
| 296 | + { | ||
| 297 | + mApplication.Quit(); | ||
| 298 | + } | ||
| 299 | + } | ||
| 286 | } | 300 | } |
| 287 | 301 | ||
| 288 | private: | 302 | private: |