-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Scale
widget
#83
Comments
I've been taking a look at this out of curiosity: For example here: renderable Entry of BaseWidget:
text: string
placeholder: string ## Shown when the Entry is empty.
width: int = -1
maxWidth: int = -1
xAlign: float = 0.0
visibility: bool = true
invisibleChar: Rune = '*'.Rune
proc changed(text: string) ## Called when the text in the Entry changed
proc activate() ## Called when the user presses enter/return
hooks:
beforeBuild:
state.internalWidget = gtk_entry_new()
connectEvents:
proc changedCallback(widget: GtkWidget, data: ptr EventObj[proc (text: string)]) {.cdecl.} =
let text = $gtk_editable_get_text(widget)
EntryState(data[].widget).text = text
data[].callback(text)
data[].redraw()
state.connect(state.changed, "changed", changedCallback)
state.connect(state.activate, "activate", eventCallback)
disconnectEvents:
state.internalWidget.disconnect(state.changed)
state.internalWidget.disconnect(state.activate) Owlkettle knows based on the fact that procs were defined on the renderable that there's a But what are "changedCallback" and "eventCallback" and how does one know when to use which? The only pattern I somewhat recognize across the file is that you're apparently supposed to always write:
with procName in the above examples being |
The last parameter refers to the proc that is passed directly to GTK for handling the event. Its job is to:
E.g. for the changed event, which is called when the user input some text, we need to read back the new text and update the Other events like In case of the |
How can you know what the signature of the callback for a given gpointer for a given signal is? void
color_set (
GtkColorButton* self,
gpointer user_data
) You wrapped that as: proc colorSetCallback(widget: GtkWidget, data: ptr EventObj[proc (color: tuple[r, g, b, a: float])]) {.cdecl.} =
var gdkColor: GdkRgba
gtk_color_chooser_get_rgba(widget, gdkColor.addr)
let color = (gdkColor.r.float, gdkColor.g.float, gdkColor.b.float, gdkColor.a.float)
ColorButtonState(data[].widget).color = color
data[].callback(color)
data[].redraw() So somehow you:
How did you figure that out? Mostly relevant as similarly I need to figure out what's hidden behind the gpointer for |
The type of data is just a pointer to an |
Check. The way I currently see it I don't think it makes sense to wrap https://docs.gtk.org/gtk4/ctor.Scale.new.html as it requires a Wrapping https://docs.gtk.org/gtk4/ctor.Scale.new_with_range.html and using that for instantiation seems "correcter" to me, any thoughts? |
I would personally use |
Hmm I'll try that out once I've got something functional. I think this has to do with the Accessible Role: https://docs.gtk.org/gtk4/property.Accessible.accessible-role.html I can't seem to find a way to define it initially, have you had to deal with that before? |
Are you sure that you set the min/max values for the slider / range? I would assume that if the interval has length 0, it might also trigger this state. You might also need to set a step/page size (if there is not special method for that, then using a method on the adjustemnt obtained via Edit: Sorry did not see the code in your fork. It looks like you set the min max, but not the step/page size. |
double in C translates to cdouble in nim, not cfloat.
Hmmm somewhat stuck on 2 separate problems now:
Screencast.from.2023-09-27.22-12-51.webm
Screencast.from.2023-09-27.22-18-02.webm |
For 2., that is expected given that you set |
Ahhh right. Okay, got an update and a build-hook now, which means I do get initial values. I am not entirely sure if the hooks updating all three of GTK (via hooks currentValue:
build:
gtk_range_set_value(state.internalWidget, widget.valCurrentValue)
echo "Build: ", widget.valCurrentValue, " - ", state.currentValue
update:
gtk_range_set_value(state.internalWidget, state.currentValue) # This seemed more correct as state.currentValue keeps being the one thing that
widget.valCurrentValue = state.currentValue # Necessary as otherwise widget.valCurrentValue remains at 0.5, meaning out of sync with the value in state
echo "Update: ", widget.valCurrentValue, " - ", state.currentValue I think looking back having a "currentValue" field might have been the wrong approach for what I wanted. Is that doable? Or is that even the right approach? |
I might be facing an actual problem with the Scale being actually "2 way" in its bindings.
However, 1) requires me to have an update field-hook on the hooks value:
update:
echo "Updated value to ", widget.valValue
gtk_range_set_value(state.internalWidget, widget.valValue) If I do that though, then changes to the widget will be impossible because they also trigger the update field-hook on I can't seem to figure that one out. You can provide an initial value, but programmatically after that basically only the user can update the value =/ |
Welp, I managed to fix the "window expands infinitely" issue at least: hooks marks:
(build, update):
state.internalWidget.gtk_scale_clear_marks()
let hasScaleMarks = widget.hasMarks and widget.valMarks.len > 0
if hasScaleMarks:
for mark in widget.valMarks:
let label: string = if mark.label.isSome(): mark.label.get() else: $mark.value
gtk_scale_add_mark(state.internalWidget, mark.value , mark.position.toGtk(), label.cstring) It fixes the issue |
Have a look at how it works for On a more general note: You should have |
Since you inherit from I think that feature wise, this issue is mostly complete (other than the |
…d-form-generator
* 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>
This issue thus closed? |
Yes 😄 |
…d-form-generator
* 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 * Remove nonsense workflow change from myself * #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 * #93 Add AutoForm function Generates a Box widget with editable dataentry widgets for each field on the state. You can exclude certain fields as desired. * #93 Minor Fix to Scale Widget example * #93 add support for DateTime with Calendar widget * Add Autoform to calendar * Add Autoform to drop_down * #93 Add ability to deal with tuples generally * #93 add basewidget fields * Add Basewidget fields to dropdown * Add autoform to picture.nim with Basewidget fields * Add autoform to popover_menu.nim Note: It appears while `hasArrow` and `tooltip` are available for PopoverMenu, they don't really do much * Add Autoform to radio group Orientation of radio group appears to not change when you change the orientation. It appears to solely rely on Box. Is that a bug or just gtk behaviour? * Fix radiogroup not allow runtime orient updates Radiogroup was missing a property hook for orient. This commit adds said missing property hook. This enables runtime-changing of the orientation of RadioGroup * Add autoform to text_view * Fix popover_menu example * Fixed wrong fix for popover_menu * Beautify Scale * Improve example * Fix Text View example image width * Update gitignore * #93 Update Autoform for scale * debug attempt * Remove nonsense workflow change from myself * #93 Add BaseWidget attributes back to example * #93 Add an auto mini form generator * Update calendar example * Update Dropdown example * Update picture example * Update Popover example * Update radiogroup * Update text_view example * Update calendar image * #93 Add nicer form fields specifically for sizeRequest tuple * #93 Fully move over to the non-form-generating approach * Update calendar image * Update popover_menu example screenshot * Update images of remaining examples * #93 Minor fixes * #93 update callback useable for calendar * Remove pointless AlignedChild export * Update Autoform to use FormulaEntry * Move Calendar into a dialog * #93 remove completely pointless overload for ints A fully generic approach using T and SomeNumber does the job better and covers more ground. * #93 Change Default widget for objects and Co It now no longer is one that represents tuples etc. as JSON and parses that back. Instead, it now provides a dummy widget that will explain to the user that they must implement a `toFormField` proc with a more elaborate tooltip. * Minimize example to menubutton instead of sidebar * #93 Move all toFormFields into autoform * #93 Update widget examples They now provide the form as a menu button popover * Undo changes to example images * #93 Overhaul autoform The new implementation enables generating an entire form based on either `toFormField` for individual entries with custom datatypes or `toListFormField` for seq[T] of custom datatypes. * #93 Remove unused imports * #93 Move examples back from WindowSurface to Window * Update doc comments * Undo examples changes * Update example headerbars * Make menubutton for form flat as per adw standards * Make headerbar buttons into flat buttons * Rename autoform to playground * Variousf ixes to popover example * Lots of example fixes * Undo unnecessary changes * Remove unnecessary defaultsize --------- Co-authored-by: Can Lehmann <can.l@posteo.de>
* 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 * Remove nonsense workflow change from myself * #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 * #93 Add AutoForm function Generates a Box widget with editable dataentry widgets for each field on the state. You can exclude certain fields as desired. * #93 Minor Fix to Scale Widget example * #93 add support for DateTime with Calendar widget * #93 Add ability to deal with tuples generally * #93 add basewidget fields * Improve example * Fix Text View example image width * Update gitignore * #93 Update Autoform for scale * debug attempt * Remove nonsense workflow change from myself * #93 Add BaseWidget attributes back to example * #93 Add an auto mini form generator * #93 Add nicer form fields specifically for sizeRequest tuple * #93 Fully move over to the non-form-generating approach * #86 Add Status Page widget + example * #86 Add mention of freedesktop spec Also update other docs to point to the tooling section. * #86 Update link to not point to localhost * #86 Update Status Page docs * #86 Remove autoform and refine example * #86 update image * Update examples/widgets/adw/status_page.nim Co-authored-by: Can Lehmann <85876381+can-lehmann@users.noreply.github.com> * #86 Fix incorrect alt attribute on example README --------- Co-authored-by: Can Lehmann <can.l@posteo.de>
* debug attempt * can-lehmann#83 Add first attempt at scale widget * can-lehmann#83 Fix types on bindings double in C translates to cdouble in nim, not cfloat. * can-lehmann#83 improve examples and implementation * stuff * can-lehmann#83 Add support for initial widget value * can-lehmann#83 Add support for inverting widget * can-lehmann#83 fix some bugs * can-lehmann#83 add update of ScaleState to change proc * can-lehmann#83 let pageSize just default to double the pageSize * can-lehmann#83 add support for showing or hiding fill level and precision * can-lehmann#83 Fix bug causing infinite window growth * can-lehmann#83 refactor state-variables to use property hooks * can-lehmann#83 implement suggestion for value 2way bindings * can-lehmann#83 Fix example * can-lehmann#83 Add support for configuring value position * can-lehmann#83 Make orientation configurable * can-lehmann#83 Fix example datatype (this was int but needs to be float64) * can-lehmann#83 Fix semantics on marks * can-lehmann#83 Ensure order of hooks is the same as order of properties * can-lehmann#83 Add build hook to make initial value assignment work again * can-lehmann#83 slightly beautify example * can-lehmann#83 Adjust proc-calling to code conventions * can-lehmann#83 Add widgets example * #can-lehmann#83 add doc comments to Scale widget * can-lehmann#83 Update widgets.md * Add notice that there's a nimble task to generate docs as well * can-lehmann#83 Remove nonsense workflow change * can-lehmann#83 Add scale to example README and mild improvements * Remove nonsense workflow change from myself * can-lehmann#83 Mild doc comment improvements * can-lehmann#83 Fix error introduced by last commit in doc comments * can-lehmann#83 Remove build hook * can-lehmann#83 Move float64 to float * can-lehmann#83 Minor doc update * can-lehmann#83 Improve Scale example to make it more configurable * can-lehmann#93 Add AutoForm function Generates a Box widget with editable dataentry widgets for each field on the state. You can exclude certain fields as desired. * can-lehmann#93 Minor Fix to Scale Widget example * can-lehmann#93 add support for DateTime with Calendar widget * can-lehmann#93 Add ability to deal with tuples generally * can-lehmann#93 add basewidget fields * Improve example * Fix Text View example image width * Update gitignore * can-lehmann#93 Update Autoform for scale * debug attempt * Remove nonsense workflow change from myself * can-lehmann#93 Add BaseWidget attributes back to example * can-lehmann#93 Add an auto mini form generator * can-lehmann#93 Add nicer form fields specifically for sizeRequest tuple * can-lehmann#93 Fully move over to the non-form-generating approach * can-lehmann#86 Add Status Page widget + example * can-lehmann#86 Add mention of freedesktop spec Also update other docs to point to the tooling section. * can-lehmann#86 Update link to not point to localhost * can-lehmann#86 Update Status Page docs * can-lehmann#86 Remove autoform and refine example * can-lehmann#86 update image * Update examples/widgets/adw/status_page.nim Co-authored-by: Can Lehmann <85876381+can-lehmann@users.noreply.github.com> * can-lehmann#86 Fix incorrect alt attribute on example README --------- Co-authored-by: Can Lehmann <can.l@posteo.de>
* 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 * Remove nonsense workflow change from myself * #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 * #93 Add AutoForm function Generates a Box widget with editable dataentry widgets for each field on the state. You can exclude certain fields as desired. * #93 Minor Fix to Scale Widget example * #93 add support for DateTime with Calendar widget * #93 Add ability to deal with tuples generally * #93 add basewidget fields * Improve example * Fix Text View example image width * Update gitignore * #93 Update Autoform for scale * debug attempt * Remove nonsense workflow change from myself * #93 Add BaseWidget attributes back to example * #93 Add an auto mini form generator * #93 Add nicer form fields specifically for sizeRequest tuple * #93 Fully move over to the non-form-generating approach * #85 Add Expander Widget including example * #85 Add BaseWidget fields * #85 Add example to README.md * #85 add Activation callback and doc comments * #85 Update and expand docs * #85 Fix expander callback delivering outdated values * #85 Move expander example over to autoform * #85 Update docs and example screenshot * #85 Refine example and remove autoform * #85 Update widgets.md The introduction of gtkminor in an earlier PR changed this doc comment. That caused a change in widgets.md * Update owlkettle/widgets.nim Co-authored-by: Can Lehmann <85876381+can-lehmann@users.noreply.github.com> * #85 Move Expander to make sure list is sorted alphabetically * #85 Update docs --------- Co-authored-by: Can Lehmann <can.l@posteo.de> Co-authored-by: Can Lehmann <85876381+can-lehmann@users.noreply.github.com>
Gtk's
Scale
widget is currently missing. See https://docs.gtk.org/gtk4/class.Scale.htmlThe text was updated successfully, but these errors were encountered: