Skip to content

Commit

Permalink
Add SwitchRow widget
Browse files Browse the repository at this point in the history
* Move gtk.nim into bindings dir

* Refactor adwaita bindings into a binding module

* Re export bound enums

* Add Switch Row widget

* Remove switchrow from github CI examples

* Move example over to PreferencesGroup

* Remove actionName and actionTarget

They are part of GTK's actions feature, which is not supported by
owlkettle

* Beautify example

* Remove unused bindings

* update docs
  • Loading branch information
PhilippMDoerner authored Oct 23, 2023
1 parent 020d4ef commit bea3e3a
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 3 deletions.
Binary file added docs/assets/examples/switch_row.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions docs/widgets_adwaita.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ The `widgets` directory contains examples for how to use different widgets.
<td><a href="https://github.com/can-lehmann/owlkettle/blob/main/examples/widgets/adw/status_page.nim">Status Page</a></td>
<td><img alt="Status Page" src="../docs/assets/examples/status_page.png" width="704px"></td>
</tr>
<tr>
<td><a href="https://github.com/can-lehmann/owlkettle/blob/main/examples/widgets/adw/switch_row.nim">Switch Row</a></td>
<td><img alt="Switch Row" src="../docs/assets/examples/switch_row.png" width="522px"></td>
</tr>
<tr>
<td><a href="https://github.com/can-lehmann/owlkettle/blob/main/examples/widgets/adw/window_title.nim">Window Title</a></td>
<td><img alt="Window Title" src="../docs/assets/examples/window_title.png" width="288px"></td>
Expand Down
61 changes: 61 additions & 0 deletions examples/widgets/adw/switch_row.nim
Original file line number Diff line number Diff line change
@@ -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()))
5 changes: 3 additions & 2 deletions owlkettle.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
31 changes: 30 additions & 1 deletion owlkettle/adw.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions owlkettle/bindings/adw.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bea3e3a

Please sign in to comment.