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

Question: advice on holding a widget state #3

Closed
dimsuz opened this issue Nov 20, 2016 · 5 comments
Closed

Question: advice on holding a widget state #3

dimsuz opened this issue Nov 20, 2016 · 5 comments

Comments

@dimsuz
Copy link

dimsuz commented Nov 20, 2016

Hi!

I am not sure if this is a proper place, but I wanted to ask you a question knowing you as an frp-expert :)
I'm rather new to FRP and haskell, but already familiar with basic concepts (am trying to write more and more functional code).

What I got interested in is to try to build a small UI-toolkit like app, which will render some widgets from ground up. I'm using a nanovg-hs library to do painting in OpenGL.

All FRP libraries I see, rely on some existing UI toolkit (for example threpenny-gui, reflex-dom use browser for this (html elements), reactive-banana gets hooked up to either wx or gtk or sdl)... so things like pushed state, click animations, focused rectangle etc are handled not by these libraries, but by lower level (and imperative-language) library.

In my case I want to do everything in Haskell and this is where I got confused. Mainly I am not sure where to put state related to animation? For example, consider user pressing a button. I want to draw it pressed, then, after user released it, I want to play some fade animation of button's background for example.
And if all I have is a function which draws a button and accepts current time (or dt between frames), it would also need to know a time at which click has happened and store the current fade value etc etc. Where should this be stored? Should I create some typeclass where I would store this state and draw-function will read/modify it?

Perhaps this is a rather generic question, but I'm trying to at least figure out a direction in which to do my reasearch/googling :) I'd be glad to dive deep in some existing libraries for an answers or examples, but none of them does this kind of stuff by itself (if I'm not mistaken).

If you would give me some advice, or if you know some existing work I could use to learn from, it would be much appreciated.
Also I guess you should immediately close this issue, because I've used it as a means to simply ask a question, it's not a real issue :)

@HeinrichApfelmus
Copy link
Owner

I'm not sure how to answer, your question is very broad. But if you want to go the "everything FRP" route, then I think that the paper "Declarative event-oriented programming" mentioned in the README might be a good starting point.

@dimsuz
Copy link
Author

dimsuz commented Nov 23, 2016

I understand that my question was very vague, but still dared to ask :)
Thank you, I will read it!

@dimsuz dimsuz closed this as completed Nov 23, 2016
@HeinrichApfelmus
Copy link
Owner

No worries. Hope I could help! 😄

@dimsuz
Copy link
Author

dimsuz commented Jan 15, 2017

Can't resist, I'm so excited! I thought I would never understand how to program using FRP, but I actually started reading that Conal Eliott's paper you suggested above and trying to replicate same stuff for widget rendering, not with Fran, but using Reactive Banana and its glfw bindings I found on github. Also created a couple of my own AddHandlers on top of that.

It almost feels like magic, I wire up some Behaviors, some fmap-ping, hook events to sample them and it works like I intended. Haskell-world just doesn't stop to amaze me with these things: when I constantly feel like I'm only starting to learn something and at the same time I'm able to actually achieve things which seemed rather non-trivial at start, it's so rewarding! But my code is still awful and that's ok for now :))

Thanks for your help and for Reactive Banana, its api is really concise and nice :)

@HeinrichApfelmus
Copy link
Owner

Glad I could help. 🍌

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

No branches or pull requests

2 participants