-
Notifications
You must be signed in to change notification settings - Fork 28
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
add raygui.c3l #37
add raygui.c3l #37
Conversation
I have ported the dark theme and the floating window example. Because the dark theme file was not included in default raygui and it is relatively simple I directly translated it to c3, but I am unsure if that is the best option. this is the floating windows example: Details
module test;
import raylib5::rl;
import raygui::rg;
//#include "raylib.h"
//#define RAYGUI_IMPLEMENTATION
//#include "../../src/raygui.h"
//#include "../../styles/dark/style_dark.h"
def DrawContentFn = fn void(Vector2 position, Vector2 scroll);
Vector2 window_position = { 10, 10 };
Vector2 window_size = { 200, 400 };
bool minimized = false;
bool moving = false;
bool resizing = false;
Vector2 scroll;
Vector2 window2_position = { 250, 10 };
Vector2 window2_size = { 200, 400 };
bool minimized2 = false;
bool moving2 = false;
bool resizing2 = false;
Vector2 scroll2;
const RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT @if(!$defined(RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT)) = 24;
const RAYGUI_WINDOW_CLOSEBUTTON_SIZE @if(!$defined(RAYGUI_WINDOW_CLOSEBUTTON_SIZE)) = 18;
fn void guiWindowFloating(Vector2 *position, Vector2 *size, bool *minimized, bool *moving, bool *resizing, DrawContentFn draw_content, Vector2 content_size, Vector2 *scroll, char* title) {
int close_title_size_delta_half = (RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT - RAYGUI_WINDOW_CLOSEBUTTON_SIZE) / 2;
// window movement and resize input and collision check
if(rl::isMouseButtonPressed(MouseButton.LEFT) && !*moving && !*resizing) {
Vector2 mouse_position = rl::getMousePosition();
Rectangle title_collision_rect = { position.x, position.y, size.x - ((float)RAYGUI_WINDOW_CLOSEBUTTON_SIZE + close_title_size_delta_half), RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT };
Rectangle resize_collision_rect = { position.x + size.x - 20, position.y + size.y - 20, 20, 20 };
if(rl::checkCollisionPointRec(mouse_position, title_collision_rect)) {
*moving = true;
} else if(!*minimized && rl::checkCollisionPointRec(mouse_position, resize_collision_rect)) {
*resizing = true;
}
}
// window movement and resize update
if(*moving) {
Vector2 mouse_delta = rl::getMouseDelta();
position.x += mouse_delta.x;
position.y += mouse_delta.y;
if (rl::isMouseButtonReleased(MouseButton.LEFT)) {
*moving = false;
// clamp window position keep it inside the application area
if(position.x < 0)
{
position.x = 0;
}
else if(position.x > rl::getScreenWidth() - size.x)
{
position.x = rl::getScreenWidth() - size.x;
}
if(position.y < 0)
{
position.y = 0;
}
else if(position.y > rl::getScreenHeight())
{
position.y = rl::getScreenHeight() - (float)RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT;
}
}
} else if(*resizing) {
Vector2 mouse = rl::getMousePosition();
if (mouse.x > position.x)
{
size.x = mouse.x - position.x;
}
if (mouse.y > position.y)
{
size.y = mouse.y - position.y;
}
// clamp window size to an arbitrary minimum value and the window size as the maximum
if(size.x < 100)
{
size.x = 100;
}
else if(size.x > rl::getScreenWidth())
{
size.x = rl::getScreenWidth();
}
if(size.y < 100)
{
size.y = 100;
}
else if(size.y > rl::getScreenHeight())
{
size.y = rl::getScreenHeight();
}
if (rl::isMouseButtonReleased(MouseButton.LEFT)) {
*resizing = false;
}
}
// window and content drawing with scissor and scroll area
if(*minimized) {
rg::guiStatusBar({ position.x, position.y, size.x, RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT }, title);
if (rg::guiButton({ position.x + size.x - RAYGUI_WINDOW_CLOSEBUTTON_SIZE - close_title_size_delta_half,
position.y + close_title_size_delta_half,
RAYGUI_WINDOW_CLOSEBUTTON_SIZE,
RAYGUI_WINDOW_CLOSEBUTTON_SIZE },
"#120#")) {
*minimized = false;
}
} else {
*minimized = rg::guiWindowBox({ position.x, position.y, size.x, size.y }, title);
// scissor and draw content within a scroll panel
if(draw_content != null) {
Rectangle scissor;
rg::guiScrollPanel({ position.x, position.y + RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT, size.x, size.y - RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT },
null,
{ position.x, position.y, content_size.x, content_size.y },
scroll,
&scissor);
bool require_scissor = size.x < content_size.x || size.y < content_size.y;
if(require_scissor) {
rl::beginScissorMode((int)scissor.x, (int)scissor.y, (int)scissor.width, (int)scissor.height);
}
draw_content(*position, *scroll);
if(require_scissor) {
rl::endScissorMode();
}
}
// draw the resize button/icon
rg::guiDrawIcon(CURSOR_SCALE_LEFT_FILL, (int)(position.x + size.x) - 20, (int)(position.y + size.y) - 20, 1, rl::WHITE);
}
}
fn void drawContent(Vector2 position, Vector2 scroll) {
rg::guiButton({ position.x + 20 + scroll.x, position.y + 50 + scroll.y, 100, 25 }, "Button 1");
rg::guiButton({ position.x + 20 + scroll.x, position.y + 100 + scroll.y, 100, 25 }, "Button 2");
rg::guiButton({ position.x + 20 + scroll.x, position.y + 150 + scroll.y, 100, 25 }, "Button 3");
rg::guiLabel({ position.x + 20 + scroll.x, position.y + 200 + scroll.y, 250, 25 }, "A Label");
rg::guiLabel({ position.x + 20 + scroll.x, position.y + 250 + scroll.y, 250, 25 }, "Another Label");
rg::guiLabel({ position.x + 20 + scroll.x, position.y + 300 + scroll.y, 250, 25 }, "Yet Another Label");
}
fn int main() {
rl::initWindow(960, 560, "raygui - floating window example");
rl::setTargetFPS(60);
rg::style::dark::load();
//rg::test::load();
while(!rl::windowShouldClose()) {
rl::beginDrawing();
rl::clearBackground(rl::DARKGREEN);
guiWindowFloating(&window_position, &window_size, &minimized, &moving, &resizing, &drawContent, { 140, 320 }, &scroll, "Movable & Scalable Window");
guiWindowFloating(&window2_position, &window2_size, &minimized2, &moving2, &resizing2, &drawContent, { 140, 320 }, &scroll2, "Another window");
rl::endDrawing();
}
rl::closeWindow();
return 0;
} |
Is this ready for inclusion now? |
this can be merged now, it seems to work fine. |
I have not provided a windows version of the library because I do not have any windows machines on me. |
Thank you! |
This isn't quite done yet.
some issues:
I have also not done enough testing yet.
this is the portable window example:
Details
I am going to work on porting more complex examples to make sure everything works properly.