gui improvement: combobox userdata
This commit is contained in:
@@ -42,7 +42,7 @@ void TransformWindow::Create(EditorComponent* editor)
|
||||
|
||||
if(args.iValue != 0)
|
||||
{
|
||||
scene.Component_Attach(entity, scene.transforms.GetEntity(args.iValue - 1));
|
||||
scene.Component_Attach(entity, args.userdata);
|
||||
}
|
||||
|
||||
});
|
||||
@@ -234,12 +234,17 @@ void TransformWindow::SetEntity(Entity entity)
|
||||
for (size_t i = 0; i < scene.transforms.GetCount(); ++i)
|
||||
{
|
||||
Entity entity = scene.transforms.GetEntity(i);
|
||||
if (entity == this->entity)
|
||||
{
|
||||
continue; // Don't list selected (don't allow attach to self)
|
||||
}
|
||||
|
||||
const NameComponent* name = scene.names.GetComponent(entity);
|
||||
parentCombo.AddItem(name == nullptr ? std::to_string(entity) : name->name);
|
||||
parentCombo.AddItem(name == nullptr ? std::to_string(entity) : name->name, entity);
|
||||
|
||||
if (hier != nullptr && hier->parentID == entity)
|
||||
{
|
||||
parentCombo.SetSelected((int)i + 1);
|
||||
parentCombo.SetSelected(parentCombo.GetItemCount() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace wiVersion
|
||||
// minor features, major updates, breaking API changes
|
||||
const int minor = 49;
|
||||
// minor bug fixes, alterations, refactors, updates
|
||||
const int revision = 17;
|
||||
const int revision = 18;
|
||||
|
||||
const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);
|
||||
|
||||
|
||||
@@ -1292,7 +1292,7 @@ void wiComboBox::Render(const wiGUI* gui, CommandList cmd) const
|
||||
|
||||
if (selected >= 0)
|
||||
{
|
||||
wiFont::Draw(items[selected], wiFontParams(translation.x + scale.x*0.5f, translation.y + scale.y*0.5f, WIFONTSIZE_DEFAULT, WIFALIGN_CENTER, WIFALIGN_CENTER,
|
||||
wiFont::Draw(items[selected].name, wiFontParams(translation.x + scale.x*0.5f, translation.y + scale.y*0.5f, WIFONTSIZE_DEFAULT, WIFALIGN_CENTER, WIFALIGN_CENTER,
|
||||
font.params.color, font.params.shadowColor), cmd);
|
||||
}
|
||||
|
||||
@@ -1359,7 +1359,7 @@ void wiComboBox::Render(const wiGUI* gui, CommandList cmd) const
|
||||
}
|
||||
}
|
||||
wiImage::Draw(wiTextureHelper::getWhite(), fx, cmd);
|
||||
wiFont::Draw(items[i], wiFontParams(translation.x + scale.x*0.5f, translation.y + scale.y*0.5f + GetItemOffset(i), WIFONTSIZE_DEFAULT, WIFALIGN_CENTER, WIFALIGN_CENTER,
|
||||
wiFont::Draw(items[i].name, wiFontParams(translation.x + scale.x*0.5f, translation.y + scale.y*0.5f + GetItemOffset(i), WIFONTSIZE_DEFAULT, WIFALIGN_CENTER, WIFALIGN_CENTER,
|
||||
font.params.color, font.params.shadowColor), cmd);
|
||||
}
|
||||
}
|
||||
@@ -1368,9 +1368,11 @@ void wiComboBox::OnSelect(function<void(wiEventArgs args)> func)
|
||||
{
|
||||
onSelect = move(func);
|
||||
}
|
||||
void wiComboBox::AddItem(const std::string& item)
|
||||
void wiComboBox::AddItem(const std::string& name, uint64_t userdata)
|
||||
{
|
||||
items.push_back(item);
|
||||
items.emplace_back();
|
||||
items.back().name = name;
|
||||
items.back().userdata = userdata;
|
||||
|
||||
if (selected < 0)
|
||||
{
|
||||
@@ -1379,7 +1381,7 @@ void wiComboBox::AddItem(const std::string& item)
|
||||
}
|
||||
void wiComboBox::RemoveItem(int index)
|
||||
{
|
||||
std::vector<string> newItems(0);
|
||||
std::vector<Item> newItems(0);
|
||||
newItems.reserve(items.size());
|
||||
for (size_t i = 0; i < items.size(); ++i)
|
||||
{
|
||||
@@ -1416,16 +1418,25 @@ void wiComboBox::SetSelected(int index)
|
||||
wiEventArgs args;
|
||||
args.iValue = selected;
|
||||
args.sValue = GetItemText(selected);
|
||||
args.userdata = GetItemUserData(selected);
|
||||
onSelect(args);
|
||||
}
|
||||
string wiComboBox::GetItemText(int index) const
|
||||
{
|
||||
if (index >= 0)
|
||||
{
|
||||
return items[index];
|
||||
return items[index].name;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
uint64_t wiComboBox::GetItemUserData(int index) const
|
||||
{
|
||||
if (index >= 0)
|
||||
{
|
||||
return items[index].userdata;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int wiComboBox::GetSelected() const
|
||||
{
|
||||
return selected;
|
||||
|
||||
@@ -222,13 +222,18 @@ protected:
|
||||
|
||||
float scrollbar_delta = 0;
|
||||
|
||||
std::vector<std::string> items;
|
||||
struct Item
|
||||
{
|
||||
std::string name;
|
||||
uint64_t userdata = 0;
|
||||
};
|
||||
std::vector<Item> items;
|
||||
|
||||
float GetItemOffset(int index) const;
|
||||
public:
|
||||
void Create(const std::string& name);
|
||||
|
||||
void AddItem(const std::string& item);
|
||||
void AddItem(const std::string& name, uint64_t userdata = 0);
|
||||
void RemoveItem(int index);
|
||||
void ClearItems();
|
||||
void SetMaxVisibleItemCount(int value);
|
||||
@@ -237,6 +242,8 @@ public:
|
||||
void SetSelected(int index);
|
||||
int GetSelected() const;
|
||||
std::string GetItemText(int index) const;
|
||||
uint64_t GetItemUserData(int index) const;
|
||||
size_t GetItemCount() const { return items.size(); }
|
||||
|
||||
void Update(wiGUI* gui, float dt ) override;
|
||||
void Render(const wiGUI* gui, wiGraphics::CommandList cmd) const override;
|
||||
|
||||
Reference in New Issue
Block a user