-
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.
* debug attempt * #83 Add first attempt at scale widget * #83 Fix types on bindings double in C translates to cdouble in nim, not cfloat. * #83 improve examples and implementation * stuff * #83 Add support for initial widget value * #83 Add support for inverting widget * #83 fix some bugs * #83 add update of ScaleState to change proc * #83 let pageSize just default to double the pageSize * #83 add support for showing or hiding fill level and precision * #83 Fix bug causing infinite window growth * #83 refactor state-variables to use property hooks * #83 implement suggestion for value 2way bindings * #83 Fix example * #83 Add support for configuring value position * #83 Make orientation configurable * #83 Fix example datatype (this was int but needs to be float64) * #83 Fix semantics on marks * #83 Ensure order of hooks is the same as order of properties * #83 Add build hook to make initial value assignment work again * #83 slightly beautify example * #83 Adjust proc-calling to code conventions * #83 Add widgets example * ##83 add doc comments to Scale widget * #83 Update widgets.md * Add notice that there's a nimble task to generate docs as well * #83 Remove nonsense workflow change * #83 Add scale to example README and mild improvements * #83 Mild doc comment improvements * #83 Fix error introduced by last commit in doc comments * #83 Remove build hook * #83 Move float64 to float * #83 Minor doc update * #83 Improve Scale example to make it more configurable * Improve example * Fix Text View example image width --------- Co-authored-by: Can Lehmann <can.l@posteo.de>
- Loading branch information
1 parent
38d2604
commit 90e5db1
Showing
8 changed files
with
388 additions
and
0 deletions.
There are no files selected for viewing
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
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,198 @@ | ||
# 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/[dataentries, adw] | ||
import std/[options, sequtils] | ||
|
||
viewable App: | ||
min: float = 0 | ||
max: float = 100 | ||
value: float = 50 | ||
marks: seq[ScaleMark] = @[] | ||
inverted: bool = false | ||
showValue: bool = true | ||
stepSize: float = 5 | ||
pageSize: float = 10 | ||
orient: Orient = OrientX | ||
showFillLevel: bool = true | ||
precision: int64 = 1 | ||
valuePosition: ScalePosition | ||
|
||
method view(app: AppState): Widget = | ||
result = gui: | ||
WindowSurface: | ||
defaultSize = (800, 600) | ||
|
||
Box(orient = OrientX): | ||
Box(orient = OrientY) {.expand: false.}: | ||
sizeRequest = (300, -1) | ||
|
||
HeaderBar {.expand: false.}: | ||
showTitleButtons = false | ||
|
||
ScrolledWindow: | ||
PreferencesGroup: | ||
title = "Fields" | ||
margin = 12 | ||
|
||
ActionRow: | ||
title = "min" | ||
NumberEntry {.addSuffix.}: | ||
value = app.min | ||
xAlign = 1.0 | ||
maxWidth = 8 | ||
proc changed(value: float) = | ||
app.min = value | ||
|
||
ActionRow: | ||
title = "max" | ||
NumberEntry {.addSuffix.}: | ||
value = app.max | ||
xAlign = 1.0 | ||
maxWidth = 8 | ||
proc changed(value: float) = | ||
app.max = value | ||
|
||
ActionRow: | ||
title = "value" | ||
NumberEntry {.addSuffix.}: | ||
value = app.value | ||
xAlign = 1.0 | ||
maxWidth = 8 | ||
proc changed(value: float) = | ||
app.value = value | ||
|
||
ActionRow: | ||
title = "inverted" | ||
Switch {.addSuffix.}: | ||
state = app.inverted | ||
proc changed(state: bool) = | ||
app.inverted = state | ||
|
||
ActionRow: | ||
title = "showValue" | ||
Switch {.addSuffix.}: | ||
state = app.showValue | ||
proc changed(state: bool) = | ||
app.showValue = state | ||
|
||
ActionRow: | ||
title = "stepSize" | ||
NumberEntry {.addSuffix.}: | ||
value = app.stepSize | ||
xAlign = 1.0 | ||
maxWidth = 8 | ||
proc changed(value: float) = | ||
app.stepSize = value | ||
|
||
ActionRow: | ||
title = "pageSize" | ||
NumberEntry {.addSuffix.}: | ||
value = app.pageSize | ||
xAlign = 1.0 | ||
maxWidth = 8 | ||
proc changed(value: float) = | ||
app.pageSize = value | ||
|
||
ActionRow: | ||
title = "showFillLevel" | ||
Switch {.addSuffix.}: | ||
state = app.showFillLevel | ||
proc changed(state: bool) = | ||
app.showFillLevel = state | ||
|
||
ActionRow: | ||
title = "precision" | ||
NumberEntry {.addSuffix.}: | ||
value = app.precision.float | ||
xAlign = 1.0 | ||
maxWidth = 8 | ||
proc changed(value: float) = | ||
app.precision = value.int | ||
|
||
ComboRow: | ||
title = "orient" | ||
items = mapIt(low(Orient)..high(Orient), $it) | ||
selected = ord(app.orient) | ||
proc select(index: int) = | ||
app.orient = Orient(index) | ||
|
||
ComboRow: | ||
title = "valuePosition" | ||
items = mapIt(low(ScalePosition)..high(ScalePosition), $it) | ||
selected = ord(app.valuePosition) | ||
proc select(index: int) = | ||
app.valuePosition = ScalePosition(index) | ||
|
||
ExpanderRow: | ||
title = "marks" | ||
|
||
for it, mark in app.marks: | ||
ActionRow {.addRow.}: | ||
title = "Mark " & $it | ||
|
||
NumberEntry {.addSuffix.}: | ||
value = mark.value | ||
xAlign = 1.0 | ||
maxWidth = 8 | ||
proc changed(value: float) = | ||
app.marks[it].value = value | ||
|
||
Button {.addSuffix.}: | ||
icon = "user-trash-symbolic" | ||
proc clicked() = | ||
app.marks.delete(it) | ||
|
||
ListBoxRow {.addRow.}: | ||
Button: | ||
icon = "list-add-symbolic" | ||
style = [ButtonFlat] | ||
proc clicked() = | ||
app.marks.add(ScaleMark()) | ||
|
||
Separator() {.expand: false.} | ||
|
||
Box(orient = OrientY): | ||
HeaderBar {.expand: false.}: | ||
WindowTitle {.addTitle.}: | ||
title = "Scale Example" | ||
subtitle = "Value: " & $app.value | ||
|
||
Scale: | ||
min = app.min | ||
max = app.max | ||
value = app.value | ||
marks = app.marks | ||
inverted = app.inverted | ||
showValue = app.showValue | ||
stepSize = app.stepSize | ||
pageSize = app.pageSize | ||
orient = app.orient | ||
showFillLevel = app.showFillLevel | ||
precision = app.precision | ||
valuePosition = app.valuePosition | ||
|
||
proc valueChanged(newValue: float64) = | ||
app.value = newValue | ||
echo "New value from Scale is ", $newValue | ||
|
||
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
Oops, something went wrong.