Eliminate the need for an explicit is_accesskit_active method, at least for now
This commit is contained in:
parent
49bbcf9b2e
commit
7763ee09dc
2 changed files with 71 additions and 77 deletions
|
@ -480,7 +480,7 @@ impl Context {
|
||||||
self.check_for_id_clash(id, rect, "widget");
|
self.check_for_id_clash(id, rect, "widget");
|
||||||
|
|
||||||
#[cfg(feature = "accesskit")]
|
#[cfg(feature = "accesskit")]
|
||||||
if self.is_accesskit_active() && sense.focusable {
|
if sense.focusable {
|
||||||
// Make sure anything that can receive focus has an AccessKit node.
|
// Make sure anything that can receive focus has an AccessKit node.
|
||||||
// TODO(mwcampbell): For nodes that are filled from widget info,
|
// TODO(mwcampbell): For nodes that are filled from widget info,
|
||||||
// some information is written to the node twice.
|
// some information is written to the node twice.
|
||||||
|
@ -1591,12 +1591,6 @@ impl Context {
|
||||||
.then(move || RwLockWriteGuard::map(ctx, |c| c.accesskit_node(id, parent_id)))
|
.then(move || RwLockWriteGuard::map(ctx, |c| c.accesskit_node(id, parent_id)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns whether AccessKit is active for the current frame.
|
|
||||||
#[cfg(feature = "accesskit")]
|
|
||||||
pub fn is_accesskit_active(&self) -> bool {
|
|
||||||
self.output().accesskit_update.is_some()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Enable generation of AccessKit tree updates in all future frames.
|
/// Enable generation of AccessKit tree updates in all future frames.
|
||||||
///
|
///
|
||||||
/// If it's practical for the egui integration to immediately run the egui
|
/// If it's practical for the egui integration to immediately run the egui
|
||||||
|
|
|
@ -659,84 +659,84 @@ impl<'t> TextEdit<'t> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "accesskit")]
|
#[cfg(feature = "accesskit")]
|
||||||
if ui.ctx().is_accesskit_active() {
|
if let Some(mut node) = ui.ctx().accesskit_node(response.id, None) {
|
||||||
use accesskit::{Role, TextDirection, TextPosition, TextSelection};
|
use accesskit::{Role, TextDirection, TextPosition, TextSelection};
|
||||||
|
|
||||||
let parent_id = response.id;
|
let parent_id = response.id;
|
||||||
for (i, row) in galley.rows.iter().enumerate() {
|
|
||||||
let id = parent_id.with(i);
|
|
||||||
if let Some(mut node) = ui.ctx().accesskit_node(id, Some(parent_id)) {
|
|
||||||
node.role = Role::InlineTextBox;
|
|
||||||
let rect = row.rect.translate(text_draw_pos.to_vec2());
|
|
||||||
node.bounds = Some(accesskit::kurbo::Rect {
|
|
||||||
x0: rect.min.x.into(),
|
|
||||||
y0: rect.min.y.into(),
|
|
||||||
x1: rect.max.x.into(),
|
|
||||||
y1: rect.max.y.into(),
|
|
||||||
});
|
|
||||||
node.text_direction = Some(TextDirection::LeftToRight);
|
|
||||||
// TODO: more info for the whole row
|
|
||||||
|
|
||||||
let glyph_count = row.glyphs.len();
|
if let Some(cursor_range) = &cursor_range {
|
||||||
let mut value = String::new();
|
let anchor = &cursor_range.secondary.rcursor;
|
||||||
value.reserve(glyph_count);
|
let focus = &cursor_range.primary.rcursor;
|
||||||
let mut character_lengths = Vec::<u8>::new();
|
node.text_selection = Some(TextSelection {
|
||||||
character_lengths.reserve(glyph_count);
|
anchor: TextPosition {
|
||||||
let mut character_positions = Vec::<f32>::new();
|
node: parent_id.with(anchor.row).accesskit_id(),
|
||||||
character_positions.reserve(glyph_count);
|
character_index: anchor.column,
|
||||||
let mut character_widths = Vec::<f32>::new();
|
},
|
||||||
character_widths.reserve(glyph_count);
|
focus: TextPosition {
|
||||||
let mut word_lengths = Vec::<u8>::new();
|
node: parent_id.with(focus.row).accesskit_id(),
|
||||||
let mut was_at_word_end = false;
|
character_index: focus.column,
|
||||||
let mut last_word_start = 0usize;
|
},
|
||||||
|
});
|
||||||
for glyph in &row.glyphs {
|
|
||||||
let is_word_char = is_word_char(glyph.chr);
|
|
||||||
if is_word_char && was_at_word_end {
|
|
||||||
word_lengths.push((character_lengths.len() - last_word_start) as _);
|
|
||||||
last_word_start = character_lengths.len();
|
|
||||||
}
|
|
||||||
was_at_word_end = !is_word_char;
|
|
||||||
let old_len = value.len();
|
|
||||||
value.push(glyph.chr);
|
|
||||||
character_lengths.push((value.len() - old_len) as _);
|
|
||||||
character_positions.push(glyph.pos.x - row.rect.min.x);
|
|
||||||
character_widths.push(glyph.size.x);
|
|
||||||
}
|
|
||||||
|
|
||||||
if row.ends_with_newline {
|
|
||||||
value.push('\n');
|
|
||||||
character_lengths.push(1);
|
|
||||||
character_positions.push(row.rect.max.x - row.rect.min.x);
|
|
||||||
character_widths.push(0.0);
|
|
||||||
}
|
|
||||||
word_lengths.push((character_lengths.len() - last_word_start) as _);
|
|
||||||
|
|
||||||
node.value = Some(value.into());
|
|
||||||
node.character_lengths = character_lengths.into();
|
|
||||||
node.character_positions = Some(character_positions.into());
|
|
||||||
node.character_widths = Some(character_widths.into());
|
|
||||||
node.word_lengths = word_lengths.into();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(mut node) = ui.ctx().accesskit_node(parent_id, None) {
|
node.default_action_verb = Some(accesskit::DefaultActionVerb::Focus);
|
||||||
if let Some(cursor_range) = &cursor_range {
|
|
||||||
let anchor = &cursor_range.secondary.rcursor;
|
drop(node);
|
||||||
let focus = &cursor_range.primary.rcursor;
|
|
||||||
node.text_selection = Some(TextSelection {
|
for (i, row) in galley.rows.iter().enumerate() {
|
||||||
anchor: TextPosition {
|
let id = parent_id.with(i);
|
||||||
node: parent_id.with(anchor.row).accesskit_id(),
|
let mut node = ui.ctx().accesskit_node(id, Some(parent_id)).unwrap();
|
||||||
character_index: anchor.column,
|
node.role = Role::InlineTextBox;
|
||||||
},
|
let rect = row.rect.translate(text_draw_pos.to_vec2());
|
||||||
focus: TextPosition {
|
node.bounds = Some(accesskit::kurbo::Rect {
|
||||||
node: parent_id.with(focus.row).accesskit_id(),
|
x0: rect.min.x.into(),
|
||||||
character_index: focus.column,
|
y0: rect.min.y.into(),
|
||||||
},
|
x1: rect.max.x.into(),
|
||||||
});
|
y1: rect.max.y.into(),
|
||||||
|
});
|
||||||
|
node.text_direction = Some(TextDirection::LeftToRight);
|
||||||
|
// TODO: more info for the whole row
|
||||||
|
|
||||||
|
let glyph_count = row.glyphs.len();
|
||||||
|
let mut value = String::new();
|
||||||
|
value.reserve(glyph_count);
|
||||||
|
let mut character_lengths = Vec::<u8>::new();
|
||||||
|
character_lengths.reserve(glyph_count);
|
||||||
|
let mut character_positions = Vec::<f32>::new();
|
||||||
|
character_positions.reserve(glyph_count);
|
||||||
|
let mut character_widths = Vec::<f32>::new();
|
||||||
|
character_widths.reserve(glyph_count);
|
||||||
|
let mut word_lengths = Vec::<u8>::new();
|
||||||
|
let mut was_at_word_end = false;
|
||||||
|
let mut last_word_start = 0usize;
|
||||||
|
|
||||||
|
for glyph in &row.glyphs {
|
||||||
|
let is_word_char = is_word_char(glyph.chr);
|
||||||
|
if is_word_char && was_at_word_end {
|
||||||
|
word_lengths.push((character_lengths.len() - last_word_start) as _);
|
||||||
|
last_word_start = character_lengths.len();
|
||||||
|
}
|
||||||
|
was_at_word_end = !is_word_char;
|
||||||
|
let old_len = value.len();
|
||||||
|
value.push(glyph.chr);
|
||||||
|
character_lengths.push((value.len() - old_len) as _);
|
||||||
|
character_positions.push(glyph.pos.x - row.rect.min.x);
|
||||||
|
character_widths.push(glyph.size.x);
|
||||||
}
|
}
|
||||||
|
|
||||||
node.default_action_verb = Some(accesskit::DefaultActionVerb::Focus);
|
if row.ends_with_newline {
|
||||||
|
value.push('\n');
|
||||||
|
character_lengths.push(1);
|
||||||
|
character_positions.push(row.rect.max.x - row.rect.min.x);
|
||||||
|
character_widths.push(0.0);
|
||||||
|
}
|
||||||
|
word_lengths.push((character_lengths.len() - last_word_start) as _);
|
||||||
|
|
||||||
|
node.value = Some(value.into());
|
||||||
|
node.character_lengths = character_lengths.into();
|
||||||
|
node.character_positions = Some(character_positions.into());
|
||||||
|
node.character_widths = Some(character_widths.into());
|
||||||
|
node.word_lengths = word_lengths.into();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue