From ffd1f760ae0bc1b85f862cfab389305278774afb Mon Sep 17 00:00:00 2001 From: Paul Wisbey Date: Tue, 3 Mar 2015 18:41:55 +0000 Subject: [PATCH] Improved layout in text-field example Change-Id: If864584881cf663d5a6ddfdf940fc94c21c4a9bf --- build/tizen/examples/CMakeLists.txt | 2 +- examples/text/edit-layout-impl.cpp | 106 +++++++++++++++++++++++++++++++++++ examples/text/edit-layout-impl.h | 79 ++++++++++++++++++++++++++ examples/text/edit-layout.cpp | 88 +++++++++++++++++++++++++++++ examples/text/edit-layout.h | 65 +++++++++++++++++++++ examples/text/text-field-example.cpp | 21 ++++++- 6 files changed, 359 insertions(+), 2 deletions(-) create mode 100644 examples/text/edit-layout-impl.cpp create mode 100644 examples/text/edit-layout-impl.h create mode 100644 examples/text/edit-layout.cpp create mode 100644 examples/text/edit-layout.h diff --git a/build/tizen/examples/CMakeLists.txt b/build/tizen/examples/CMakeLists.txt index 9bb53a1..d05820d 100644 --- a/build/tizen/examples/CMakeLists.txt +++ b/build/tizen/examples/CMakeLists.txt @@ -115,7 +115,7 @@ ADD_EXECUTABLE(text-label-multi-language.example ${TEXT_LABEL_MULTI_LANGUAGE_SRC TARGET_LINK_LIBRARIES(text-label-multi-language.example ${REQUIRED_PKGS_LDFLAGS}) INSTALL(TARGETS text-label-multi-language.example DESTINATION ${BINDIR}) -SET(TEXT_FIELD_SRCS ${EXAMPLES_SRC_DIR}/text/text-field-example.cpp) +SET(TEXT_FIELD_SRCS ${EXAMPLES_SRC_DIR}/text/text-field-example.cpp ${EXAMPLES_SRC_DIR}/text/edit-layout.cpp ${EXAMPLES_SRC_DIR}/text/edit-layout-impl.cpp) ADD_EXECUTABLE(text-field.example ${TEXT_FIELD_SRCS}) TARGET_LINK_LIBRARIES(text-field.example ${REQUIRED_PKGS_LDFLAGS}) INSTALL(TARGETS text-field.example DESTINATION ${BINDIR}) diff --git a/examples/text/edit-layout-impl.cpp b/examples/text/edit-layout-impl.cpp new file mode 100644 index 0000000..16e8146 --- /dev/null +++ b/examples/text/edit-layout-impl.cpp @@ -0,0 +1,106 @@ +/* + * 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 "edit-layout-impl.h" + +// INTERNAL INCLUDES +#include "edit-layout.h" + +namespace +{ + +const float INNER_BORDER_TOP = 4.0f; +const float INNER_BORDER_LEFT = 20.0f; +const float INNER_BORDER_RIGHT = 20.0f; + +} + +namespace Dali +{ + +namespace Toolkit +{ + +namespace Internal +{ + +Toolkit::EditLayout EditLayout::New() +{ + // Create the implementation, temporarily owned by this handle on stack + IntrusivePtr< EditLayout > impl = new EditLayout(); + + // Pass ownership to CustomActor handle + Toolkit::EditLayout handle( *impl ); + + // Second-phase init of the implementation + // This can only be done after the CustomActor connection has been made... + impl->Initialize(); + + return handle; +} + +void EditLayout::SetTopPanel( Dali::Toolkit::Control panel ) +{ + mTopPanel = panel; + mTopPanel.SetParentOrigin( ParentOrigin::TOP_CENTER ); + mTopPanel.SetAnchorPoint( AnchorPoint::TOP_CENTER ); + mTopPanel.SetY( INNER_BORDER_TOP ); + + Self().Add( panel ); +} + +EditLayout::EditLayout() +: Control( ControlBehaviour( CONTROL_BEHAVIOUR_NONE ) ) +{ +} + +EditLayout::~EditLayout() +{ +} + +void EditLayout::OnInitialize() +{ + CustomActor self = Self(); + + // Move background behind text label + Dali::Toolkit::Control::DownCast( self ).SetBackgroundColor( Color::BLUE ); + self.GetChildAt(0).SetZ(-1.0f); +} + +void EditLayout::OnRelayout( const Vector2& size, ActorSizeContainer& container ) +{ + CustomActor self = Self(); + + if( self.GetChildCount() > 0 ) + { + if( mTopPanel ) + { + float panelWidth = size.width - INNER_BORDER_LEFT - INNER_BORDER_RIGHT; + + float height = mTopPanel.GetHeightForWidth( panelWidth ); + + container.push_back( ActorSizePair( mTopPanel, Vector2(panelWidth, height) ) ); + } + } +} + +} // namespace Internal + +} // namespace Toolkit + +} // namespace Dali diff --git a/examples/text/edit-layout-impl.h b/examples/text/edit-layout-impl.h new file mode 100644 index 0000000..a710de8 --- /dev/null +++ b/examples/text/edit-layout-impl.h @@ -0,0 +1,79 @@ +#ifndef __DALI_DEMO_EDIT_LAYOUT_IMPL_H__ +#define __DALI_DEMO_EDIT_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 "edit-layout.h" + +namespace Dali +{ + +namespace Toolkit +{ + +namespace Internal +{ + +class EditLayout : public Control +{ +public: + /** + * @copydoc Dali::Toollkit::TextLabel::New() + */ + static Toolkit::EditLayout New(); + + /** + * @copydoc Dali::Toolkit::EditLayout::SetTopPanel() + */ + void SetTopPanel( Dali::Toolkit::Control panel ); + + EditLayout(); + + virtual ~EditLayout(); + + /** + * @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: + + // Undefined copy constructor and assignment operators + EditLayout(const EditLayout&); + EditLayout& operator=(const EditLayout& rhs); + +private: + + Dali::Toolkit::Control mTopPanel; +}; + +} // namespace Internal + +} // namespace Toolkit + +} // namespace Dali + +#endif // __DALI_DEMO_EDIT_LAYOUT_IMPL_H__ diff --git a/examples/text/edit-layout.cpp b/examples/text/edit-layout.cpp new file mode 100644 index 0000000..81ab94b --- /dev/null +++ b/examples/text/edit-layout.cpp @@ -0,0 +1,88 @@ +/* + * 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 "edit-layout.h" + +// INTERNAL INCLUDES +#include "edit-layout-impl.h" + +namespace Dali +{ + +namespace Toolkit +{ + +EditLayout EditLayout::New() +{ + return Internal::EditLayout::New(); +} + +void EditLayout::SetTopPanel( Control panel ) +{ + GetImpl( *this ).SetTopPanel( panel ); +} + +EditLayout::EditLayout() +{ +} + +EditLayout::EditLayout( const EditLayout& handle ) +: Control( handle ) +{ +} + +EditLayout& EditLayout::operator=( const EditLayout& handle ) +{ + if( &handle != this ) + { + Control::operator=( handle ); + } + return *this; +} + +EditLayout EditLayout::DownCast( BaseHandle handle ) +{ + return Control::DownCast( handle ); +} + +EditLayout::~EditLayout() +{ +} + +EditLayout::EditLayout( Internal::EditLayout& internal ) +: Control( internal ) +{ +} + +EditLayout::EditLayout( Dali::Internal::CustomActor* internal ) +: Control( internal ) +{ +} + +Internal::EditLayout& EditLayout::GetImpl( EditLayout& verticalLayout ) +{ + DALI_ASSERT_ALWAYS( verticalLayout ); + + Dali::RefObject& handle = verticalLayout.GetImplementation(); + + return static_cast(handle); +} + +} // namespace Toolkit + +} // namespace Dali diff --git a/examples/text/edit-layout.h b/examples/text/edit-layout.h new file mode 100644 index 0000000..d8ef906 --- /dev/null +++ b/examples/text/edit-layout.h @@ -0,0 +1,65 @@ +#ifndef __DALI_DEMO_EDIT_LAYOUT_H__ +#define __DALI_DEMO_EDIT_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 EditLayout; +} // namespace Internal + +class EditLayout : public Toolkit::Control +{ +public: + static EditLayout New(); + + void SetTopPanel( Control panel ); + + EditLayout(); + + EditLayout( const EditLayout& handle ); + + EditLayout& operator=( const EditLayout& handle ); + + ~EditLayout(); + + EditLayout( Internal::EditLayout& internal ); + + explicit EditLayout( Dali::Internal::CustomActor* internal ); + + EditLayout DownCast( BaseHandle handle ); + + Internal::EditLayout& GetImpl( EditLayout& verticalLayout ); + +private: +}; + +} // namespace Toolkit + +} // namespace Dali + +#endif // __DALI_DEMO_EDIT_LAYOUT_H__ diff --git a/examples/text/text-field-example.cpp b/examples/text/text-field-example.cpp index 0c43d8a..a9ea8cb 100644 --- a/examples/text/text-field-example.cpp +++ b/examples/text/text-field-example.cpp @@ -24,9 +24,19 @@ #include #include +// INTERNAL INCLUDES +#include "edit-layout.h" + using namespace Dali; using namespace Dali::Toolkit; +namespace +{ + +const float BORDER_WIDTH = 4.0f; + +} // unnamed namespace + /** * @brief The main class of the demo. */ @@ -55,9 +65,18 @@ public: stage.KeyEventSignal().Connect(this, &TextFieldExample::OnKeyEvent); + Vector2 stageSize = stage.GetSize(); + + EditLayout layout = EditLayout::New(); + layout.SetParentOrigin( ParentOrigin::CENTER ); + layout.SetAnchorPoint( AnchorPoint::CENTER ); + layout.SetSize( stageSize.width - BORDER_WIDTH*2.0f, stageSize.height*0.2f ); + stage.Add( layout ); + TextField field = TextField::New(); field.SetParentOrigin( ParentOrigin::CENTER ); - stage.Add( field ); + field.SetBackgroundColor( Color::BLACK ); + layout.SetTopPanel( field ); field.SetProperty( TextField::PROPERTY_TEXT, "A Quick Brown Fox Jumps Over The Lazy Dog" ); -- 2.7.4