diff --git a/build/tizen/examples/CMakeLists.txt b/build/tizen/examples/CMakeLists.txt index 26be5fd..9bb53a1 100644 --- a/build/tizen/examples/CMakeLists.txt +++ b/build/tizen/examples/CMakeLists.txt @@ -105,7 +105,7 @@ ADD_EXECUTABLE(logging.example ${LOGGING_SRCS}) TARGET_LINK_LIBRARIES(logging.example ${REQUIRED_PKGS_LDFLAGS}) INSTALL(TARGETS logging.example DESTINATION ${BINDIR}) -SET(TEXT_LABEL_SRCS ${EXAMPLES_SRC_DIR}/text/text-label-example.cpp) +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) ADD_EXECUTABLE(text-label.example ${TEXT_LABEL_SRCS}) TARGET_LINK_LIBRARIES(text-label.example ${REQUIRED_PKGS_LDFLAGS}) INSTALL(TARGETS text-label.example DESTINATION ${BINDIR}) diff --git a/examples/text/center-layout-impl.cpp b/examples/text/center-layout-impl.cpp new file mode 100644 index 0000000..e08db35 --- /dev/null +++ b/examples/text/center-layout-impl.cpp @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// CLASS HEADER +#include "center-layout-impl.h" + +// INTERNAL INCLUDES +#include "center-layout.h" + +namespace +{ + int ConvertToEven(int value) + { + return (value % 2 == 0) ? value : (value + 1); + } +} + +namespace Dali +{ + +namespace Toolkit +{ + +namespace Internal +{ + +Toolkit::CenterLayout CenterLayout::New() +{ + // Create the implementation, temporarily owned by this handle on stack + IntrusivePtr< CenterLayout > impl = new CenterLayout(); + + // Pass ownership to CustomActor handle + Toolkit::CenterLayout handle( *impl ); + + // Second-phase init of the implementation + // This can only be done after the CustomActor connection has been made... + impl->Initialize(); + + return handle; +} + +CenterLayout::CenterLayout() +: Control( ControlBehaviour( CONTROL_BEHAVIOUR_NONE ) ) +{ +} + +CenterLayout::~CenterLayout() +{ +} + +void CenterLayout::OnInitialize() +{ + CustomActor self = Self(); + + // Move background behind text label + Dali::Toolkit::Control::DownCast( self ).SetBackgroundColor( Vector4(0.1f,0.1f,0.1f,1.0f) ); + self.GetChildAt(0).SetZ(-1.0f); + + Stage stage = Stage::GetCurrent(); + Vector2 stageSize = stage.GetSize(); + + // Resize the center layout when the corner is grabbed + mGrabCorner = CreateSolidColorActor( Color::GREEN ); + mGrabCorner.SetAnchorPoint( AnchorPoint::BOTTOM_RIGHT ); + mGrabCorner.SetParentOrigin( ParentOrigin::BOTTOM_RIGHT ); + mGrabCorner.SetSize( stageSize.width*0.1f, stageSize.width*0.1f ); + mGrabCorner.SetZ(1.0f); + self.Add( mGrabCorner ); + + mPanGestureDetector = PanGestureDetector::New(); + mPanGestureDetector.Attach( mGrabCorner ); + mPanGestureDetector.DetectedSignal().Connect( this, &CenterLayout::OnPan ); +} + +void CenterLayout::OnRelayout( const Vector2& size, ActorSizeContainer& container ) +{ + CustomActor self = Self(); + + if( mLayoutSize.x <= 0.0f ) + { + mLayoutSize = size; + } + + for( unsigned int i=0; i(mLayoutSize.x)), + ConvertToEven(static_cast(mLayoutSize.y)) ); + + Self().SetSize( clampedSize ); + + RelayoutRequest(); +} + +} // namespace Internal + +} // namespace Toolkit + +} // namespace Dali diff --git a/examples/text/center-layout-impl.h b/examples/text/center-layout-impl.h new file mode 100644 index 0000000..850b9b8 --- /dev/null +++ b/examples/text/center-layout-impl.h @@ -0,0 +1,80 @@ +#ifndef __DALI_DEMO_CENTER_LAYOUT_IMPL_H__ +#define __DALI_DEMO_CENTER_LAYOUT_IMPL_H__ + +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// INTERNAL INCLUDES +#include "center-layout.h" + +namespace Dali +{ + +namespace Toolkit +{ + +namespace Internal +{ + +class CenterLayout : public Control +{ +public: + /** + * @copydoc Dali::Toollkit::TextLabel::New() + */ + static Toolkit::CenterLayout New(); + + CenterLayout(); + + virtual ~CenterLayout(); + + /** + * @copydoc Control::OnInitialize() + */ + virtual void OnInitialize(); + + // Size negotiation methods inherited from Internal::Control + + /** + * @copydoc Control::OnRelayout() + */ + virtual void OnRelayout( const Vector2& size, ActorSizeContainer& container ); + +private: + + void OnPan( Actor actor, const PanGesture& gesture ); + + // Undefined copy constructor and assignment operators + CenterLayout(const CenterLayout&); + CenterLayout& operator=(const CenterLayout& rhs); + +private: + + Vector3 mLayoutSize; + + Actor mGrabCorner; + + PanGestureDetector mPanGestureDetector; +}; + +} // namespace Internal + +} // namespace Toolkit + +} // namespace Dali + +#endif // __DALI_DEMO_CENTER_LAYOUT_IMPL_H__ diff --git a/examples/text/center-layout.cpp b/examples/text/center-layout.cpp new file mode 100644 index 0000000..e49be0e --- /dev/null +++ b/examples/text/center-layout.cpp @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// CLASS HEADER +#include "center-layout.h" + +// INTERNAL INCLUDES +#include "center-layout-impl.h" + +namespace Dali +{ + +namespace Toolkit +{ + +CenterLayout CenterLayout::New() +{ + return Internal::CenterLayout::New(); +} + +CenterLayout::CenterLayout() +{ +} + +CenterLayout::CenterLayout( const CenterLayout& handle ) +: Control( handle ) +{ +} + +CenterLayout& CenterLayout::operator=( const CenterLayout& handle ) +{ + if( &handle != this ) + { + Control::operator=( handle ); + } + return *this; +} + +CenterLayout CenterLayout::DownCast( BaseHandle handle ) +{ + return Control::DownCast( handle ); +} + +CenterLayout::~CenterLayout() +{ +} + +CenterLayout::CenterLayout( Internal::CenterLayout& internal ) +: Control( internal ) +{ +} + +CenterLayout::CenterLayout( Dali::Internal::CustomActor* internal ) +: Control( internal ) +{ +} + +Internal::CenterLayout& CenterLayout::GetImpl( CenterLayout& verticalLayout ) +{ + DALI_ASSERT_ALWAYS( verticalLayout ); + + Dali::RefObject& handle = verticalLayout.GetImplementation(); + + return static_cast(handle); +} + +} // namespace Toolkit + +} // namespace Dali diff --git a/examples/text/center-layout.h b/examples/text/center-layout.h new file mode 100644 index 0000000..2807fcc --- /dev/null +++ b/examples/text/center-layout.h @@ -0,0 +1,63 @@ +#ifndef __DALI_DEMO_CENTER_LAYOUT_H__ +#define __DALI_DEMO_CENTER_LAYOUT_H__ + +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// EXTERNAL INCLUDES +#include + +namespace Dali +{ + +namespace Toolkit +{ + +namespace Internal +{ +class CenterLayout; +} // namespace Internal + +class CenterLayout : public Toolkit::Control +{ +public: + static CenterLayout New(); + + CenterLayout(); + + CenterLayout( const CenterLayout& handle ); + + CenterLayout& operator=( const CenterLayout& handle ); + + ~CenterLayout(); + + CenterLayout( Internal::CenterLayout& internal ); + + explicit CenterLayout( Dali::Internal::CustomActor* internal ); + + CenterLayout DownCast( BaseHandle handle ); + + Internal::CenterLayout& GetImpl( CenterLayout& verticalLayout ); + +private: +}; + +} // namespace Toolkit + +} // namespace Dali + +#endif // __DALI_DEMO_CENTER_LAYOUT_H__ diff --git a/examples/text/text-label-example.cpp b/examples/text/text-label-example.cpp index a557927..7c18de1 100644 --- a/examples/text/text-label-example.cpp +++ b/examples/text/text-label-example.cpp @@ -24,6 +24,9 @@ #include #include +// INTERNAL INCLUDES +#include "center-layout.h" + using namespace Dali; using namespace Dali::Toolkit; @@ -53,14 +56,20 @@ public: { Stage stage = Stage::GetCurrent(); + stage.SetBackgroundColor( Color::BLUE ); stage.KeyEventSignal().Connect(this, &TextLabelExample::OnKeyEvent); + Vector2 stageSize = stage.GetSize(); + + CenterLayout centerLayout = CenterLayout::New(); + centerLayout.SetParentOrigin( ParentOrigin::CENTER ); + centerLayout.SetSize( stageSize.width*0.6f, stageSize.width*0.6f ); + stage.Add( centerLayout ); TextLabel label = TextLabel::New(); - label.SetParentOrigin( ParentOrigin::CENTER ); - stage.Add( label ); + label.SetBackgroundColor( Color::BLACK ); + centerLayout.Add( label ); label.SetProperty( TextLabel::PROPERTY_MULTI_LINE, true ); - label.SetProperty( TextLabel::PROPERTY_TEXT, "A Quick Brown Fox Jumps Over The Lazy Dog" ); // TODO