Commit ffd1f760ae0bc1b85f862cfab389305278774afb

Authored by Paul Wisbey
1 parent d477c1bb

Improved layout in text-field example

Change-Id: If864584881cf663d5a6ddfdf940fc94c21c4a9bf
build/tizen/examples/CMakeLists.txt
@@ -115,7 +115,7 @@ ADD_EXECUTABLE(text-label-multi-language.example ${TEXT_LABEL_MULTI_LANGUAGE_SRC @@ -115,7 +115,7 @@ ADD_EXECUTABLE(text-label-multi-language.example ${TEXT_LABEL_MULTI_LANGUAGE_SRC
115 TARGET_LINK_LIBRARIES(text-label-multi-language.example ${REQUIRED_PKGS_LDFLAGS}) 115 TARGET_LINK_LIBRARIES(text-label-multi-language.example ${REQUIRED_PKGS_LDFLAGS})
116 INSTALL(TARGETS text-label-multi-language.example DESTINATION ${BINDIR}) 116 INSTALL(TARGETS text-label-multi-language.example DESTINATION ${BINDIR})
117 117
118 -SET(TEXT_FIELD_SRCS ${EXAMPLES_SRC_DIR}/text/text-field-example.cpp) 118 +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)
119 ADD_EXECUTABLE(text-field.example ${TEXT_FIELD_SRCS}) 119 ADD_EXECUTABLE(text-field.example ${TEXT_FIELD_SRCS})
120 TARGET_LINK_LIBRARIES(text-field.example ${REQUIRED_PKGS_LDFLAGS}) 120 TARGET_LINK_LIBRARIES(text-field.example ${REQUIRED_PKGS_LDFLAGS})
121 INSTALL(TARGETS text-field.example DESTINATION ${BINDIR}) 121 INSTALL(TARGETS text-field.example DESTINATION ${BINDIR})
examples/text/edit-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 "edit-layout-impl.h"
  20 +
  21 +// INTERNAL INCLUDES
  22 +#include "edit-layout.h"
  23 +
  24 +namespace
  25 +{
  26 +
  27 +const float INNER_BORDER_TOP = 4.0f;
  28 +const float INNER_BORDER_LEFT = 20.0f;
  29 +const float INNER_BORDER_RIGHT = 20.0f;
  30 +
  31 +}
  32 +
  33 +namespace Dali
  34 +{
  35 +
  36 +namespace Toolkit
  37 +{
  38 +
  39 +namespace Internal
  40 +{
  41 +
  42 +Toolkit::EditLayout EditLayout::New()
  43 +{
  44 + // Create the implementation, temporarily owned by this handle on stack
  45 + IntrusivePtr< EditLayout > impl = new EditLayout();
  46 +
  47 + // Pass ownership to CustomActor handle
  48 + Toolkit::EditLayout handle( *impl );
  49 +
  50 + // Second-phase init of the implementation
  51 + // This can only be done after the CustomActor connection has been made...
  52 + impl->Initialize();
  53 +
  54 + return handle;
  55 +}
  56 +
  57 +void EditLayout::SetTopPanel( Dali::Toolkit::Control panel )
  58 +{
  59 + mTopPanel = panel;
  60 + mTopPanel.SetParentOrigin( ParentOrigin::TOP_CENTER );
  61 + mTopPanel.SetAnchorPoint( AnchorPoint::TOP_CENTER );
  62 + mTopPanel.SetY( INNER_BORDER_TOP );
  63 +
  64 + Self().Add( panel );
  65 +}
  66 +
  67 +EditLayout::EditLayout()
  68 +: Control( ControlBehaviour( CONTROL_BEHAVIOUR_NONE ) )
  69 +{
  70 +}
  71 +
  72 +EditLayout::~EditLayout()
  73 +{
  74 +}
  75 +
  76 +void EditLayout::OnInitialize()
  77 +{
  78 + CustomActor self = Self();
  79 +
  80 + // Move background behind text label
  81 + Dali::Toolkit::Control::DownCast( self ).SetBackgroundColor( Color::BLUE );
  82 + self.GetChildAt(0).SetZ(-1.0f);
  83 +}
  84 +
  85 +void EditLayout::OnRelayout( const Vector2& size, ActorSizeContainer& container )
  86 +{
  87 + CustomActor self = Self();
  88 +
  89 + if( self.GetChildCount() > 0 )
  90 + {
  91 + if( mTopPanel )
  92 + {
  93 + float panelWidth = size.width - INNER_BORDER_LEFT - INNER_BORDER_RIGHT;
  94 +
  95 + float height = mTopPanel.GetHeightForWidth( panelWidth );
  96 +
  97 + container.push_back( ActorSizePair( mTopPanel, Vector2(panelWidth, height) ) );
  98 + }
  99 + }
  100 +}
  101 +
  102 +} // namespace Internal
  103 +
  104 +} // namespace Toolkit
  105 +
  106 +} // namespace Dali
examples/text/edit-layout-impl.h 0 → 100644
  1 +#ifndef __DALI_DEMO_EDIT_LAYOUT_IMPL_H__
  2 +#define __DALI_DEMO_EDIT_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 "edit-layout.h"
  23 +
  24 +namespace Dali
  25 +{
  26 +
  27 +namespace Toolkit
  28 +{
  29 +
  30 +namespace Internal
  31 +{
  32 +
  33 +class EditLayout : public Control
  34 +{
  35 +public:
  36 + /**
  37 + * @copydoc Dali::Toollkit::TextLabel::New()
  38 + */
  39 + static Toolkit::EditLayout New();
  40 +
  41 + /**
  42 + * @copydoc Dali::Toolkit::EditLayout::SetTopPanel()
  43 + */
  44 + void SetTopPanel( Dali::Toolkit::Control panel );
  45 +
  46 + EditLayout();
  47 +
  48 + virtual ~EditLayout();
  49 +
  50 + /**
  51 + * @copydoc Control::OnInitialize()
  52 + */
  53 + virtual void OnInitialize();
  54 +
  55 + // Size negotiation methods inherited from Internal::Control
  56 +
  57 + /**
  58 + * @copydoc Control::OnRelayout()
  59 + */
  60 + virtual void OnRelayout( const Vector2& size, ActorSizeContainer& container );
  61 +
  62 +private:
  63 +
  64 + // Undefined copy constructor and assignment operators
  65 + EditLayout(const EditLayout&);
  66 + EditLayout& operator=(const EditLayout& rhs);
  67 +
  68 +private:
  69 +
  70 + Dali::Toolkit::Control mTopPanel;
  71 +};
  72 +
  73 +} // namespace Internal
  74 +
  75 +} // namespace Toolkit
  76 +
  77 +} // namespace Dali
  78 +
  79 +#endif // __DALI_DEMO_EDIT_LAYOUT_IMPL_H__
examples/text/edit-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 "edit-layout.h"
  20 +
  21 +// INTERNAL INCLUDES
  22 +#include "edit-layout-impl.h"
  23 +
  24 +namespace Dali
  25 +{
  26 +
  27 +namespace Toolkit
  28 +{
  29 +
  30 +EditLayout EditLayout::New()
  31 +{
  32 + return Internal::EditLayout::New();
  33 +}
  34 +
  35 +void EditLayout::SetTopPanel( Control panel )
  36 +{
  37 + GetImpl( *this ).SetTopPanel( panel );
  38 +}
  39 +
  40 +EditLayout::EditLayout()
  41 +{
  42 +}
  43 +
  44 +EditLayout::EditLayout( const EditLayout& handle )
  45 +: Control( handle )
  46 +{
  47 +}
  48 +
  49 +EditLayout& EditLayout::operator=( const EditLayout& handle )
  50 +{
  51 + if( &handle != this )
  52 + {
  53 + Control::operator=( handle );
  54 + }
  55 + return *this;
  56 +}
  57 +
  58 +EditLayout EditLayout::DownCast( BaseHandle handle )
  59 +{
  60 + return Control::DownCast<EditLayout, Internal::EditLayout>( handle );
  61 +}
  62 +
  63 +EditLayout::~EditLayout()
  64 +{
  65 +}
  66 +
  67 +EditLayout::EditLayout( Internal::EditLayout& internal )
  68 +: Control( internal )
  69 +{
  70 +}
  71 +
  72 +EditLayout::EditLayout( Dali::Internal::CustomActor* internal )
  73 +: Control( internal )
  74 +{
  75 +}
  76 +
  77 +Internal::EditLayout& EditLayout::GetImpl( EditLayout& verticalLayout )
  78 +{
  79 + DALI_ASSERT_ALWAYS( verticalLayout );
  80 +
  81 + Dali::RefObject& handle = verticalLayout.GetImplementation();
  82 +
  83 + return static_cast<Internal::EditLayout&>(handle);
  84 +}
  85 +
  86 +} // namespace Toolkit
  87 +
  88 +} // namespace Dali
examples/text/edit-layout.h 0 → 100644
  1 +#ifndef __DALI_DEMO_EDIT_LAYOUT_H__
  2 +#define __DALI_DEMO_EDIT_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 EditLayout;
  33 +} // namespace Internal
  34 +
  35 +class EditLayout : public Toolkit::Control
  36 +{
  37 +public:
  38 + static EditLayout New();
  39 +
  40 + void SetTopPanel( Control panel );
  41 +
  42 + EditLayout();
  43 +
  44 + EditLayout( const EditLayout& handle );
  45 +
  46 + EditLayout& operator=( const EditLayout& handle );
  47 +
  48 + ~EditLayout();
  49 +
  50 + EditLayout( Internal::EditLayout& internal );
  51 +
  52 + explicit EditLayout( Dali::Internal::CustomActor* internal );
  53 +
  54 + EditLayout DownCast( BaseHandle handle );
  55 +
  56 + Internal::EditLayout& GetImpl( EditLayout& verticalLayout );
  57 +
  58 +private:
  59 +};
  60 +
  61 +} // namespace Toolkit
  62 +
  63 +} // namespace Dali
  64 +
  65 +#endif // __DALI_DEMO_EDIT_LAYOUT_H__
