imgui on ring

248 views
Skip to first unread message

Shadi

unread,
Oct 26, 2022, 2:53:49 PM10/26/22
to The Ring Programming Language
Hello you can now test imgui on ring. not everything is supported but with time i will do that and i will add new example every day.

if you are on ubuntu you should edit cmake file.
 
See Video befor you use it


Github repo:

Ilir

unread,
Oct 26, 2022, 4:03:36 PM10/26/22
to The Ring Programming Language
Hello Shadi,

impressive, so many demonstrations inside.

Greetings.
Ilir

Mahmoud Fayed

unread,
Oct 26, 2022, 5:49:59 PM10/26/22
to The Ring Programming Language
Hello Shadi

Thanks for sharing

(1) A little comment (Try to avoid int2bytes(), bytes2int() and VarPtr() in cases that doesn't need this)
You can just pass a Ring number to the function
Also, When you must use these functions, write a wrapper functions & classes around it using Ring code

(2) You can create a package using RingPM & GitHub - So we can easily install the extension and get updates
You will find many packages here as examples : https://github.com/ringpackages

Keep up the GREAT WORK :D

Greetings,
Mahmoud
Message has been deleted
Message has been deleted

Shadi

unread,
Oct 26, 2022, 6:37:00 PM10/26/22
to The Ring Programming Language
Hello Mahmoud, 
thank you for replying. That was one of the biggest questions I wanted to ask. but how do I do that. how do I avoid that. are there any examples of how they have done that with other extensions. because I don't know exactly how ring works internally.


(1) A little comment (Try to avoid int2bytes(), bytes2int() and VarPtr() in cases that doesn't need this)

Should I manipulate the original C function. I hope you will give me an example and I will continue.

I have already looked in Raylib extension and I will convert all Struct to Class. and I will write the functions for it.
I have done so far for two struct
in file Classes.ring and Funktions.ring will see.

Mahmoud Fayed

unread,
Oct 26, 2022, 6:58:11 PM10/26/22
to The Ring Programming Language
Hello Shadi

>> "Should I manipulate the original C function. I hope you will give me an example and I will continue."

There are two ways to do this - Select the one that you like based on the case
(1) Using C/C++ code - Here we modify the configuration file (*.cf)
We use <register> </register> and <code> </code>

A direct example that match your case (passing integer pointer) is the stbimage extension


In the implementation get a Ring Number using RING_API_GETNUMBER
Use casting to integer:  (int) to store the value in an integer defined in your C code
Pass the integer pointer to the function that you call in DearImGUI

Remember that we register the function by typing it's prototype
But when defining it using RING_FUNC, we add ring_ before the function name

(2) Using Ring Code
In this case, You define new functions or classes that hide the details as you have seen in RingRayLib

Greetings,
Mahmoud

Shadi

unread,
Oct 27, 2022, 10:34:47 AM10/27/22
to The Ring Programming Language
hello mahmoud,
I do not know where the problem is but it does not work. I try since yesterday to create this but it does not work.

the function prototype looks like this:

bool SliderInt(const char * label, int * v, int v_min, int v_max, const char * format = "%d", ImGuiSliderFlags flags = 0)

int*v : expects a pointer to int. I also have many that expect float * and bool *.

when you change the slider then the new value should be stored in variable we passed to (int *v).

bool ImGui::SliderInt(const char *label, int *v, int v_min, int v_max, const char *format, ImGuiSliderFlags flags)

and

bool ImGui::SliderFloat(const char *label, float *v, float v_min, float v_max, const char *format, ImGuiSliderFlags flags)

the idea of these two function just like this small function

void changeValue(int *var)
{
    *var = (*var) + 1;
}

how would you write this.
i have done so but does not work

RING_FUNC(ring_changeValue)
{

    if (RING_API_PARACOUNT != 1)
    {
        RING_API_ERROR(RING_API_BADPARACOUNT);
        return;
    }

    // if (!RING_API_ISNUMBER(1))
    // {
    // RING_API_ERROR(RING_API_BADPARATYPE);
    // return;
    // }

    int *p1 = RING_API_GETINTPOINTER(1);
    changeValue(p1);
    RING_API_ACCEPTINTVALUE(1);

    // int value = (int)RING_API_GETNUMBER(1);
    // int *ptr = &value;

    // changeValue(ptr);
    // RING_API_ACCEPTINTVALUE(1);
}


Translated with www.DeepL.com/Translator (free version)

Mahmoud Fayed

unread,
Oct 27, 2022, 7:01:25 PM10/27/22
to The Ring Programming Language
Hello Shadi

(1) With respect to RING_API_GETINTPOINTER & RING_API_ACCEPTINTVALUE
This API is designed to pass integer pointer (To Get A Value From a C Function) - (Not to Pass a Value from Ring to a C Function)

I considered this a bug, Thank you very much for the report :D

fixed in Ring 1.18 in this commit by adding one line of code and converting the (double) value to (int) value before passing the integer pointer to the C function :


Please build Ring 1.18 from source code and use it

(2) >> " the function prototype looks like this: bool SliderInt(const char * label, int * v, int v_min, int v_max, const char * format = "%d", ImGuiSliderFlags flags = 0)"

Don't write default values in function prototype in the configuration file (*.cf)
It should be written like this
bool SliderInt(const char * label, int * v, int v_min, int v_max, const char * format, ImGuiSliderFlags flags)
So the code generator can understand it correctly

Greetings,
Mahmoud

Shadi

unread,
Oct 27, 2022, 7:27:45 PM10/27/22
to The Ring Programming Language
Hello mahmoud,

thank you very much for your answer.

Can you please add for other data types as well:

like float and boolean

RING_API_GETFLOATPOINTER & RING_API_ACCEPTFLOATVALUE

ring api has
RING_API_GETDOUBLEPOINTER
but it does not have
RING_API_ACCEPTDOUBLEVALUE

für example like 

void changeValue(float *var)
{
    *var = (*var) + 1.5 ;
}


oder boolean like :

void changeValue(bool *var)
{
    *var = true ;
}


Greetings,
Shadi

Mahmoud Fayed

unread,
Oct 27, 2022, 7:46:48 PM10/27/22
to The Ring Programming Language
Hello Shadi

>> "like float and boolean"

Ring variables have internal representation for (int & double) - Both of float and boolean are not used
Just use integer instead of Boolean 
With respect to the float type I will think about adding it

>> "ring api has  RING_API_GETDOUBLEPOINTER but it does not have RING_API_ACCEPTDOUBLEVALUE "

Because RING_API_ACCEPTDOUBLEVALUE is not required
Ring uses (double) for representing numbers
The idea behind RING_API_ACCEPTINTVALUE is converting the (int) to (double)

Greetings,
Mahmoud

Mahmoud Fayed

unread,
Oct 28, 2022, 7:10:10 PM10/28/22
to The Ring Programming Language
Hello Shadi

>> "Can you please add for other data types as well like float"

I have already supported the float type in this commit : https://github.com/ring-lang/ring/commit/9983419ba09058d551ba1473d68306954c77eefa

Example:

#include "ring.h"
#include "stdlib.h"

void changevalue(float *var)

{
    *var = (*var) + 1.5;
}

RING_FUNC(ring_changevalue)

{

    if (RING_API_PARACOUNT != 1)
    {
        RING_API_ERROR(RING_API_BADPARACOUNT);
        return;
    }

    if (!RING_API_ISSTRING(1))
    {
        RING_API_ERROR(RING_API_BADPARATYPE);
        return;
    }

    float *p1 = RING_API_GETFLOATPOINTER(1);
    changevalue(p1);
    RING_API_ACCEPTFLOATVALUE(1);

}

RING_LIBINIT
{
    RING_API_REGISTER("changevalue",ring_changevalue);
}


Greetings,
Mahmoud

Shadi

unread,
Oct 29, 2022, 11:31:10 AM10/29/22
to The Ring Programming Language

Hello Mahmoud,

thank you so much for making this possible. this will allow us to simply support many function.

I have encountered a new problem today.
 
Is it possible that C_function change the ring string. 

RING_API_GETCHARPOINTER & RING_API_ACCEPTCHARVALUE

code.png

in ImGUI the inputText widget expects a predefined array of char.
The idea of this function is when you type on the keyboard, the value is stored in the array (string) and when you delete something, the widget will replace the array elements with " ".

code.pngcode.png

Greetings,
Shadi

Mahmoud Fayed

unread,
Oct 29, 2022, 1:49:22 PM10/29/22
to The Ring Programming Language
Hello Shadi

>> "thank you so much for making this possible. this will allow us to simply support many function."

You are welcome :D

>> "Is it possible that C_function change the ring string."

Nice suggestion, We only need RING_API_GETCHARPOINTER
I have already did that by adding one line of code in this commit : https://github.com/ring-lang/ring/commit/79d26708ce4ccd4a19811775f6e9ee26a37fa188


    #include "ring.h"
    #include "stdlib.h"

    void changeValue(char *var)
    {
        strcpy(var,"Hello from C Code");

    }

    RING_FUNC(ring_changevalue)
    {

        if (RING_API_PARACOUNT != 1)
        {
            RING_API_ERROR(RING_API_BADPARACOUNT);
            return;
        }

        if (!RING_API_ISSTRING(1))
        {
            RING_API_ERROR(RING_API_BADPARATYPE);
            return;
        }

        char *p1 = RING_API_GETCHARPOINTER(1);
        changeValue(p1);

    }

    RING_LIBINIT
    {
        RING_API_REGISTER("changevalue",ring_changevalue);
    }

Greetings,
Mahmoud
Reply all
Reply to author
Forward
0 new messages