-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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>
- Loading branch information
1 parent
4cf8a3e
commit 0ffacf8
Showing
6 changed files
with
188 additions
and
3 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# MIT License | ||
# | ||
# Copyright (c) 2023 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, dataentries] | ||
import std/[strutils, sets, sequtils] | ||
|
||
viewable App: | ||
searchDelay: uint = 100 | ||
text: string = "" | ||
placeholderText: string = "Search List" | ||
sensitive: bool = true | ||
tooltip: string = "" | ||
sizeRequest: tuple[x, y: int] = (-1, -1) | ||
|
||
items: seq[string] = mapIt(0..<100, "Item " & $it) | ||
filteredItems: seq[string] = mapIt(0..<100, "Item " & $it) | ||
selected: int = 0 | ||
|
||
method view(app: AppState): Widget = | ||
let isInActiveSearch = app.text != "" | ||
result = gui: | ||
Window(): | ||
defaultSize = (600, 400) | ||
HeaderBar() {.addTitlebar.}: | ||
insert(app.toAutoFormMenu(ignoreFields = @["filteredItems"])) {.addRight.} | ||
|
||
SearchEntry() {.addTitle, expand: true.}: | ||
margin = Margin(top:0, left: 48, bottom:0, right: 48) | ||
text = app.text | ||
searchDelay = app.searchDelay | ||
placeholderText = app.placeholderText | ||
sensitive = app.sensitive | ||
tooltip = app.tooltip | ||
sizeRequest = app.sizeRequest | ||
|
||
proc nextMatch() = | ||
if app.selected < app.filteredItems.high: | ||
app.selected += 1 | ||
|
||
proc previousMatch() = | ||
if app.selected > 0: | ||
app.selected -= 1 | ||
|
||
proc activate() = | ||
echo "activated search for entry: ": $app.filteredItems[app.selected] | ||
|
||
proc changed(searchString: string) = | ||
app.text = searchString | ||
app.selected = 0 | ||
app.filteredItems = app.items.filterIt(searchString in it) | ||
|
||
proc stopSearch() = | ||
echo "Search Stopped" | ||
app.text = "" | ||
app.filteredItems = app.items | ||
|
||
ScrolledWindow: | ||
ListBox: | ||
selected = [app.selected].toHashSet() | ||
selectionMode = SelectionSingle | ||
|
||
proc select(rows: Hashset[int]) = | ||
for num in rows: | ||
app.selected = num | ||
|
||
for index, item in app.filteredItems: | ||
Box(): | ||
Label(text = item, margin = 6) {.hAlign: AlignStart, expand: false.} | ||
|
||
|
||
adw.brew(gui(App())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters