Skip to content

Commit

Permalink
Add a checked property on checkbox. Close #693. (#916)
Browse files Browse the repository at this point in the history
* feat: add a checked property on checkbox. Close #693.

* chore: update CHANGELOG.md

---------

Co-authored-by: ElKowar <[email protected]>
  • Loading branch information
levnikmyskin and elkowar authored Apr 6, 2024
1 parent 5fdaa4e commit ebe5f34
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 3 additions & 1 deletion crates/eww/src/widgets/widget_definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}));
Expand Down

0 comments on commit ebe5f34

Please sign in to comment.