Skip to content
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

#93 add form generator #94

Closed

Conversation

PhilippMDoerner
Copy link
Contributor

@PhilippMDoerner PhilippMDoerner commented Oct 2, 2023

This PR adds a generic proc that generates a Box with a List of Widgets for every field in a given object.
Which mostly means for every field in a given <Widget>State.

This autoform was only used in the Scale.nim example for now, other examples shall be updated in a separate PR to keep these small and easily reviewable.

The reasoning for why I chose a generic proc rather than writing a generic viewable I laid out in #93

This PR actually only adds an autoform.nim file, but as this branch is one that branched off the one for #90 it contains the same changes as that one.

This PR depends on #90 as #90 provides the scale.nim example and that was what I used as reference to implement this.

As per the usual, it's all up for change regardless. Even if I already have #95, I should be able to relatively simply adjust that to whatever we decide here as I'm semi-sure the concept of "take in a state, iterate over it and spit out a widget based on that" will remain.

closes #93

double in C translates to cdouble in nim, not cfloat.
@PhilippMDoerner
Copy link
Contributor Author

PhilippMDoerner commented Oct 2, 2023

Okay, this is a first draft that basically recreates the sidebar as before.
Well almost.
I don't really control the order of this one so the marks field is not at the end of the list, it's somewhere in the middle.
Also I added a DropDown field so you can decide the ScalePosition of a given mark.

My next step will be to see if I can't move from a custom toFormField method to something that fully generates a proc like that just from a given type.

@PhilippMDoerner
Copy link
Contributor Author

PhilippMDoerner commented Oct 2, 2023

@can-lehmann I've got a... let's say first draft working for auto-generating ExpanderRows per entry for a given type seq[T].

I'm honestly not too sure what to make of this.
I can either pretty this up, or we just remove it again and instead implement custom toFormField procs for every custom data type we have in a seq.
Might be less of a headache (and code) overall because the generic manner of this is starting to get somewhat abstract, but on the other hand having to write your own toFormField for custom data types every time might be repeated effort.

Then again, I don't think this should happen too often.
Thoughts?

@PhilippMDoerner PhilippMDoerner marked this pull request as ready for review October 2, 2023 19:02
@PhilippMDoerner
Copy link
Contributor Author

PhilippMDoerner commented Oct 3, 2023

I've decided to just move over to the approach where you defined a custom toFormField for every custom type you have.
Generating forms for every normal type in an action Row is way too annoying.

Added a general custom toFormField for the datatype of sizeRequest though since that's from baseWidget and we can expect it everywhere.

@PhilippMDoerner PhilippMDoerner changed the title (Draft until #90 is merged) #93 add form generator #93 add form generator Oct 3, 2023
owlkettle/autoform.nim Outdated Show resolved Hide resolved
owlkettle/autoform.nim Outdated Show resolved Hide resolved
owlkettle/autoform.nim Outdated Show resolved Hide resolved
owlkettle/autoform.nim Outdated Show resolved Hide resolved
owlkettle/autoform.nim Outdated Show resolved Hide resolved
owlkettle/autoform.nim Outdated Show resolved Hide resolved
owlkettle/autoform.nim Outdated Show resolved Hide resolved
owlkettle/autoform.nim Outdated Show resolved Hide resolved
owlkettle/autoform.nim Outdated Show resolved Hide resolved
@can-lehmann
Copy link
Owner

#91 (comment) also applies here, so I would personally prefer to merge this after the JSON discussion and then move any discussions & changes to #95.

A fully generic approach using T and SomeNumber does the job better
and covers more ground.
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.
@PhilippMDoerner
Copy link
Contributor Author

PhilippMDoerner commented Oct 4, 2023

Ohhh merge this into #95 and close this PR? Works for me.
I'd proclaim the JSON discussion as finished with the new dummy "toFormField" proc that acts as a fallback when nothing else works.

@PhilippMDoerner
Copy link
Contributor Author

PhilippMDoerner commented Oct 4, 2023

Basically, if you tell me now this looks okay with the new toFormField for any types that aren't caught by any of the other toFormFields, I'll merge this branch into #95 and close this PR

@can-lehmann
Copy link
Owner

Ohhh merge this into #95 and close this PR? Works for me.

Sounds good.

@PhilippMDoerner
Copy link
Contributor Author

Merged into branch of #95, closing this PR.

@PhilippMDoerner PhilippMDoerner deleted the #93-add-form-generator branch October 17, 2023 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a "Form-Generating"-feature to Owlkettle
2 participants