Skip to content

Commit

Permalink
Merge pull request #102 from pec1985/timob-14144-3_1_X
Browse files Browse the repository at this point in the history
backport - [TIMOB-14144] moved defer control rendering flag to not collide with size property
  • Loading branch information
Russ McMahon committed Jun 13, 2013
2 parents 4dace1e + 1c0dbd5 commit ea51882
Show file tree
Hide file tree
Showing 5 changed files with 289 additions and 33 deletions.
34 changes: 26 additions & 8 deletions src/tibb/NativeAbstractTextControlObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,25 @@ int NativeAbstractTextControlObject::setColor(TiObject* obj)

int NativeAbstractTextControlObject::setTextAlign(TiObject* obj)
{
int value;
int error = NativeControlObject::getInteger(obj, &value);
if (error != NATIVE_ERROR_OK)
{
return error;
Handle<Value> value = obj->getValue();
int alignment;

if (!value->IsNumber()) {
QString s = V8ValueToQString(value);
if (s == "left") {
alignment = Ti::UI::TEXT_ALIGNMENT_LEFT;
} else if (s == "center") {
alignment = Ti::UI::TEXT_ALIGNMENT_CENTER;
} else if (s == "right") {
alignment = Ti::UI::TEXT_ALIGNMENT_RIGHT;
} else {
return NATIVE_ERROR_INVALID_ARG;
}
} else {
alignment = value->IntegerValue();
}

switch (value)
switch (alignment)
{
case Ti::UI::TEXT_ALIGNMENT_LEFT:
textControl_->textStyle()->setTextAlign(bb::cascades::TextAlign::Left);
Expand All @@ -95,8 +106,7 @@ int NativeAbstractTextControlObject::setTextAlign(TiObject* obj)
textControl_->textStyle()->setTextAlign(bb::cascades::TextAlign::Right);
break;
default:
N_DEBUG(Native::Msg::Unknown_value_received << ": " << value);
break;
return NATIVE_ERROR_INVALID_ARG;
}

return NATIVE_ERROR_OK;
Expand Down Expand Up @@ -170,3 +180,11 @@ int NativeAbstractTextControlObject::setFont(TiObject* obj)

return NATIVE_ERROR_OK;
}

void NativeAbstractTextControlObject::resize(float width, float height)
{
NativeControlObject::resize(width, height);
textControl_->setPreferredWidth(width);
textControl_->setPreferredHeight(height);
}

2 changes: 2 additions & 0 deletions src/tibb/NativeAbstractTextControlObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class NativeAbstractTextControlObject : public NativeControlObject
virtual int setColor(TiObject* obj);
virtual int setTextAlign(TiObject* obj);

virtual void resize(float width, float height);

protected:
explicit NativeAbstractTextControlObject(TiObject* tiObject, NATIVE_TYPE objType = N_TYPE_UNDEFINED);
virtual ~NativeAbstractTextControlObject();
Expand Down
103 changes: 79 additions & 24 deletions src/tibb/NativeControlObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ static void onPostLayout(struct Node* node)
return;
}

native->resize(width, height);
native->resize(width, height);

bb::cascades::AbsoluteLayoutProperties* layoutProperties = static_cast<bb::cascades::AbsoluteLayoutProperties*>(control->layoutProperties());

