---
--- Generated manually.
--- Created by liaogaocan.
--- DateTime: 2020-6-18 17:38:53
---


Combo = Combo or class("Combo");

function Combo:ctor(name, currentIdx, item)
    self.m_szName = util.a2u8(name or "");
    self.m_nSelectedIdx = currentIdx or 1;
    self.m_items = {};
    self.m_nCount = 0;
    self:UpdateItems(item);
end

function Combo:dtor()
    self.m_nCount = 0;
    self.m_items = nil;
    self.m_nSelectedIdx = 0;
    self.m_szName = nil;
end

function Combo:Draw()
    local bChanged, idx = ImGui.Combo(self.m_szName, self.m_nSelectedIdx - 1, self.m_items, self.m_nCount);
    local luaIndex = idx + 1;
    self.m_nSelectedIdx = luaIndex;
    return bChanged, luaIndex, self.m_items[luaIndex];
end

function Combo:UpdateItems(item)
    self.m_items = {};
    for _, value in ipairs(item) do
        table.insert(self.m_items, util.a2u8(value));
    end
    self.m_nCount = #self.m_items;
    if self.m_nCount == 0 then
        table.insert(self.m_items, "");
        self.m_nCount = 1;
    end
    if self.m_nSelectedIdx < 1 then
        self.m_nSelectedIdx = 1;
    elseif self.m_nSelectedIdx > self.m_nCount then
        self.m_nSelectedIdx = self.m_nCount;
    end
end

function Combo:Select(idx)
    if idx == nil then
        return;
    end
    if idx < 1 then
        idx = 1;
    elseif idx > self.m_nCount then
        idx = self.m_nCount;
    end
    self.m_nSelectedIdx = idx;
end