Skip to content

Commit

Permalink
Add toolbar view (#127)
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 SearchEntry widget

* Add Search Entry Widget

* Add text field to searchEntry widget

* Add missing text hook

* Improve search entry example

* Further improve example

* Refine which fields you shouldn't have access to

* Add activity to when you stop a search

* Add activity to when you stop a search

* Fix search entry displaying weird spacing

* Unify GtkMinor into a single constant

* Debug change

Attempt to cat out the gtk.nim file to see how the hell it is
getting the impression that GtkMinor is defined twice.

* Move GtkMInor before the passL flag is passed?

Maybe this fixes the problem with the pipeline sudenly thinking
that value was defined twice.

* Unto test-pipeline debug change

* Comment out unsupported search thingy

* Minor tweaks

- Removed searchstring parameter from callbacks
- made sure only changed callback can modify search value
- Updated example
- Moved example to far nicer looking ListBox

* Remove unnecessary Box

* Update examples/widgets/search_entry.nim

Co-authored-by: Can Lehmann <85876381+can-lehmann@users.noreply.github.com>

---------

Co-authored-by: Can Lehmann <85876381+can-lehmann@users.noreply.github.com>

* Add PasswordEntry widget

* Add core of password entry widget

* Add bindings for menu model

I do not plan to act on them yet but I'd like to
at least already add them so I don't have to
make the effort later

* Update password entry docs

* Improve gitignore

* Use unsafeAddr for nim version 1.0

* Fix GValue being let instead of var

* Add text field to password entry

* Ensure activateEventCallback also updates state

* Add missing text hook

* Add way to demonstrate 2 way binding

* Remove unnecessary pragma ping pong

* Removed password from activate callback parameters

* Add ActionBar widget

* Make Centerbox orientable

* Add Action Bar Widget and docs

* Minor refinement to the action bar example

It now actually "deletes" the contents of the label.
There's also a button to reset its value.

* Improve example button styling

* Add examples to .gitignore

* Update docs

* Add toolbar view widget

* Set actionbar revealed default value as in gtk

* Add toolbar view to examples ignored by CI

* Update docs

* Fix merge

* Use since pragma

* Improve examples

---------

Co-authored-by: Can Lehmann <can.l@posteo.de>
  • Loading branch information
PhilippMDoerner and can-lehmann committed Jun 11, 2024
1 parent 78a9acc commit 8388233
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 0 deletions.
Binary file added docs/assets/examples/toolbar_view.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions docs/widgets_adwaita.md
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,35 @@ renderable StatusPage of BaseWidget
- `addPaintable`


## ToolbarView

```nim
renderable ToolbarView of BaseWidget
```

Since: `AdwVersion >= (1, 4)`

###### Fields

- All fields from [BaseWidget](#BaseWidget)
- `content: Widget`
- `bottomBars: seq[Widget]`
- `topBars: seq[Widget]`
- `bottomBarStyle: ToolbarStyle = ToolbarFlat`
- `extendContentToBottomEdge: bool = false`
- `extendContentToTopEdge: bool = false`
- `revealBottomBars: bool = true`
- `revealTopBars: bool = true`
- `topBarStyle: ToolbarStyle = ToolbarFlat`

###### Adders

- All adders from [BaseWidget](#BaseWidget)
- `add`
- `addBottom`
- `addTop`


## AboutWindow

```nim
Expand Down
4 changes: 4 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,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/switch_row.nim">Switch Row</a></td>
<td><img alt="Switch Row" src="../docs/assets/examples/switch_row.png" width="480px"></td>
</tr>
<tr>
<td><a href="https://github.com/can-lehmann/owlkettle/blob/main/examples/widgets/adw/toolbar_view.nim">Toolbar View</a></td>
<td><img alt="Toolbar View" src="../docs/assets/examples/toolbar_view.png" width="622px"></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
85 changes: 85 additions & 0 deletions examples/widgets/adw/toolbar_view.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# 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:
bottomBarStyle: ToolbarStyle = ToolbarRaisedBorder
extendContentToBottomEdge: bool = true
extendContentToTopEdge: bool = true
revealBottomBars: bool = true
revealTopBars: bool = true
topBarStyle: ToolbarStyle = ToolbarRaisedBorder
sensitive: bool = true
tooltip: string = ""
sizeRequest: tuple[x, y: int] = (-1, -1)

method view(app: AppState): Widget =
result = gui:
Window:
title = "Toolbar View Example"
defaultSize = (500, 300)

HeaderBar {.addTitlebar.}:
insert(app.toAutoFormMenu(sizeRequest = (400, 250))) {.addRight.}

ToolbarView:
bottomBarStyle = app.bottomBarStyle
extendContentToBottomEdge = app.extendContentToBottomEdge
extendContentToTopEdge = app.extendContentToTopEdge
revealBottomBars = app.revealBottomBars
revealTopBars = app.revealTopBars
topBarStyle = app.topBarStyle
sensitive = app.sensitive
tooltip = app.tooltip
sizeRequest = app.sizeRequest

Box:
Box {.hAlign: AlignCenter, vAlign: AlignCenter.}:
orient = OrientY
spacing = 12

Label(text = "I am a child of a Toolbar View")

Button:
text = "Toggle Top"
proc clicked() =
app.revealTopBars = not app.revealTopBars

Button:
text = "Toggle Bottom"
proc clicked() =
app.revealBottomBars = not app.revealBottomBars

ActionBar {.addTop.}:
revealed = true

Label:
text = "Top bar"

ActionBar {.addBottom.}:
revealed = true

Label:
text = "Bottom Bar"

adw.brew(gui(App()))
1 change: 1 addition & 0 deletions owlkettle.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ task examples, "Build examples":
"widgets/adw/banner.nim",
"widgets/adw/entry_row.nim",
"widgets/adw/switch_row.nim",
"widgets/adw/toolbar_view.nim",
"widgets/adw/overlay_split_view.nim",
"widgets/adw/button_content.nim",
"widgets/adw/about_window.nim"
Expand Down
82 changes: 82 additions & 0 deletions owlkettle/adw.nim
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export adw.ColorScheme
export adw.FlapFoldPolicy
export adw.FoldThresholdPolicy
export adw.FlapTransitionType
export adw.ToolbarStyle
export adw.LengthUnit
export adw.CenteringPolicy
export adw.AdwVersion
Expand Down Expand Up @@ -1005,6 +1006,87 @@ renderable StatusPage of BaseWidget:
widget.hasPaintable = true
widget.valPaintable = child

renderable ToolbarView {.since: AdwVersion >= (1, 4).} of BaseWidget:
content: Widget
bottomBars: seq[Widget]
topBars: seq[Widget]
bottomBarStyle: ToolbarStyle = ToolbarFlat
extendContentToBottomEdge: bool = false
extendContentToTopEdge: bool = false
revealBottomBars: bool = true
revealTopBars: bool = true
topBarStyle: ToolbarStyle = ToolbarFlat

hooks:
beforeBuild:
state.internalWidget = adw_toolbar_view_new()

hooks content:
(build, update):
state.updateChild(
state.content,
widget.valContent,
adw_toolbar_view_set_content
)

hooks bottomBars:
(build, update):
state.updateChildren(
state.bottomBars,
widget.valBottomBars,
adw_toolbar_view_add_bottom_bar,
adw_toolbar_view_remove
)

hooks topBars:
(build, update):
state.updateChildren(
state.topBars,
widget.valTopBars,
adw_toolbar_view_add_top_bar,
adw_toolbar_view_remove
)

hooks bottomBarStyle:
property:
adw_toolbar_view_set_bottom_bar_style(state.internalWidget, state.bottomBarStyle)

hooks extendContentToBottomEdge:
property:
adw_toolbar_view_set_extend_content_to_bottom_edge(state.internalWidget, state.extendContentToBottomEdge.cbool)

hooks extendContentToTopEdge:
property:
adw_toolbar_view_set_extend_content_to_top_edge(state.internalWidget, state.extendContentToTopEdge.cbool)

hooks revealBottomBars:
property:
adw_toolbar_view_set_reveal_bottom_bars(state.internalWidget, state.revealBottomBars.cbool)

hooks revealTopBars:
property:
adw_toolbar_view_set_reveal_top_bars(state.internalWidget, state.revealTopBars.cbool)

hooks topBarStyle:
property:
adw_toolbar_view_set_top_bar_style(state.internalWidget, state.topBarStyle)

adder add:
if widget.hasContent:
raise newException(ValueError, "Unable to add multiple children to a ToolbarView. Use a Box widget to display multiple widgets!")
widget.hasContent = true
widget.valContent = child

adder addBottom:
widget.hasBottomBars = true
widget.valBottomBars.add(child)

adder addTop:
widget.hasTopBars = true
widget.valTopBars.add(child)

when AdwVersion >= (1, 4):
export ToolbarView

type LicenseType* = enum
LicenseUnknown = 0
Expand Down
18 changes: 18 additions & 0 deletions owlkettle/bindings/adw.nim
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ type
LengthPoint
LengthScaleIndependent

ToolbarStyle* = enum
ToolbarFlat
ToolbarRaised
ToolbarRaisedBorder

proc isNil*(manager: StyleManager): bool {.borrow.}

{.push importc, cdecl.}
Expand Down Expand Up @@ -224,6 +229,19 @@ proc adw_status_page_set_icon_name*(self: GtkWidget, icon_name: cstring)
proc adw_status_page_set_paintable*(self: GtkWidget, paintable: GtkWidget)
proc adw_status_page_set_title*(self: GtkWidget, title: cstring)

when AdwVersion >= (1, 4):
proc adw_toolbar_view_new*(): GtkWidget
proc adw_toolbar_view_add_bottom_bar*(self, widget: GtkWidget)
proc adw_toolbar_view_add_top_bar*(self, widget: GtkWidget)
proc adw_toolbar_view_remove*(self, widget: GtkWidget)
proc adw_toolbar_view_set_bottom_bar_style*(self: GtkWidget, style: ToolbarStyle)
proc adw_toolbar_view_set_content*(self, content: GtkWidget)
proc adw_toolbar_view_set_extend_content_to_bottom_edge*(self: GtkWidget, extend: cbool)
proc adw_toolbar_view_set_extend_content_to_top_edge*(self: GtkWidget, extend: cbool)
proc adw_toolbar_view_set_reveal_bottom_bars*(self: GtkWidget, reveal: cbool)
proc adw_toolbar_view_set_reveal_top_bars*(self: GtkWidget, reveal: cbool)
proc adw_toolbar_view_set_top_bar_style*(self: GtkWidget, style: ToolbarStyle)

# Adw.HeaderBar
proc adw_header_bar_new*(): GtkWidget
proc adw_header_bar_pack_end*(self, child: GtkWidget)
Expand Down

0 comments on commit 8388233

Please sign in to comment.