diff --git a/docs/assets/examples/switch_row.png b/docs/assets/examples/switch_row.png new file mode 100644 index 00000000..7b304907 Binary files /dev/null and b/docs/assets/examples/switch_row.png differ diff --git a/docs/widgets_adwaita.md b/docs/widgets_adwaita.md index 20ece73a..fddd1080 100644 --- a/docs/widgets_adwaita.md +++ b/docs/widgets_adwaita.md @@ -434,6 +434,22 @@ renderable AboutWindow - `license: string` +## SwitchRow + +```nim +renderable SwitchRow of ActionRow +``` + +###### Fields + +- All fields from [ActionRow](#ActionRow) +- `active: bool` + +###### Events + +- activated: `proc (active: bool)` + + ## Banner ```nim diff --git a/examples/README.md b/examples/README.md index bfcbe103..2278ad09 100644 --- a/examples/README.md +++ b/examples/README.md @@ -240,6 +240,10 @@ The `widgets` directory contains examples for how to use different widgets. Status Page Status Page + + Switch Row + Switch Row + Window Title Window Title diff --git a/examples/widgets/adw/switch_row.nim b/examples/widgets/adw/switch_row.nim new file mode 100644 index 00000000..67361d12 --- /dev/null +++ b/examples/widgets/adw/switch_row.nim @@ -0,0 +1,61 @@ +# MIT License +# +# Copyright (c) 2022 Can Joshua Lehmann +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +import owlkettle, owlkettle/[playground, adw] + +viewable App: + active: bool = false + title: string = "Switch Row Title" + subtitle: string = "subtitle" + sensitive: bool = true + tooltip: string = "" + sizeRequest: tuple[x, y: int] = (-1, -1) + +method view(app: AppState): Widget = + result = gui: + Window(): + defaultSize = (400, 150) + title = "Switch Row Example" + HeaderBar {.addTitlebar.}: + insert(app.toAutoFormMenu(sizeRequest = (400, 510))){.addRight.} + + Clamp: + maximumSize = 500 + margin = 12 + + Box(): + margin = 12 + PreferencesGroup(): + title = "Switch Row" + + SwitchRow(): + title = app.title + active = app.active + subtitle = app.subtitle + sensitive = app.sensitive + tooltip = app.tooltip + sizeRequest = app.sizeRequest + + proc activated(active: bool) = + app.active = active + echo "New Value: ", active +adw.brew(gui(App())) diff --git a/owlkettle.nimble b/owlkettle.nimble index d60f7576..3479adeb 100644 --- a/owlkettle.nimble +++ b/owlkettle.nimble @@ -16,10 +16,11 @@ proc findExamples(path: string): seq[string] = task examples, "Build examples": when defined(github): - # Can not compile because they rely on an adwaita version higher than available in test-image of CI pipeline + # Can not compile because they rely on an adwaita version higher than available in test-image of CI pipeline let uncompileable: seq[string] = @[ "widgets/adw/banner.nim", - "widgets/adw/entry_row.nim" + "widgets/adw/entry_row.nim", + "widgets/adw/switch_row.nim" ] let adwaitaFlag = "" else: diff --git a/owlkettle/adw.nim b/owlkettle/adw.nim index 45d473aa..0ba401d8 100644 --- a/owlkettle/adw.nim +++ b/owlkettle/adw.nim @@ -717,7 +717,6 @@ when AdwVersion >= (1, 2) or defined(owlkettleDocs): property: when AdwVersion >= (1, 2): adw_about_window_set_issue_url(state.internalWidget, state.issueUrl.cstring) - hooks website: property: @@ -735,6 +734,36 @@ when AdwVersion >= (1, 2) or defined(owlkettleDocs): adw_about_window_set_license(state.internalWidget, state.license.cstring) export AboutWindow + +when AdwVersion >= (1, 4) or defined(owlkettleDocs): + renderable SwitchRow of ActionRow: + active: bool + + proc activated(active: bool) + + hooks: + beforeBuild: + when AdwVersion >= (1, 4): + state.internalWidget = adw_switch_row_new() + connectEvents: + when AdwVersion >= (1, 4): + proc activatedCallback(widget: GtkWidget, data: ptr EventObj[proc (active: bool)]) {.cdecl.} = + let active: bool = adw_switch_row_get_active(widget).bool + SwitchRowState(data[].widget).active = active + data[].callback(active) + data[].redraw() + + state.connect(state.activated, "activated", activatedCallback) + disconnectEvents: + when AdwVersion >= (1, 4): + state.internalWidget.disconnect(state.activated) + + hooks active: + property: + when AdwVersion >= (1, 4): + adw_switch_row_set_active(state.internalWidget, state.active.cbool) + + export SwitchRow when AdwVersion >= (1, 3) or defined(owlkettleDocs): renderable Banner of BaseWidget: diff --git a/owlkettle/bindings/adw.nim b/owlkettle/bindings/adw.nim index 4025be2f..c55caefa 100644 --- a/owlkettle/bindings/adw.nim +++ b/owlkettle/bindings/adw.nim @@ -167,6 +167,11 @@ when AdwVersion >= (1, 2): proc adw_about_window_set_copyright*(window: GtkWidget, value: cstring) proc adw_about_window_set_license*(window: GtkWidget, value: cstring) +when AdwVersion >= (1, 4): + # Adw.SwitchRow + proc adw_switch_row_new*(): GtkWidget + proc adw_switch_row_set_active*(self: GtkWidget, is_active: cbool) + proc adw_switch_row_get_active*(self: GtkWidget): cbool when AdwVersion >= (1, 3): # Adw.Banner proc adw_banner_new*(title: cstring): GtkWidget