use super::{Table, Ui};
use crate::{accessibility::Scope, AccessRole, Context, Id, Rect};
impl Table {
pub fn accessible_label(mut self, label: impl Into<String>) -> Self {
self.label = label.into();
self
}
}
pub(super) struct Nodes {
table: Scope,
header: Option<u32>,
}
pub(super) fn begin(ui: &mut Ui<'_>, id: Id, label: &str, columns: usize) -> Nodes {
let table = ui.a11y_begin(id, AccessRole::Table, |node| {
node.label(label);
node.table().column_count = Some(columns as u32);
});
let row = ui.a11y_begin(id.with("header-row"), AccessRole::Row, |node| {
node.table().row = Some(0);
});
let header = row.0;
ui.a11y_end(row, None);
Nodes { table, header }
}
impl Nodes {
pub(super) fn open_header(&self, context: &mut Context) {
if let Some(header) = self.header {
context.a11y.stack.push(header);
}
}
pub(super) fn finish(self, ui: &mut Ui<'_>, header: Rect, rect: Rect, rows: usize, body: Id) {
ui.a11y_end(Scope(self.header), Some(header));
if let Some(node) = self
.table
.0
.and_then(|at| ui.context.a11y_node_mut(at as usize))
{
node.table().row_count = Some(rows.saturating_add(1).min(u32::MAX as usize) as u32);
}
ui.context.a11y_scroll(&self.table, body);
ui.a11y_end(self.table, Some(rect));
}
}