-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
// 表格控件组
$tableGroup = Group::create("进程表格 (libui Table)");
Group::setMargined($tableGroup, true);
Box::append($container, $tableGroup, true);
$tableBox = Box::newVerticalBox();
Box::setPadded($tableBox, true);
Group::setChild($tableGroup, $tableBox);
try {
// 创建表格模型处理器
$handler = \Kingbes\Libui\Base::ffi()->new("uiTableModelHandler");
// 定义回调函数
$numColumnsFunc = function($h, $m) {
return 4; // ID, PID, User, Command
};
$columnTypeFunc = function($h, $m, $column) {
// 所有列都使用字符串类型
return TableValueType::String->value;
};
$numRowsFunc = function($h, $m) {
return 3; // 固定3行数据
};
$cellValueFunc = function($h, $m, $row, $column) {
// 模拟数据
$mockData = [
['1', '1234', 'root', '/usr/bin/systemd'],
['2', '5678', 'www-data', 'nginx: worker process'],
['3', '9012', 'mysql', '/usr/sbin/mysqld']
];
// 确保行索引不超出范围
$rowIndex = min($row, count($mockData) - 1);
// 返回对应单元格的数据
if (isset($mockData[$rowIndex][$column])) {
return Table::createValueStr($mockData[$rowIndex][$column]);
}
return Table::createValueStr('');
};
$setCellValueFunc = function($h, $m, $row, $column, $value) {
// 简单的设置处理
return 0;
};
// 设置回调函数
$handler->NumColumns = $numColumnsFunc;
$handler->ColumnType = $columnTypeFunc;
$handler->NumRows = $numRowsFunc;
$handler->CellValue = $cellValueFunc;
$handler->SetCellValue = $setCellValueFunc;
// 创建文本列参数
$textParams = \Kingbes\Libui\Base::ffi()->new("uiTableTextColumnOptionalParams");
$textParamsPtr = \FFI::addr($textParams);
// 创建表格模型
$model = Table::createModel(\FFI::addr($handler));
// 创建表格参数
$params = \Kingbes\Libui\Base::ffi()->new("uiTableParams");
$params->Model = $model;
$params->RowBackgroundColorModelColumn = -1;
// 创建表格
$table = Table::create($params);
// 添加列
Table::appendTextColumn($table, "ID", 0, -1, $textParamsPtr);
Table::appendTextColumn($table, "PID", 1, -1, $textParamsPtr);
Table::appendTextColumn($table, "User", 2, -1, $textParamsPtr);
Table::appendTextColumn($table, "Command", 3, -1, $textParamsPtr);
// 将表格添加到容器
Box::append($tableBox, $table, true);
// 添加说明标签
$infoLabel = Label::create("这是简单的表格示例 - 显示ID、PID、User、Command四列");
Box::append($tableBox, $infoLabel, false);
} catch (\Exception $e) {
// 如果表格创建失败,显示错误信息
$errorLabel = Label::create("表格创建失败: " . $e->getMessage());
Box::append($tableBox, $errorLabel, false);
}
经过ai 尝试,不管普通表格还是 带复选框的表格, 添加数据后,文本列 不显示内容。请给出表格正确用法。
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels