-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.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://floralicense.org/license/
-//
-// 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.
-//
+/*
+ * Copyright (c) 2014 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.
+ *
+ */
#include <dali-toolkit/internal/controls/scroll-bar/scroll-bar-impl.h>
#include <dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.h>
{
const char* DEFAULT_INDICATOR_IMAGE_PATH = DALI_IMAGE_DIR "popup_scroll.png";
-const Vector4 DEFAULT_INDICATOR_NINE_PATCH_BORDER(0.0f, 12.0f, 14.0f, 14.0f);
+const Vector4 DEFAULT_INDICATOR_NINE_PATCH_BORDER(4.0f, 9.0f, 7.0f, 11.0f);
+const float MINIMUM_INDICATOR_HEIGHT(20.0f); // The minimum indicator height for the nine patch border
const float DEFAULT_SLIDER_DEPTH(1.0f);
const float INDICATOR_SHOW_TIME(0.5f);
const float INDICATOR_HIDE_TIME(0.5f);
const float DEFAULT_PAN_GESTURE_PROCESS_TIME(16.7f); // 16.7 milliseconds, i.e. one frame
+const float DEFAULT_INDICATOR_FIXED_HEIGHT(80.0f);
/**
* Indicator size constraint
{
const Vector3& parentSize = parentSizeProperty.GetVector3();
float height = mContentSize > parentSize.height ? parentSize.height * ( parentSize.height / mContentSize ) : parentSize.height * ( (parentSize.height - mContentSize * 0.5f) / parentSize.height);
- return Vector3( parentSize.width, height, parentSize.depth );
+ return Vector3( parentSize.width, std::max(MINIMUM_INDICATOR_HEIGHT, height), parentSize.depth );
}
float mContentSize; ///< The size of scrollable content
namespace Toolkit
{
+const Property::Index ScrollBar::PROPERTY_INDICATOR_HEIGHT_POLICY( Internal::ScrollBar::SCROLLBAR_PROPERTY_START_INDEX );
+const Property::Index ScrollBar::PROPERTY_INDICATOR_FIXED_HEIGHT( Internal::ScrollBar::SCROLLBAR_PROPERTY_START_INDEX + 1 );
+
namespace Internal
{
using namespace Dali;
+const char* INDICATOR_HEIGHT_POLICY_NAME[] = {"Variable", "Fixed"};
+
BaseHandle Create()
{
- return BaseHandle();
+ return Toolkit::ScrollBar::New();
}
-TypeRegistration mType( typeid(Toolkit::ScrollBar), typeid(Toolkit::Control), Create );
+TypeRegistration typeRegistration( typeid(Toolkit::ScrollBar), typeid(Toolkit::ScrollComponent), Create );
+PropertyRegistration property1( typeRegistration, "indicator-height-policy", Toolkit::ScrollBar::PROPERTY_INDICATOR_HEIGHT_POLICY, Property::STRING, &ScrollBar::SetProperty, &ScrollBar::GetProperty );
+PropertyRegistration property2( typeRegistration, "indicator-fixed-height", Toolkit::ScrollBar::PROPERTY_INDICATOR_FIXED_HEIGHT, Property::FLOAT, &ScrollBar::SetProperty, &ScrollBar::GetProperty );
}
ScrollBar::ScrollBar()
: mScrollStart(0.0f),
mIsPanning(false),
- mCurrentScrollPosition(0.0f)
+ mCurrentScrollPosition(0.0f),
+ mIndicatorHeightPolicy(Toolkit::ScrollBar::Variable),
+ mIndicatorFixedHeight(DEFAULT_INDICATOR_FIXED_HEIGHT)
{
}
{
mBackground.SetImage(image);
}
-
mBackground.SetNinePatchBorder( border );
mBackground.SetStyle( ImageActor::STYLE_NINE_PATCH );
}
+void ScrollBar::SetIndicatorImage( Image image )
+{
+ mIndicator.SetImage(image);
+}
+
void ScrollBar::SetIndicatorImage( Image image, const Vector4& border )
{
mIndicator.SetImage(image);
void ScrollBar::ApplyConstraints()
{
- mIndicator.RemoveConstraints();
+ if( mScrollConnector )
+ {
+ Constraint constraint;
- Constraint constraint = Constraint::New<Vector3>( Actor::SIZE,
- ParentSource( Actor::SIZE ),
- IndicatorSizeConstraint( mScrollConnector.GetContentLength() ) );
- mIndicator.ApplyConstraint( constraint );
+ if(mIndicatorSizeConstraint)
+ {
+ mIndicator.RemoveConstraint(mIndicatorSizeConstraint);
+ }
- constraint = Constraint::New<Vector3>( Actor::POSITION,
- LocalSource( Actor::SIZE ),
- ParentSource( Actor::SIZE ),
- Source( mScrollPositionObject, Toolkit::ScrollConnector::SCROLL_POSITION ),
- IndicatorPositionConstraint( mScrollConnector.GetMinLimit(), mScrollConnector.GetMaxLimit() ) );
- mIndicator.ApplyConstraint( constraint );
+ // Set indicator height according to the indicator's height policy
+ if(mIndicatorHeightPolicy == Toolkit::ScrollBar::Fixed)
+ {
+ mIndicator.SetSize(Self().GetCurrentSize().width, mIndicatorFixedHeight);
+ }
+ else
+ {
+ constraint = Constraint::New<Vector3>( Actor::SIZE,
+ ParentSource( Actor::SIZE ),
+ IndicatorSizeConstraint( mScrollConnector.GetContentLength() ) );
+ mIndicatorSizeConstraint = mIndicator.ApplyConstraint( constraint );
+ }
- if( mBackground )
- {
- mBackground.RemoveConstraints();
+ if(mIndicatorPositionConstraint)
+ {
+ mIndicator.RemoveConstraint(mIndicatorPositionConstraint);
+ }
- constraint = Constraint::New<Vector3>(Actor::SIZE,
- ParentSource(Actor::SIZE),
- EqualToConstraint());
- mBackground.ApplyConstraint(constraint);
+ constraint = Constraint::New<Vector3>( Actor::POSITION,
+ LocalSource( Actor::SIZE ),
+ ParentSource( Actor::SIZE ),
+ Source( mScrollPositionObject, Toolkit::ScrollConnector::SCROLL_POSITION ),
+ IndicatorPositionConstraint( mScrollConnector.GetMinLimit(), mScrollConnector.GetMaxLimit() ) );
+ mIndicatorPositionConstraint = mIndicator.ApplyConstraint( constraint );
+
+ if( mBackground )
+ {
+ mBackground.RemoveConstraints();
+
+ constraint = Constraint::New<Vector3>(Actor::SIZE,
+ ParentSource(Actor::SIZE),
+ EqualToConstraint());
+ mBackground.ApplyConstraint(constraint);
+ }
}
}
ApplyConstraints();
}
+void ScrollBar::SetIndicatorHeightPolicy( Toolkit::ScrollBar::IndicatorHeightPolicy policy )
+{
+ mIndicatorHeightPolicy = policy;
+ ApplyConstraints();
+}
+
+Toolkit::ScrollBar::IndicatorHeightPolicy ScrollBar::GetIndicatorHeightPolicy()
+{
+ return mIndicatorHeightPolicy;
+}
+
+void ScrollBar::SetIndicatorFixedHeight( float height )
+{
+ mIndicatorFixedHeight = height;
+ ApplyConstraints();
+}
+
+float ScrollBar::GetIndicatorFixedHeight()
+{
+ return mIndicatorFixedHeight;
+}
+
+void ScrollBar::OnIndicatorHeightPolicyPropertySet( Property::Value propertyValue )
+{
+ std::string policyName( propertyValue.Get<std::string>() );
+ if(policyName == "Variable")
+ {
+ SetIndicatorHeightPolicy(Toolkit::ScrollBar::Variable);
+ }
+ else if(policyName == "Fixed")
+ {
+ SetIndicatorHeightPolicy(Toolkit::ScrollBar::Fixed);
+ }
+ else
+ {
+ DALI_ASSERT_ALWAYS( !"ScrollBar::OnIndicatorHeightPolicyPropertySet(). Invalid Property value." );
+ }
+}
+
+void ScrollBar::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
+{
+ Toolkit::ScrollBar scrollBar = Toolkit::ScrollBar::DownCast( Dali::BaseHandle( object ) );
+
+ if( scrollBar )
+ {
+ ScrollBar& scrollBarImpl( GetImpl( scrollBar ) );
+ switch( index )
+ {
+ case Toolkit::ScrollBar::PROPERTY_INDICATOR_HEIGHT_POLICY:
+ {
+ scrollBarImpl.OnIndicatorHeightPolicyPropertySet( value );
+ break;
+ }
+ case Toolkit::ScrollBar::PROPERTY_INDICATOR_FIXED_HEIGHT:
+ {
+ scrollBarImpl.SetIndicatorFixedHeight(value.Get<float>());
+ break;
+ }
+ }
+ }
+}
+
+Property::Value ScrollBar::GetProperty( BaseObject* object, Property::Index index )
+{
+ Property::Value value;
+
+ Toolkit::ScrollBar scrollBar = Toolkit::ScrollBar::DownCast( Dali::BaseHandle( object ) );
+
+ if( scrollBar )
+ {
+ ScrollBar& scrollBarImpl( GetImpl( scrollBar ) );
+ switch( index )
+ {
+ case Toolkit::ScrollBar::PROPERTY_INDICATOR_HEIGHT_POLICY:
+ {
+ value = INDICATOR_HEIGHT_POLICY_NAME[ scrollBarImpl.GetIndicatorHeightPolicy() ];
+ break;
+ }
+ case Toolkit::ScrollBar::PROPERTY_INDICATOR_FIXED_HEIGHT:
+ {
+ value = scrollBarImpl.GetIndicatorFixedHeight();
+ break;
+ }
+ }
+ }
+ return value;
+}
+
Toolkit::ScrollBar ScrollBar::New()
{
// Create the implementation, temporarily owned by this handle on stack