mirror of https://github.com/axmolengine/axmol.git
issue #5047, refactor LayoutParameterType
This commit is contained in:
parent
d12a71f738
commit
0c0f18e7f3
|
@ -52,6 +52,9 @@ CC_DEPRECATED_ATTRIBUTE const Layout::BackGroundColorType LAYOUT_COLOR_NONE = La
|
||||||
CC_DEPRECATED_ATTRIBUTE const Layout::BackGroundColorType LAYOUT_COLOR_SOLID = Layout::BackGroundColorType::SOLID;
|
CC_DEPRECATED_ATTRIBUTE const Layout::BackGroundColorType LAYOUT_COLOR_SOLID = Layout::BackGroundColorType::SOLID;
|
||||||
CC_DEPRECATED_ATTRIBUTE const Layout::BackGroundColorType LAYOUT_COLOR_GRADIENT
|
CC_DEPRECATED_ATTRIBUTE const Layout::BackGroundColorType LAYOUT_COLOR_GRADIENT
|
||||||
= Layout::BackGroundColorType::GRADIENT;
|
= Layout::BackGroundColorType::GRADIENT;
|
||||||
|
CC_DEPRECATED_ATTRIBUTE const LayoutParameter::Type LAYOUT_PARAMETER_NONE = LayoutParameter::Type::NONE;
|
||||||
|
CC_DEPRECATED_ATTRIBUTE const LayoutParameter::Type LAYOUT_PARAMETER_LINEAR = LayoutParameter::Type::LINEAR;
|
||||||
|
CC_DEPRECATED_ATTRIBUTE const LayoutParameter::Type LAYOUT_PARAMETER_RELATIVE = LayoutParameter::Type::RELATIVE;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -63,6 +66,7 @@ CC_DEPRECATED_ATTRIBUTE typedef Widget::BrightStyle BrightStyle;
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef Layout::ClippingType LayoutClippingType;
|
CC_DEPRECATED_ATTRIBUTE typedef Layout::ClippingType LayoutClippingType;
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef Layout::LayoutType LayoutType;
|
CC_DEPRECATED_ATTRIBUTE typedef Layout::LayoutType LayoutType;
|
||||||
CC_DEPRECATED_ATTRIBUTE typedef Layout::BackGroundColorType LayoutBackGroundColorType;
|
CC_DEPRECATED_ATTRIBUTE typedef Layout::BackGroundColorType LayoutBackGroundColorType;
|
||||||
|
CC_DEPRECATED_ATTRIBUTE typedef LayoutParameter::Type LayoutParameterType;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,7 +130,7 @@ void LinearVerticalLayoutExecutant::doLayout(const cocos2d::Size &layoutSize, Ve
|
||||||
Widget* child = dynamic_cast<Widget*>(subWidget);
|
Widget* child = dynamic_cast<Widget*>(subWidget);
|
||||||
if (child)
|
if (child)
|
||||||
{
|
{
|
||||||
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter(LAYOUT_PARAMETER_LINEAR));
|
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter(LayoutParameter::Type::LINEAR));
|
||||||
|
|
||||||
if (layoutParameter)
|
if (layoutParameter)
|
||||||
{
|
{
|
||||||
|
@ -171,7 +171,7 @@ void LinearHorizontalLayoutExecutant::doLayout(const cocos2d::Size &layoutSize,
|
||||||
Widget* child = dynamic_cast<Widget*>(subWidget);
|
Widget* child = dynamic_cast<Widget*>(subWidget);
|
||||||
if (child)
|
if (child)
|
||||||
{
|
{
|
||||||
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter(LAYOUT_PARAMETER_LINEAR));
|
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter(LayoutParameter::Type::LINEAR));
|
||||||
if (layoutParameter)
|
if (layoutParameter)
|
||||||
{
|
{
|
||||||
LinearGravity childGravity = layoutParameter->getGravity();
|
LinearGravity childGravity = layoutParameter->getGravity();
|
||||||
|
@ -212,7 +212,7 @@ void RelativeLayoutExecutant::doLayout(const cocos2d::Size &layoutSize, Vector<c
|
||||||
Widget* child = dynamic_cast<Widget*>(subWidget);
|
Widget* child = dynamic_cast<Widget*>(subWidget);
|
||||||
if (child)
|
if (child)
|
||||||
{
|
{
|
||||||
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(child->getLayoutParameter(LAYOUT_PARAMETER_RELATIVE));
|
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(child->getLayoutParameter(LayoutParameter::Type::RELATIVE));
|
||||||
layoutParameter->_put = false;
|
layoutParameter->_put = false;
|
||||||
unlayoutChildCount++;
|
unlayoutChildCount++;
|
||||||
widgetChildren.pushBack(child);
|
widgetChildren.pushBack(child);
|
||||||
|
@ -223,7 +223,7 @@ void RelativeLayoutExecutant::doLayout(const cocos2d::Size &layoutSize, Vector<c
|
||||||
for (auto& subWidget : widgetChildren)
|
for (auto& subWidget : widgetChildren)
|
||||||
{
|
{
|
||||||
Widget* child = static_cast<Widget*>(subWidget);
|
Widget* child = static_cast<Widget*>(subWidget);
|
||||||
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(child->getLayoutParameter(LAYOUT_PARAMETER_RELATIVE));
|
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(child->getLayoutParameter(LayoutParameter::Type::RELATIVE));
|
||||||
|
|
||||||
if (layoutParameter)
|
if (layoutParameter)
|
||||||
{
|
{
|
||||||
|
@ -245,7 +245,7 @@ void RelativeLayoutExecutant::doLayout(const cocos2d::Size &layoutSize, Vector<c
|
||||||
{
|
{
|
||||||
if (sWidget)
|
if (sWidget)
|
||||||
{
|
{
|
||||||
RelativeLayoutParameter* rlayoutParameter = dynamic_cast<RelativeLayoutParameter*>(sWidget->getLayoutParameter(LAYOUT_PARAMETER_RELATIVE));
|
RelativeLayoutParameter* rlayoutParameter = dynamic_cast<RelativeLayoutParameter*>(sWidget->getLayoutParameter(LayoutParameter::Type::RELATIVE));
|
||||||
if (rlayoutParameter && strcmp(rlayoutParameter->getRelativeName(), relativeName) == 0)
|
if (rlayoutParameter && strcmp(rlayoutParameter->getRelativeName(), relativeName) == 0)
|
||||||
{
|
{
|
||||||
relativeWidget = sWidget;
|
relativeWidget = sWidget;
|
||||||
|
@ -1180,7 +1180,7 @@ void Layout::supplyTheLayoutParameterLackToChild(Widget *child)
|
||||||
case LayoutType::HORIZONTAL:
|
case LayoutType::HORIZONTAL:
|
||||||
case LayoutType::VERTICAL:
|
case LayoutType::VERTICAL:
|
||||||
{
|
{
|
||||||
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter(LAYOUT_PARAMETER_LINEAR));
|
LinearLayoutParameter* layoutParameter = dynamic_cast<LinearLayoutParameter*>(child->getLayoutParameter(LayoutParameter::Type::LINEAR));
|
||||||
if (!layoutParameter)
|
if (!layoutParameter)
|
||||||
{
|
{
|
||||||
child->setLayoutParameter(LinearLayoutParameter::create());
|
child->setLayoutParameter(LinearLayoutParameter::create());
|
||||||
|
@ -1189,7 +1189,7 @@ void Layout::supplyTheLayoutParameterLackToChild(Widget *child)
|
||||||
}
|
}
|
||||||
case LayoutType::RELATIVE:
|
case LayoutType::RELATIVE:
|
||||||
{
|
{
|
||||||
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(child->getLayoutParameter(LAYOUT_PARAMETER_RELATIVE));
|
RelativeLayoutParameter* layoutParameter = dynamic_cast<RelativeLayoutParameter*>(child->getLayoutParameter(LayoutParameter::Type::RELATIVE));
|
||||||
if (!layoutParameter)
|
if (!layoutParameter)
|
||||||
{
|
{
|
||||||
child->setLayoutParameter(RelativeLayoutParameter::create());
|
child->setLayoutParameter(RelativeLayoutParameter::create());
|
||||||
|
@ -1557,7 +1557,7 @@ Size Layout::getLayoutContentSize()const
|
||||||
if (w)
|
if (w)
|
||||||
{
|
{
|
||||||
widgetCount++;
|
widgetCount++;
|
||||||
Margin m = w->getLayoutParameter(LAYOUT_PARAMETER_LINEAR)->getMargin();
|
Margin m = w->getLayoutParameter(LayoutParameter::Type::LINEAR)->getMargin();
|
||||||
layoutSize = layoutSize + w->getSize() + Size(m.right + m.left, m.top + m.bottom) * 0.5;
|
layoutSize = layoutSize + w->getSize() + Size(m.right + m.left, m.top + m.bottom) * 0.5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,7 @@ const Margin& LayoutParameter::getMargin() const
|
||||||
return _margin;
|
return _margin;
|
||||||
}
|
}
|
||||||
|
|
||||||
LayoutParameterType LayoutParameter::getLayoutType() const
|
LayoutParameter::Type LayoutParameter::getLayoutType() const
|
||||||
{
|
{
|
||||||
return _layoutParameterType;
|
return _layoutParameterType;
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,12 +56,6 @@ public:
|
||||||
|
|
||||||
const Margin MarginZero = Margin();
|
const Margin MarginZero = Margin();
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
LAYOUT_PARAMETER_NONE,
|
|
||||||
LAYOUT_PARAMETER_LINEAR,
|
|
||||||
LAYOUT_PARAMETER_RELATIVE
|
|
||||||
}LayoutParameterType;
|
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
|
@ -107,10 +101,19 @@ typedef enum
|
||||||
class LayoutParameter : public Ref
|
class LayoutParameter : public Ref
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
enum class Type : int
|
||||||
|
{
|
||||||
|
NONE = 0,
|
||||||
|
LINEAR,
|
||||||
|
RELATIVE
|
||||||
|
};
|
||||||
/**
|
/**
|
||||||
* Default constructor
|
* Default constructor
|
||||||
*/
|
*/
|
||||||
LayoutParameter() : _margin(Margin()){_layoutParameterType = LAYOUT_PARAMETER_NONE;};
|
LayoutParameter() : _margin(Margin())
|
||||||
|
{
|
||||||
|
_layoutParameterType = Type::NONE;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default destructor
|
* Default destructor
|
||||||
|
@ -148,14 +151,14 @@ public:
|
||||||
*
|
*
|
||||||
* @return LayoutParameterType
|
* @return LayoutParameterType
|
||||||
*/
|
*/
|
||||||
LayoutParameterType getLayoutType() const;
|
Type getLayoutType() const;
|
||||||
|
|
||||||
LayoutParameter* clone();
|
LayoutParameter* clone();
|
||||||
virtual LayoutParameter* createCloneInstance();
|
virtual LayoutParameter* createCloneInstance();
|
||||||
virtual void copyProperties(LayoutParameter* model);
|
virtual void copyProperties(LayoutParameter* model);
|
||||||
protected:
|
protected:
|
||||||
Margin _margin;
|
Margin _margin;
|
||||||
LayoutParameterType _layoutParameterType;
|
Type _layoutParameterType;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* @js NA
|
* @js NA
|
||||||
|
@ -167,7 +170,10 @@ public:
|
||||||
/**
|
/**
|
||||||
* Default constructor
|
* Default constructor
|
||||||
*/
|
*/
|
||||||
LinearLayoutParameter() : _linearGravity(LINEAR_GRAVITY_NONE){_layoutParameterType = LAYOUT_PARAMETER_LINEAR;};
|
LinearLayoutParameter() : _linearGravity(LINEAR_GRAVITY_NONE)
|
||||||
|
{
|
||||||
|
_layoutParameterType = Type::LINEAR;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default destructor
|
* Default destructor
|
||||||
|
@ -213,7 +219,14 @@ public:
|
||||||
/**
|
/**
|
||||||
* Default constructor
|
* Default constructor
|
||||||
*/
|
*/
|
||||||
RelativeLayoutParameter() : _relativeAlign(RELATIVE_ALIGN_NONE),_relativeWidgetName(""),_relativeLayoutName(""),_put(false){_layoutParameterType = LAYOUT_PARAMETER_RELATIVE;};
|
RelativeLayoutParameter()
|
||||||
|
: _relativeAlign(RELATIVE_ALIGN_NONE),
|
||||||
|
_relativeWidgetName(""),
|
||||||
|
_relativeLayoutName(""),
|
||||||
|
_put(false)
|
||||||
|
{
|
||||||
|
_layoutParameterType = Type::RELATIVE;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default destructor
|
* Default destructor
|
||||||
|
|
|
@ -129,7 +129,7 @@ void ListView::remedyLayoutParameter(Widget *item)
|
||||||
switch (_direction) {
|
switch (_direction) {
|
||||||
case SCROLLVIEW_DIR_VERTICAL:
|
case SCROLLVIEW_DIR_VERTICAL:
|
||||||
{
|
{
|
||||||
LinearLayoutParameter* llp = (LinearLayoutParameter*)(item->getLayoutParameter(LAYOUT_PARAMETER_LINEAR));
|
LinearLayoutParameter* llp = (LinearLayoutParameter*)(item->getLayoutParameter(LayoutParameter::Type::LINEAR));
|
||||||
if (!llp)
|
if (!llp)
|
||||||
{
|
{
|
||||||
LinearLayoutParameter* defaultLp = LinearLayoutParameter::create();
|
LinearLayoutParameter* defaultLp = LinearLayoutParameter::create();
|
||||||
|
@ -184,7 +184,7 @@ void ListView::remedyLayoutParameter(Widget *item)
|
||||||
}
|
}
|
||||||
case SCROLLVIEW_DIR_HORIZONTAL:
|
case SCROLLVIEW_DIR_HORIZONTAL:
|
||||||
{
|
{
|
||||||
LinearLayoutParameter* llp = (LinearLayoutParameter*)(item->getLayoutParameter(LAYOUT_PARAMETER_LINEAR));
|
LinearLayoutParameter* llp = (LinearLayoutParameter*)(item->getLayoutParameter(LayoutParameter::Type::LINEAR));
|
||||||
if (!llp)
|
if (!llp)
|
||||||
{
|
{
|
||||||
LinearLayoutParameter* defaultLp = LinearLayoutParameter::create();
|
LinearLayoutParameter* defaultLp = LinearLayoutParameter::create();
|
||||||
|
|
|
@ -845,12 +845,12 @@ void Widget::setLayoutParameter(LayoutParameter *parameter)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_layoutParameterDictionary.insert(parameter->getLayoutType(), parameter);
|
_layoutParameterDictionary.insert((int)parameter->getLayoutType(), parameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
LayoutParameter* Widget::getLayoutParameter(LayoutParameterType type)
|
LayoutParameter* Widget::getLayoutParameter(LayoutParameter::Type type)
|
||||||
{
|
{
|
||||||
return dynamic_cast<LayoutParameter*>(_layoutParameterDictionary.at(type));
|
return dynamic_cast<LayoutParameter*>(_layoutParameterDictionary.at((int)type));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Widget::getDescription() const
|
std::string Widget::getDescription() const
|
||||||
|
@ -920,6 +920,7 @@ void Widget::copyProperties(Widget *widget)
|
||||||
setFlippedY(widget->isFlippedY());
|
setFlippedY(widget->isFlippedY());
|
||||||
setColor(widget->getColor());
|
setColor(widget->getColor());
|
||||||
setOpacity(widget->getOpacity());
|
setOpacity(widget->getOpacity());
|
||||||
|
//FIXME:copy focus properties, also make sure all the subclass the copy behavior is correct
|
||||||
Map<int, LayoutParameter*>& layoutParameterDic = widget->_layoutParameterDictionary;
|
Map<int, LayoutParameter*>& layoutParameterDic = widget->_layoutParameterDictionary;
|
||||||
for (auto iter = layoutParameterDic.begin(); iter != layoutParameterDic.end(); ++iter)
|
for (auto iter = layoutParameterDic.begin(); iter != layoutParameterDic.end(); ++iter)
|
||||||
{
|
{
|
||||||
|
|
|
@ -490,7 +490,7 @@ public:
|
||||||
*
|
*
|
||||||
* @return LayoutParameter
|
* @return LayoutParameter
|
||||||
*/
|
*/
|
||||||
LayoutParameter* getLayoutParameter(LayoutParameterType type);
|
LayoutParameter* getLayoutParameter(LayoutParameter::Type type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ignore the widget size
|
* Ignore the widget size
|
||||||
|
|
Loading…
Reference in New Issue