Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabled widgets are now also disabled in the accesskit output #4750

Merged
merged 4 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions crates/egui/src/containers/collapsing_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,9 @@ impl CollapsingHeader {
header_response.mark_changed();
}

header_response
.widget_info(|| WidgetInfo::labeled(WidgetType::CollapsingHeader, galley.text()));
header_response.widget_info(|| {
WidgetInfo::labeled(WidgetType::CollapsingHeader, ui.is_enabled(), galley.text())
});

let openness = state.openness(ui.ctx());

Expand Down
7 changes: 4 additions & 3 deletions crates/egui/src/containers/combo_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,13 @@ impl ComboBox {
(width, height),
);
if let Some(label) = label {
ir.response
.widget_info(|| WidgetInfo::labeled(WidgetType::ComboBox, label.text()));
ir.response.widget_info(|| {
WidgetInfo::labeled(WidgetType::ComboBox, ui.is_enabled(), label.text())
});
ir.response |= ui.label(label);
} else {
ir.response
.widget_info(|| WidgetInfo::labeled(WidgetType::ComboBox, ""));
.widget_info(|| WidgetInfo::labeled(WidgetType::ComboBox, ui.is_enabled(), ""));
}
ir
})
Expand Down
21 changes: 16 additions & 5 deletions crates/egui/src/data/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,42 +547,50 @@ impl WidgetInfo {
}

