Add the accessible-expandable property

This commit is contained in:
Arnold Loubriat 2024-12-22 16:15:37 +01:00 committed by Simon Hausmann
parent e442965889
commit 53fd7b12e4
12 changed files with 42 additions and 0 deletions

View file

@ -382,6 +382,19 @@ public:
return std::nullopt;
}
/// Returns the accessible-expandable of that element, if any.
std::optional<bool> accessible_expandable() const
{
if (auto result = get_accessible_string_property(
cbindgen_private::AccessibleStringProperty::Expandable)) {
if (*result == "true")
return true;
else if (*result == "false")
return false;
}
return std::nullopt;
}
/// Sets the accessible-value of that element.
///
/// Setting the value will invoke the `accessible-action-set-value` callback.

View file

@ -207,6 +207,11 @@ The description for the current element.
Whether the element is enabled or not. This maps to the "enabled" state of most widgets. (default value: `true`)
</SlintProperty>
### accessible-expandable
<SlintProperty typeName="bool" propName="accessible-expandable" default="false">
Whether the element can be expanded or not.
</SlintProperty>
### accessible-label
<SlintProperty typeName="string" propName="accessible-label" default='""'>
The label for an interactive element. (default value: empty for most elements, or the value of the `text` property for Text elements)

View file

@ -30,6 +30,7 @@ const VALUE_MINIMUM: u32 = CHECKED + 1;
const VALUE_MAXIMUM: u32 = VALUE_MINIMUM + 1;
const VALUE_STEP: u32 = VALUE_MAXIMUM + 1;
const CHECKABLE: u32 = VALUE_STEP + 1;
const EXPANDABLE: u32 = CHECKABLE + 1;
pub struct AccessibleItemPropertiesTracker {
obj: *mut c_void,
@ -208,6 +209,7 @@ impl SlintAccessibleItemData {
if let Some(item_rc) = item.upgrade() {
item_rc.accessible_string_property(AccessibleStringProperty::Checkable);
item_rc.accessible_string_property(AccessibleStringProperty::Checked);
item_rc.accessible_string_property(AccessibleStringProperty::Expandable);
}
});
}
@ -267,6 +269,7 @@ cpp! {{
const uint32_t VALUE_MAXIMUM { VALUE_MINIMUM + 1 };
const uint32_t VALUE_STEP { VALUE_MAXIMUM + 1 };
const uint32_t CHECKABLE { VALUE_STEP + 1 };
const uint32_t EXPANDABLE { CHECKABLE + 1 };
// ------------------------------------------------------------------------------
// Helper:
@ -362,6 +365,7 @@ cpp! {{
VALUE_MAXIMUM => item.accessible_string_property(AccessibleStringProperty::ValueMaximum),
VALUE_STEP => item.accessible_string_property(AccessibleStringProperty::ValueStep),
CHECKABLE => item.accessible_string_property(AccessibleStringProperty::Checkable),
EXPANDABLE => item.accessible_string_property(AccessibleStringProperty::Expandable),
_ => None,
};
if let Some(string) = string {
@ -621,6 +625,7 @@ cpp! {{
state.focused = has_focus_delegation;
state.checked = (checked == "true") ? 1 : 0;
state.checkable = (item_string_property(m_data, CHECKABLE) == "true") ? 1 : 0;
state.expandable = (item_string_property(m_data, EXPANDABLE) == "true") ? 1 : 0;
return state; /* FIXME */
}

View file

@ -647,6 +647,17 @@ impl ElementHandle {
})
}
/// Returns the value of the `accessible-expandable` property, if present
pub fn accessible_expandable(&self) -> Option<bool> {
if self.element_index != 0 {
return None;
}
self.item
.upgrade()
.and_then(|item| item.accessible_string_property(AccessibleStringProperty::Expandable))
.and_then(|item| item.parse().ok())
}
/// Returns the size of the element in logical pixels. This corresponds to the value of the `width` and
/// `height` properties in Slint code. Returns a zero size if the element is not valid.
pub fn size(&self) -> i_slint_core::api::LogicalSize {

View file

@ -197,6 +197,7 @@ pub fn reserved_accessibility_properties() -> impl Iterator<Item = (&'static str
("accessible-delegate-focus", Type::Int32),
("accessible-description", Type::String),
("accessible-enabled", Type::Bool),
("accessible-expandable", Type::Bool),
("accessible-label", Type::String),
("accessible-value", Type::String),
("accessible-value-maximum", Type::Float32),

View file

@ -26,6 +26,7 @@ export component ComboBox {
forward-focus: base;
accessible-role: combobox;
accessible-enabled: root.enabled;
accessible-expandable: true;
accessible-value <=> root.current-value;
states [

View file

@ -26,6 +26,7 @@ export component ComboBox {
forward-focus: base;
accessible-role: combobox;
accessible-enabled: root.enabled;
accessible-expandable: true;
accessible-value <=> root.current-value;
states [

View file

@ -26,6 +26,7 @@ export component ComboBox {
accessible-role: combobox;
accessible-enabled: root.enabled;
accessible-expandable: true;
accessible-value <=> root.current-value;
states [

View file

@ -25,6 +25,7 @@ export component ComboBox {
forward-focus: base;
accessible-role: combobox;
accessible-enabled: root.enabled;
accessible-expandable: true;
accessible-value <=> root.current-value;
states [

View file

@ -15,6 +15,7 @@ export component ComboBox {
accessible-role: combobox;
accessible-enabled: root.enabled;
accessible-expandable: true;
accessible-value <=> root.current-value;
forward-focus: base;

View file

@ -17,6 +17,7 @@ pub enum AccessibleStringProperty {
DelegateFocus,
Description,
Enabled,
Expandable,
ItemCount,
ItemIndex,
ItemSelectable,

View file

@ -45,6 +45,7 @@ assert_eq!(instance.get_has_focus(), false);
let mut combobox_search = slint_testing::ElementHandle::find_by_element_id(&instance, "TestCase::box");
let combobox = combobox_search.next().unwrap();
assert_eq!(combobox.accessible_expandable(), Some(true));
assert_eq!(combobox.accessible_value(), Some(SharedString::from("Aaa")));
// Change the index programmatically