mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-02 11:59:58 +00:00
Show a DitheringSelector item in the combobox when it's closed
In this way we can show listbox/custom items in the combobox when we select an item instead of showing text-only (the ui::Entry).
This commit is contained in:
parent
bcdf598392
commit
523b6a0a51
@ -114,6 +114,8 @@ private:
|
||||
|
||||
DitheringSelector::DitheringSelector()
|
||||
{
|
||||
setUseCustomWidget(true);
|
||||
|
||||
addItem(new DitherItem(render::DitheringAlgorithm::None,
|
||||
render::DitheringMatrix(), "No Dithering"));
|
||||
addItem(new DitherItem(render::DitheringAlgorithm::Ordered,
|
||||
|
@ -56,8 +56,11 @@ class ComboBoxListBox : public ListBox {
|
||||
public:
|
||||
ComboBoxListBox(ComboBox* comboBox)
|
||||
: m_comboBox(comboBox) {
|
||||
for (auto it=comboBox->begin(), end=comboBox->end(); it!=end; ++it)
|
||||
addChild(*it);
|
||||
for (auto item : *comboBox) {
|
||||
if (item->parent())
|
||||
item->parent()->removeChild(item);
|
||||
addChild(item);
|
||||
}
|
||||
}
|
||||
|
||||
void clean() {
|
||||
@ -88,6 +91,8 @@ ComboBox::ComboBox()
|
||||
, m_editable(false)
|
||||
, m_clickopen(true)
|
||||
, m_casesensitive(true)
|
||||
, m_filtering(false)
|
||||
, m_useCustomWidget(false)
|
||||
{
|
||||
// TODO this separation should be from the Theme*
|
||||
this->setChildSpacing(0);
|
||||
@ -108,6 +113,7 @@ ComboBox::ComboBox()
|
||||
|
||||
ComboBox::~ComboBox()
|
||||
{
|
||||
removeMessageFilters();
|
||||
removeAllItems();
|
||||
}
|
||||
|
||||
@ -135,6 +141,11 @@ void ComboBox::setCaseSensitive(bool state)
|
||||
m_casesensitive = state;
|
||||
}
|
||||
|
||||
void ComboBox::setUseCustomWidget(bool state)
|
||||
{
|
||||
m_useCustomWidget = state;
|
||||
}
|
||||
|
||||
int ComboBox::addItem(ListItem* item)
|
||||
{
|
||||
bool sel_first = m_items.empty();
|
||||
@ -398,6 +409,8 @@ void ComboBox::onResize(ResizeEvent& ev)
|
||||
// Entry
|
||||
m_entry->setBounds(Rect(bounds.x, bounds.y,
|
||||
bounds.w - buttonSize.w, bounds.h));
|
||||
|
||||
putSelectedItemAsCustomWidget();
|
||||
}
|
||||
|
||||
void ComboBox::onSizeHint(SizeHintEvent& ev)
|
||||
@ -609,8 +622,7 @@ void ComboBox::openListBox()
|
||||
m_window->positionWindow(rc.x, rc.y);
|
||||
m_window->openWindow();
|
||||
|
||||
manager()->addMessageFilter(kMouseDownMessage, this);
|
||||
manager()->addMessageFilter(kKeyDownMessage, this);
|
||||
filterMessages();
|
||||
|
||||
if (isEditable())
|
||||
m_entry->requestFocus();
|
||||
@ -630,8 +642,8 @@ void ComboBox::closeListBox()
|
||||
m_window = nullptr;
|
||||
m_listbox = nullptr;
|
||||
|
||||
manager()->removeMessageFilter(kMouseDownMessage, this);
|
||||
manager()->removeMessageFilter(kKeyDownMessage, this);
|
||||
removeMessageFilters();
|
||||
putSelectedItemAsCustomWidget();
|
||||
m_entry->requestFocus();
|
||||
|
||||
onCloseListBox();
|
||||
@ -675,4 +687,39 @@ void ComboBox::onCloseListBox()
|
||||
CloseListBox();
|
||||
}
|
||||
|
||||
void ComboBox::filterMessages()
|
||||
{
|
||||
if (!m_filtering) {
|
||||
manager()->addMessageFilter(kMouseDownMessage, this);
|
||||
manager()->addMessageFilter(kKeyDownMessage, this);
|
||||
m_filtering = true;
|
||||
}
|
||||
}
|
||||
|
||||
void ComboBox::removeMessageFilters()
|
||||
{
|
||||
if (m_filtering) {
|
||||
manager()->removeMessageFilter(kMouseDownMessage, this);
|
||||
manager()->removeMessageFilter(kKeyDownMessage, this);
|
||||
m_filtering = false;
|
||||
}
|
||||
}
|
||||
|
||||
void ComboBox::putSelectedItemAsCustomWidget()
|
||||
{
|
||||
if (!useCustomWidget())
|
||||
return;
|
||||
|
||||
ListItem* item = getSelectedItem();
|
||||
if (item && item->parent() == nullptr) {
|
||||
if (!m_listbox) {
|
||||
item->setBounds(m_entry->childrenBounds());
|
||||
m_entry->addChild(item);
|
||||
}
|
||||
else {
|
||||
m_entry->removeChild(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ui
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite UI Library
|
||||
// Copyright (C) 2001-2016 David Capello
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
@ -42,10 +42,12 @@ namespace ui {
|
||||
void setEditable(bool state);
|
||||
void setClickOpen(bool state);
|
||||
void setCaseSensitive(bool state);
|
||||
void setUseCustomWidget(bool state);
|
||||
|
||||
bool isEditable() const { return m_editable; }
|
||||
bool isClickOpen() const { return m_clickopen; }
|
||||
bool isCaseSensitive() const { return m_casesensitive; }
|
||||
bool useCustomWidget() const { return m_useCustomWidget; }
|
||||
|
||||
int addItem(ListItem* item);
|
||||
int addItem(const std::string& text);
|
||||
@ -100,6 +102,9 @@ namespace ui {
|
||||
|
||||
private:
|
||||
void onButtonClick(Event& ev);
|
||||
void filterMessages();
|
||||
void removeMessageFilters();
|
||||
void putSelectedItemAsCustomWidget();
|
||||
|
||||
ComboBoxEntry* m_entry;
|
||||
Button* m_button;
|
||||
@ -110,6 +115,8 @@ namespace ui {
|
||||
bool m_editable;
|
||||
bool m_clickopen;
|
||||
bool m_casesensitive;
|
||||
bool m_filtering;
|
||||
bool m_useCustomWidget;
|
||||
};
|
||||
|
||||
} // namespace ui
|
||||
|
Loading…
Reference in New Issue
Block a user