/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 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.
#include <dali/public-api/object/type-registry-helper.h>
#include <dali/public-api/size-negotiation/relayout-container.h>
#include <dali/public-api/math/math-utils.h>
+#include <dali-toolkit/public-api/align-enumerations.h>
+#include <dali-toolkit/devel-api/controls/control-devel.h>
+#include <dali-toolkit/devel-api/visual-factory/visual-base.h>
+#include <dali-toolkit/internal/visuals/visual-base-impl.h>
+#include <dali-toolkit/internal/visuals/visual-string-constants.h>
+#include <dali-toolkit/devel-api/visuals/arc-visual-properties-devel.h>
+#include <dali-toolkit/public-api/visuals/color-visual-properties.h>
+#include <dali-toolkit/public-api/visuals/image-visual-properties.h>
+#include <dali-toolkit/public-api/visuals/text-visual-properties.h>
+#include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
+
+#include <dali/integration-api/debug.h>
namespace Dali
{
// Setup properties, signals and actions using the type-registry.
DALI_TYPE_REGISTRATION_BEGIN( Toolkit::ProgressBar, Toolkit::Control, Create )
-DALI_PROPERTY_REGISTRATION( Toolkit, ProgressBar, "progressValue", FLOAT, PROGRESS_VALUE )
-DALI_PROPERTY_REGISTRATION( Toolkit, ProgressBar, "trackVisual", MAP, TRACK_VISUAL )
-DALI_PROPERTY_REGISTRATION( Toolkit, ProgressBar, "progressVisual", MAP, PROGRESS_VISUAL )
-DALI_SIGNAL_REGISTRATION( Toolkit, ProgressBar, "valueChanged", SIGNAL_VALUE_CHANGED )
+DALI_PROPERTY_REGISTRATION( Toolkit, ProgressBar, "progressValue", FLOAT, PROGRESS_VALUE )
+DALI_PROPERTY_REGISTRATION( Toolkit, ProgressBar, "secondaryProgressValue", FLOAT, SECONDARY_PROGRESS_VALUE )
+DALI_PROPERTY_REGISTRATION( Toolkit, ProgressBar, "indeterminate", BOOLEAN, INDETERMINATE )
+DALI_PROPERTY_REGISTRATION( Toolkit, ProgressBar, "trackVisual", MAP, TRACK_VISUAL )
+DALI_PROPERTY_REGISTRATION( Toolkit, ProgressBar, "progressVisual", MAP, PROGRESS_VISUAL )
+DALI_PROPERTY_REGISTRATION( Toolkit, ProgressBar, "secondaryProgressVisual", MAP, SECONDARY_PROGRESS_VISUAL )
+DALI_PROPERTY_REGISTRATION( Toolkit, ProgressBar, "indeterminateVisual", MAP, INDETERMINATE_VISUAL )
+DALI_PROPERTY_REGISTRATION( Toolkit, ProgressBar, "indeterminateVisualAnimation", ARRAY, INDETERMINATE_VISUAL_ANIMATION )
+DALI_PROPERTY_REGISTRATION( Toolkit, ProgressBar, "labelVisual", MAP, LABEL_VISUAL )
+DALI_SIGNAL_REGISTRATION( Toolkit, ProgressBar, "valueChanged", SIGNAL_VALUE_CHANGED )
DALI_TYPE_REGISTRATION_END()
-const char* SKINNED_TRACK_VISUAL = DALI_IMAGE_DIR "slider-skin.9.png";
-const char* SKINNED_PROGRESS_VISUAL = DALI_IMAGE_DIR "slider-skin-progress.9.png";
+struct ProgressDepthIndex
+{
+ // Enum to make sure the visual order
+ enum
+ {
+ TRACK_VISUAL,
+ SECONDARY_PROGRESS_VISUAL,
+ PROGRESS_VISUAL,
+ LABEL_VISUAL,
+ INDETERMINATE_VISUAL
+ };
+};
float DEFAULT_VALUE = 0.0f;
float DEFAULT_LOWER_BOUND = 0.0f;
float DEFAULT_UPPER_BOUND = 1.0f;
-float DEFAULT_PADDING = 24.0f;
+float DEFAULT_FONT_SIZE = 12.0f;
+const char* CIRCULAR_PROGRESS_BAR_STYLE_NAME = "CircularProgressBar";
+
+
+void BackupVisualProperties( const Control* control, Property::Index index, Property::Map& map )
+{
+ Toolkit::Visual::Base visual = DevelControl::GetVisual( *control, index );
+
+ if( visual )
+ {
+ map.Clear();
+ visual.CreatePropertyMap( map );
+ }
+}
+
+void RestoreVisualProperties( Control* control, Property::Index index, Property::Map& map, int depth )
+{
+ if( !map.Empty() )
+ {
+ Toolkit::Visual::Base visual = DevelControl::GetVisual( *control, index );
+
+ Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
+
+ visualImpl.SetProperties( map );
+
+ DevelControl::UnregisterVisual( *control, index );
+
+ DevelControl::RegisterVisual( *control, index, visual, true, depth );
+ }
+}
} // Unnamed namespace
// ProgressBar
///////////////////////////////////////////////////////////////////////////////////////////////////
-Dali::Toolkit::ProgressBar ProgressBar::New()
+Dali::Toolkit::ProgressBar ProgressBar::New( DevelProgressBar::Style progressBarStyle )
{
// Create the implementation
ProgressBarPtr progressBar( new ProgressBar() );
- // Pass ownership to CustomActor via derived handle
Dali::Toolkit::ProgressBar handle( *progressBar );
+ switch( progressBarStyle )
+ {
+ case DevelProgressBar::Style::CIRCULAR:
+ {
+ progressBar->SetStyleName( CIRCULAR_PROGRESS_BAR_STYLE_NAME );
+ break;
+ }
+ default:
+ {
+ break;
+ }
+ }
+
// Second-phase init of the implementation
// This can only be done after the CustomActor connection has been made...
progressBar->Initialize();
}
ProgressBar::ProgressBar()
-: Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
- mTrackVisual(""),
- mProgressVisual(""),
- mTrackMap(),
- mTrackVisualSize(),
- mProgressVisualSize(),
- mValue( DEFAULT_VALUE )
+: Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
+ mProgressValue( DEFAULT_VALUE ),
+ mSecondaryProgressValue( DEFAULT_VALUE ),
+ mIndeterminate( false )
{
}
void ProgressBar::OnInitialize()
{
- // Setup
- CreateChildren();
-
- // Properties
- SetTrackVisual( SKINNED_TRACK_VISUAL );
- SetProgressVisual( SKINNED_PROGRESS_VISUAL );
-
- DisplayValue( mValue, false ); // Run this last to display the correct value
}
void ProgressBar::OnRelayout( const Vector2& size, RelayoutContainer& container )
{
+
Vector2 trackSize( size );
- trackSize.width = std::max( 0.0f, size.width - DEFAULT_PADDING ); // Ensure we don't go negative
+ mDomain = CalcDomain( size );
+
+ trackSize.width = std::max( 0.0f, size.width ); // Ensure we don't go negative
- // Track
- if( mTrack )
+ Toolkit::Visual::Base trackVisual = DevelControl::GetVisual( *this, Toolkit::ProgressBar::Property::TRACK_VISUAL );
+ Toolkit::Visual::Base labelVisual = DevelControl::GetVisual( *this, Toolkit::ProgressBar::Property::LABEL_VISUAL );
+ Toolkit::Visual::Base indeterminateVisual = DevelControl::GetVisual( *this, Toolkit::ProgressBar::Property::INDETERMINATE_VISUAL );
+
+ if( trackVisual )
{
- container.Add( mTrack, trackSize );
+ Property::Map visualTransform;
+
+ visualTransform.Add( Toolkit::Visual::Transform::Property::SIZE, trackSize )
+ .Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
+ .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) );
- // mValueTextLabel will have its relayout method called automatically as it's a child of mTrack,
- // which is added to the container
+ trackVisual.SetTransformAndSize( visualTransform, trackSize );
}
- // Progress bar
- if( mProgress )
+ ApplyProgressToVisualTransform( mSecondaryProgressValue, trackSize, Toolkit::ProgressBar::Property::SECONDARY_PROGRESS_VISUAL );
+
+ ApplyProgressToVisualTransform( mProgressValue, trackSize, Toolkit::ProgressBar::Property::PROGRESS_VISUAL );
+
+ if( labelVisual )
{
- mDomain = CalcDomain( trackSize );
+ Property::Map visualTransform;
- Vector2 progressSize( trackSize );
+ visualTransform.Add( Toolkit::Visual::Transform::Property::SIZE, trackSize )
+ .Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
+ .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) );
+ labelVisual.SetTransformAndSize( visualTransform, trackSize );
+ }
- // If no progress, then we do not want a n-patch image shown incorrectly
- progressSize.width = std::max( mProgressVisualSize.width, mDomain.from.x + mValue * ( mDomain.to.x - mDomain.from.x ) );
- progressSize.width = std::min( progressSize.width, trackSize.width ); // We should not exceed given size
+ if( indeterminateVisual )
+ {
+ Property::Map visualTransform;
- container.Add( mProgress, progressSize );
+ visualTransform.Add( Toolkit::Visual::Transform::Property::SIZE, trackSize )
+ .Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
+ .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) );
+ indeterminateVisual.SetTransformAndSize( visualTransform, trackSize );
}
+
}
Vector3 ProgressBar::GetNaturalSize()
{
- // Return the maximum width/height combinations of our visuals
+ // Return the bigger size after comparing trackVisual naturalSize and labelVisual naturalSize
+ Toolkit::Visual::Base trackVisual = DevelControl::GetVisual( *this, Toolkit::ProgressBar::Property::TRACK_VISUAL );
+ Toolkit::Visual::Base labelVisual = DevelControl::GetVisual( *this, Toolkit::ProgressBar::Property::LABEL_VISUAL );
+
+ Size trackSize;
+ Size labelSize;
+
+ if ( trackVisual )
+ {
+ trackVisual.GetNaturalSize( trackSize );
+ }
+ if ( labelVisual )
+ {
+ labelVisual.GetNaturalSize( labelSize );
+ }
Vector3 naturalSize;
- naturalSize.width = std::max( mTrackVisualSize.width, mProgressVisualSize.width );
- naturalSize.height = std::max( mTrackVisualSize.height, mProgressVisualSize.height );
+ naturalSize.width = ( trackSize.width > labelSize.width ) ? trackSize.width: labelSize.width;
+ naturalSize.height = ( trackSize.height > labelSize.height ) ? trackSize.height: labelSize.height;
+
return naturalSize;
}
return Domain( Vector2( 0.0f, 0.0f ), currentSize );
}
-void ProgressBar::DisplayValue( float value, bool raiseSignals )
+Toolkit::ProgressBar::ValueChangedSignalType& ProgressBar::ValueChangedSignal()
{
- // Signals
- if( raiseSignals )
- {
- Toolkit::ProgressBar self = Toolkit::ProgressBar::DownCast( Self() );
- mValueChangedSignal.Emit( self, value );
- }
+ return mValueChangedSignal;
+}
- // Change the value of the text label
- if( mValueTextLabel )
+void ProgressBar::SetProgressValue( float value )
+{
+ // update the progress bar value (taking float precision errors into account)
+ // TODO : it seems 0.0f cannot into this statement.
+ if( ( mProgressValue != value ) &&
+ ( ( value >= DEFAULT_LOWER_BOUND ) || ( Equals( value, DEFAULT_LOWER_BOUND ) ) ) &&
+ ( ( value <= DEFAULT_UPPER_BOUND ) || ( Equals( value, DEFAULT_UPPER_BOUND ) ) ) )
{
- std::stringstream ss;
- ss.precision( 0 );
- ss << std::fixed << ( value * 100 ) << "%";
+ mProgressValue = Clamp( value, DEFAULT_LOWER_BOUND, DEFAULT_UPPER_BOUND );
- std::string label = mValueTextLabel.GetProperty<std::string>( Toolkit::TextLabel::Property::TEXT );
- if( label.compare(ss.str()) )
- {
- mValueTextLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, ss.str() );
- }
+ ApplyProgressToVisual( mProgressValue, Toolkit::ProgressBar::Property::PROGRESS_VISUAL, ProgressDepthIndex::PROGRESS_VISUAL );
+
+ Toolkit::ProgressBar self = Toolkit::ProgressBar::DownCast( Self() );
+ mValueChangedSignal.Emit( self, mProgressValue, mSecondaryProgressValue );
+ RelayoutRequest();
}
}
-Toolkit::ImageView ProgressBar::CreateTrack()
+float ProgressBar::GetProgressValue() const
{
- Toolkit::ImageView track = Toolkit::ImageView::New();
- track.SetParentOrigin( ParentOrigin::CENTER );
- track.SetAnchorPoint( AnchorPoint::CENTER );
- track.SetResizePolicy(ResizePolicy::USE_ASSIGNED_SIZE, Dimension::ALL_DIMENSIONS );
-
- return track;
+ return mProgressValue;
}
-void ProgressBar::SetTrackVisual( const std::string& filename )
+void ProgressBar::SetSecondaryProgressValue( float value )
{
- if( mTrack && filename.size() > 0 )
+ // update the progress bar value (taking float precision errors into account)
+ // TODO : it seems 0.0f cannot into this statement.
+ if( ( mSecondaryProgressValue != value ) &&
+ ( ( value >= DEFAULT_LOWER_BOUND ) || ( Equals( value, DEFAULT_LOWER_BOUND ) ) ) &&
+ ( ( value <= DEFAULT_UPPER_BOUND ) || ( Equals( value, DEFAULT_UPPER_BOUND ) ) ) )
{
- mTrack.SetImage( filename );
- mTrackVisual = filename;
- mTrackVisualSize = Vector2::ZERO;
+ mSecondaryProgressValue = Clamp( value, DEFAULT_LOWER_BOUND, DEFAULT_UPPER_BOUND );
+
+ ApplyProgressToVisual( mSecondaryProgressValue, Toolkit::ProgressBar::Property::SECONDARY_PROGRESS_VISUAL, ProgressDepthIndex::SECONDARY_PROGRESS_VISUAL );
+
+ Toolkit::ProgressBar self = Toolkit::ProgressBar::DownCast( Self() );
+ mValueChangedSignal.Emit( self, mProgressValue, mSecondaryProgressValue );
+
RelayoutRequest();
}
}
-void ProgressBar::SetTrackVisual( Property::Map map )
+float ProgressBar::GetSecondaryProgressValue() const
+{
+ return mSecondaryProgressValue;
+}
+
+void ProgressBar::SetIndeterminate( bool value )
{
- bool relayoutRequired = false;
+ mIndeterminate = value;
+ DevelControl::EnableVisual( *this, Toolkit::ProgressBar::Property::INDETERMINATE_VISUAL, mIndeterminate );
- Property::Value* imageValue = map.Find( "url" );
- if( imageValue )
+ if( mIndeterminate )
{
- mTrackVisual.clear();
- std::string filename;
- if( imageValue->Get( filename ) )
+ RelayoutRequest();
+ if( mIndeterminateVisualTransition )
{
- if( mTrack && ( filename.size() > 0 ) )
- {
- mTrack.SetImage( filename );
- mTrackMap = map;
- relayoutRequired = true;
- }
+ PlayIndeterminateVisualTransition();
}
}
-
- Property::Value* sizeValue = map.Find( "size" );
- if( sizeValue )
+ else
{
- Vector2 size;
- if( sizeValue->Get( size ) )
+ if( mIndeterminateVisualAni )
{
- mTrackVisualSize = size;
- relayoutRequired = true;
+ mIndeterminateVisualAni.Stop();
}
- }
- // Visual and/or visual size changed so we need to relayout
- if( relayoutRequired )
- {
+ // Restore previous visual data after animation finished.
+ RestoreVisualProperties( this, Toolkit::ProgressBar::Property::TRACK_VISUAL, mTrackVisualMap, ProgressDepthIndex::TRACK_VISUAL );
+ RestoreVisualProperties( this, Toolkit::ProgressBar::Property::SECONDARY_PROGRESS_VISUAL, mSecondaryProgressVisualMap, ProgressDepthIndex::SECONDARY_PROGRESS_VISUAL );
+ RestoreVisualProperties( this, Toolkit::ProgressBar::Property::PROGRESS_VISUAL, mProgressVisualMap, ProgressDepthIndex::PROGRESS_VISUAL );
+
RelayoutRequest();
}
}
-std::string ProgressBar::GetTrackVisual()
+bool ProgressBar::GetIndeterminate() const
{
- return mTrackVisual;
+ return mIndeterminate;
}
-Toolkit::ImageView ProgressBar::CreateProgress()
+void ProgressBar::SetIndeterminateVisualTransition( Toolkit::TransitionData transition )
{
- Toolkit::ImageView progress = Toolkit::ImageView::New();
- progress.SetParentOrigin( ParentOrigin::CENTER_LEFT );
- progress.SetAnchorPoint( AnchorPoint::CENTER_LEFT );
- progress.SetResizePolicy(ResizePolicy::USE_ASSIGNED_SIZE, Dimension::ALL_DIMENSIONS );
+ mIndeterminateVisualTransition = transition;
+ if( mIndeterminate )
+ {
+ PlayIndeterminateVisualTransition();
+ }
+}
+
+void ProgressBar::PlayIndeterminateVisualTransition()
+{
+ // Store current visual data before animation changes it.
+ BackupVisualProperties( this, Toolkit::ProgressBar::Property::TRACK_VISUAL, mTrackVisualMap );
+ BackupVisualProperties( this, Toolkit::ProgressBar::Property::SECONDARY_PROGRESS_VISUAL, mSecondaryProgressVisualMap );
+ BackupVisualProperties( this, Toolkit::ProgressBar::Property::PROGRESS_VISUAL, mProgressVisualMap );
+
+ if( mIndeterminateVisualAni )
+ {
+ mIndeterminateVisualAni.Stop();
+ mIndeterminateVisualAni.Clear();
+ }
+
+ mIndeterminateVisualAni = DevelControl::CreateTransition( *this, mIndeterminateVisualTransition );
- return progress;
+ if( mIndeterminate && mIndeterminateVisualAni )
+ {
+ mIndeterminateVisualAni.SetLooping(true);
+ mIndeterminateVisualAni.Play();
+ }
}
-void ProgressBar::SetProgressVisual( const std::string& filename )
+Toolkit::TransitionData ProgressBar::ConvertPropertyToTransition( const Property::Value& value )
{
- if( mProgress && ( filename.size() > 0 ) )
+ Toolkit::TransitionData transitionData;
+
+ if( value.GetType() == Property::ARRAY )
{
- mProgress.SetImage( filename );
- mProgressVisual = filename;
- mProgressVisualSize = Vector2::ZERO;
- RelayoutRequest();
+ transitionData = Toolkit::TransitionData::New( *value.GetArray() );
+ }
+ else if( value.GetType() == Property::MAP )
+ {
+ transitionData = Toolkit::TransitionData::New( *value.GetMap() );
}
+
+ return transitionData;
}
-void ProgressBar::SetProgressVisual( Property::Map map )
+/**
+ * Create Visual for given index from a property map or url.
+ * 1) Check if value passed in is a url and create visual
+ * 2) Create visual from map if step (1) is false
+ * 3) Register visual with control with false for enable flag.
+ * 4) Unregister visual if empty map was provided. This is the method to remove a visual
+ */
+
+void ProgressBar::CreateVisualsForComponent( Property::Index index, const Property::Value& value, const int visualDepth )
{
- bool relayoutRequired = false;
+ Toolkit::VisualFactory visualFactory = Toolkit::VisualFactory::Get();
+ Toolkit::Visual::Base progressVisual;
- Property::Value* imageValue = map.Find( "url" );
- if( imageValue )
+ std::string imageUrl;
+ if( value.Get( imageUrl ) )
{
- mProgressVisual.clear();
- std::string filename;
- if( imageValue->Get( filename ) )
+ if ( !imageUrl.empty() )
{
- if( mProgress && ( filename.size() > 0 ) )
- {
- mProgress.SetImage( filename );
- mProgressMap = map;
- relayoutRequired = true;
- }
+ progressVisual = visualFactory.CreateVisual( imageUrl, ImageDimensions() );
}
}
-
- Property::Value* sizeValue = map.Find( "size" );
- if( sizeValue )
+ else // Does this code make text-visual can be accepted as visual?
{
- Vector2 size;
- if( sizeValue->Get( size ) )
+ // if its not a string then get a Property::Map from the property if possible.
+ const Property::Map *map = value.GetMap();
+ if( map && !map->Empty() ) // Empty map results in current visual removal.
{
- mProgressVisualSize = size;
- relayoutRequired = true;
+ progressVisual = visualFactory.CreateVisual( *map );
}
}
- // Visual and/or visual size changed so we need to relayout
- if( relayoutRequired )
+ if ( progressVisual )
{
- RelayoutRequest();
+ if( index == Toolkit::ProgressBar::Property::INDETERMINATE_VISUAL )
+ {
+ DevelControl::RegisterVisual( *this, index, progressVisual, mIndeterminate, visualDepth );
+ }
+ else
+ {
+ DevelControl::RegisterVisual( *this, index, progressVisual, true, visualDepth );
+ }
+ }
+ else
+ {
+ DevelControl::UnregisterVisual( *this, index );
}
}
-std::string ProgressBar::GetProgressVisual()
+bool ProgressBar::GetPropertyMapForVisual( Property::Index visualIndex, Property::Map& retreivedMap ) const
{
- return mProgressVisual;
-}
+ bool success = false;
+ Toolkit::Visual::Base visual = DevelControl::GetVisual( *this, visualIndex );
-Toolkit::ProgressBar::ValueChangedSignalType& ProgressBar::ValueChangedSignal()
-{
- return mValueChangedSignal;
+ if ( visual )
+ {
+ visual.CreatePropertyMap( retreivedMap );
+ success = true;
+ }
+
+ return success;
}
-void ProgressBar::CreateChildren()
+
+void ProgressBar::ApplyProgressToVisual( float progress, Property::Index index, int depth )
{
- Actor self = Self();
+ Toolkit::Visual::Base visual = DevelControl::GetVisual( *this, index );
- // Track
- mTrack = CreateTrack();
- self.Add( mTrack ); // Needs to be a direct child as we want to manipulate its size
+ if( visual && static_cast<DevelVisual::Type>( visual.GetType() ) == DevelVisual::ARC && !mIndeterminate )
+ {
+ Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
- // Progress bar
- mProgress = CreateProgress();
- self.Add( mProgress ); // Needs to be a direct child as we want to manipulate its size
+ Property::Map map;
- // Value Text
- mValueTextLabel = Toolkit::TextLabel::New();
- mValueTextLabel.SetName( "ProgressBarValueTextLabel" );
- mValueTextLabel.SetStyleName( "ProgressBarValueTextLabel" );
- mValueTextLabel.SetParentOrigin( ParentOrigin::CENTER );
- mValueTextLabel.SetAnchorPoint( AnchorPoint::CENTER );
- mValueTextLabel.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
- mValueTextLabel.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
- mTrack.Add( mValueTextLabel ); // Add to mTrack and let it automatically set its size
-}
+ map[ Toolkit::DevelArcVisual::Property::SWEEP_ANGLE ] = Property::Value( 360.0f * progress );
-void ProgressBar::SetProgressValue( float value )
-{
- // update the progress bar value (taking float precision errors into account)
- if( ( mValue != value ) &&
- ( ( value >= DEFAULT_LOWER_BOUND ) || ( Equals( value, DEFAULT_LOWER_BOUND ) ) ) &&
- ( ( value <= DEFAULT_UPPER_BOUND ) || ( Equals( value, DEFAULT_UPPER_BOUND ) ) ) )
- {
- mValue = Clamp( value, DEFAULT_LOWER_BOUND, DEFAULT_UPPER_BOUND );
- DisplayValue( mValue, true );
- RelayoutRequest();
+ visualImpl.SetProperties( map );
+
+ DevelControl::UnregisterVisual( *this, index );
+ DevelControl::RegisterVisual( *this, index, visual, true, depth );
}
}
-float ProgressBar::GetProgressValue() const
+void ProgressBar::ApplyProgressToVisualTransform( float progress, Vector2 trackSize, Property::Index index )
{
- return mValue;
+ Toolkit::Visual::Base visual = DevelControl::GetVisual( *this, index );
+
+ if( visual )
+ {
+ Property::Map visualTransform;
+
+ if( static_cast<DevelVisual::Type>( visual.GetType() ) != DevelVisual::ARC )
+ {
+ visualTransform.Add( Toolkit::Visual::Transform::Property::SIZE, Vector2( mDomain.from.x + progress * ( mDomain.to.x - mDomain.from.x ), trackSize.height ) )
+ .Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
+ .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
+ .Add( Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN )
+ .Add( Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN );
+ }
+
+ visual.SetTransformAndSize( visualTransform, trackSize );
+ }
}
// Static class method to support script connecting signals
switch ( propertyIndex )
{
- case Toolkit::ProgressBar::Property::PROGRESS_VALUE:
+ case Toolkit::ProgressBar::Property::TRACK_VISUAL:
{
- progressBarImpl.SetProgressValue( value.Get< float >() );
+ progressBarImpl.CreateVisualsForComponent( propertyIndex, value, ProgressDepthIndex::TRACK_VISUAL );
break;
}
- case Toolkit::ProgressBar::Property::TRACK_VISUAL:
+ case Toolkit::ProgressBar::Property::SECONDARY_PROGRESS_VISUAL:
{
- Property::Map map;
- if( value.Get( map ) )
- {
- progressBarImpl.SetTrackVisual( map );
- }
+ progressBarImpl.CreateVisualsForComponent( propertyIndex, value, ProgressDepthIndex::SECONDARY_PROGRESS_VISUAL );
+ progressBarImpl.ApplyProgressToVisual( progressBarImpl.mSecondaryProgressValue, propertyIndex, ProgressDepthIndex::SECONDARY_PROGRESS_VISUAL );
break;
}
case Toolkit::ProgressBar::Property::PROGRESS_VISUAL:
{
+ progressBarImpl.CreateVisualsForComponent( propertyIndex, value, ProgressDepthIndex::PROGRESS_VISUAL );
+ progressBarImpl.ApplyProgressToVisual( progressBarImpl.mProgressValue, propertyIndex, ProgressDepthIndex::PROGRESS_VISUAL );
+ break;
+ }
+
+ case Toolkit::ProgressBar::Property::INDETERMINATE_VISUAL:
+ {
+ progressBarImpl.CreateVisualsForComponent( propertyIndex, value, ProgressDepthIndex::INDETERMINATE_VISUAL );
+ break;
+ }
+
+ case Toolkit::ProgressBar::Property::LABEL_VISUAL:
+ {
Property::Map map;
- if( value.Get( map ) )
+ std::string textString;
+
+ if ( value.Get( textString ) )
{
- progressBarImpl.SetProgressVisual( map );
+ // set new text string as TEXT property
+ Property::Map newTextMap;
+ Toolkit::Visual::Base label = DevelControl::GetVisual( progressBarImpl, Toolkit::ProgressBar::Property::LABEL_VISUAL );
+
+ if( label )
+ {
+ label.CreatePropertyMap( map );
+ }
+
+ // if LABEL_VISUAL doesn't set before, add Visual property "TYPE" to create new text Visual
+ if( map.Empty() )
+ {
+ newTextMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT );
+ newTextMap.Add( Toolkit::TextVisual::Property::POINT_SIZE, DEFAULT_FONT_SIZE );
+ }
+ newTextMap.Add( Toolkit::TextVisual::Property::TEXT, textString );
+
+ map.Merge( newTextMap );
+ }
+ else
+ {
+ value.Get( map );
+ }
+
+ if( !map.Empty() )
+ {
+ progressBarImpl.CreateVisualsForComponent( propertyIndex, map, ProgressDepthIndex::LABEL_VISUAL );
}
break;
}
+
+ case Toolkit::ProgressBar::Property::PROGRESS_VALUE:
+ {
+ progressBarImpl.SetProgressValue( value.Get< float >() );
+ break;
+ }
+
+ case Toolkit::ProgressBar::Property::SECONDARY_PROGRESS_VALUE:
+ {
+ progressBarImpl.SetSecondaryProgressValue( value.Get< float >() );
+ break;
+ }
+
+ case Toolkit::ProgressBar::Property::INDETERMINATE:
+ {
+ progressBarImpl.SetIndeterminate( value.Get< bool >() );
+ break;
+ }
+
+ case Toolkit::ProgressBar::Property::INDETERMINATE_VISUAL_ANIMATION:
+ {
+ progressBarImpl.SetIndeterminateVisualTransition( progressBarImpl.ConvertPropertyToTransition( value ) );
+ break;
+ }
}
}
}
switch ( propertyIndex )
{
+ case Toolkit::ProgressBar::Property::TRACK_VISUAL:
+ case Toolkit::ProgressBar::Property::PROGRESS_VISUAL:
+ case Toolkit::ProgressBar::Property::SECONDARY_PROGRESS_VISUAL:
+ case Toolkit::ProgressBar::Property::INDETERMINATE_VISUAL:
+ case Toolkit::ProgressBar::Property::LABEL_VISUAL:
+ {
+ Property::Map visualProperty;
+ if ( progressBarImpl.GetPropertyMapForVisual( propertyIndex, visualProperty ) )
+ {
+ value = visualProperty;
+ }
+ break;
+ }
+
case Toolkit::ProgressBar::Property::PROGRESS_VALUE:
{
value = progressBarImpl.GetProgressValue();
break;
}
- case Toolkit::ProgressBar::Property::TRACK_VISUAL:
+ case Toolkit::ProgressBar::Property::SECONDARY_PROGRESS_VALUE:
{
- if( !progressBarImpl.mTrackVisual.empty() )
- {
- value = progressBarImpl.GetTrackVisual();
- }
- else if( !progressBarImpl.mTrackMap.Empty() )
- {
- value = progressBarImpl.mTrackMap;
- }
+ value = progressBarImpl.GetSecondaryProgressValue();
break;
}
- case Toolkit::ProgressBar::Property::PROGRESS_VISUAL:
+ case Toolkit::ProgressBar::Property::INDETERMINATE:
{
- if( !progressBarImpl.mProgressVisual.empty() )
- {
- value = progressBarImpl.GetProgressVisual();
- }
- else if( !progressBarImpl.mProgressMap.Empty() )
- {
- value = progressBarImpl.mProgressMap;
- }
+ value = progressBarImpl.GetIndeterminate();
break;
}
+
+ case Toolkit::ProgressBar::Property::INDETERMINATE_VISUAL_ANIMATION:
+ {
+ //TODO: Return INDETERMINATE_VISUAL_TRANSITION;
+ }
}
}
return value;
}
+void ProgressBar::OnSceneConnection( int depth )
+{
+ // Chain up first (ensures visuals are ready to draw)
+ Control::OnSceneConnection( depth );
+
+ if( mIndeterminate )
+ {
+ PlayIndeterminateVisualTransition();
+ }
+}
+
} // namespace Internal
} // namespace Toolkit