#[allow(clippy::needless_pass_by_value)]
pub fn labeled(typ: WidgetType, label: impl ToString) -> Self {
pub fn labeled(typ: WidgetType, enabled: bool, label: impl ToString) -> Self {
Self {
enabled,
label: Some(label.to_string()),
..Self::new(typ)
}
}

/// checkboxes, radio-buttons etc
#[allow(clippy::needless_pass_by_value)]
pub fn selected(typ: WidgetType, selected: bool, label: impl ToString) -> Self {
pub fn selected(typ: WidgetType, enabled: bool, selected: bool, label: impl ToString) -> Self {
Self {
enabled,
label: Some(label.to_string()),
selected: Some(selected),
..Self::new(typ)
}
}

pub fn drag_value(value: f64) -> Self {
pub fn drag_value(enabled: bool, value: f64) -> Self {
Self {
enabled,
value: Some(value),
..Self::new(WidgetType::DragValue)
}
}

#[allow(clippy::needless_pass_by_value)]
pub fn slider(value: f64, label: impl ToString) -> Self {
pub fn slider(enabled: bool, value: f64, label: impl ToString) -> Self {
let label = label.to_string();
Self {
enabled,
label: if label.is_empty() { None } else { Some(label) },
value: Some(value),
..Self::new(WidgetType::Slider)
}
}

#[allow(clippy::needless_pass_by_value)]
pub fn text_edit(prev_text_value: impl ToString, text_value: impl ToString) -> Self {
pub fn text_edit(
enabled: bool,
prev_text_value: impl ToString,
text_value: impl ToString,
) -> Self {
let text_value = text_value.to_string();
let prev_text_value = prev_text_value.to_string();
let prev_text_value = if text_value == prev_text_value {
Expand All @@ -591,6 +599,7 @@ impl WidgetInfo {
Some(prev_text_value)
};
Self {
enabled,
current_text_value: Some(text_value),
prev_text_value,
..Self::new(WidgetType::TextEdit)
Expand All @@ -599,10 +608,12 @@ impl WidgetInfo {

#[allow(clippy::needless_pass_by_value)]
pub fn text_selection_changed(
enabled: bool,
text_selection: std::ops::RangeInclusive<usize>,
current_text_value: impl ToString,
) -> Self {
Self {
enabled,
text_selection: Some(text_selection),
current_text_value: Some(current_text_value.to_string()),
..Self::new(WidgetType::TextEdit)
Expand Down
6 changes: 5 additions & 1 deletion crates/egui/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,11 @@ impl SubMenuButton {

let (rect, response) = ui.allocate_at_least(desired_size, sense);
response.widget_info(|| {
crate::WidgetInfo::labeled(crate::WidgetType::Button, text_galley.text())
crate::WidgetInfo::labeled(
crate::WidgetType::Button,
ui.is_enabled(),
text_galley.text(),
)
});

if ui.is_rect_visible(rect) {
Expand Down
6 changes: 6 additions & 0 deletions crates/egui/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,9 @@ impl Response {

#[cfg(feature = "accesskit")]
pub(crate) fn fill_accesskit_node_common(&self, builder: &mut accesskit::NodeBuilder) {
if !self.enabled {
builder.set_disabled();
}
builder.set_bounds(accesskit::Rect {
x0: self.rect.min.x.into(),
y0: self.rect.min.y.into(),
Expand Down Expand Up @@ -921,6 +924,9 @@ impl Response {
WidgetType::ProgressIndicator => Role::ProgressIndicator,
WidgetType::Other => Role::Unknown,
});
if !info.enabled {
builder.set_disabled();
}
if let Some(label) = info.label {
builder.set_name(label);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/egui/src/widgets/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ impl Widget for Button<'_> {
let (rect, mut response) = ui.allocate_at_least(desired_size, sense);
response.widget_info(|| {
if let Some(galley) = &galley {
WidgetInfo::labeled(WidgetType::Button, galley.text())
WidgetInfo::labeled(WidgetType::Button, ui.is_enabled(), galley.text())
} else {
WidgetInfo::new(WidgetType::Button)
}
Expand Down
2 changes: 2 additions & 0 deletions crates/egui/src/widgets/checkbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@ impl<'a> Widget for Checkbox<'a> {
if indeterminate {
WidgetInfo::labeled(
WidgetType::Checkbox,
ui.is_enabled(),
galley.as_ref().map_or("", |x| x.text()),
)
} else {
WidgetInfo::selected(
WidgetType::Checkbox,
ui.is_enabled(),
*checked,
galley.as_ref().map_or("", |x| x.text()),
)
Expand Down
2 changes: 1 addition & 1 deletion crates/egui/src/widgets/drag_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ impl<'a> Widget for DragValue<'a> {

response.changed = get(&mut get_set_value) != old_value;

response.widget_info(|| WidgetInfo::drag_value(value));
response.widget_info(|| WidgetInfo::drag_value(ui.is_enabled(), value));

#[cfg(feature = "accesskit")]
ui.ctx().accesskit_node_builder(response.id, |builder| {
Expand Down
3 changes: 2 additions & 1 deletion crates/egui/src/widgets/hyperlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ impl Widget for Link {
let label = Label::new(text).sense(Sense::click());

let (galley_pos, galley, response) = label.layout_in_ui(ui);
response.widget_info(|| WidgetInfo::labeled(WidgetType::Link, galley.text()));
response
.widget_info(|| WidgetInfo::labeled(WidgetType::Link, ui.is_enabled(), galley.text()));

if ui.is_rect_visible(response.rect) {
let color = ui.visuals().hyperlink_color;
Expand Down
3 changes: 2 additions & 1 deletion crates/egui/src/widgets/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ impl Widget for Label {
let selectable = self.selectable;

let (galley_pos, galley, mut response) = self.layout_in_ui(ui);
response.widget_info(|| WidgetInfo::labeled(WidgetType::Label, galley.text()));
response
.widget_info(|| WidgetInfo::labeled(WidgetType::Label, ui.is_enabled(), galley.text()));

if ui.is_rect_visible(response.rect) {
if galley.elided {
Expand Down
2 changes: 1 addition & 1 deletion crates/egui/src/widgets/progress_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl Widget for ProgressBar {

response.widget_info(|| {
let mut info = if let Some(ProgressBarText::Custom(text)) = &text {
WidgetInfo::labeled(WidgetType::ProgressIndicator, text.text())
WidgetInfo::labeled(WidgetType::ProgressIndicator, ui.is_enabled(), text.text())
} else {
WidgetInfo::new(WidgetType::ProgressIndicator)
};
Expand Down
1 change: 1 addition & 0 deletions crates/egui/src/widgets/radio_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ impl Widget for RadioButton {
response.widget_info(|| {
WidgetInfo::selected(
WidgetType::RadioButton,
ui.is_enabled(),
checked,
galley.as_ref().map_or("", |x| x.text()),
)
Expand Down
7 changes: 6 additions & 1 deletion crates/egui/src/widgets/selected_label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ impl Widget for SelectableLabel {
desired_size.y = desired_size.y.at_least(ui.spacing().interact_size.y);
let (rect, response) = ui.allocate_at_least(desired_size, Sense::click());
response.widget_info(|| {
WidgetInfo::selected(WidgetType::SelectableLabel, selected, galley.text())
WidgetInfo::selected(
WidgetType::SelectableLabel,
ui.is_enabled(),
selected,
galley.text(),
)
});

if ui.is_rect_visible(response.rect) {
Expand Down
2 changes: 1 addition & 1 deletion crates/egui/src/widgets/slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ impl<'a> Slider<'a> {

let value = self.get_value();
response.changed = value != old_value;
response.widget_info(|| WidgetInfo::slider(value, self.text.text()));
response.widget_info(|| WidgetInfo::slider(ui.is_enabled(), value, self.text.text()));

#[cfg(feature = "accesskit")]
ui.ctx().accesskit_node_builder(response.id, |builder| {
Expand Down
3 changes: 3 additions & 0 deletions crates/egui/src/widgets/text_edit/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,7 @@ impl<'t> TextEdit<'t> {
if response.changed {
response.widget_info(|| {
WidgetInfo::text_edit(
ui.is_enabled(),
mask_if_password(password, prev_text.as_str()),
mask_if_password(password, text.as_str()),
)
Expand All @@ -753,13 +754,15 @@ impl<'t> TextEdit<'t> {
let char_range =
cursor_range.primary.ccursor.index..=cursor_range.secondary.ccursor.index;
let info = WidgetInfo::text_selection_changed(
ui.is_enabled(),
char_range,
mask_if_password(password, text.as_str()),
);
response.output_event(OutputEvent::TextSelectionChanged(info));
} else {
response.widget_info(|| {
WidgetInfo::text_edit(
ui.is_enabled(),
mask_if_password(password, prev_text.as_str()),
mask_if_password(password, text.as_str()),
)
Expand Down
Loading
Loading