Skip to content

Commit 67166fc

Browse files
DataTrinytronical
authored andcommitted
Add the accessible-position-in-set property
1 parent d00655b commit 67166fc

File tree

11 files changed

+50
-0
lines changed

11 files changed

+50
-0
lines changed

api/cpp/include/slint-testing.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "slint.h"
55
#include "slint_testing_internal.h"
6+
#include <cstdint>
67
#include <optional>
78
#include <string_view>
89
#include <type_traits>
@@ -355,6 +356,19 @@ class ElementHandle
355356
return std::nullopt;
356357
}
357358

359+
/// Returns the accessible-position-in-set of that element, if any.
360+
std::optional<uintptr_t> accessible_position_in_set() const
361+
{
362+
if (auto result = get_accessible_string_property(
363+
cbindgen_private::AccessibleStringProperty::PositionInSet)) {
364+
uintptr_t value = 0;
365+
if (cbindgen_private::slint_string_to_usize(&*result, &value)) {
366+
return value;
367+
}
368+
}
369+
return std::nullopt;
370+
}
371+
358372
/// Sets the accessible-value of that element.
359373
///
360374
/// Setting the value will invoke the `accessible-action-set-value` callback.

api/cpp/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,17 @@ pub extern "C" fn slint_string_to_float(string: &SharedString, value: &mut f32)
152152
}
153153
}
154154

155+
#[no_mangle]
156+
pub extern "C" fn slint_string_to_usize(string: &SharedString, value: &mut usize) -> bool {
157+
match string.as_str().parse::<usize>() {
158+
Ok(v) => {
159+
*value = v;
160+
true
161+
}
162+
Err(_) => false,
163+
}
164+
}
165+
155166
#[no_mangle]
156167
pub extern "C" fn slint_debug(string: &SharedString) {
157168
i_slint_core::debug_log!("{string}");

docs/reference/src/language/builtins/elements.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Use the following `accessible-` properties to make your items interact well with
7878
- **`accessible-placeholder-text`** (_in_ _string_): A placeholder text to use when the item's value is empty. Applies to text elements.
7979
- **`accessible-selectable`** (_in_ _bool_): Whether the element can be selected or not.
8080
- **`accessible-selected`** (_in_ _bool_): Whether the element is selected or not. This maps to the "is-selected" state of listview items.
81+
- **`accessible-position-in-set`** (_in_ _int_): The index (starting from 1) of this element in a group of similar elements. Applies to list items, radio buttons and other elements.
8182

8283
You can also use the following callbacks that are going to be called by the accessibility framework:
8384

internal/backends/testing/search_api.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,17 @@ impl ElementHandle {
621621
.and_then(|item| item.parse().ok())
622622
}
623623

624+
/// Returns the value of the element's `accessible-position-in-set` property, if present.
625+
pub fn accessible_position_in_set(&self) -> Option<usize> {
626+
if self.element_index != 0 {
627+
return None;
628+
}
629+
self.item.upgrade().and_then(|item| {
630+
item.accessible_string_property(AccessibleStringProperty::PositionInSet)
631+
.and_then(|s| s.parse().ok())
632+
})
633+
}
634+
624635
/// Returns the size of the element in logical pixels. This corresponds to the value of the `width` and
625636
/// `height` properties in Slint code. Returns a zero size if the element is not valid.
626637
pub fn size(&self) -> i_slint_core::api::LogicalSize {

internal/backends/winit/accesskit.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,13 @@ impl NodeCollection {
489489
);
490490
}
491491

492+
if let Some(position_in_set) = item
493+
.accessible_string_property(AccessibleStringProperty::PositionInSet)
494+
.and_then(|s| s.parse::<usize>().ok())
495+
{
496+
builder.set_position_in_set(position_in_set);
497+
}
498+
492499
let supported = item.supported_accessibility_actions();
493500
if supported.contains(SupportedAccessibilityAction::Default) {
494501
builder.add_action(accesskit::Action::Default);

internal/compiler/typeregister.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ pub fn reserved_accessibility_properties() -> impl Iterator<Item = (&'static str
206206
("accessible-action-set-value", strarg_callback_type()),
207207
("accessible-selectable", Type::Bool),
208208
("accessible-selected", Type::Bool),
209+
("accessible-position-in-set", Type::Int32),
209210
]
210211
.into_iter()
211212
}

internal/compiler/widgets/cosmic/components.slint

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ export component ListItem {
106106
accessible-label: root.item.text;
107107
accessible-selectable: true;
108108
accessible-selected: root.is-selected;
109+
accessible-position-in-set: root.index + 1;
109110

110111
states [
111112
is-selected when root.is-selected : {

internal/compiler/widgets/cupertino/components.slint

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export component ListItem {
6262
accessible-label: root.item.text;
6363
accessible-selectable: true;
6464
accessible-selected: root.is-selected;
65+
accessible-position-in-set: root.index + 1;
6566

6667
states [
6768
has-focus when root.has-focus : {

internal/compiler/widgets/fluent/components.slint

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export component ListItem {
5050
accessible-label: root.item.text;
5151
accessible-selectable: true;
5252
accessible-selected: root.is-selected;
53+
accessible-position-in-set: root.index + 1;
5354

5455
states [
5556
pressed when root.pressed : {

internal/compiler/widgets/material/components.slint

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export component ListItem {
108108
accessible-label: root.item.text;
109109
accessible-selectable: true;
110110
accessible-selected: root.is-selected;
111+
accessible-position-in-set: root.index + 1;
111112

112113
states [
113114
pressed when root.pressed: {

0 commit comments

Comments
 (0)