We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
The Rectangle (and all other) struct doesn't have a initialization constructor.
Due to this, initializing Rectangle with argument throws exception.
using
LibRaylib::Rectangle.new(100, 100, 100, 100)
throws the error
In src\sceneMainMenu.cr:22:55 22 | if LibRayGUI.button( LibRaylib::Rectangle.new(100, 100, 100, 100), "Press me!" ) ^-- Error: wrong number of arguments for 'LibRaylib::Rectangle.new' (given 4, expected 0) Overloads are: - LibRaylib::Rectangle.new()
The way to make this work is to update the properties of Rectangle after it is initialized. This works;
LibRaylib.draw_text("Scene Main Menu", 190, 200, 20, LibRaylib::BLACK) btnRec = LibRaylib::Rectangle.new btnRec.x = 100 btnRec.y = 100 btnRec.width = 100 btnRec.height = 100 if LibRayGUI.button( btnRec, "Press me!" ) pp "Pressed"; end
but this is cumbersome to write and deviates from the raylib api where users can create Rectangle with inline parameters like this;
if LibRayGUI.button( LibRaylib::Rectangle.new(100, 100, 100, 100), "Press me!" ) pp "Pressed"; end
Recommendation would be to update the Rectangle struct. instead of having the Rectangle struct like this;
struct Rectangle x : LibC::Float y : LibC::Float width : LibC::Float height : LibC::Float end
we can go for more idiomatic properties with default values and overloaded constructors;
struct Rectangle property x : LibC::Float = 0 property y : LibC::Float = 0 property width : LibC::Float = 120 property height : LibC::Float = 30 def initialize end def initialize(x, y, width, height) @x = x @y = y @width = width @height = height end end
The text was updated successfully, but these errors were encountered:
lib structs use named arguments, you need to use it like
lib
Rl::Rectangle.new( x: 0, y: 0, width: 0, height: 0 )
Sorry, something went wrong.
can confirm that works. Thanks.
No branches or pull requests
The Rectangle (and all other) struct doesn't have a initialization constructor.
Due to this, initializing Rectangle with argument throws exception.
using
throws the error
The way to make this work is to update the properties of Rectangle after it is initialized.
This works;
but this is cumbersome to write and deviates from the raylib api where users can create Rectangle with inline parameters like this;
Recommendation would be to update the Rectangle struct.
instead of having the Rectangle struct like this;
we can go for more idiomatic properties with default values and overloaded constructors;
The text was updated successfully, but these errors were encountered: