Skip to content
Snippets Groups Projects
Commit 1bdae789 authored by Mike Antipov's avatar Mike Antipov
Browse files

Work on low task EXT-3456 (Code Improvements: Improve LLAvatarListItem to...

Work on low task EXT-3456 (Code Improvements: Improve LLAvatarListItem to show/hide its buttons properly)
Initial implementation:
 * implemented common functionality to update Avatar List Item children positions & size (for name) depend on children visibility
 * added its usage whereve visibility of child view is changed
 * removed direct changing of "info button" visibility in Avatar List when Avatar List Item is added

--HG--
branch : product-engine
parent 8be80d14
No related branches found
No related tags found
No related merge requests found
...@@ -323,14 +323,12 @@ boost::signals2::connection LLAvatarList::setRefreshCompleteCallback(const commi ...@@ -323,14 +323,12 @@ boost::signals2::connection LLAvatarList::setRefreshCompleteCallback(const commi
void LLAvatarList::addNewItem(const LLUUID& id, const std::string& name, BOOL is_online, EAddPosition pos) void LLAvatarList::addNewItem(const LLUUID& id, const std::string& name, BOOL is_online, EAddPosition pos)
{ {
LLAvatarListItem* item = new LLAvatarListItem(); LLAvatarListItem* item = new LLAvatarListItem();
item->showInfoBtn(true);
item->showSpeakingIndicator(true); item->showSpeakingIndicator(true);
item->setName(name); item->setName(name);
item->setAvatarId(id, mIgnoreOnlineStatus); item->setAvatarId(id, mIgnoreOnlineStatus);
item->setOnline(mIgnoreOnlineStatus ? true : is_online); item->setOnline(mIgnoreOnlineStatus ? true : is_online);
item->showLastInteractionTime(mShowLastInteractionTime); item->showLastInteractionTime(mShowLastInteractionTime);
item->childSetVisible("info_btn", false);
item->setAvatarIconVisible(mShowIcons); item->setAvatarIconVisible(mShowIcons);
item->setShowInfoBtn(mShowInfoBtn); item->setShowInfoBtn(mShowInfoBtn);
item->setShowProfileBtn(mShowProfileBtn); item->setShowProfileBtn(mShowProfileBtn);
......
...@@ -48,6 +48,10 @@ S32 LLAvatarListItem::sIconWidth = 0; ...@@ -48,6 +48,10 @@ S32 LLAvatarListItem::sIconWidth = 0;
S32 LLAvatarListItem::sInfoBtnWidth = 0; S32 LLAvatarListItem::sInfoBtnWidth = 0;
S32 LLAvatarListItem::sProfileBtnWidth = 0; S32 LLAvatarListItem::sProfileBtnWidth = 0;
S32 LLAvatarListItem::sSpeakingIndicatorWidth = 0; S32 LLAvatarListItem::sSpeakingIndicatorWidth = 0;
S32 LLAvatarListItem::sLeftPadding = 0;
S32 LLAvatarListItem::sRightNamePadding = 0;
S32 LLAvatarListItem::sChildrenWidths[LLAvatarListItem::ALIC_COUNT];
LLAvatarListItem::LLAvatarListItem(bool not_from_ui_factory/* = true*/) LLAvatarListItem::LLAvatarListItem(bool not_from_ui_factory/* = true*/)
: LLPanel(), : LLPanel(),
...@@ -95,10 +99,7 @@ BOOL LLAvatarListItem::postBuild() ...@@ -95,10 +99,7 @@ BOOL LLAvatarListItem::postBuild()
// so that we can hide and show the icon again later. // so that we can hide and show the icon again later.
if (!sStaticInitialized) if (!sStaticInitialized)
{ {
sIconWidth = mAvatarName->getRect().mLeft - mAvatarIcon->getRect().mLeft; initChildrenWidths(this);
sInfoBtnWidth = mInfoBtn->getRect().mRight - mSpeakingIndicator->getRect().mRight;
sProfileBtnWidth = mProfileBtn->getRect().mRight - mInfoBtn->getRect().mRight;
sSpeakingIndicatorWidth = mSpeakingIndicator->getRect().mRight - mAvatarName->getRect().mRight;
sStaticInitialized = true; sStaticInitialized = true;
} }
...@@ -137,6 +138,8 @@ void LLAvatarListItem::onMouseEnter(S32 x, S32 y, MASK mask) ...@@ -137,6 +138,8 @@ void LLAvatarListItem::onMouseEnter(S32 x, S32 y, MASK mask)
mProfileBtn->setVisible(mShowProfileBtn); mProfileBtn->setVisible(mShowProfileBtn);
LLPanel::onMouseEnter(x, y, mask); LLPanel::onMouseEnter(x, y, mask);
updateChildren();
} }
void LLAvatarListItem::onMouseLeave(S32 x, S32 y, MASK mask) void LLAvatarListItem::onMouseLeave(S32 x, S32 y, MASK mask)
...@@ -146,6 +149,8 @@ void LLAvatarListItem::onMouseLeave(S32 x, S32 y, MASK mask) ...@@ -146,6 +149,8 @@ void LLAvatarListItem::onMouseLeave(S32 x, S32 y, MASK mask)
mProfileBtn->setVisible(false); mProfileBtn->setVisible(false);
LLPanel::onMouseLeave(x, y, mask); LLPanel::onMouseLeave(x, y, mask);
updateChildren();
} }
// virtual, called by LLAvatarTracker // virtual, called by LLAvatarTracker
...@@ -215,12 +220,8 @@ void LLAvatarListItem::showLastInteractionTime(bool show) ...@@ -215,12 +220,8 @@ void LLAvatarListItem::showLastInteractionTime(bool show)
if (show) if (show)
return; return;
LLRect name_rect = mAvatarName->getRect();
LLRect time_rect = mLastInteractionTime->getRect();
mLastInteractionTime->setVisible(false); mLastInteractionTime->setVisible(false);
name_rect.mRight += (time_rect.mRight - name_rect.mRight); updateChildren();
mAvatarName->setRect(name_rect);
} }
void LLAvatarListItem::setLastInteractionTime(U32 secs_since) void LLAvatarListItem::setLastInteractionTime(U32 secs_since)
...@@ -234,12 +235,6 @@ void LLAvatarListItem::setShowInfoBtn(bool show) ...@@ -234,12 +235,6 @@ void LLAvatarListItem::setShowInfoBtn(bool show)
if(mShowInfoBtn == show) if(mShowInfoBtn == show)
return; return;
mShowInfoBtn = show; mShowInfoBtn = show;
S32 width_delta = show ? - sInfoBtnWidth : sInfoBtnWidth;
//Translating speaking indicator
mSpeakingIndicator->translate(width_delta, 0);
//Reshaping avatar name
mAvatarName->reshape(mAvatarName->getRect().getWidth() + width_delta, mAvatarName->getRect().getHeight());
} }
void LLAvatarListItem::setShowProfileBtn(bool show) void LLAvatarListItem::setShowProfileBtn(bool show)
...@@ -248,12 +243,6 @@ void LLAvatarListItem::setShowProfileBtn(bool show) ...@@ -248,12 +243,6 @@ void LLAvatarListItem::setShowProfileBtn(bool show)
if(mShowProfileBtn == show) if(mShowProfileBtn == show)
return; return;
mShowProfileBtn = show; mShowProfileBtn = show;
S32 width_delta = show ? - sProfileBtnWidth : sProfileBtnWidth;
//Translating speaking indicator
mSpeakingIndicator->translate(width_delta, 0);
//Reshaping avatar name
mAvatarName->reshape(mAvatarName->getRect().getWidth() + width_delta, mAvatarName->getRect().getHeight());
} }
void LLAvatarListItem::setSpeakingIndicatorVisible(bool visible) void LLAvatarListItem::setSpeakingIndicatorVisible(bool visible)
...@@ -262,10 +251,7 @@ void LLAvatarListItem::setSpeakingIndicatorVisible(bool visible) ...@@ -262,10 +251,7 @@ void LLAvatarListItem::setSpeakingIndicatorVisible(bool visible)
if (mSpeakingIndicator->getVisible() == (BOOL)visible) if (mSpeakingIndicator->getVisible() == (BOOL)visible)
return; return;
mSpeakingIndicator->setVisible(visible); mSpeakingIndicator->setVisible(visible);
S32 width_delta = visible ? - sSpeakingIndicatorWidth : sSpeakingIndicatorWidth; updateChildren();
//Reshaping avatar name
mAvatarName->reshape(mAvatarName->getRect().getWidth() + width_delta, mAvatarName->getRect().getHeight());
} }
void LLAvatarListItem::setAvatarIconVisible(bool visible) void LLAvatarListItem::setAvatarIconVisible(bool visible)
...@@ -276,11 +262,7 @@ void LLAvatarListItem::setAvatarIconVisible(bool visible) ...@@ -276,11 +262,7 @@ void LLAvatarListItem::setAvatarIconVisible(bool visible)
// Show/hide avatar icon. // Show/hide avatar icon.
mAvatarIcon->setVisible(visible); mAvatarIcon->setVisible(visible);
updateChildren();
// Move the avatar name horizontally by icon size + its distance from the avatar name.
LLRect name_rect = mAvatarName->getRect();
name_rect.mLeft += visible ? sIconWidth : -sIconWidth;
mAvatarName->setRect(name_rect);
} }
void LLAvatarListItem::onInfoBtnClick() void LLAvatarListItem::onInfoBtnClick()
...@@ -346,6 +328,7 @@ void LLAvatarListItem::onNameCache(const std::string& first_name, const std::str ...@@ -346,6 +328,7 @@ void LLAvatarListItem::onNameCache(const std::string& first_name, const std::str
void LLAvatarListItem::reshapeAvatarName() void LLAvatarListItem::reshapeAvatarName()
{ {
/*
S32 width_delta = 0; S32 width_delta = 0;
width_delta += mShowProfileBtn ? sProfileBtnWidth : 0; width_delta += mShowProfileBtn ? sProfileBtnWidth : 0;
width_delta += mSpeakingIndicator->getVisible() ? sSpeakingIndicatorWidth : 0; width_delta += mSpeakingIndicator->getVisible() ? sSpeakingIndicatorWidth : 0;
...@@ -357,6 +340,7 @@ void LLAvatarListItem::reshapeAvatarName() ...@@ -357,6 +340,7 @@ void LLAvatarListItem::reshapeAvatarName()
S32 width = getRect().getWidth() - width_delta; S32 width = getRect().getWidth() - width_delta;
mAvatarName->reshape(width, height); mAvatarName->reshape(width, height);
*/
} }
// Convert given number of seconds to a string like "23 minutes", "15 hours" or "3 years", // Convert given number of seconds to a string like "23 minutes", "15 hours" or "3 years",
...@@ -492,4 +476,133 @@ LLAvatarListItem::icon_color_map_t& LLAvatarListItem::getItemIconColorMap() ...@@ -492,4 +476,133 @@ LLAvatarListItem::icon_color_map_t& LLAvatarListItem::getItemIconColorMap()
return item_icon_color_map; return item_icon_color_map;
} }
// static
void LLAvatarListItem::initChildrenWidths(LLAvatarListItem* avatar_item)
{
//profile btn width + padding
S32 profile_btn_width = avatar_item->getRect().getWidth() - avatar_item->mProfileBtn->getRect().mLeft;
//info btn width + padding
S32 info_btn_width = avatar_item->mProfileBtn->getRect().mLeft - avatar_item->mInfoBtn->getRect().mLeft;
//speaking indicator width + padding
S32 speaking_indicator_width = avatar_item->mInfoBtn->getRect().mLeft - avatar_item->mSpeakingIndicator->getRect().mLeft;
// last interaction time textbox width + padding
S32 last_interaction_time_width = avatar_item->mSpeakingIndicator->getRect().mLeft - avatar_item->mLastInteractionTime->getRect().mLeft;
// icon width + padding
S32 icon_width = avatar_item->mAvatarName->getRect().mLeft - avatar_item->mAvatarIcon->getRect().mLeft;
sLeftPadding = avatar_item->mAvatarIcon->getRect().mLeft;
sRightNamePadding = avatar_item->mLastInteractionTime->getRect().mLeft - avatar_item->mAvatarName->getRect().mRight;
S32 index = ALIC_COUNT;
sChildrenWidths[--index] = icon_width;
sChildrenWidths[--index] = 0; // for avatar name we don't need its width, it will be calculated as "left available space"
sChildrenWidths[--index] = last_interaction_time_width;
sChildrenWidths[--index] = speaking_indicator_width;
sChildrenWidths[--index] = info_btn_width;
sChildrenWidths[--index] = profile_btn_width;
}
void LLAvatarListItem::updateChildren()
{
LL_DEBUGS("AvatarItemReshape") << LL_ENDL;
LL_DEBUGS("AvatarItemReshape") << "Updating for: " << getAvatarName() << LL_ENDL;
S32 name_new_width = getRect().getWidth();
S32 ctrl_new_left = name_new_width;
S32 name_new_left = sLeftPadding;
// iterate through all children and set them into correct position depend on each child visibility
// assume that child indexes are in back order: the first in Enum is the last (right) in the item
// iterate & set child views starting from right to left
for (S32 i = 0; i < ALIC_COUNT; ++i)
{
// skip "name" textbox, it will be processed out of loop later
if (ALIC_NAME == i) continue;
LLView* control = getItemChildView((EAvatarListItemChildIndex)i);
LL_DEBUGS("AvatarItemReshape") << "Processing control: " << control->getName() << LL_ENDL;
// skip invisible views
if (!control->getVisible()) continue;
S32 ctrl_width = sChildrenWidths[i]; // including space between current & left controls
// decrease available for
name_new_width -= ctrl_width;
LL_DEBUGS("AvatarItemReshape") << "width: " << ctrl_width << ", name_new_width: " << name_new_width << LL_ENDL;
LLRect control_rect = control->getRect();
LL_DEBUGS("AvatarItemReshape") << "rect before: " << control_rect << LL_ENDL;
if (ALIC_ICON == i)
{
// assume that this is the last iteration,
// so it is not necessary to save "ctrl_new_left" value calculated on previous iterations
ctrl_new_left = sLeftPadding;//control_rect.mLeft;
name_new_left = ctrl_new_left + ctrl_width;
}
else
{
ctrl_new_left -= ctrl_width;
}
LL_DEBUGS("AvatarItemReshape") << "ctrl_new_left: " << ctrl_new_left << LL_ENDL;
control_rect.setLeftTopAndSize(
ctrl_new_left,
control_rect.mTop,
control_rect.getWidth(),
control_rect.getHeight());
LL_DEBUGS("AvatarItemReshape") << "rect after: " << control_rect << LL_ENDL;
control->setShape(control_rect);
}
// set size and position of the "name" child
LLView* name_view = getItemChildView(ALIC_NAME);
LLRect name_view_rect = name_view->getRect();
LL_DEBUGS("AvatarItemReshape") << "name rect before: " << name_view_rect << LL_ENDL;
// apply paddings
name_new_width -= sLeftPadding;
name_new_width -= sRightNamePadding;
name_view_rect.setLeftTopAndSize(
name_new_left,
name_view_rect.mTop,
name_new_width,
name_view_rect.getHeight());
name_view->setShape(name_view_rect);
LL_DEBUGS("AvatarItemReshape") << "name rect after: " << name_view_rect << LL_ENDL;
}
LLView* LLAvatarListItem::getItemChildView(EAvatarListItemChildIndex child_view_index)
{
LLView* child_view = mAvatarName;
if (child_view_index < 0 || ALIC_COUNT <= child_view_index)
{
LL_WARNS("AvatarItemReshape") << "Child view index is out of range: " << child_view_index << LL_ENDL;
return child_view;
}
switch (child_view_index)
{
case ALIC_ICON: child_view = mAvatarIcon; break;
case ALIC_NAME: child_view = mAvatarName; break;
case ALIC_INTERACTION_TIME: child_view = mLastInteractionTime; break;
case ALIC_SPEAKER_INDICATOR: child_view = mSpeakingIndicator; break;
case ALIC_INFO_BUTTON: child_view = mInfoBtn; break;
case ALIC_PROFILE_BUTTON: child_view = mProfileBtn; break;
default:
LL_WARNS("AvatarItemReshape") << "Unexpected child view index is passed: " << child_view_index << LL_ENDL;
}
return child_view;
}
// EOF // EOF
...@@ -98,7 +98,6 @@ class LLAvatarListItem : public LLPanel, public LLFriendObserver ...@@ -98,7 +98,6 @@ class LLAvatarListItem : public LLPanel, public LLFriendObserver
void onProfileBtnClick(); void onProfileBtnClick();
void showSpeakingIndicator(bool show) { mSpeakingIndicator->setVisible(show); } void showSpeakingIndicator(bool show) { mSpeakingIndicator->setVisible(show); }
void showInfoBtn(bool show_info_btn) {mInfoBtn->setVisible(show_info_btn); }
void showLastInteractionTime(bool show); void showLastInteractionTime(bool show);
/** /**
...@@ -124,6 +123,23 @@ class LLAvatarListItem : public LLPanel, public LLFriendObserver ...@@ -124,6 +123,23 @@ class LLAvatarListItem : public LLPanel, public LLFriendObserver
E_UNKNOWN, E_UNKNOWN,
} EOnlineStatus; } EOnlineStatus;
/**
* Enumeration of item elements in order from right to left.
*
* updateChildren() assumes that indexes are in the such order to process avatar icon easier.
*
* @see updateChildren()
*/
typedef enum e_avatar_item_child {
ALIC_PROFILE_BUTTON,
ALIC_INFO_BUTTON,
ALIC_SPEAKER_INDICATOR,
ALIC_INTERACTION_TIME,
ALIC_NAME,
ALIC_ICON,
ALIC_COUNT,
} EAvatarListItemChildIndex;
void setNameInternal(const std::string& name, const std::string& highlight); void setNameInternal(const std::string& name, const std::string& highlight);
void onNameCache(const std::string& first_name, const std::string& last_name); void onNameCache(const std::string& first_name, const std::string& last_name);
...@@ -135,6 +151,26 @@ class LLAvatarListItem : public LLPanel, public LLFriendObserver ...@@ -135,6 +151,26 @@ class LLAvatarListItem : public LLPanel, public LLFriendObserver
typedef std::map<EItemState, LLColor4> icon_color_map_t; typedef std::map<EItemState, LLColor4> icon_color_map_t;
static icon_color_map_t& getItemIconColorMap(); static icon_color_map_t& getItemIconColorMap();
/**
* Initializes widths of all children to use them while changing visibility of any of them.
*
* @see updateChildren()
*/
static void initChildrenWidths(LLAvatarListItem* self);
/**
* Updates position and rectangle of visible children to fit all available item's width.
*/
void updateChildren();
/**
* Gets child view specified by index.
*
* This method implemented via switch by all EAvatarListItemChildIndex values.
* It is used to not store children in array or vector to avoid of increasing memory usage.
*/
LLView* getItemChildView(EAvatarListItemChildIndex child_index);
LLTextBox* mAvatarName; LLTextBox* mAvatarName;
LLTextBox* mLastInteractionTime; LLTextBox* mLastInteractionTime;
LLStyle::Params mAvatarNameStyle; LLStyle::Params mAvatarNameStyle;
...@@ -155,6 +191,17 @@ class LLAvatarListItem : public LLPanel, public LLFriendObserver ...@@ -155,6 +191,17 @@ class LLAvatarListItem : public LLPanel, public LLFriendObserver
static S32 sInfoBtnWidth; //info btn width + padding static S32 sInfoBtnWidth; //info btn width + padding
static S32 sProfileBtnWidth; //profile btn width + padding static S32 sProfileBtnWidth; //profile btn width + padding
static S32 sSpeakingIndicatorWidth; //speaking indicator width + padding static S32 sSpeakingIndicatorWidth; //speaking indicator width + padding
static S32 sLeftPadding; // padding to first left visible child (icon or name)
static S32 sRightNamePadding; // right padding from name to next visible child
/**
* Contains widths of each child specified by EAvatarListItemChildIndex
* including padding to the next right one.
*
* @see initChildrenWidths()
*/
static S32 sChildrenWidths[ALIC_COUNT];
}; };
#endif //LL_LLAVATARLISTITEM_H #endif //LL_LLAVATARLISTITEM_H
...@@ -58,13 +58,13 @@ ...@@ -58,13 +58,13 @@
top="6" top="6"
use_ellipses="true" use_ellipses="true"
value="Unknown" value="Unknown"
width="182" /> width="180" />
<text <text
follows="right" follows="right"
font="SansSerifSmall" font="SansSerifSmall"
height="15" height="15"
layout="topleft" layout="topleft"
left_pad="8" left_pad="5"
name="last_interaction" name="last_interaction"
text_color="LtGray_50" text_color="LtGray_50"
value="0s" value="0s"
...@@ -75,7 +75,7 @@ ...@@ -75,7 +75,7 @@
draw_border="false" draw_border="false"
height="16" height="16"
layout="topleft" layout="topleft"
left_pad="0" left_pad="5"
mouse_opaque="true" mouse_opaque="true"
name="speaking_indicator" name="speaking_indicator"
visible="true" visible="true"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment