Skip to content
Snippets Groups Projects
Commit 90e27299 authored by Kitty Barnett's avatar Kitty Barnett
Browse files

Autosize the mini emoji helper to fit the number of shown emojis

parent 3acb4caa
No related branches found
No related tags found
No related merge requests found
......@@ -39,12 +39,18 @@ constexpr U32 MIN_MOUSE_MOVE_DELTA = 4;
static LLDefaultChildRegistry::Register<LLPanelEmojiComplete> r("emoji_complete");
LLPanelEmojiComplete::Params::Params()
: selected_image("selected_image")
: autosize("autosize")
, max_emoji("max_emoji")
, padding("padding")
, selected_image("selected_image")
{
}
LLPanelEmojiComplete::LLPanelEmojiComplete(const LLPanelEmojiComplete::Params& p)
: LLUICtrl(p)
, mAutoSize(p.autosize)
, mMaxVisible(p.max_emoji)
, mPadding(p.padding)
, mSelectedImage(p.selected_image)
{
setFont(p.font);
......@@ -125,9 +131,23 @@ void LLPanelEmojiComplete::reshape(S32 width, S32 height, BOOL called_from_paren
void LLPanelEmojiComplete::setEmojiHint(const std::string& hint)
{
llwchar curEmoji = (mCurSelected < mEmojis.size()) ? mEmojis.at(mCurSelected) : 0;
size_t curEmojiIdx = (curEmoji) ? mEmojis.find(curEmoji) : std::string::npos;
mEmojis = LLEmojiDictionary::instance().findMatchingEmojis(hint);
mCurSelected = (std::string::npos != curEmojiIdx) ? curEmojiIdx : 0;
if (mAutoSize)
{
mVisibleEmojis = std::min(mEmojis.size(), mMaxVisible);
reshape(mVisibleEmojis * mEmojiWidth, getRect().getHeight(), false);
}
else
{
updateConstraints();
}
mScrollPos = llmin(mScrollPos, mEmojis.size());
updateConstraints();
}
size_t LLPanelEmojiComplete::posToIndex(S32 x, S32 y) const
......@@ -200,11 +220,34 @@ LLFloaterEmojiComplete::LLFloaterEmojiComplete(const LLSD& sdKey)
setFocusStealsFrontmost(false);
setAutoFocus(false);
setBackgroundVisible(false);
setIsChrome(true);
}
void LLFloaterEmojiComplete::onOpen(const LLSD& key)
{
findChild<LLPanelEmojiComplete>("emoji_complete_ctrl")->setEmojiHint(key["hint"].asString());
mEmojiCtrl->setEmojiHint(key["hint"].asString());
}
BOOL LLFloaterEmojiComplete::postBuild()
{
mEmojiCtrl = findChild<LLPanelEmojiComplete>("emoji_complete_ctrl");
mEmojiCtrlHorz = getRect().getWidth() - mEmojiCtrl->getRect().getWidth();
return TRUE;
}
void LLFloaterEmojiComplete::reshape(S32 width, S32 height, BOOL called_from_parent)
{
if (!called_from_parent)
{
LLRect rctFloater = getRect(), rctCtrl = mEmojiCtrl->getRect();
rctFloater.mRight = rctFloater.mLeft + rctCtrl.getWidth() + mEmojiCtrlHorz;
setRect(rctFloater);
return;
}
LLFloater::reshape(width, height, called_from_parent);
}
// ============================================================================
......@@ -39,6 +39,10 @@ class LLPanelEmojiComplete : public LLUICtrl
public:
struct Params : public LLInitParam::Block<Params, LLUICtrl::Params>
{
Optional<bool> autosize;
Optional<S32> max_emoji,
padding;
Optional<LLUIImage*> selected_image;
Params();
......@@ -68,8 +72,12 @@ class LLPanelEmojiComplete : public LLUICtrl
protected:
static constexpr auto npos = std::numeric_limits<size_t>::max();
bool mAutoSize = false;
const LLFontGL* mFont;
U16 mEmojiWidth = 0;
size_t mMaxVisible = 0;
S32 mPadding = 8;
LLRect mRenderRect;
LLUIImagePtr mSelectedImage;
LLWString mEmojis;
......@@ -78,9 +86,6 @@ class LLPanelEmojiComplete : public LLUICtrl
size_t mScrollPos = 0;
size_t mCurSelected = 0;
LLVector2 mLastHover;
S32 mPadding = 8;
LLRect mRenderRect;
};
// ============================================================================
......@@ -94,6 +99,12 @@ class LLFloaterEmojiComplete : public LLFloater
public:
void onOpen(const LLSD& key) override;
BOOL postBuild() override;
void reshape(S32 width, S32 height, BOOL called_from_parent) override;
protected:
LLPanelEmojiComplete* mEmojiCtrl = nullptr;
S32 mEmojiCtrlHorz = 0;
};
// ============================================================================
......@@ -13,14 +13,16 @@
single_instance="true"
width="240"
>
<emoji_complete
height="30"
follows="top|left"
layout="topleft"
left="5"
top="5"
width="230"
name="emoji_complete_ctrl"
>
</emoji_complete>
<emoji_complete
autosize="true"
height="30"
follows="top|left"
layout="topleft"
left="5"
max_emoji="7"
name="emoji_complete_ctrl"
top="5"
width="230"
>
</emoji_complete>
</floater>
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