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");
|
||||
|
||||
#[cfg(feature = "accesskit")]
|
||||
if self.is_accesskit_active() && sense.focusable {
|
||||
if sense.focusable {
|
||||
// Make sure anything that can receive focus has an AccessKit node.
|
||||
// TODO(mwcampbell): For nodes that are filled from widget info,
|
||||
// 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)))
|
||||
}
|
||||
|
||||
/// 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.
|
||||
///
|
||||
/// If it's practical for the egui integration to immediately run the egui
|
||||
|
|
|
@ -659,84 +659,84 @@ impl<'t> TextEdit<'t> {
|
|||
}
|
||||
|
||||
#[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};
|
||||
|
||||
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();
|
||||
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);
|
||||
}
|
||||
|
||||
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(cursor_range) = &cursor_range {
|
||||
let anchor = &cursor_range.secondary.rcursor;
|
||||
let focus = &cursor_range.primary.rcursor;
|
||||
node.text_selection = Some(TextSelection {
|
||||
anchor: TextPosition {
|
||||
node: parent_id.with(anchor.row).accesskit_id(),
|
||||
character_index: anchor.column,
|
||||
},
|
||||
focus: TextPosition {
|
||||
node: parent_id.with(focus.row).accesskit_id(),
|
||||
character_index: focus.column,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if let Some(mut node) = ui.ctx().accesskit_node(parent_id, None) {
|
||||
if let Some(cursor_range) = &cursor_range {
|
||||
let anchor = &cursor_range.secondary.rcursor;
|
||||
let focus = &cursor_range.primary.rcursor;
|
||||
node.text_selection = Some(TextSelection {
|
||||
anchor: TextPosition {
|
||||
node: parent_id.with(anchor.row).accesskit_id(),
|
||||
character_index: anchor.column,
|
||||
},
|
||||
focus: TextPosition {
|
||||
node: parent_id.with(focus.row).accesskit_id(),
|
||||
character_index: focus.column,
|
||||
},
|
||||
});
|
||||
node.default_action_verb = Some(accesskit::DefaultActionVerb::Focus);
|
||||
|
||||
drop(node);
|
||||
|
||||
for (i, row) in galley.rows.iter().enumerate() {
|
||||
let id = parent_id.with(i);
|
||||
let mut node = ui.ctx().accesskit_node(id, Some(parent_id)).unwrap();
|
||||
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();
|
||||
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