examples/text/text-field-example.cpp
@@ -24,9 +24,19 @@ @@ -24,9 +24,19 @@
24 #include <dali-toolkit/dali-toolkit.h> 24 #include <dali-toolkit/dali-toolkit.h>
25 #include <dali/public-api/text-abstraction/text-abstraction.h> 25 #include <dali/public-api/text-abstraction/text-abstraction.h>
26 26
  27 +// INTERNAL INCLUDES
  28 +#include "edit-layout.h"
  29 +
27 using namespace Dali; 30 using namespace Dali;
28 using namespace Dali::Toolkit; 31 using namespace Dali::Toolkit;
29 32
  33 +namespace
  34 +{
  35 +
  36 +const float BORDER_WIDTH = 4.0f;
  37 +
  38 +} // unnamed namespace
  39 +
30 /** 40 /**
31 * @brief The main class of the demo. 41 * @brief The main class of the demo.
32 */ 42 */
@@ -55,9 +65,18 @@ public: @@ -55,9 +65,18 @@ public:
55 65
56 stage.KeyEventSignal().Connect(this, &TextFieldExample::OnKeyEvent); 66 stage.KeyEventSignal().Connect(this, &TextFieldExample::OnKeyEvent);
57 67
  68 + Vector2 stageSize = stage.GetSize();
  69 +
  70 + EditLayout layout = EditLayout::New();
  71 + layout.SetParentOrigin( ParentOrigin::CENTER );
  72 + layout.SetAnchorPoint( AnchorPoint::CENTER );
  73 + layout.SetSize( stageSize.width - BORDER_WIDTH*2.0f, stageSize.height*0.2f );
  74 + stage.Add( layout );
  75 +
58 TextField field = TextField::New(); 76 TextField field = TextField::New();
59 field.SetParentOrigin( ParentOrigin::CENTER ); 77 field.SetParentOrigin( ParentOrigin::CENTER );
60 - stage.Add( field ); 78 + field.SetBackgroundColor( Color::BLACK );
  79 + layout.SetTopPanel( field );
61 80
62 field.SetProperty( TextField::PROPERTY_TEXT, "A Quick Brown Fox Jumps Over The Lazy Dog" ); 81 field.SetProperty( TextField::PROPERTY_TEXT, "A Quick Brown Fox Jumps Over The Lazy Dog" );
63 82