-
Notifications
You must be signed in to change notification settings - Fork 23
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
Adding chapter "Advanced Topics/Custom Programs" #108
base: main
Are you sure you want to change the base?
Conversation
Thank you! I will review this today :-) |
Thank you very much for your contribution! Super nice to have one more person writing!!! I think I could tweak some sentences so they match the tone of other parts of the guide, but before getting into that... I was wondering if you are aware of I wonder if that is a simpler approach to achieve part of what you can do with your approach (which may be more flexible, but also a bit more verbose). An example I use to add screenshots, video recording and ESC=quit to all sketches:
Do you think it's worth including both approaches in the guide? |
In https://github.com/openrndr/openrndr-guide/wiki we had planned a section for reusing code. Maybe both approaches could be listed there, together with others like creating a library, or sharing a source folder across multiple projects. What do you think? |
Hi Abe, I was not aware of The guide page should be adjusted for sure :D |
Hi! One actually doesn't need to subclass, but just put that class (the example I shared) in a file, for example in If @edwinRNDR agrees, I think I could do this:
|
I see the following situation:
-> Future projects:
Depending on how experimental/stable the code is and if the intention is more for personal use/community use of the written code, In my opinion, more options would be more confusing than helpful. |
That's a good point. More options can be confusing. It's tricky because each option has its benefits. shared src folder vs library-templateI think including a src folder with shared code in a project is very easy to understand and implement by anyone. It may be better to use the library-template, but it has a drawback: to edit the code one needs to open a separate project, change the code, then publish to maven local (instead of just editing the code inside the open project). Benefits: is that it is easier to share with others via jitpack and build times are better. I'm ok with not showing how to use the shared src folder. ApplicationPreload vs extending ProgramExtending Program is more flexible, but the code can be confusing for people not experienced with Kotlin. Also, it requires more code than using ApplicationPreload. For example, to make all programs quit on ESC, package org.openrndr
class Preload : ApplicationPreload() {
override fun onProgramSetup(program: Program) {
program.keyboard.keyDown.listen {
if(it.key == KEY_ESCAPE) program.application.exit()
}
}
} vs something like this: class MyProgram(private val init: suspend MyProgram.() -> Unit) : ProgramImplementation(suspend = false) {
override suspend fun setup() {
super.setup()
init()
keyboard.keyDown.listen {
if(it.key == KEY_ESCAPE) program.application.exit()
}
}
}
fun ApplicationBuilder.myProgram(
init: suspend MyProgram.() -> Unit
): MyProgram {
program = MyProgram(init)
return program as MyProgram
} It is very nice though that with the second approach you can easily choose if you want to use That's why I would go for showing both alternatives and suggest using ApplicationPreload until you are comfortable with the more advanced approach. I'm concerned that by suggesting code that is harder to understand it may scare some people away, so it's nice to provide a simpler solution as well. What do you think? |
I was not thinking for the people unfamiliar with Kotlin. As an Android Dev, I am maybe too used to it :D It also makes sense as this allows for reuse within one IntelliJ project, which is the logical unit of project/bundle of apps. My only concern with the Preload class is that it enforces a I would encourage creating a library only in the context of orx/orml - this way people are more keen on contributing back if they have something worthy of a lib |
Thanks for the feedback :) I agree with your concern regarding the location of the Preload file. I guess one could place it anywhere, but it would complain about package not matching the location. So I'll do as I mentioned above: merge, clean up, convert into a "reusing code" section and continue with the plan in the wiki. |
This PR adds the chapter 11_Advanced_Topics/C135_Custom_programs.kt
The chapter explains how to inherit from ProgramImplementation to write a custom program that adds to the scope of the normal
program { ... }
block.This is useful for more experienced OPENRNDR users, that want to reuse code with minimal effort.