Add a checked property on checkbox. Close #693. (#916)

* feat: add a checked property on checkbox. Close #693.

* chore: update CHANGELOG.md

---------

Co-authored-by: ElKowar <5300871+elkowar@users.noreply.github.com>
This commit is contained in:
Alessio Molinari 2024-04-06 13:11:59 +02:00 committed by GitHub
parent 5fdaa4e03f
commit ebe5f349d1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 1 deletions

View File

@ -11,6 +11,7 @@ All notable changes to eww will be listed here, starting at changes since versio
### Features
- Add `systray` widget (By: ralismark)
- Add `:checked` property to checkbox (By: levnikmyskin)
## [0.5.0] (17.02.2024)

View File

@ -345,10 +345,12 @@ const WIDGET_NAME_CHECKBOX: &str = "checkbox";
fn build_gtk_checkbox(bargs: &mut BuilderArgs) -> Result<gtk::CheckButton> {
let gtk_widget = gtk::CheckButton::new();
def_widget!(bargs, _g, gtk_widget, {
// @prop checked - whether the checkbox is toggled or not when created
// @prop timeout - timeout of the command. Default: "200ms"
// @prop onchecked - action (command) to be executed when checked by the user
// @prop onunchecked - similar to onchecked but when the widget is unchecked
prop(timeout: as_duration = Duration::from_millis(200), onchecked: as_string = "", onunchecked: as_string = "") {
prop(checked: as_bool = false, timeout: as_duration = Duration::from_millis(200), onchecked: as_string = "", onunchecked: as_string = "") {
gtk_widget.set_active(checked);
connect_signal_handler!(gtk_widget, gtk_widget.connect_toggled(move |gtk_widget| {
run_command(timeout, if gtk_widget.is_active() { &onchecked } else { &onunchecked }, &[] as &[&str]);
}));