Expand All @@ -175,6 +175,10 @@ NativeControlObject::NativeControlObject(TiObject* tiObject, NATIVE_TYPE objType
control_(NULL),
layout_(NULL),
layoutHandler_(0),
deferWidth_(false),
deferHeight_(false),
deferWidthType_((enum ValueType)-1),
deferHeightType_((enum ValueType)-1),
batchUpdating_(false)
{
nodeInitialize(&layoutNode_);
Expand All @@ -192,13 +196,23 @@ NativeControlObject::NativeControlObject(TiObject* tiObject, NATIVE_TYPE objType
layoutNode_.properties.defaultWidthType = Size;
layoutNode_.properties.defaultHeightType = Size;


// in Cascades controls like labels and buttons there is no way to know the size of the control, and
// even if the container is larger then the control the actually control surface is based on the size
// calculated during the Cascades rendering phase, to know the size the os calls back the size during the
// updateLayout() method, the Defer type allows the Titanium layout engine to hold off setting the
// control size and any parents sized to content until rendering is complete
layoutNode_.properties.width.valueType = Defer;
layoutNode_.properties.height.valueType = Defer;
// even if the container is larger then the control the actually control surface is based on the size
// calculated during the Cascades rendering phase, to know the size the os calls back the size during the
// updateLayout() method, the Defer type allows the Titanium layout engine to hold off setting the
// control size and any parents sized to content until rendering is complete
deferWidth_ = true;
deferHeight_ = true;

deferWidthType_ = Size;
deferHeightType_ = Size;

}

if (objType == N_TYPE_LIST_ITEM) {
layoutNode_.properties.width.valueType = Fill;
layoutNode_.properties.height.valueType = Defer;
}

objType_ = objType;
Expand Down Expand Up @@ -235,20 +249,28 @@ void NativeControlObject::updateLayout(QRectF rect)
bool requestLayout = false;
rect_ = rect;

if ((layoutNode_.properties.width.valueType == Defer || layoutNode_.properties.width.valueType == Size) && rect.width() != 0) {
// do not set width if it will be calculated from left and right properties
if (!((layoutNode_.properties.left.valueType == Fixed || layoutNode_.properties.left.valueType == Percent) &&
(layoutNode_.properties.right.valueType == Fixed || layoutNode_.properties.right.valueType == Percent))) {
layoutNode_.properties.width.value = rect.width();
layoutNode_.properties.width.valueType = Fixed;
requestLayout = true;
if (deferWidth_ == true && rect.width() != 0) {
if (deferWidth_ && (layoutNode_.properties.left.valueType == Fixed || layoutNode_.properties.left.valueType == Percent) &&
(layoutNode_.properties.right.valueType == Fixed || layoutNode_.properties.right.valueType == Percent) &&
deferWidthType_ != Size) {
}
else {
control_->setMinWidth(rect.width());
control_->setMaxWidth((float)rect.width());
layoutNode_.properties.width.value = rect.width();
layoutNode_.properties.width.valueType = Fixed;
requestLayout = true;
}
}

if ((layoutNode_.properties.height.valueType == Defer || layoutNode_.properties.height.valueType == Size) && rect.height() != 0) {
// do not set height if it will be calculated from top and bottom properties
if (!((layoutNode_.properties.top.valueType == Fixed || layoutNode_.properties.top.valueType == Percent) &&
(layoutNode_.properties.bottom.valueType == Fixed || layoutNode_.properties.bottom.valueType == Percent))) {
if (deferHeight_ == true && rect.height() != 0) {
if (deferHeight_ && (layoutNode_.properties.top.valueType == Fixed || layoutNode_.properties.top.valueType == Percent) &&
(layoutNode_.properties.bottom.valueType == Fixed || layoutNode_.properties.bottom.valueType == Percent) &&
deferHeightType_ != Size) {
}
else {
control_->setMinHeight((float)rect.height());
control_->setMaxHeight((float)rect.height());
layoutNode_.properties.height.value = rect.height();
layoutNode_.properties.height.valueType = Fixed;
requestLayout = true;
Expand Down Expand Up @@ -292,6 +314,7 @@ void NativeControlObject::setControl(bb::cascades::Control* control)
setContainer(new Container());
}
container_->add(control);

control_ = control;
}

Expand Down Expand Up @@ -323,7 +346,6 @@ void NativeControlObject::setupEvents(TiEventContainerFactory* containerFactory)
FocusChangeEventHandler* blurHandler = new FocusChangeEventHandler(container);
QObject::connect(handler, SIGNAL(blur()), blurHandler, SLOT(focusChanged()));
events_.insert("blur", EventPairSmartPtr(container, blurHandler));

}

int NativeControlObject::addChildNativeObject(NativeObject* obj)
Expand Down Expand Up @@ -463,10 +485,34 @@ int NativeControlObject::finishLayout()
void NativeControlObject::resize(float width, float height)
{
Control* control = static_cast<Control*>(getNativeHandle());
control->setMinWidth(width);
control->setMaxWidth(width);
control->setMinHeight(height);
control->setMaxHeight(height);

if (objType_ == N_TYPE_WINDOW) {
return;
}

if (!deferWidth_) {
control->setMinWidth(width);
control->setMaxWidth(width);
}

if (!deferHeight_) {
control->setMinHeight(height);
control->setMaxHeight(height);
}

if (deferWidth_ && (layoutNode_.properties.left.valueType == Fixed || layoutNode_.properties.left.valueType == Percent) &&
(layoutNode_.properties.right.valueType == Fixed || layoutNode_.properties.right.valueType == Percent) &&
deferWidthType_ != Size) {
control->setMinWidth(width);
control->setMaxWidth(width);
}

if (deferHeight_ && (layoutNode_.properties.top.valueType == Fixed || layoutNode_.properties.top.valueType == Percent) &&
(layoutNode_.properties.bottom.valueType == Fixed || layoutNode_.properties.bottom.valueType == Percent) &&
deferHeightType_ != Size) {
control->setMinHeight(height);
control->setMaxHeight(height);
}
}

void NativeControlObject::updateLayoutProperty(ValueName name, TiObject* val) {
Expand Down Expand Up @@ -623,6 +669,11 @@ int NativeControlObject::setHeight(TiObject* obj)
return NATIVE_ERROR_OK;
}

if (deferHeight_ && str == "UI.SIZE") {
deferHeightType_ = Size;
return NATIVE_ERROR_OK;
}

updateLayoutProperty(Height, obj);

return NATIVE_ERROR_OK;
Expand Down Expand Up @@ -896,13 +947,17 @@ int NativeControlObject::getSize(TiObject* obj)
PROP_SETGET(setWidth)
int NativeControlObject::setWidth(TiObject* obj)
{
// auto uses defaults that have already been set for the control type
string str = *String::Utf8Value(obj->getValue());

if (str == "auto") {
return NATIVE_ERROR_OK;
}

if (deferWidth_ && str == "UI.SIZE") {
deferWidthType_ = Size;
return NATIVE_ERROR_OK;
}

updateLayoutProperty(Width, obj);

return NATIVE_ERROR_OK;
Expand Down
10 changes: 9 additions & 1 deletion src/tibb/NativeControlObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,14 @@ class NativeControlObject : public NativeProxyObject
// Show tab description
virtual int setShowTabsOnActionBar(TiObject* obj);


virtual void animate(NativeObject* obj);
virtual void animate(v8::Local<v8::Object> obj);
virtual void animate(v8::Local<v8::Object> obj, TiV8Event* event);

Node* layout() {
return &layoutNode_;
}

bb::cascades::Container* container_;

protected:
Expand Down Expand Up @@ -230,6 +234,10 @@ class NativeControlObject : public NativeProxyObject
float ppi_; // pixels per inch
int displayWidth_;
int displayHeight_;
bool deferWidth_;
bool deferHeight_;
enum ValueType deferWidthType_;
enum ValueType deferHeightType_;
};

// Event handler for Ti.UI.View
Expand Down

0 comments on commit ea51882

Please sign in to comment.