Accessibility: rename a few properties after API review:

- Rename `accessible-selectable` and `accessible-selected` to `accessible-item-{selectable,selected}`.
   Because the property is for items in list rather than eg Text
 - Rename `accessible-position-in-set` to `accessible-item-index`.
 - Rename `accessible-size-of-set` to `accessible-item-count` and move
   the property to the container element rather than the item itself
This commit is contained in:
Olivier Goffart 2024-12-02 11:46:27 +01:00
parent 0f72791977
commit a3dad45f0b
15 changed files with 81 additions and 79 deletions

View file

@ -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)

View file

@ -330,11 +330,11 @@ public:
return std::nullopt;
}
/// Returns the accessible-selected of that element, if any.
std::optional<bool> accessible_selected() const
/// Returns the accessible-item-selected of that element, if any.
std::optional<bool> 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<bool> accessible_selectable() const
/// Returns the accessible-item-selectable of that element, if any.
std::optional<bool> 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<uintptr_t> accessible_position_in_set() const
/// Returns the accessible-item-index of that element, if any.
std::optional<uintptr_t> 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<uintptr_t> accessible_size_of_set() const
/// Returns the accessible-item-count of that element, if any.
std::optional<uintptr_t> 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;

View file

@ -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;

View file

@ -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
<SlintProperty propName="x" typeName="length" >
<SlintProperty propName="x" typeName="length" >
The position of the element relative to its parent.
</SlintProperty>
### y
<SlintProperty propName="y" typeName="length" >
<SlintProperty propName="y" typeName="length" >
The position of the element relative to its parent.
</SlintProperty>
### z
<SlintProperty propName="z" typeName="float" >
<SlintProperty propName="z" typeName="float" >
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
</SlintProperty>
### absolute-position
<SlintProperty propName="absolute-position" typeName="struct" structName="Point" >
<SlintProperty propName="absolute-position" typeName="struct" structName="Point" >
The position of the element within the contained window.
</SlintProperty>
### width
<SlintProperty propName="width" typeName="length" >
<SlintProperty propName="width" typeName="length" >
The width of the element. When set, this overrides the default width.
</SlintProperty>
### height
<SlintProperty propName="height" typeName="length" >
<SlintProperty propName="height" typeName="length" >
The height of the element. When set, this overrides the default height.
</SlintProperty>
@ -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.
:::
</SlintProperty>
@ -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:

View file

@ -11,7 +11,6 @@ use super::*;
pub struct NativeStandardListViewItem {
pub item: Property<i_slint_core::model::StandardListViewItem>,
pub index: Property<i32>,
pub total_items: Property<i32>,
pub is_selected: Property<bool>,
pub cached_rendering_data: CachedRenderingData,
pub has_hover: Property<bool>,

View file

@ -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<bool> {
/// Returns the value of the `accessible-item-selected` property, if present
pub fn accessible_item_selected(&self) -> Option<bool> {
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<bool> {
/// Returns the value of the `accessible-item-selectable` property, if present
pub fn accessible_item_selectable(&self) -> Option<bool> {
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<usize> {
/// Returns the value of the element's `accessible-item-index` property, if present.
pub fn accessible_item_index(&self) -> Option<usize> {
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<usize> {
/// Returns the value of the element's `accessible-item-count` property, if present.
pub fn accessible_item_count(&self) -> Option<usize> {
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())
})
}

View file

@ -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::<usize>().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::<usize>().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::<usize>().ok())
{
node.set_size_of_set(size_of_set);
}
break;
}
}
let supported = item.supported_accessibility_actions();

View file

@ -576,7 +576,6 @@ export component NativeScrollView {
export component NativeStandardListViewItem {
in property <int> index;
in property <int> total-items;
in property <StandardListViewItem> item;
in-out property <bool> is_selected;
in property <bool> has_hover;

View file

@ -206,10 +206,10 @@ pub fn reserved_accessibility_properties() -> impl Iterator<Item = (&'static str
("accessible-action-increment", noarg_callback_type()),
("accessible-action-decrement", noarg_callback_type()),
("accessible-action-set-value", strarg_callback_type()),
("accessible-selectable", Type::Bool),
("accessible-selected", Type::Bool),
("accessible-position-in-set", Type::Int32),
("accessible-size-of-set", Type::Int32),
("accessible-item-selectable", Type::Bool),
("accessible-item-selected", Type::Bool),
("accessible-item-index", Type::Int32),
("accessible-item-count", Type::Int32),
]
.into_iter()
}

View file

@ -34,6 +34,7 @@ component StandardListViewBase inherits ListView {
private property <int> 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;

View file

@ -95,7 +95,6 @@ export component ListItem {
in property <bool> has-hover;
in property <bool> pressed;
in property <int> index;
in property <int> total-items;
in property <length> pressed-x;
in property <length> 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 : {

View file

@ -51,7 +51,6 @@ export component ListItem {
in property <bool> has-hover;
in property <bool> pressed;
in property <int> index;
in property <int> total-items;
in property <length> pressed-x;
in property <length> 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 : {

View file

@ -39,7 +39,6 @@ export component ListItem {
in property <bool> has-hover;
in property <bool> pressed;
in property <int> index;
in property <int> total-items;
in property <length> pressed-x;
in property <length> 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 : {

View file

@ -97,7 +97,6 @@ export component ListItem {
in property <bool> has_focus;
in property <bool> pressed;
in property <int> index;
in property <int> total-items;
in property <length> pressed-x;
in property <length> 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: {

View file

@ -20,12 +20,12 @@ pub enum AccessibleStringProperty {
DelegateFocus,
Description,
Enabled,
ItemCount,
ItemIndex,
ItemSelectable,
ItemSelected,
Label,
PlaceholderText,
PositionInSet,
Selectable,
Selected,
SizeOfSet,
Value,
ValueMaximum,
ValueMinimum,