diff --git a/CHANGELOG.md b/CHANGELOG.md index a7e099077..5deb71070 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,7 +23,7 @@ All notable changes to this project are documented in this file. - Deprecated two way binding between `in` and `in-out` property (#6400) - TouchArea: Send cancel event and update `pressed` and `has-hover` property when `enabled` is set to false while pressed. (#6422) - Added `font-metrics` property to `Text` and `TextInput`. (#6047) - - Added `accessible-selectable`, `accessible-selected`, `accessible-enabled`, `accessible-position-in-set`, and `accessible-delegate-focus` properties + - Added `accessible-item-selectable`, `accessible-item-selected`, `accessible-enabled`, `accessible-item-index`, and `accessible-delegate-focus` properties - Emit a warning when the case of the import file differ from the case of the file that was imported (#4265) - Support property changed callbacks in globals (#6599) - PopupWindow: added `close-policy` property, deprecated `close-on-click` (#6614) diff --git a/api/cpp/include/slint-testing.h b/api/cpp/include/slint-testing.h index c4176bece..4dc102d74 100644 --- a/api/cpp/include/slint-testing.h +++ b/api/cpp/include/slint-testing.h @@ -330,11 +330,11 @@ public: return std::nullopt; } - /// Returns the accessible-selected of that element, if any. - std::optional accessible_selected() const + /// Returns the accessible-item-selected of that element, if any. + std::optional accessible_item_selected() const { if (auto result = get_accessible_string_property( - cbindgen_private::AccessibleStringProperty::Selected)) { + cbindgen_private::AccessibleStringProperty::ItemSelected)) { if (*result == "true") return true; else if (*result == "false") @@ -343,11 +343,11 @@ public: return std::nullopt; } - /// Returns the accessible-selectable of that element, if any. - std::optional accessible_selectable() const + /// Returns the accessible-item-selectable of that element, if any. + std::optional accessible_item_selectable() const { if (auto result = get_accessible_string_property( - cbindgen_private::AccessibleStringProperty::Selectable)) { + cbindgen_private::AccessibleStringProperty::ItemSelectable)) { if (*result == "true") return true; else if (*result == "false") @@ -356,11 +356,11 @@ public: return std::nullopt; } - /// Returns the accessible-position-in-set of that element, if any. - std::optional accessible_position_in_set() const + /// Returns the accessible-item-index of that element, if any. + std::optional accessible_item_index() const { if (auto result = get_accessible_string_property( - cbindgen_private::AccessibleStringProperty::PositionInSet)) { + cbindgen_private::AccessibleStringProperty::ItemIndex)) { uintptr_t value = 0; if (cbindgen_private::slint_string_to_usize(&*result, &value)) { return value; @@ -369,11 +369,11 @@ public: return std::nullopt; } - /// Returns the accessible-size-of-set of that element, if any. - std::optional accessible_size_of_set() const + /// Returns the accessible-item-count of that element, if any. + std::optional accessible_item_count() const { if (auto result = get_accessible_string_property( - cbindgen_private::AccessibleStringProperty::SizeOfSet)) { + cbindgen_private::AccessibleStringProperty::ItemCount)) { uintptr_t value = 0; if (cbindgen_private::slint_string_to_usize(&*result, &value)) { return value; diff --git a/demos/energy-monitor/ui/widgets/list_view.slint b/demos/energy-monitor/ui/widgets/list_view.slint index 22d547e9e..2f14bf272 100644 --- a/demos/energy-monitor/ui/widgets/list_view.slint +++ b/demos/energy-monitor/ui/widgets/list_view.slint @@ -36,8 +36,8 @@ component ListViewItem { padding-right: Theme.spaces.medium; spacing: Theme.spaces.medium; accessible-role: list-item; - accessible-selectable: true; - accessible-selected: root.selected; + accessible-item-selectable: true; + accessible-item-selected: root.selected; i-text := Text { horizontal-stretch: 1; diff --git a/docs/astro/src/content/docs/reference/overview.mdx b/docs/astro/src/content/docs/reference/overview.mdx index 0161ec658..2581f75f8 100644 --- a/docs/astro/src/content/docs/reference/overview.mdx +++ b/docs/astro/src/content/docs/reference/overview.mdx @@ -8,7 +8,7 @@ import SlintProperty from '/src/components/SlintProperty.astro'; import CodeSnippetMD from '/src/components/CodeSnippetMD.astro'; import Link from '/src/components/Link.astro'; -The Slint elements have many common properties, callbacks and behavior. +The Slint elements have many common properties, callbacks and behavior. This page describes these properties and their usage. ## `init()` @@ -78,17 +78,17 @@ export component AppWindow inherits Window { These properties are valid on all **visible** items: ### x - + The position of the element relative to its parent. ### y - + The position of the element relative to its parent. ### z - + Allows to specify a different order to stack the items with its siblings. The value must be a compile time constant. @@ -99,18 +99,18 @@ Currently the `z` value is a compile time constant and cannot be changed at runt ### absolute-position - + The position of the element within the contained window. ### width - + The width of the element. When set, this overrides the default width. ### height - + The height of the element. When set, this overrides the default height. @@ -124,7 +124,7 @@ were first drawn into an intermediate layer, and then the whole layer is rendere :::caution[Caution] When an element has 0 opacity it will still take up layout space and any gesture handling will continue -to work. If the intent is to hide an element so it has no gesture handling or takes up layout space, +to work. If the intent is to hide an element so it has no gesture handling or takes up layout space, use the `visible` property instead. ::: @@ -202,10 +202,10 @@ Use the following `accessible-` properties to make your items interact well with - **`accessible-value-step`** (_in_ _float_) The smallest increment or decrement by which the current value can change. This corresponds to the step by which a handle on a slider can be dragged. - **`accessible-value`** (_in_ _string_): The current value of the item. - **`accessible-placeholder-text`** (_in_ _string_): A placeholder text to use when the item's value is empty. Applies to text elements. -- **`accessible-selectable`** (_in_ _bool_): Whether the element can be selected or not. -- **`accessible-selected`** (_in_ _bool_): Whether the element is selected or not. This maps to the "is-selected" state of listview items. -- **`accessible-position-in-set`** (_in_ _int_): The index (starting from 0) of this element in a group of similar elements. Applies to list items, radio buttons and other elements. -- **`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. +- **`accessible-item-selectable`** (_in_ _bool_): Whether the element can be selected or not. +- **`accessible-item-selected`** (_in_ _bool_): Whether the element is selected or not. This maps to the "is-selected" state of listview items. +- **`accessible-item-index`** (_in_ _int_): The index (starting from 0) of this element in a group of similar elements. Applies to list items, radio buttons and other elements. +- **`accessible-item-count`** (_in_ _int_): The total number of elements in a group. Applies to the parent container of a group of element such as list views, radio button groups or other grouping elements. You can also use the following callbacks that are going to be called by the accessibility framework: diff --git a/internal/backends/qt/qt_widgets/listviewitem.rs b/internal/backends/qt/qt_widgets/listviewitem.rs index b80fbf585..fa0ee2ef2 100644 --- a/internal/backends/qt/qt_widgets/listviewitem.rs +++ b/internal/backends/qt/qt_widgets/listviewitem.rs @@ -11,7 +11,6 @@ use super::*; pub struct NativeStandardListViewItem { pub item: Property, pub index: Property, - pub total_items: Property, pub is_selected: Property, pub cached_rendering_data: CachedRenderingData, pub has_hover: Property, diff --git a/internal/backends/testing/search_api.rs b/internal/backends/testing/search_api.rs index f2b54787f..0b682e74f 100644 --- a/internal/backends/testing/search_api.rs +++ b/internal/backends/testing/search_api.rs @@ -599,46 +599,50 @@ impl ElementHandle { .and_then(|item| item.parse().ok()) } - /// Returns the value of the `accessible-selected` property, if present - pub fn accessible_selected(&self) -> Option { + /// Returns the value of the `accessible-item-selected` property, if present + pub fn accessible_item_selected(&self) -> Option { if self.element_index != 0 { return None; } self.item .upgrade() - .and_then(|item| item.accessible_string_property(AccessibleStringProperty::Selected)) + .and_then(|item| { + item.accessible_string_property(AccessibleStringProperty::ItemSelected) + }) .and_then(|item| item.parse().ok()) } - /// Returns the value of the `accessible-selectable` property, if present - pub fn accessible_selectable(&self) -> Option { + /// Returns the value of the `accessible-item-selectable` property, if present + pub fn accessible_item_selectable(&self) -> Option { if self.element_index != 0 { return None; } self.item .upgrade() - .and_then(|item| item.accessible_string_property(AccessibleStringProperty::Selectable)) + .and_then(|item| { + item.accessible_string_property(AccessibleStringProperty::ItemSelectable) + }) .and_then(|item| item.parse().ok()) } - /// Returns the value of the element's `accessible-position-in-set` property, if present. - pub fn accessible_position_in_set(&self) -> Option { + /// Returns the value of the element's `accessible-item-index` property, if present. + pub fn accessible_item_index(&self) -> Option { if self.element_index != 0 { return None; } self.item.upgrade().and_then(|item| { - item.accessible_string_property(AccessibleStringProperty::PositionInSet) + item.accessible_string_property(AccessibleStringProperty::ItemIndex) .and_then(|s| s.parse().ok()) }) } - /// Returns the value of the element's `accessible-size-of-set` property, if present. - pub fn accessible_size_of_set(&self) -> Option { + /// Returns the value of the element's `accessible-item-count` property, if present. + pub fn accessible_item_count(&self) -> Option { if self.element_index != 0 { return None; } self.item.upgrade().and_then(|item| { - item.accessible_string_property(AccessibleStringProperty::SizeOfSet) + item.accessible_string_property(AccessibleStringProperty::ItemCount) .and_then(|s| s.parse().ok()) }) } diff --git a/internal/backends/winit/accesskit.rs b/internal/backends/winit/accesskit.rs index fb500101c..ded7c6766 100644 --- a/internal/backends/winit/accesskit.rs +++ b/internal/backends/winit/accesskit.rs @@ -497,26 +497,34 @@ impl NodeCollection { } if item - .accessible_string_property(AccessibleStringProperty::Selectable) + .accessible_string_property(AccessibleStringProperty::ItemSelectable) .is_some_and(|x| x == "true") { node.set_selected( - item.accessible_string_property(AccessibleStringProperty::Selected) + item.accessible_string_property(AccessibleStringProperty::ItemSelected) .is_some_and(|x| x == "true"), ); } if let Some(position_in_set) = item - .accessible_string_property(AccessibleStringProperty::PositionInSet) + .accessible_string_property(AccessibleStringProperty::ItemIndex) .and_then(|s| s.parse::().ok()) { node.set_position_in_set(position_in_set); - } - if let Some(size_of_set) = item - .accessible_string_property(AccessibleStringProperty::SizeOfSet) - .and_then(|s| s.parse::().ok()) - { - node.set_size_of_set(size_of_set); + let mut item = item.clone(); + while let Some(parent) = item.parent_item() { + if !parent.is_accessible() { + item = parent; + continue; + } + if let Some(size_of_set) = parent + .accessible_string_property(AccessibleStringProperty::ItemCount) + .and_then(|s| s.parse::().ok()) + { + node.set_size_of_set(size_of_set); + } + break; + } } let supported = item.supported_accessibility_actions(); diff --git a/internal/compiler/builtins.slint b/internal/compiler/builtins.slint index 9e2cc8ab2..5697d167f 100644 --- a/internal/compiler/builtins.slint +++ b/internal/compiler/builtins.slint @@ -576,7 +576,6 @@ export component NativeScrollView { export component NativeStandardListViewItem { in property index; - in property total-items; in property item; in-out property is_selected; in property has_hover; diff --git a/internal/compiler/typeregister.rs b/internal/compiler/typeregister.rs index a93bfa752..72d5428ff 100644 --- a/internal/compiler/typeregister.rs +++ b/internal/compiler/typeregister.rs @@ -206,10 +206,10 @@ pub fn reserved_accessibility_properties() -> impl Iterator focus-item: 0; accessible-delegate-focus: root.focus-item; + accessible-item-count: root.model.length; pure function first-visible-item() -> int { return min(root.model.length - 1, max(0, round(-root.viewport-y / root.item-height))); @@ -89,7 +90,6 @@ component StandardListViewBase inherits ListView { height: self.min-height; item: item; index: index; - total-items: root.model.length; is-selected: index == root.current-item; has-focus: root.has-focus && index == root.focus-item; has-hover: i-touch-area.has-hover; diff --git a/internal/compiler/widgets/cosmic/components.slint b/internal/compiler/widgets/cosmic/components.slint index 49d2f9f76..5ac7c583b 100644 --- a/internal/compiler/widgets/cosmic/components.slint +++ b/internal/compiler/widgets/cosmic/components.slint @@ -95,7 +95,6 @@ export component ListItem { in property has-hover; in property pressed; in property index; - in property total-items; in property pressed-x; in property pressed-y; @@ -105,10 +104,9 @@ export component ListItem { horizontal-stretch: 1; accessible-role: list-item; accessible-label: root.item.text; - accessible-selectable: true; - accessible-selected: root.is-selected; - accessible-position-in-set: root.index; - accessible-size-of-set: root.total-items; + accessible-item-selectable: true; + accessible-item-selected: root.is-selected; + accessible-item-index: root.index; states [ is-selected when root.is-selected : { diff --git a/internal/compiler/widgets/cupertino/components.slint b/internal/compiler/widgets/cupertino/components.slint index 6603fc9cc..81cc0fb61 100644 --- a/internal/compiler/widgets/cupertino/components.slint +++ b/internal/compiler/widgets/cupertino/components.slint @@ -51,7 +51,6 @@ export component ListItem { in property has-hover; in property pressed; in property index; - in property total-items; in property pressed-x; in property pressed-y; @@ -61,10 +60,9 @@ export component ListItem { horizontal-stretch: 1; accessible-role: list-item; accessible-label: root.item.text; - accessible-selectable: true; - accessible-selected: root.is-selected; - accessible-position-in-set: root.index; - accessible-size-of-set: root.total-items; + accessible-item-selectable: true; + accessible-item-selected: root.is-selected; + accessible-item-index: root.index; states [ has-focus when root.has-focus : { diff --git a/internal/compiler/widgets/fluent/components.slint b/internal/compiler/widgets/fluent/components.slint index 0980d9234..b3d554f51 100644 --- a/internal/compiler/widgets/fluent/components.slint +++ b/internal/compiler/widgets/fluent/components.slint @@ -39,7 +39,6 @@ export component ListItem { in property has-hover; in property pressed; in property index; - in property total-items; in property pressed-x; in property pressed-y; @@ -49,10 +48,9 @@ export component ListItem { horizontal-stretch: 1; accessible-role: list-item; accessible-label: root.item.text; - accessible-selectable: true; - accessible-selected: root.is-selected; - accessible-position-in-set: root.index; - accessible-size-of-set: root.total-items; + accessible-item-selectable: true; + accessible-item-selected: root.is-selected; + accessible-item-index: root.index; states [ pressed when root.pressed : { diff --git a/internal/compiler/widgets/material/components.slint b/internal/compiler/widgets/material/components.slint index 322fc642d..bdb7a2155 100644 --- a/internal/compiler/widgets/material/components.slint +++ b/internal/compiler/widgets/material/components.slint @@ -97,7 +97,6 @@ export component ListItem { in property has_focus; in property pressed; in property index; - in property total-items; in property pressed-x; in property pressed-y; @@ -107,10 +106,9 @@ export component ListItem { horizontal-stretch: 1; accessible-role: list-item; accessible-label: root.item.text; - accessible-selectable: true; - accessible-selected: root.is-selected; - accessible-position-in-set: root.index; - accessible-size-of-set: root.total-items; + accessible-item-selectable: true; + accessible-item-selected: root.is-selected; + accessible-item-index: root.index; states [ pressed when root.pressed: { diff --git a/internal/core/accessibility.rs b/internal/core/accessibility.rs index 328ce02f3..d66b2f1aa 100644 --- a/internal/core/accessibility.rs +++ b/internal/core/accessibility.rs @@ -20,12 +20,12 @@ pub enum AccessibleStringProperty { DelegateFocus, Description, Enabled, + ItemCount, + ItemIndex, + ItemSelectable, + ItemSelected, Label, PlaceholderText, - PositionInSet, - Selectable, - Selected, - SizeOfSet, Value, ValueMaximum, ValueMinimum,