添加ComboBox的xml实现

This commit is contained in:
睿 安
2026-01-29 09:45:03 +08:00
parent 415d9ab518
commit 0811c0eabb
19 changed files with 123 additions and 11 deletions

View File

@@ -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();

View File

@@ -757,8 +757,8 @@ namespace ezui {
}
if (key == "multiline") {
if (value == "true") {
// 兼容旧版multiline=true 表示自动换行+手动换行
this->m_autoWrap = true;
// 兼容旧版multiline=true 表示自动换行+手动换行
this->m_autoWrap = false;
this->m_allowManualLineBreak = true;
break;
}