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

Raygui ? #10

Open
ejemba opened this issue May 27, 2020 · 17 comments
Open

Raygui ? #10

ejemba opened this issue May 27, 2020 · 17 comments

Comments

@ejemba
Copy link

ejemba commented May 27, 2020

Thank you for jaylib it works like a charm !

https://github.com/raysan5/raygui

Do you know if I can use raygui with jaylib ? if yes how ?

raygui looks like a set of .h files.

Regards

@pepe
Copy link
Member

pepe commented May 28, 2020

You would need to wrap raygui to be accesible from the Janet, like this lib is wrapped around raylib.

I think it is good idea, even if we have janetui.

@ejemba
Copy link
Author

ejemba commented May 28, 2020

HI pepe, thank you, yes I think it can be a quick win.

My problem is I don't have the knowledge to handle the mapping.
I don't even understand raygui : just a set of .h files
(not a c programmer)

@pepe
Copy link
Member

pepe commented May 28, 2020

Well, I am not C programmer at all (25 years ago I was kind of it in the high school) and I still managed to wrap LevelDB for Janet.

I will take look at the raygui and maybe we can make it (by copying jaylib :-).

@ejemba
Copy link
Author

ejemba commented Jun 1, 2020

It would be great if you can have a look,
I'm not sure I can help .C .H mechanisms are very far behind me

@kamisori
Copy link
Contributor

Working on it:
https://github.com/kamisori/jaylib

@pepe
Copy link
Member

pepe commented Jun 15, 2020

Oh. I was not able to compile with musl stdlib. Great @kamisori!

@kamisori
Copy link
Contributor

kamisori commented Jun 17, 2020

sorry, at the moment im working on windows.
there are some bugs I found but at least it compiled when I commited :D

@uvtc
Copy link
Contributor

uvtc commented Dec 16, 2020

I'd also like to see this (I'm on GNU/Linux).

@uvtc
Copy link
Contributor

uvtc commented Dec 16, 2020

@kamisori oh, that's awesome! Where you planning on creating a PR here for your work?

@sogaiu
Copy link

sogaiu commented May 5, 2021

A fair bit seems to be working in kamisori's fork:

raygui-via-kamisori-jaylib

That is based on this test file: https://github.com/kamisori/jaylib/blob/master/test/test5.janet

The following file seems to be related to the implementation: https://github.com/kamisori/jaylib/blob/master/src/gui.h

@ejemba
Copy link
Author

ejemba commented May 5, 2021

@sogaiu @kamisori this is great !
I hope I can use this very soon !

@sogaiu
Copy link

sogaiu commented May 5, 2021

FWIW, I went through kamisori's test5.janet and made a simplified version of it to just demo a list view. I think it might be an easier starting point (well, it would have been for me anyway :) ).

The following is the resulting script -- it's meant to work from the project directory:

(use ./build/jaylib)

(defn- make-window
  "open window with default values" 
  []
  (set-config-flags :msaa-4x-hint)
  (init-window 800 600 "Place")
  (set-target-fps 60)
  (set-exit-key 0))

(defn main
  [& args]

  (make-window)

  (var listview @{:result {:active -1
                           :scrollindex 0}})
  (var show-message-box false)
  (var exit-window false)

  (while (not exit-window)

    (set exit-window
      (window-should-close))

    (when (key-pressed? :escape)
      (set show-message-box (not show-message-box)))

    (begin-drawing)

    (clear-background
      (get-color
        (gui-get-style :default :background-color)))

    (let [result
          (gui-list-view [165 25 140 240]
                         (string/join ["gui-window-box"
                                       "gui-panel"
                                       "gui-scroll-panel"
                                       "gui-group-box"
                                       "gui-label"
                                       "gui-button"
                                       "gui-label-button"
                                       "gui-line"]
                                      ";")
                         ((listview :result) :scrollindex)
                         ((listview :result) :active))]
      (set (listview :result) result))

    (when show-message-box
      (draw-rectangle 0 0 (get-screen-width) (get-screen-height) (fade :ray-white 0.8))
      (var result 
        (gui-message-box [(- (/ (get-screen-width) 2) 125)
                          (- (/ (get-screen-height) 2) 50)
                          250 100 ]
                         "Close Window" #(gui-icon-text :ricon-exit "Close Window")
                         "Do you really want to exit?"
                         "Yes;No"))
      (if (or (= result 0)
              (= result 2))
        (set show-message-box false)
        (when (= result 1)
          (set exit-window true))))

    (case ((listview :result) :active)
      0 (gui-window-box [200 10 500 500] "PORTABLE WINDOW")
      1 (gui-panel [200 10 500 500] )
      2 (gui-scroll-panel [200 10 200 200] [0 0 495 495] [0 0])
      3 (gui-group-box [200 10 200 200] "GROUP BOX")
      4 (gui-label [ 200 10 15 15 ] "LABEL")
      5 (gui-button [ 200 10 75 25 ] "BUTTON")
      6 (gui-label-button [ 200 10 75 25 ] "LABEL BUTTON")
      7 (gui-line [ 200 10 150 15 ] "LINE"))

    (gui-unlock)
    (end-drawing))
  
  (close-window))

(main)
(os/exit)

@uvtc
Copy link
Contributor

uvtc commented May 7, 2021

Thanks, @sogaiu !

I also appreciate the simplified example here. Personally, I also like to (import jaylib :as jl) so that everything from the library is prefixed with jl/, making it easier for me to differentiate the jaylib code from everything else.

How did you run this test file? Did you have to build and install @kamisori 's jaylib instead of jpm install jaylib?

@sogaiu
Copy link

sogaiu commented May 7, 2021

Re: (import jaylib :as jl) - I do a similar thing sometimes for similar reasons, but it depends on the situation. In this case I was modifying someone else's code where a decision had already been made one way (and I didn't go through to change everything). (One benefit of this approach is that comparison with the original file is easier.)

Re: running the test file - In this case, just to run the test file, I don't think any invocation of jpm install is necessary (the use refers to things relatively and references the directory named build), though building is.

Basically the following sort of steps in a (--recursive) cloned directory of kamisori's fork works here:

jpm build
janet listview.janet

Note that listview.janet is the name of the "test" file containing the content posted earlier.

@uvtc
Copy link
Contributor

uvtc commented May 7, 2021

I don't understand. I currently have jaylib installed. So, I should jpm uninstall jaylib, and then... maybe git clone @kamisori 's jaylib so I can then run:

cd jaylib             # the one I just git cloned
jpm build
janet listview.janet  # your program above

?

@uvtc
Copy link
Contributor

uvtc commented May 7, 2021

BTW, not sure how relevant this is here, but it looks like raysan recently removed the tooltip API. raysan5/raygui@13aac61

@sogaiu
Copy link

sogaiu commented May 7, 2021

@uvtc I don't think whether you have jaylib installed should affect the instructions above because AFAIK all of the relevant code in this case refers to things in the cloned directory using relative paths.

To spell that out a bit, in listview.janet, the way kamisori's jaylib code is referenced is via (use ./build/jaylib), which IIUC means when janet loads listview.janet, it will look for jaylib (kamisori's in this case) within a directory named build relative to listview.janet. Note that this is assuming listview.janet lives in the project root for kamisori's fork (as mentioned in my original instructions).

I don't have any version of jaylib installed and the instructions work for me [1].


Didn't know about the tooltip thing -- thanks for the tip :)


[1] I gather though that we manage our janet setups differently. I have a user-specific setup (i.e. it's not a setup where janet lives in a place like /usr/local/bin or /usr/bin).

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

5 participants