修改和新增单元格内容的对齐方式

This commit is contained in:
睿 安
2026-01-28 23:21:04 +08:00
parent 814f42120c
commit 76be13001f
16 changed files with 134 additions and 2 deletions

View File

@@ -131,7 +131,8 @@ mainForm::mainForm() :LayeredWindow(1000, 750)
tableView->SetColumnType(5, ezui::CellType::CheckBox);
tableView->SetColumnType(2, ezui::CellType::ComboBox);
tableView->SetColumnComboItems(2, { L"默认", L"禁止" , L"验机" });
tableView->SetDefaultTextAlign(Align::MiddleCenter);
//设置列宽
std::vector<int> withs = {60, 120, 50, 90, 85, 85, 100, 70, 70, 80, 80, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90};
for(auto i=0;i< withs.size();i++)

View File

@@ -44,10 +44,12 @@ namespace ezui {
StrokeStyle BorderStyle = StrokeStyle::None;
Color BackColor;
Color ForeColor;
TextAlign Align = TextAlign::TopLeft;
bool HasBorderColor = false;
bool HasBorderStyle = false;
bool HasBackColor = false;
bool HasForeColor = false;
bool HasTextAlign = false;
void SetBorderColor(const Color& color) {
BorderColor = color;
@@ -65,11 +67,16 @@ namespace ezui {
ForeColor = color;
HasForeColor = true;
}
void SetTextAlign(ezui::TextAlign align) {
Align = align;
HasTextAlign = true;
}
void Reset() {
HasBorderColor = false;
HasBorderStyle = false;
HasBackColor = false;
HasForeColor = false;
HasTextAlign = false;
}
};
@@ -88,6 +95,7 @@ namespace ezui {
CellType Type = CellType::TextBox; // 单元格类型
std::vector<UIString> ComboItems; // 下拉选项(仅 ComboBox 类型有效)
SortOrder CurrentSort = SortOrder::None; // 当前排序状态
TextAlign CellTextAlign = TextAlign::TopLeft; // 该列的默认对齐方式
};
class UI_EXPORT TableView : public Control {
@@ -121,6 +129,8 @@ namespace ezui {
Color m_cellForeColor = Color::Black;
int m_cellFontSize = 14;
std::wstring m_cellFontFamily = L"Microsoft YaHei";
TextAlign m_cellTextAlign = TextAlign::TopLeft; // 默认对齐方式
std::vector<TextAlign> m_rowTextAlign; // 每行的对齐方式(未设置时使用默认值)
// 表头样式
Color m_headerBackColor = Color(0xFFE0E0E0);
@@ -429,6 +439,23 @@ namespace ezui {
void SetHeaderBackColor(const Color& color);
void SetHeaderForeColor(const Color& color);
// ============ 对齐方式设置 ============
// 设置默认对齐方式(影响所有未单独设置对齐方式的单元格)
void SetDefaultTextAlign(TextAlign align);
// 设置某列的对齐方式
void SetColumnTextAlign(int colIndex, TextAlign align);
// 设置某行的对齐方式
void SetRowTextAlign(int rowIndex, TextAlign align);
// 设置单个单元格的对齐方式
void SetCellTextAlign(int row, int col, TextAlign align);
// 获取单元格的对齐方式(考虑优先级:单元格 > 行 > 列 > 默认)
TextAlign GetCellTextAlign(int row, int col) const;
// ============ 鼠标悬停信息 ============
// 获取鼠标当前悬停的行号(-1表示表头或未悬停在任何行