Commit d477c1bbaa4a4eed3986e98d398d3930407ffa67
1 parent
c9b498ac
Tweaks to label example
Change-Id: Ifd9ab356030fc8235e6518b7bfb059697444d14b
Showing
6 changed files
with
371 additions
and
4 deletions
build/tizen/examples/CMakeLists.txt
| ... | ... | @@ -105,7 +105,7 @@ ADD_EXECUTABLE(logging.example ${LOGGING_SRCS}) |
| 105 | 105 | TARGET_LINK_LIBRARIES(logging.example ${REQUIRED_PKGS_LDFLAGS}) |
| 106 | 106 | INSTALL(TARGETS logging.example DESTINATION ${BINDIR}) |
| 107 | 107 | |
| 108 | -SET(TEXT_LABEL_SRCS ${EXAMPLES_SRC_DIR}/text/text-label-example.cpp) | |
| 108 | +SET(TEXT_LABEL_SRCS ${EXAMPLES_SRC_DIR}/text/text-label-example.cpp ${EXAMPLES_SRC_DIR}/text/center-layout.cpp ${EXAMPLES_SRC_DIR}/text/center-layout-impl.cpp) | |
| 109 | 109 | ADD_EXECUTABLE(text-label.example ${TEXT_LABEL_SRCS}) |
| 110 | 110 | TARGET_LINK_LIBRARIES(text-label.example ${REQUIRED_PKGS_LDFLAGS}) |
| 111 | 111 | INSTALL(TARGETS text-label.example DESTINATION ${BINDIR}) | ... | ... |
examples/text/center-layout-impl.cpp
0 → 100644
| 1 | +/* | |
| 2 | + * Copyright (c) 2015 Samsung Electronics Co., Ltd. | |
| 3 | + * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | + * you may not use this file except in compliance with the License. | |
| 6 | + * You may obtain a copy of the License at | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | + * See the License for the specific language governing permissions and | |
| 14 | + * limitations under the License. | |
| 15 | + * | |
| 16 | + */ | |
| 17 | + | |
| 18 | +// CLASS HEADER | |
| 19 | +#include "center-layout-impl.h" | |
| 20 | + | |
| 21 | +// INTERNAL INCLUDES | |
| 22 | +#include "center-layout.h" | |
| 23 | + | |
| 24 | +namespace | |
| 25 | +{ | |
| 26 | + int ConvertToEven(int value) | |
| 27 | + { | |
| 28 | + return (value % 2 == 0) ? value : (value + 1); | |
| 29 | + } | |
| 30 | +} | |
| 31 | + | |
| 32 | +namespace Dali | |
| 33 | +{ | |
| 34 | + | |
| 35 | +namespace Toolkit | |
| 36 | +{ | |
| 37 | + | |
| 38 | +namespace Internal | |
| 39 | +{ | |
| 40 | + | |
| 41 | +Toolkit::CenterLayout CenterLayout::New() | |
| 42 | +{ | |
| 43 | + // Create the implementation, temporarily owned by this handle on stack | |
| 44 | + IntrusivePtr< CenterLayout > impl = new CenterLayout(); | |
| 45 | + | |
| 46 | + // Pass ownership to CustomActor handle | |
| 47 | + Toolkit::CenterLayout handle( *impl ); | |
| 48 | + | |
| 49 | + // Second-phase init of the implementation | |
| 50 | + // This can only be done after the CustomActor connection has been made... | |
| 51 | + impl->Initialize(); | |
| 52 | + | |
| 53 | + return handle; | |
| 54 | +} | |
| 55 | + | |
| 56 | +CenterLayout::CenterLayout() | |
| 57 | +: Control( ControlBehaviour( CONTROL_BEHAVIOUR_NONE ) ) | |
| 58 | +{ | |
| 59 | +} | |
| 60 | + | |
| 61 | +CenterLayout::~CenterLayout() | |
| 62 | +{ | |
| 63 | +} | |
| 64 | + | |
| 65 | +void CenterLayout::OnInitialize() | |
| 66 | +{ | |
| 67 | + CustomActor self = Self(); | |
| 68 | + | |
| 69 | + // Move background behind text label | |
| 70 | + Dali::Toolkit::Control::DownCast( self ).SetBackgroundColor( Vector4(0.1f,0.1f,0.1f,1.0f) ); | |
| 71 | + self.GetChildAt(0).SetZ(-1.0f); | |
| 72 | + | |
| 73 | + Stage stage = Stage::GetCurrent(); | |
| 74 | + Vector2 stageSize = stage.GetSize(); | |
| 75 | + | |
| 76 | + // Resize the center layout when the corner is grabbed | |
| 77 | + mGrabCorner = CreateSolidColorActor( Color::GREEN ); | |
| 78 | + mGrabCorner.SetAnchorPoint( AnchorPoint::BOTTOM_RIGHT ); | |
| 79 | + mGrabCorner.SetParentOrigin( ParentOrigin::BOTTOM_RIGHT ); | |
| 80 | + mGrabCorner.SetSize( stageSize.width*0.1f, stageSize.width*0.1f ); | |
| 81 | + mGrabCorner.SetZ(1.0f); | |
| 82 | + self.Add( mGrabCorner ); | |
| 83 | + | |
| 84 | + mPanGestureDetector = PanGestureDetector::New(); | |
| 85 | + mPanGestureDetector.Attach( mGrabCorner ); | |
| 86 | + mPanGestureDetector.DetectedSignal().Connect( this, &CenterLayout::OnPan ); | |
| 87 | +} | |
| 88 | + | |
| 89 | +void CenterLayout::OnRelayout( const Vector2& size, ActorSizeContainer& container ) | |
| 90 | +{ | |
| 91 | + CustomActor self = Self(); | |
| 92 | + | |
| 93 | + if( mLayoutSize.x <= 0.0f ) | |
| 94 | + { | |
| 95 | + mLayoutSize = size; | |
| 96 | + } | |
| 97 | + | |
| 98 | + for( unsigned int i=0; i<self.GetChildCount(); ++i ) | |
| 99 | + { | |
| 100 | + Dali::Toolkit::Control child = Dali::Toolkit::Control::DownCast( self.GetChildAt(i) ); | |
| 101 | + | |
| 102 | + if( child ) | |
| 103 | + { | |
| 104 | + child.SetParentOrigin( ParentOrigin::TOP_CENTER ); | |
| 105 | + child.SetAnchorPoint( AnchorPoint::TOP_CENTER ); | |
| 106 | + | |
| 107 | + float height = child.GetHeightForWidth( size.width ); | |
| 108 | + | |
| 109 | + container.push_back( ActorSizePair( child, Vector2( size.width, std::min(height, size.height) ) ) ); | |
| 110 | + } | |
| 111 | + } | |
| 112 | +} | |
| 113 | + | |
| 114 | +void CenterLayout::OnPan( Actor actor, const PanGesture& gesture ) | |
| 115 | +{ | |
| 116 | + mLayoutSize.x += gesture.displacement.x * 2.0f; | |
| 117 | + mLayoutSize.y += gesture.displacement.y * 2.0f; | |
| 118 | + | |
| 119 | + // Avoid pixel mis-alignment issue | |
| 120 | + Vector2 clampedSize = Vector2( ConvertToEven(static_cast<int>(mLayoutSize.x)), | |
| 121 | + ConvertToEven(static_cast<int>(mLayoutSize.y)) ); | |
| 122 | + | |
| 123 | + Self().SetSize( clampedSize ); | |
| 124 | + | |
| 125 | + RelayoutRequest(); | |
| 126 | +} | |
| 127 | + | |
| 128 | +} // namespace Internal | |
| 129 | + | |
| 130 | +} // namespace Toolkit | |
| 131 | + | |
| 132 | +} // namespace Dali | ... | ... |
examples/text/center-layout-impl.h
0 → 100644
| 1 | +#ifndef __DALI_DEMO_CENTER_LAYOUT_IMPL_H__ | |
| 2 | +#define __DALI_DEMO_CENTER_LAYOUT_IMPL_H__ | |
| 3 | + | |
| 4 | +/* | |
| 5 | + * Copyright (c) 2015 Samsung Electronics Co., Ltd. | |
| 6 | + * | |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 8 | + * you may not use this file except in compliance with the License. | |
| 9 | + * You may obtain a copy of the License at | |
| 10 | + * | |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 12 | + * | |
| 13 | + * Unless required by applicable law or agreed to in writing, software | |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 16 | + * See the License for the specific language governing permissions and | |
| 17 | + * limitations under the License. | |
| 18 | + * | |
| 19 | + */ | |
| 20 | + | |
| 21 | +// INTERNAL INCLUDES | |
| 22 | +#include "center-layout.h" | |
| 23 | + | |
| 24 | +namespace Dali | |
| 25 | +{ | |
| 26 | + | |
| 27 | +namespace Toolkit | |
| 28 | +{ | |
| 29 | + | |
| 30 | +namespace Internal | |
| 31 | +{ | |
| 32 | + | |
| 33 | +class CenterLayout : public Control | |
| 34 | +{ | |
| 35 | +public: | |
| 36 | + /** | |
| 37 | + * @copydoc Dali::Toollkit::TextLabel::New() | |
| 38 | + */ | |
| 39 | + static Toolkit::CenterLayout New(); | |
| 40 | + | |
| 41 | + CenterLayout(); | |
| 42 | + | |
| 43 | + virtual ~CenterLayout(); | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * @copydoc Control::OnInitialize() | |
| 47 | + */ | |
| 48 | + virtual void OnInitialize(); | |
| 49 | + | |
| 50 | + // Size negotiation methods inherited from Internal::Control | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * @copydoc Control::OnRelayout() | |
| 54 | + */ | |
| 55 | + virtual void OnRelayout( const Vector2& size, ActorSizeContainer& container ); | |
| 56 | + | |
| 57 | +private: | |
| 58 | + | |
| 59 | + void OnPan( Actor actor, const PanGesture& gesture ); | |
| 60 | + | |
| 61 | + // Undefined copy constructor and assignment operators | |
| 62 | + CenterLayout(const CenterLayout&); | |
| 63 | + CenterLayout& operator=(const CenterLayout& rhs); | |
| 64 | + | |
| 65 | +private: | |
| 66 | + | |
| 67 | + Vector3 mLayoutSize; | |
| 68 | + | |
| 69 | + Actor mGrabCorner; | |
| 70 | + | |
| 71 | + PanGestureDetector mPanGestureDetector; | |
| 72 | +}; | |
| 73 | + | |
| 74 | +} // namespace Internal | |
| 75 | + | |
| 76 | +} // namespace Toolkit | |
| 77 | + | |
| 78 | +} // namespace Dali | |
| 79 | + | |
| 80 | +#endif // __DALI_DEMO_CENTER_LAYOUT_IMPL_H__ | ... | ... |
examples/text/center-layout.cpp
0 → 100644
| 1 | +/* | |
| 2 | + * Copyright (c) 2015 Samsung Electronics Co., Ltd. | |
| 3 | + * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | + * you may not use this file except in compliance with the License. | |
| 6 | + * You may obtain a copy of the License at | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | + * See the License for the specific language governing permissions and | |
| 14 | + * limitations under the License. | |
| 15 | + * | |
| 16 | + */ | |
| 17 | + | |
| 18 | +// CLASS HEADER | |
| 19 | +#include "center-layout.h" | |
| 20 | + | |
| 21 | +// INTERNAL INCLUDES | |
| 22 | +#include "center-layout-impl.h" | |
| 23 | + | |
| 24 | +namespace Dali | |
| 25 | +{ | |
| 26 | + | |
| 27 | +namespace Toolkit | |
| 28 | +{ | |
| 29 | + | |
| 30 | +CenterLayout CenterLayout::New() | |
| 31 | +{ | |
| 32 | + return Internal::CenterLayout::New(); | |
| 33 | +} | |
| 34 | + | |
| 35 | +CenterLayout::CenterLayout() | |
| 36 | +{ | |
| 37 | +} | |
| 38 | + | |
| 39 | +CenterLayout::CenterLayout( const CenterLayout& handle ) | |
| 40 | +: Control( handle ) | |
| 41 | +{ | |
| 42 | +} | |
| 43 | + | |
| 44 | +CenterLayout& CenterLayout::operator=( const CenterLayout& handle ) | |
| 45 | +{ | |
| 46 | + if( &handle != this ) | |
| 47 | + { | |
| 48 | + Control::operator=( handle ); | |
| 49 | + } | |
| 50 | + return *this; | |
| 51 | +} | |
| 52 | + | |
| 53 | +CenterLayout CenterLayout::DownCast( BaseHandle handle ) | |
| 54 | +{ | |
| 55 | + return Control::DownCast<CenterLayout, Internal::CenterLayout>( handle ); | |
| 56 | +} | |
| 57 | + | |
| 58 | +CenterLayout::~CenterLayout() | |
| 59 | +{ | |
| 60 | +} | |
| 61 | + | |
| 62 | +CenterLayout::CenterLayout( Internal::CenterLayout& internal ) | |
| 63 | +: Control( internal ) | |
| 64 | +{ | |
| 65 | +} | |
| 66 | + | |
| 67 | +CenterLayout::CenterLayout( Dali::Internal::CustomActor* internal ) | |
| 68 | +: Control( internal ) | |
| 69 | +{ | |
| 70 | +} | |
| 71 | + | |
| 72 | +Internal::CenterLayout& CenterLayout::GetImpl( CenterLayout& verticalLayout ) | |
| 73 | +{ | |
| 74 | + DALI_ASSERT_ALWAYS( verticalLayout ); | |
| 75 | + | |
| 76 | + Dali::RefObject& handle = verticalLayout.GetImplementation(); | |
| 77 | + | |
| 78 | + return static_cast<Internal::CenterLayout&>(handle); | |
| 79 | +} | |
| 80 | + | |
| 81 | +} // namespace Toolkit | |
| 82 | + | |
| 83 | +} // namespace Dali | ... | ... |
examples/text/center-layout.h
0 → 100644
| 1 | +#ifndef __DALI_DEMO_CENTER_LAYOUT_H__ | |
| 2 | +#define __DALI_DEMO_CENTER_LAYOUT_H__ | |
| 3 | + | |
| 4 | +/* | |
| 5 | + * Copyright (c) 2015 Samsung Electronics Co., Ltd. | |
| 6 | + * | |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 8 | + * you may not use this file except in compliance with the License. | |
| 9 | + * You may obtain a copy of the License at | |
| 10 | + * | |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 12 | + * | |
| 13 | + * Unless required by applicable law or agreed to in writing, software | |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 16 | + * See the License for the specific language governing permissions and | |
| 17 | + * limitations under the License. | |
| 18 | + * | |
| 19 | + */ | |
| 20 | + | |
| 21 | +// EXTERNAL INCLUDES | |
| 22 | +#include <dali-toolkit/dali-toolkit.h> | |
| 23 | + | |
| 24 | +namespace Dali | |
| 25 | +{ | |
| 26 | + | |
| 27 | +namespace Toolkit | |
| 28 | +{ | |
| 29 | + | |
| 30 | +namespace Internal | |
| 31 | +{ | |
| 32 | +class CenterLayout; | |
| 33 | +} // namespace Internal | |
| 34 | + | |
| 35 | +class CenterLayout : public Toolkit::Control | |
| 36 | +{ | |
| 37 | +public: | |
| 38 | + static CenterLayout New(); | |
| 39 | + | |
| 40 | + CenterLayout(); | |
| 41 | + | |
| 42 | + CenterLayout( const CenterLayout& handle ); | |
| 43 | + | |
| 44 | + CenterLayout& operator=( const CenterLayout& handle ); | |
| 45 | + | |
| 46 | + ~CenterLayout(); | |
| 47 | + | |
| 48 | + CenterLayout( Internal::CenterLayout& internal ); | |
| 49 | + | |
| 50 | + explicit CenterLayout( Dali::Internal::CustomActor* internal ); | |
| 51 | + | |
| 52 | + CenterLayout DownCast( BaseHandle handle ); | |
| 53 | + | |
| 54 | + Internal::CenterLayout& GetImpl( CenterLayout& verticalLayout ); | |
| 55 | + | |
| 56 | +private: | |
| 57 | +}; | |
| 58 | + | |
| 59 | +} // namespace Toolkit | |
| 60 | + | |
| 61 | +} // namespace Dali | |
| 62 | + | |
| 63 | +#endif // __DALI_DEMO_CENTER_LAYOUT_H__ | ... | ... |
examples/text/text-label-example.cpp
| ... | ... | @@ -24,6 +24,9 @@ |
| 24 | 24 | #include <dali-toolkit/dali-toolkit.h> |
| 25 | 25 | #include <dali/public-api/text-abstraction/text-abstraction.h> |
| 26 | 26 | |
| 27 | +// INTERNAL INCLUDES | |
| 28 | +#include "center-layout.h" | |
| 29 | + | |
| 27 | 30 | using namespace Dali; |
| 28 | 31 | using namespace Dali::Toolkit; |
| 29 | 32 | |
| ... | ... | @@ -53,14 +56,20 @@ public: |
| 53 | 56 | { |
| 54 | 57 | Stage stage = Stage::GetCurrent(); |
| 55 | 58 | |
| 59 | + stage.SetBackgroundColor( Color::BLUE ); | |
| 56 | 60 | stage.KeyEventSignal().Connect(this, &TextLabelExample::OnKeyEvent); |
| 61 | + Vector2 stageSize = stage.GetSize(); | |
| 62 | + | |
| 63 | + CenterLayout centerLayout = CenterLayout::New(); | |
| 64 | + centerLayout.SetParentOrigin( ParentOrigin::CENTER ); | |
| 65 | + centerLayout.SetSize( stageSize.width*0.6f, stageSize.width*0.6f ); | |
| 66 | + stage.Add( centerLayout ); | |
| 57 | 67 | |
| 58 | 68 | TextLabel label = TextLabel::New(); |
| 59 | - label.SetParentOrigin( ParentOrigin::CENTER ); | |
| 60 | - stage.Add( label ); | |
| 69 | + label.SetBackgroundColor( Color::BLACK ); | |
| 70 | + centerLayout.Add( label ); | |
| 61 | 71 | |
| 62 | 72 | label.SetProperty( TextLabel::PROPERTY_MULTI_LINE, true ); |
| 63 | - | |
| 64 | 73 | label.SetProperty( TextLabel::PROPERTY_TEXT, "A Quick Brown Fox Jumps Over The Lazy Dog" ); |
| 65 | 74 | |
| 66 | 75 | // TODO | ... | ... |