How to do a setPosition to respect the alignment?

icaromotta

20-09-2011 18:53:17

Hi,

I am having a problem.

When I create a Widget with alignment RIGHT BOTTOM and I set the position to -600, -80, it stay in corner bottom and right.

lista = GRender->getMyGUI()->createWidget<MyGUI::List>("List", -600, -80, 600, 80, MyGUI::Align::Right | MyGUI::Align::Bottom, "Popup");


But, when I do a setPositon(-600, -80), the widget considers than the alignment setted is LEFT TOP.

lista->setPosition(-600, -80);


How to do a setPosition to respect the alignment?


Thanks.

Altren

20-09-2011 20:32:10

No, position is offset from left top, and alignment doesn't affect widget's position until it's parent is resized. In case where you create widget it have same position as in case when you set it manually using setPosition method.

icaromotta

20-09-2011 21:34:27

not really.

Please. Take this test to verify.

zombielei

21-09-2011 08:03:00

Hi,

I am having a problem.

When I create a Widget with alignment RIGHT BOTTOM and I set the position to -600, -80, it stay in corner bottom and right.

lista = GRender->getMyGUI()->createWidget<MyGUI::List>("List", -600, -80, 600, 80, MyGUI::Align::Right | MyGUI::Align::Bottom, "Popup");


But, when I do a setPositon(-600, -80), the widget considers than the alignment setted is LEFT TOP.

lista->setPosition(-600, -80);


How to do a setPosition to respect the alignment?


Thanks.


hi,may be this could explain:
When you create widget,mygui first create it and then set align it.see the following code snipet:

Widget* Widget::baseCreateWidget(WidgetStyle _style, const std::string& _type, const std::string& _skin, const IntCoord& _coord, Align _align, const std::string& _layer, const std::string& _name, bool _template)
{
Widget* widget = nullptr;

if (_template)
{
widget = WidgetManager::getInstance().createWidget(_style, _type, _skin, _coord, this, _style == WidgetStyle::Popup ? nullptr : this, _name);
mWidgetChildSkin.push_back(widget);
}
else
{
if (mWidgetClient != nullptr)
{
widget = mWidgetClient->baseCreateWidget(_style, _type, _skin, _coord, _align, _layer, _name, _template);
onWidgetCreated(widget);
return widget;
}
else
{
widget = WidgetManager::getInstance().createWidget(_style, _type, _skin, _coord, this, _style == WidgetStyle::Popup ? nullptr : this, _name);
mWidgetChild.push_back(widget);
}
}

widget->setAlign(_align);

// присоединяем виджет с уровню
if (!_layer.empty() && widget->isRootWidget())
LayerManager::getInstance().attachToLayerNode(_layer, widget);

onWidgetCreated(widget);

return widget;
}

After your creation complete,when you set the widget position,mygui just set the position,don't process alignment property.See the following code snipet:

void Widget::setPosition(const IntPoint& _point)
{
// обновляем абсолютные координаты
mAbsolutePosition += _point - mCoord.point();

for (VectorWidgetPtr::iterator widget = mWidgetChild.begin(); widget != mWidgetChild.end(); ++widget)
(*widget)->_updateAbsolutePoint();
for (VectorWidgetPtr::iterator widget = mWidgetChildSkin.begin(); widget != mWidgetChildSkin.end(); ++widget)
(*widget)->_updateAbsolutePoint();

mCoord = _point;

_updateView();
}

Altren

21-09-2011 09:04:10

not really.

Please. Take this test to verify.

MyGUI::Gui::getInstance().createWidget<MyGUI::List>("List", 5, 5, 50, 100, MyGUI::Align::Right | MyGUI::Align::Bottom, "Popup");
MyGUI::Gui::getInstance().createWidget<MyGUI::List>("List", 5, 5, 100, 50, MyGUI::Align::Left | MyGUI::Align::Top, "Popup");
See, both widgets are in the left-top corner.
MyGUI never used alignment to place widgets, it always was used only for behaviour during parent widget resizing.

icaromotta

21-09-2011 20:19:18


MyGUI::List *lista;
lista = GRender->getMyGUI()->createWidget<MyGUI::List>("List", -600, -80, 600, 80, MyGUI::Align::Right | MyGUI::Align::Bottom, "Popup");



See in attachment please.

The list is created with -600 and -80.

Altren

21-09-2011 23:12:22

This is not default behaviour, I'll repeat that align doesn't work so. Possible ways how you got this behaviour is either you had window with zero size, then you created widget and then it was resized to proper size, so widget was moved according to it's alignment. Well, another possible reason is that you have modified source, and you have some additional alignment behaviour.