Derive LLScrollColumnHeader from a button
Fixes the issue with single-click sorting not working Fixes internal issue with initial column header names being used as their labels
This commit is contained in:
@@ -39,23 +39,22 @@ const S32 MIN_COLUMN_WIDTH = 20;
|
|||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
// LLScrollColumnHeader
|
// LLScrollColumnHeader
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
LLScrollColumnHeader::LLScrollColumnHeader(const std::string& label, const LLRect& rect, LLScrollListColumn* column, const LLFontGL* fontp)
|
LLScrollColumnHeader::LLScrollColumnHeader(const std::string& name, const LLRect& rect, LLScrollListColumn* column)
|
||||||
: LLComboBox(label, rect, label),
|
: LLButton("", rect),
|
||||||
mColumn(column),
|
mColumn(column),
|
||||||
mOrigLabel(label),
|
|
||||||
mHasResizableElement(FALSE)
|
mHasResizableElement(FALSE)
|
||||||
{
|
{
|
||||||
mListPosition = LLComboBox::ABOVE;
|
setClickedCallback(boost::bind(&LLScrollColumnHeader::onClick, this, _2));
|
||||||
setCommitCallback(boost::bind(&LLScrollColumnHeader::onSelectSort, this));
|
setName(name); // Singu Note: Passing this to LLButton set the label, too, which we don't want in the case of column headers with images.
|
||||||
mButton->setTabStop(FALSE);
|
// Set base images for column header button
|
||||||
mButton->setClickedCallback(boost::bind(&LLScrollColumnHeader::onClick, this, _2));
|
{
|
||||||
|
LLPointer<LLUIImage> selected = LLUI::getUIImage("square_btn_selected_32x128.tga");
|
||||||
mButton->setToolTip(label);
|
LLPointer<LLUIImage> unselected = LLUI::getUIImage("square_btn_32x128.tga");
|
||||||
|
setImageUnselected(unselected);
|
||||||
mAscendingText = std::string("[LOW]...[HIGH](Ascending)"); // *TODO: Translate
|
setImageSelected(selected);
|
||||||
mDescendingText = std::string("[HIGH]...[LOW](Descending)"); // *TODO: Translate
|
setImageDisabled(unselected);
|
||||||
|
setImageDisabledSelected(selected);
|
||||||
mList->reshape(llmax(mList->getRect().getWidth(), 110, getRect().getWidth()), mList->getRect().getHeight());
|
}
|
||||||
|
|
||||||
// resize handles on left and right
|
// resize handles on left and right
|
||||||
const S32 RESIZE_BAR_THICKNESS = 3;
|
const S32 RESIZE_BAR_THICKNESS = 3;
|
||||||
@@ -67,9 +66,6 @@ LLScrollColumnHeader::LLScrollColumnHeader(const std::string& label, const LLRec
|
|||||||
resize_bar_p.enabled(false);
|
resize_bar_p.enabled(false);
|
||||||
mResizeBar = LLUICtrlFactory::create<LLResizeBar>(resize_bar_p);
|
mResizeBar = LLUICtrlFactory::create<LLResizeBar>(resize_bar_p);
|
||||||
addChild(mResizeBar);
|
addChild(mResizeBar);
|
||||||
|
|
||||||
mImageOverlayAlignment = LLFontGL::HCENTER;
|
|
||||||
mImageOverlayColor = LLColor4::white;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LLScrollColumnHeader::~LLScrollColumnHeader()
|
LLScrollColumnHeader::~LLScrollColumnHeader()
|
||||||
@@ -86,111 +82,15 @@ void LLScrollColumnHeader::draw()
|
|||||||
BOOL is_ascending = mColumn->mParentCtrl->getSortAscending();
|
BOOL is_ascending = mColumn->mParentCtrl->getSortAscending();
|
||||||
if (draw_arrow)
|
if (draw_arrow)
|
||||||
{
|
{
|
||||||
mButton->setImageOverlay(is_ascending ? "up_arrow.tga" : "down_arrow.tga", LLFontGL::RIGHT, LLColor4::white);
|
setImageOverlay(is_ascending ? "up_arrow.tga" : "down_arrow.tga", LLFontGL::RIGHT, LLColor4::white);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mButton->setImageOverlay(LLUUID::null);
|
setImageOverlay(LLUUID::null);
|
||||||
}
|
}
|
||||||
mArrowImage = mButton->getImageOverlay();
|
|
||||||
|
|
||||||
// Draw children
|
// Draw children
|
||||||
LLComboBox::draw();
|
LLButton::draw();
|
||||||
|
|
||||||
if (mImageOverlay.notNull()) //Ugly dupe code from llbutton...
|
|
||||||
{
|
|
||||||
BOOL pressed_by_keyboard = FALSE;
|
|
||||||
if (mButton->hasFocus())
|
|
||||||
{
|
|
||||||
pressed_by_keyboard = gKeyboard->getKeyDown(' ') || (mButton->getCommitOnReturn() && gKeyboard->getKeyDown(KEY_RETURN));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unselected image assignments
|
|
||||||
S32 local_mouse_x;
|
|
||||||
S32 local_mouse_y;
|
|
||||||
LLUI::getMousePositionLocal(mButton, &local_mouse_x, &local_mouse_y);
|
|
||||||
|
|
||||||
BOOL pressed = pressed_by_keyboard
|
|
||||||
|| (mButton->hasMouseCapture() && mButton->pointInView(local_mouse_x, local_mouse_y))
|
|
||||||
|| mButton->getToggleState();
|
|
||||||
|
|
||||||
// Now draw special overlay..
|
|
||||||
// let overlay image and text play well together
|
|
||||||
S32 button_width = mButton->getRect().getWidth();
|
|
||||||
S32 button_height = mButton->getRect().getHeight();
|
|
||||||
S32 text_left = mButton->getLeftHPad();
|
|
||||||
S32 text_right = button_width - mButton->getRightHPad();
|
|
||||||
S32 text_width = text_right - text_left;
|
|
||||||
|
|
||||||
// draw overlay image
|
|
||||||
|
|
||||||
// get max width and height (discard level 0)
|
|
||||||
S32 overlay_width = mImageOverlay->getWidth();
|
|
||||||
S32 overlay_height = mImageOverlay->getHeight();
|
|
||||||
|
|
||||||
F32 scale_factor = llmin((F32)button_width / (F32)overlay_width, (F32)button_height / (F32)overlay_height, 1.f);
|
|
||||||
overlay_width = llround((F32)overlay_width * scale_factor);
|
|
||||||
overlay_height = llround((F32)overlay_height * scale_factor);
|
|
||||||
|
|
||||||
S32 center_x = mButton->getLocalRect().getCenterX();
|
|
||||||
S32 center_y = mButton->getLocalRect().getCenterY();
|
|
||||||
|
|
||||||
//FUGLY HACK FOR "DEPRESSED" BUTTONS
|
|
||||||
if (pressed)
|
|
||||||
{
|
|
||||||
center_y--;
|
|
||||||
center_x++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// fade out overlay images on disabled buttons
|
|
||||||
LLColor4 overlay_color = mImageOverlayColor;
|
|
||||||
if (!mButton->getEnabled())
|
|
||||||
{
|
|
||||||
overlay_color.mV[VALPHA] = 0.5f;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch(mImageOverlayAlignment)
|
|
||||||
{
|
|
||||||
case LLFontGL::LEFT:
|
|
||||||
text_left += overlay_width + 1;
|
|
||||||
text_width -= overlay_width + 1;
|
|
||||||
mImageOverlay->draw(
|
|
||||||
text_left,
|
|
||||||
center_y - (overlay_height / 2),
|
|
||||||
overlay_width,
|
|
||||||
overlay_height,
|
|
||||||
overlay_color);
|
|
||||||
break;
|
|
||||||
case LLFontGL::HCENTER:
|
|
||||||
mImageOverlay->draw(
|
|
||||||
center_x - (overlay_width / 2),
|
|
||||||
center_y - (overlay_height / 2),
|
|
||||||
overlay_width,
|
|
||||||
overlay_height,
|
|
||||||
overlay_color);
|
|
||||||
break;
|
|
||||||
case LLFontGL::RIGHT:
|
|
||||||
text_right -= overlay_width + 1;
|
|
||||||
text_width -= overlay_width + 1;
|
|
||||||
mImageOverlay->draw(
|
|
||||||
text_right - overlay_width,
|
|
||||||
center_y - (overlay_height / 2),
|
|
||||||
overlay_width,
|
|
||||||
overlay_height,
|
|
||||||
overlay_color);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
// draw nothing
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (mList->getVisible())
|
|
||||||
{
|
|
||||||
// sync sort order with list selection every frame
|
|
||||||
mColumn->mParentCtrl->sortByColumn(mColumn->mSortingColumn, getCurrentIndex() == 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL LLScrollColumnHeader::handleDoubleClick(S32 x, S32 y, MASK mask)
|
BOOL LLScrollColumnHeader::handleDoubleClick(S32 x, S32 y, MASK mask)
|
||||||
@@ -210,53 +110,14 @@ BOOL LLScrollColumnHeader::handleDoubleClick(S32 x, S32 y, MASK mask)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LLScrollColumnHeader::setImage(const std::string& image_name)
|
|
||||||
{
|
|
||||||
if (mButton)
|
|
||||||
{
|
|
||||||
mButton->setImageSelected(LLUI::getUIImage(image_name));
|
|
||||||
mButton->setImageUnselected(LLUI::getUIImage(image_name));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void LLScrollColumnHeader::setImageOverlay(const std::string& image_name, LLFontGL::HAlign alignment, const LLColor4& color)
|
|
||||||
{
|
|
||||||
if (image_name.empty())
|
|
||||||
{
|
|
||||||
mImageOverlay = NULL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mImageOverlay = LLUI::getUIImage(image_name);
|
|
||||||
mImageOverlayAlignment = alignment;
|
|
||||||
mImageOverlayColor = color;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void LLScrollColumnHeader::onClick(const LLSD& data)
|
void LLScrollColumnHeader::onClick(const LLSD& data)
|
||||||
{
|
{
|
||||||
if (mColumn)
|
if (mColumn)
|
||||||
{
|
{
|
||||||
if (mList->getVisible()) hideList();
|
|
||||||
LLScrollListCtrl::onClickColumn(mColumn);
|
LLScrollListCtrl::onClickColumn(mColumn);
|
||||||
|
|
||||||
// propagate new sort order to sort order list
|
|
||||||
mList->selectNthItem(mColumn->mParentCtrl->getSortAscending() ? 0 : 1);
|
|
||||||
mList->setFocus(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LLScrollColumnHeader::onSelectSort()
|
|
||||||
{
|
|
||||||
if (!mColumn) return;
|
|
||||||
LLScrollListCtrl* parent = mColumn->mParentCtrl;
|
|
||||||
if (!parent) return;
|
|
||||||
parent->sortByColumn(mColumn->mSortingColumn, getCurrentIndex() == 0);
|
|
||||||
|
|
||||||
// restore original column header
|
|
||||||
setLabel(mOrigLabel);
|
|
||||||
}
|
|
||||||
|
|
||||||
LLView* LLScrollColumnHeader::findSnapEdge(S32& new_edge_val, const LLCoordGL& mouse_dir, ESnapEdge snap_edge, ESnapType snap_type, S32 threshold, S32 padding)
|
LLView* LLScrollColumnHeader::findSnapEdge(S32& new_edge_val, const LLCoordGL& mouse_dir, ESnapEdge snap_edge, ESnapType snap_type, S32 threshold, S32 padding)
|
||||||
{
|
{
|
||||||
// this logic assumes dragging on right
|
// this logic assumes dragging on right
|
||||||
|
|||||||
@@ -30,48 +30,36 @@
|
|||||||
|
|
||||||
#include "llrect.h"
|
#include "llrect.h"
|
||||||
#include "lluistring.h"
|
#include "lluistring.h"
|
||||||
#include "llcombobox.h"
|
#include "llbutton.h"
|
||||||
|
|
||||||
class LLScrollListColumn;
|
class LLScrollListColumn;
|
||||||
class LLResizeBar;
|
class LLResizeBar;
|
||||||
class LLScrollListCtrl;
|
class LLScrollListCtrl;
|
||||||
|
|
||||||
class LLScrollColumnHeader : public LLComboBox
|
class LLScrollColumnHeader : public LLButton
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LLScrollColumnHeader(const std::string& label, const LLRect& rect, LLScrollListColumn* column, const LLFontGL* font = NULL);
|
LLScrollColumnHeader(const std::string& name, const LLRect& rect, LLScrollListColumn* column);
|
||||||
~LLScrollColumnHeader();
|
~LLScrollColumnHeader();
|
||||||
|
|
||||||
/*virtual*/ void draw();
|
/*virtual*/ void draw();
|
||||||
/*virtual*/ BOOL handleDoubleClick(S32 x, S32 y, MASK mask);
|
/*virtual*/ BOOL handleDoubleClick(S32 x, S32 y, MASK mask);
|
||||||
|
|
||||||
/*virtual*/ void showList() {}; // block the normal showList() behavior
|
|
||||||
/*virtual*/ LLView* findSnapEdge(S32& new_edge_val, const LLCoordGL& mouse_dir, ESnapEdge snap_edge, ESnapType snap_type, S32 threshold, S32 padding);
|
/*virtual*/ LLView* findSnapEdge(S32& new_edge_val, const LLCoordGL& mouse_dir, ESnapEdge snap_edge, ESnapType snap_type, S32 threshold, S32 padding);
|
||||||
/*virtual*/ void handleReshape(const LLRect& new_rect, bool by_user = false);
|
/*virtual*/ void handleReshape(const LLRect& new_rect, bool by_user = false);
|
||||||
|
|
||||||
void setImage(const std::string& image_name);
|
|
||||||
void setImageOverlay(const std::string& overlay_image, LLFontGL::HAlign alignment = LLFontGL::HCENTER, const LLColor4& color = LLColor4::white);
|
|
||||||
LLScrollListColumn* getColumn() { return mColumn; }
|
LLScrollListColumn* getColumn() { return mColumn; }
|
||||||
void setHasResizableElement(BOOL resizable);
|
void setHasResizableElement(BOOL resizable);
|
||||||
void updateResizeBars();
|
void updateResizeBars();
|
||||||
BOOL canResize();
|
BOOL canResize();
|
||||||
void enableResizeBar(BOOL enable);
|
void enableResizeBar(BOOL enable);
|
||||||
std::string getLabel() { return mOrigLabel; }
|
|
||||||
|
|
||||||
void onSelectSort();
|
|
||||||
void onClick(const LLSD& data);
|
void onClick(const LLSD& data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LLScrollListColumn* mColumn;
|
LLScrollListColumn* mColumn;
|
||||||
LLResizeBar* mResizeBar;
|
LLResizeBar* mResizeBar;
|
||||||
std::string mOrigLabel;
|
|
||||||
LLUIString mAscendingText;
|
|
||||||
LLUIString mDescendingText;
|
|
||||||
BOOL mHasResizableElement;
|
BOOL mHasResizableElement;
|
||||||
|
|
||||||
LLPointer<LLUIImage> mImageOverlay;
|
|
||||||
LLFontGL::HAlign mImageOverlayAlignment;
|
|
||||||
LLColor4 mImageOverlayColor;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -2853,7 +2853,7 @@ void LLScrollListCtrl::addColumn(const LLSD& column, EAddPosition pos)
|
|||||||
|
|
||||||
if(!column["image"].asString().empty())
|
if(!column["image"].asString().empty())
|
||||||
{
|
{
|
||||||
new_column->mHeader->setImage(column["image"].asString());
|
new_column->mHeader->setImages(column["image"].asString(), column["image"].asString());
|
||||||
}
|
}
|
||||||
else if(!column["image_overlay"].asString().empty())
|
else if(!column["image_overlay"].asString().empty())
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user