Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions internal/compiler/widgets/common/textedit-base.slint
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,19 @@ export component TextEditBase inherits Rectangle {
}

public function cut() {
text-input.cut();
if (!root.read_only && root.enabled) {
text-input.cut();
}
}

public function copy() {
text-input.copy();
}

public function paste() {
text-input.paste();
if (!root.read_only && root.enabled) {
text-input.paste();
}
}

forward-focus: text-input;
Expand Down
6 changes: 4 additions & 2 deletions internal/compiler/widgets/cosmic/switch.slint
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ export component Switch {
accessible-checked <=> root.checked;
accessible-role: switch;
accessible-action-default => {
root.checked = !root.checked;
root.toggled();
if(root.enabled) {
root.checked = !root.checked;
root.toggled();
}
}
forward-focus: state-layer;

Expand Down
6 changes: 4 additions & 2 deletions internal/compiler/widgets/cupertino/switch.slint
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ export component Switch {
accessible-checked <=> root.checked;
accessible-role: switch;
accessible-action-default => {
root.checked = !root.checked;
root.toggled();
if (root.enabled) {
root.checked = !root.checked;
root.toggled();
}
}
forward-focus: i-focus-scope;

Expand Down
8 changes: 6 additions & 2 deletions internal/compiler/widgets/cupertino/textedit.slint
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,19 @@ export component TextEdit {
}

public function cut() {
text-input.cut();
if (!root.read-only && root.enabled) {
text-input.cut();
}
}

public function copy() {
text-input.copy();
}

public function paste() {
text-input.paste();
if (!root.read-only && root.enabled) {
text-input.paste();
}
}

forward-focus: text-input;
Expand Down
6 changes: 4 additions & 2 deletions internal/compiler/widgets/fluent/switch.slint
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ export component Switch {
accessible-checked <=> root.checked;
accessible-role: switch;
accessible-action-default => {
root.checked = !root.checked;
root.toggled();
if(root.enabled) {
root.checked = !root.checked;
root.toggled();
}
}
forward-focus: focus-scope;

Expand Down
6 changes: 4 additions & 2 deletions internal/compiler/widgets/material/switch.slint
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ export component Switch {
accessible-checked <=> root.checked;
accessible-role: switch;
accessible-action-default => {
root.checked = !root.checked;
root.toggled();
if(root.enabled) {
root.checked = !root.checked;
root.toggled();
}
}

states [
Expand Down
6 changes: 4 additions & 2 deletions internal/compiler/widgets/qt/switch.slint
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ export component Switch inherits NativeCheckBox {
accessible-label <=> root.text;
accessible-role: switch;
accessible-action-default => {
root.checked = !root.checked;
root.toggled();
if(root.enabled) {
root.checked = !root.checked;
root.toggled();
}
}
}
17 changes: 17 additions & 0 deletions tests/cases/widgets/switch.slint
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export component TestCase inherits Window {

in-out property <string> toggled;
in-out property <bool> checked <=> a.checked;
in-out property <bool> enabled <=> a.enabled;

HorizontalLayout {
alignment: start;
Expand Down Expand Up @@ -40,6 +41,15 @@ aaa.invoke_accessible_default_action();
assert_eq!(instance.get_checked(), true, "Switch a was not checked");
assert_eq!(aaa.accessible_checked(), Some(true));
assert_eq!(instance.get_toggled(), SharedString::from("a"));

assert_eq!(aaa.accessible_enabled(), Some(true));
instance.set_enabled(false);
assert_eq!(aaa.accessible_enabled(), Some(false));
assert_eq!(instance.get_toggled(), SharedString::from("a"));

aaa.invoke_accessible_default_action();
assert_eq!(instance.get_toggled(), SharedString::from("a"));

```

```cpp
Expand All @@ -61,6 +71,13 @@ assert_eq(instance.get_checked(), true);
assert_eq(aaa.accessible_checked().value(), true);
assert_eq(instance.get_toggled(), "a");

assert_eq(aaa.accessible_enabled().value(), true);

instance.set_enabled(false);
assert_eq(aaa.accessible_enabled().value(), false);
assert_eq(instance.get_toggled(), "a");
aaa.invoke_accessible_default_action();
assert_eq(instance.get_toggled(), "a");
```

*/
10 changes: 10 additions & 0 deletions tests/cases/widgets/textedit.slint
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export component TestCase inherits Window {
callback edited <=> edit.edited;
in-out property <string> text <=> edit.text;
in-out property <bool> read-only <=> edit.read-only;
in-out property <bool> enabled <=> edit.enabled;
public function paste() {
edit.paste();
}
Expand Down Expand Up @@ -98,6 +99,15 @@ let edit = edit_search.next().unwrap();
assert_eq!(edit.accessible_read_only(), Some(false));
instance.set_read_only(true);
assert_eq!(edit.accessible_read_only(), Some(true));

instance.set_read_only(true);
instance.invoke_paste();
assert_eq!(instance.get_text(), "XxxHello👋");
instance.set_read_only(false);

instance.set_enabled(false);
instance.invoke_paste();
assert_eq!(instance.get_text(), "XxxHello👋");
```

*/
2 changes: 1 addition & 1 deletion ui-libraries/material/src/ui/components/switch.slint
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export component Switch {
accessible-checkable: true;
accessible-checked <=> root.checked;
accessible-role: switch;
accessible-action-default => { touch_area.clicked(); }
accessible-action-default => { if(root.enabled) {touch_area.clicked();} }
forward_focus: touch_area;

touch_area := FocusTouchArea {
Expand Down
Loading