添加ComboBox的xml实现
This commit is contained in:
@@ -111,13 +111,85 @@ namespace ezui {
|
||||
}
|
||||
};
|
||||
|
||||
return m_list.GetControls().size() - 1;
|
||||
int newIndex = m_list.GetControls().size() - 1;
|
||||
// 检查是否有待设置的索引
|
||||
if (m_pendingIndex >= 0 && m_pendingIndex == newIndex) {
|
||||
SetCheck(m_pendingIndex);
|
||||
m_pendingIndex = -1; // 清除待设置标志
|
||||
}
|
||||
return newIndex;
|
||||
}
|
||||
void ComboBox::RemoveItem(int index)
|
||||
{
|
||||
Control* lb = m_list.GetControl(index);
|
||||
m_list.Remove(lb, true);
|
||||
}
|
||||
void ComboBox::SetAttribute(const UIString& key, const UIString& value)
|
||||
{
|
||||
do
|
||||
{
|
||||
if (key == "item") {
|
||||
// 添加下拉选项,支持多个选项用逗号分隔
|
||||
if (value.find(',') != UIString::npos) {
|
||||
// 解析多个选项
|
||||
size_t start = 0;
|
||||
size_t end = value.find(',');
|
||||
while (end != UIString::npos) {
|
||||
UIString item = value.substr(start, end - start);
|
||||
// 去除首尾空格
|
||||
while (!item.empty() && (item[0] == ' ' || item[0] == '\t')) {
|
||||
item = item.substr(1);
|
||||
}
|
||||
while (!item.empty() && (item[item.length() - 1] == ' ' || item[item.length() - 1] == '\t')) {
|
||||
item = item.substr(0, item.length() - 1);
|
||||
}
|
||||
if (!item.empty()) {
|
||||
AddItem(item);
|
||||
}
|
||||
start = end + 1;
|
||||
end = value.find(',', start);
|
||||
}
|
||||
// 处理最后一个选项
|
||||
UIString item = value.substr(start);
|
||||
while (!item.empty() && (item[0] == ' ' || item[0] == '\t')) {
|
||||
item = item.substr(1);
|
||||
}
|
||||
while (!item.empty() && (item[item.length() - 1] == ' ' || item[item.length() - 1] == '\t')) {
|
||||
item = item.substr(0, item.length() - 1);
|
||||
}
|
||||
if (!item.empty()) {
|
||||
AddItem(item);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 单个选项
|
||||
AddItem(value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (key == "checked" || key == "selected" || key == "index") {
|
||||
// 设置选中的下标
|
||||
int index = std::atoi(value.c_str());
|
||||
if (!SetCheck(index)) {
|
||||
// 如果设置失败(可能是因为还没有添加item),保存索引稍后设置
|
||||
m_pendingIndex = index;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (key == "readonly") {
|
||||
// 设置文本框只读状态
|
||||
if (value == "true") {
|
||||
m_textBox.SetReadOnly(true);
|
||||
break;
|
||||
}
|
||||
if (value == "false") {
|
||||
m_textBox.SetReadOnly(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (false);
|
||||
__super::SetAttribute(key, value);
|
||||
}
|
||||
void ComboBox::OnLayout() {
|
||||
this->m_UpDown.SetFixedSize(Size(Height(), Height()));
|
||||
__super::OnLayout();
|
||||
|
||||
Reference in New Issue
Block a user