mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 18:58:36 +00:00
Widgets: test that widgets have the same accessible-role in all styles (#5065)
This commit is contained in:
parent
01e0f0c526
commit
eb2b7bf178
11 changed files with 38 additions and 7 deletions
|
@ -3,6 +3,7 @@
|
|||
|
||||
//! Test that all styles have the same API.
|
||||
|
||||
use i_slint_compiler::expression_tree::Expression;
|
||||
use i_slint_compiler::langtype::Type;
|
||||
use i_slint_compiler::object_tree::PropertyVisibility;
|
||||
use i_slint_compiler::typeloader::TypeLoader;
|
||||
|
@ -28,6 +29,7 @@ impl Display for PropertyInfo {
|
|||
#[derive(Default)]
|
||||
struct Component {
|
||||
properties: BTreeMap<String, PropertyInfo>,
|
||||
accessible_role: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
@ -56,6 +58,22 @@ fn load_component(component: &Rc<i_slint_compiler::object_tree::Component>) -> C
|
|||
)
|
||||
}),
|
||||
);
|
||||
|
||||
if result.accessible_role.is_none() {
|
||||
if let Some(role) = elem.borrow().bindings.get("accessible-role") {
|
||||
match &role.borrow().expression {
|
||||
Expression::Invalid => (),
|
||||
Expression::EnumerationValue(e) => {
|
||||
result.accessible_role = Some(e.enumeration.values[e.value].clone())
|
||||
}
|
||||
e => panic!(
|
||||
"accessible-role not an EnumerationValue : {e:?} (for {:?})",
|
||||
role.borrow().span
|
||||
),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
let e = match &elem.borrow().base_type {
|
||||
i_slint_compiler::langtype::ElementType::Component(r) => r.root_element.clone(),
|
||||
i_slint_compiler::langtype::ElementType::Builtin(b) => {
|
||||
|
@ -150,6 +168,14 @@ fn compare_styles(base: &Style, mut other: Style, style_name: &str) -> bool {
|
|||
let ignore_extra =
|
||||
matches!(compo_name.as_str(), "TabImpl" | "TabWidgetImpl" | "StyleMetrics");
|
||||
if let Some(mut c2) = other.components.remove(compo_name) {
|
||||
if c1.accessible_role != c2.accessible_role {
|
||||
eprintln!(
|
||||
"Mismatch accessible-role for {compo_name} in {style_name} : {:?} != {:?}",
|
||||
c2.accessible_role, c1.accessible_role
|
||||
);
|
||||
ok = false;
|
||||
}
|
||||
|
||||
for (prop_name, p1) in c1.properties.iter() {
|
||||
if let Some(p2) = c2.properties.remove(prop_name) {
|
||||
if p1 != &p2 {
|
||||
|
|
|
@ -19,6 +19,7 @@ export component ComboBox {
|
|||
horizontal-stretch: 1;
|
||||
vertical-stretch: 0;
|
||||
forward-focus: base;
|
||||
accessible-role: combobox;
|
||||
|
||||
states [
|
||||
disabled when !root.enabled : {
|
||||
|
|
|
@ -175,6 +175,7 @@ export component StandardTableView {
|
|||
horizontal-stretch: 1;
|
||||
vertical-stretch: 1;
|
||||
forward-focus: focus-scope;
|
||||
accessible-role: table;
|
||||
|
||||
VerticalLayout {
|
||||
Rectangle {
|
||||
|
|
|
@ -21,6 +21,7 @@ export component ComboBox {
|
|||
horizontal-stretch: 1;
|
||||
vertical-stretch: 0;
|
||||
forward-focus: i-base;
|
||||
accessible-role: combobox;
|
||||
|
||||
states [
|
||||
disabled when !root.enabled : {
|
||||
|
|
|
@ -10,7 +10,6 @@ component TableViewColumn inherits Rectangle {
|
|||
|
||||
callback clicked <=> i-touch-area.clicked;
|
||||
callback adjust-size(/* size **/ length);
|
||||
accessible-role: table;
|
||||
|
||||
background: transparent;
|
||||
|
||||
|
@ -174,6 +173,7 @@ export component StandardTableView {
|
|||
horizontal-stretch: 1;
|
||||
vertical-stretch: 1;
|
||||
forward-focus: i-focus-scope;
|
||||
accessible-role: table;
|
||||
|
||||
VerticalLayout {
|
||||
Rectangle {
|
||||
|
|
|
@ -20,6 +20,8 @@ export component ComboBox {
|
|||
vertical-stretch: 0;
|
||||
forward-focus: i-base;
|
||||
|
||||
accessible-role: combobox;
|
||||
|
||||
states [
|
||||
disabled when !root.enabled : {
|
||||
i-background.background: FluentPalette.control-disabled;
|
||||
|
|
|
@ -10,7 +10,7 @@ export component ProgressIndicator {
|
|||
min-height: 3px;
|
||||
horizontal-stretch: 1;
|
||||
vertical-stretch: 0;
|
||||
accessible-role: none;
|
||||
accessible-role: progress-indicator;
|
||||
accessible-value: root.progress;
|
||||
|
||||
Rectangle {
|
||||
|
|
|
@ -9,7 +9,6 @@ component TableViewColumn inherits Rectangle {
|
|||
|
||||
callback clicked <=> i-touch-area.clicked;
|
||||
callback adjust_size(length);
|
||||
accessible-role: table;
|
||||
|
||||
background: FluentPalette.background;
|
||||
|
||||
|
@ -197,6 +196,7 @@ export component StandardTableView {
|
|||
horizontal-stretch: 1;
|
||||
vertical-stretch: 1;
|
||||
forward-focus: i-focus-scope;
|
||||
accessible-role: table;
|
||||
|
||||
VerticalLayout {
|
||||
Rectangle {
|
||||
|
|
|
@ -20,6 +20,7 @@ export component ComboBox {
|
|||
horizontal-stretch: 1;
|
||||
vertical-stretch: 0;
|
||||
forward-focus: i-base;
|
||||
accessible-role: combobox;
|
||||
|
||||
states [
|
||||
disabled when !root.enabled : {
|
||||
|
|
|
@ -10,7 +10,6 @@ component TableViewColumn inherits Rectangle {
|
|||
|
||||
callback clicked <=> i-state-layer.clicked;
|
||||
callback adjust-size(/* size */ length);
|
||||
accessible-role: table;
|
||||
|
||||
i-state-layer := StateLayer {
|
||||
background: MaterialPalette.accent-background;
|
||||
|
@ -165,6 +164,7 @@ export component StandardTableView {
|
|||
horizontal-stretch: 1;
|
||||
vertical-stretch: 1;
|
||||
forward-focus: i-focus-scope;
|
||||
accessible-role: table;
|
||||
|
||||
VerticalLayout {
|
||||
Rectangle {
|
||||
|
|
|
@ -36,11 +36,10 @@ export component StandardButton {
|
|||
|
||||
callback clicked <=> native.clicked;
|
||||
|
||||
accessible-label: native.text;
|
||||
accessible-role: button;
|
||||
|
||||
HorizontalLayout {
|
||||
native := NativeButton {
|
||||
accessible-label: native.text;
|
||||
accessible-role: button;
|
||||
is-standard-button: true;
|
||||
checkable: false;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue