Skip to content

Commit

Permalink
Create a general EntryRow example from the Password Entry Row example
Browse files Browse the repository at this point in the history
  • Loading branch information
can-lehmann committed Oct 22, 2023
1 parent cd3c761 commit 74026cd
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ examples/widgets/adw/preferences_group
examples/widgets/adw/flap
examples/widgets/adw/expander_row
examples/widgets/adw/combo_row
examples/widgets/adw/entry_row
examples/dialogs/file_dialog
examples/dialogs/message_dialog
examples/dialogs/about_dialog
Expand Down
Binary file added docs/assets/examples/entry_row.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/assets/examples/password_entry_row.png
Binary file not shown.
25 changes: 24 additions & 1 deletion docs/widgets_adwaita.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ renderable EntryRow of PreferencesRow
###### Fields

- All fields from [PreferencesRow](#PreferencesRow)
- `subtitle: string`
- `suffixes: seq[AlignedChild[Widget]]`
- `text: string`

Expand All @@ -277,17 +276,41 @@ renderable EntryRow of PreferencesRow
- `hAlign = AlignFill`
- `vAlign = AlignCenter`

###### Example

```nim
EntryRow:
title = "Name"
text = app.name
proc changed(name: string) =
app.name = name
```


## PasswordEntryRow

```nim
renderable PasswordEntryRow of EntryRow
```

An `EntryRow` that hides the user input

###### Fields

- All fields from [EntryRow](#EntryRow)

###### Example

```nim
PasswordEntryRow:
title = "Password"
text = app.name
proc changed(name: string) =
app.name = name
```


## Flap

Expand Down
8 changes: 4 additions & 4 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,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/combo_row.nim">Combo Row</a></td>
<td><img alt="Combo Row" src="../docs/assets/examples/combo_row.png" width="684px"></td>
</tr>
<tr>
<td><a href="https://github.com/can-lehmann/owlkettle/blob/main/examples/widgets/adw/entry_row.nim">Entry Row</a></td>
<td><img alt="Entry Row" src="../docs/assets/examples/entry_row.png" width="622px"></td>
</tr>
<tr>
<td><a href="https://github.com/can-lehmann/owlkettle/blob/main/examples/widgets/adw/expander_row.nim">Expander Row</a></td>
<td><img alt="Expander Row" src="../docs/assets/examples/expander_row.png" width="803px"></td>
Expand All @@ -228,10 +232,6 @@ 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/flap.nim">Flap</a></td>
<td><img alt="Flap" src="../docs/assets/examples/flap.png" width="622px"></td>
</tr>
<tr>
<td><a href="https://github.com/can-lehmann/owlkettle/blob/main/examples/widgets/adw/password_entry_row.nim">Password Entry Row</a></td>
<td><img alt="Password Entry Row" src="../docs/assets/examples/password_entry_row.png" width="622px"></td>
</tr>
<tr>
<td><a href="https://github.com/can-lehmann/owlkettle/blob/main/examples/widgets/adw/preferences_group.nim">Preferences Group</a></td>
<td><img alt="Preferences Group" src="../docs/assets/examples/preferences_group.png" width="721px"></td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,69 @@
import owlkettle, owlkettle/[adw, playground]

viewable App:
title: string = "Password"
password: string
text: string

title: string = "Entry Row"
sensitive: bool = true
tooltip: string = ""
sizeRequest: tuple[x, y: int] = (-1, -1)

method view(app: AppState): Widget =
result = gui:
Window:
title = "Password Entry Row Example"
defaultSize = (500, 120)
title = "Entry Row Example"
defaultSize = (500, 300)

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

ListBox:
PasswordEntryRow {.addRow.}:
title = app.title
sensitive = app.sensitive
tooltip = app.tooltip
sizeRequest = app.sizeRequest
Clamp:
maximumSize = 500
margin = 12

Box:
orient = OrientY
spacing = 12

PreferencesGroup {.expand: false.}:
title = "Entry Row"

EntryRow:
text = app.text

title = app.title
sensitive = app.sensitive
tooltip = app.tooltip
sizeRequest = app.sizeRequest

proc changed(text: string) =
app.text = text

EntryRow:
text = app.text

title = "With Suffix"

proc changed(text: string) =
app.text = text

Button {.addSuffix.}:
icon = "user-trash-symbolic"
style = [ButtonFlat]

proc clicked() =
app.text = ""

proc changed(newPassword: string) =
app.password = newPassword
PreferencesGroup {.expand: false.}:
title = "Password Entry Row"
description = "Hides the user input"

PasswordEntryRow:
text = app.text

title = "Password"

proc changed(text: string) =
app.text = text

adw.brew(gui(App()))
6 changes: 5 additions & 1 deletion owlkettle.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ proc findExamples(path: string): seq[string] =

task examples, "Build examples":
when defined(github):
let uncompileable: seq[string] = @["widgets/adw/banner.nim", "widgets/adw/password_entry_row.nim"] # 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"
]
let adwaitaFlag = ""
else:
let uncompileable: seq[string] = @[] # You should be able to run any example locally assuming you have an up-to-date system.
Expand Down
22 changes: 19 additions & 3 deletions owlkettle/adw.nim
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,9 @@ renderable ComboRow of ActionRow:

when AdwVersion >= (1, 2) or defined(owlkettleDocs):
renderable EntryRow of PreferencesRow:
subtitle: string
suffixes: seq[AlignedChild[Widget]]

text: string

proc changed(text: string)

hooks:
Expand Down Expand Up @@ -406,12 +404,30 @@ when AdwVersion >= (1, 2) or defined(owlkettleDocs):
hAlign: hAlign,
vAlign: vAlign
))

example:
EntryRow:
title = "Name"
text = app.name

proc changed(name: string) =
app.name = name

renderable PasswordEntryRow of EntryRow:
## An `EntryRow` that hides the user input

hooks:
beforeBuild:
when AdwVersion >= (1, 2):
state.internalWidget = adw_password_entry_row_new()

example:
PasswordEntryRow:
title = "Password"
text = app.name

proc changed(name: string) =
app.name = name

export EntryRow, PasswordEntryRow

Expand Down

0 comments on commit 74026cd

Please sign in to comment.