Skip to content

Commit 97219c2

Browse files
DataTrinytronical
authored andcommitted
Add the accessible-size-of-set property
1 parent 67166fc commit 97219c2

File tree

13 files changed

+44
-0
lines changed

13 files changed

+44
-0
lines changed

api/cpp/include/slint-testing.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,19 @@ class ElementHandle
369369
return std::nullopt;
370370
}
371371

372+
/// Returns the accessible-size-of-set of that element, if any.
373+
std::optional<uintptr_t> accessible_size_of_set() const
374+
{
375+
if (auto result = get_accessible_string_property(
376+
cbindgen_private::AccessibleStringProperty::SizeOfSet)) {
377+
uintptr_t value = 0;
378+
if (cbindgen_private::slint_string_to_usize(&*result, &value)) {
379+
return value;
380+
}
381+
}
382+
return std::nullopt;
383+
}
384+
372385
/// Sets the accessible-value of that element.
373386
///
374387
/// Setting the value will invoke the `accessible-action-set-value` callback.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ Use the following `accessible-` properties to make your items interact well with
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.
8181
- **`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.
82+
- **`accessible-size-of-set`** (_in_ _int_): The total number of elements in a group. Applies to all elements of a group like list items, radio buttons and other elements, but not to their parent container like list views, radio button groups or other grouping elements.
8283

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

internal/backends/qt/qt_widgets/listviewitem.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use super::*;
1111
pub struct NativeStandardListViewItem {
1212
pub item: Property<i_slint_core::model::StandardListViewItem>,
1313
pub index: Property<i32>,
14+
pub total_items: Property<i32>,
1415
pub is_selected: Property<bool>,
1516
pub cached_rendering_data: CachedRenderingData,
1617
pub has_hover: Property<bool>,

internal/backends/testing/search_api.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,17 @@ impl ElementHandle {
632632
})
633633
}
634634

635+
/// Returns the value of the element's `accessible-size-of-set` property, if present.
636+
pub fn accessible_size_of_set(&self) -> Option<usize> {
637+
if self.element_index != 0 {
638+
return None;
639+
}
640+
self.item.upgrade().and_then(|item| {
641+
item.accessible_string_property(AccessibleStringProperty::SizeOfSet)
642+
.and_then(|s| s.parse().ok())
643+
})
644+
}
645+
635646
/// Returns the size of the element in logical pixels. This corresponds to the value of the `width` and
636647
/// `height` properties in Slint code. Returns a zero size if the element is not valid.
637648
pub fn size(&self) -> i_slint_core::api::LogicalSize {

internal/backends/winit/accesskit.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,12 @@ impl NodeCollection {
495495
{
496496
builder.set_position_in_set(position_in_set);
497497
}
498+
if let Some(size_of_set) = item
499+
.accessible_string_property(AccessibleStringProperty::SizeOfSet)
500+
.and_then(|s| s.parse::<usize>().ok())
501+
{
502+
builder.set_size_of_set(size_of_set);
503+
}
498504

499505
let supported = item.supported_accessibility_actions();
500506
if supported.contains(SupportedAccessibilityAction::Default) {

internal/compiler/builtins.slint

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ export component NativeScrollView {
547547

548548
export component NativeStandardListViewItem {
549549
in property <int> index;
550+
in property <int> total-items;
550551
in property <StandardListViewItem> item;
551552
in-out property <bool> is_selected;
552553
in property <bool> has_hover;

internal/compiler/typeregister.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ pub fn reserved_accessibility_properties() -> impl Iterator<Item = (&'static str
207207
("accessible-selectable", Type::Bool),
208208
("accessible-selected", Type::Bool),
209209
("accessible-position-in-set", Type::Int32),
210+
("accessible-size-of-set", Type::Int32),
210211
]
211212
.into_iter()
212213
}

internal/compiler/widgets/common/listview.slint

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ component StandardListViewBase inherits ListView {
8989
height: self.min-height;
9090
item: item;
9191
index: index;
92+
total-items: root.model.length;
9293
is-selected: index == root.current-item;
9394
has-focus: root.has-focus && index == root.focus-item;
9495
has-hover: i-touch-area.has-hover;

internal/compiler/widgets/cosmic/components.slint

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ export component ListItem {
9595
in property <bool> has-hover;
9696
in property <bool> pressed;
9797
in property <int> index;
98+
in property <int> total-items;
9899
in property <length> pressed-x;
99100
in property <length> pressed-y;
100101

@@ -107,6 +108,7 @@ export component ListItem {
107108
accessible-selectable: true;
108109
accessible-selected: root.is-selected;
109110
accessible-position-in-set: root.index + 1;
111+
accessible-size-of-set: root.total-items;
110112

111113
states [
112114
is-selected when root.is-selected : {

internal/compiler/widgets/cupertino/components.slint

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export component ListItem {
5151
in property <bool> has-hover;
5252
in property <bool> pressed;
5353
in property <int> index;
54+
in property <int> total-items;
5455
in property <length> pressed-x;
5556
in property <length> pressed-y;
5657

@@ -63,6 +64,7 @@ export component ListItem {
6364
accessible-selectable: true;
6465
accessible-selected: root.is-selected;
6566
accessible-position-in-set: root.index + 1;
67+
accessible-size-of-set: root.total-items;
6668

6769
states [
6870
has-focus when root.has-focus : {

0 commit comments

Comments
 (0)