feat(virtual_advanced_table): Integrate CellEditor in draw loop with result handling
This commit is contained in:
parent
93836aef50
commit
97ddf28c15
1 changed files with 78 additions and 0 deletions
|
|
@ -81,6 +81,31 @@ pub const VirtualAdvancedTableResult = struct {
|
||||||
|
|
||||||
/// El widget fue clickeado
|
/// El widget fue clickeado
|
||||||
clicked: bool = false,
|
clicked: bool = false,
|
||||||
|
|
||||||
|
// =========================================================================
|
||||||
|
// Edición CRUD Excel-style
|
||||||
|
// =========================================================================
|
||||||
|
|
||||||
|
/// Una celda fue modificada (el usuario hizo commit con Enter/Tab)
|
||||||
|
cell_committed: bool = false,
|
||||||
|
|
||||||
|
/// La fila cambió de edición (auto-save requerido)
|
||||||
|
row_changed: bool = false,
|
||||||
|
|
||||||
|
/// El usuario canceló edición (Escape 2x = descartar fila)
|
||||||
|
row_discarded: bool = false,
|
||||||
|
|
||||||
|
/// Celda que fue editada (si cell_committed = true)
|
||||||
|
edited_cell: ?CellId = null,
|
||||||
|
|
||||||
|
/// Nuevo valor de la celda (si cell_committed = true)
|
||||||
|
edited_value: ?[]const u8 = null,
|
||||||
|
|
||||||
|
/// Fila anterior (si row_changed = true, para auto-save)
|
||||||
|
previous_row: ?usize = null,
|
||||||
|
|
||||||
|
/// Navegación solicitada después de commit
|
||||||
|
navigate_direction: cell_editor.CellEditorResult.NavigateDirection = .none,
|
||||||
};
|
};
|
||||||
|
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
|
|
@ -222,6 +247,59 @@ pub fn virtualAdvancedTableRect(
|
||||||
|
|
||||||
drawRows(ctx, content_bounds, config, &colors, list_state, visible_rows, &result, list_state.scroll_offset_x);
|
drawRows(ctx, content_bounds, config, &colors, list_state, visible_rows, &result, list_state.scroll_offset_x);
|
||||||
|
|
||||||
|
// Draw CellEditor overlay if editing
|
||||||
|
if (list_state.isEditing()) {
|
||||||
|
const editing = list_state.editing_cell.?;
|
||||||
|
|
||||||
|
// Calculate cell geometry for the editing cell
|
||||||
|
if (list_state.getCellGeometry(
|
||||||
|
editing.row,
|
||||||
|
editing.col,
|
||||||
|
config.columns,
|
||||||
|
config.row_height,
|
||||||
|
bounds.x,
|
||||||
|
bounds.y,
|
||||||
|
header_h,
|
||||||
|
filter_bar_h,
|
||||||
|
)) |geom| {
|
||||||
|
// Draw cell editor
|
||||||
|
const editor_result = cell_editor.drawCellEditor(
|
||||||
|
ctx,
|
||||||
|
list_state,
|
||||||
|
geom,
|
||||||
|
cell_editor.CellEditorColors{},
|
||||||
|
);
|
||||||
|
|
||||||
|
// Handle editor results
|
||||||
|
if (editor_result.committed) {
|
||||||
|
const edited_cell = list_state.editing_cell.?;
|
||||||
|
const new_value = list_state.getEditText();
|
||||||
|
|
||||||
|
// Check if row changed (for auto-save)
|
||||||
|
if (list_state.last_edited_row) |last_row| {
|
||||||
|
if (edited_cell.row != last_row and list_state.row_dirty) {
|
||||||
|
result.row_changed = true;
|
||||||
|
result.previous_row = last_row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Commit the edit
|
||||||
|
if (list_state.commitEdit()) {
|
||||||
|
result.cell_committed = true;
|
||||||
|
result.edited_cell = edited_cell;
|
||||||
|
result.edited_value = new_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
result.navigate_direction = editor_result.navigate;
|
||||||
|
} else if (editor_result.escaped) {
|
||||||
|
const action = list_state.handleEscape();
|
||||||
|
if (action == .discard_row) {
|
||||||
|
result.row_discarded = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// End clipping
|
// End clipping
|
||||||
ctx.pushCommand(Command.clipEnd());
|
ctx.pushCommand(Command.clipEnd());
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue