Proposition for scroll panel example improvment

Open Beginner friendly
#583 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
1-3 hours
Newbie friendliness
88/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Active
Tech stack
c
Domain
game-dev

Research direction

Read examples/scroll_panel/scroll_panel.c and compare the current drawing coordinates with the attached diff. Use panelContentRec.x and .y for the content position when drawing the grid and rectangle, then run the scroll panel example to confirm the content moves and clips as expected.

Written by the indexing model from the issue text.

Description

Currently inside examples/scroll_panel/scroll_panel.c x and y fields of panelContentRec variable are unused.
Since panelContentRec suppose to represent contents of scroll panel i think those fields should be used as position of scroll panel by being assigned results of panelRec + panelScroll calculation, and be used in drawing grid and rectangle (becasue both of those are visual representation of pane's content) as seen in snippet below

GuiScrollPanel(panelRec, NULL, panelContentRec, &panelScroll, &panelView);
panelContentRec.x = panelRec.x + panelScroll.x;
panelContentRec.y = panelRec.y + panelScroll.y;

BeginScissorMode(panelView.x, panelView.y, panelView.width, panelView.height);
    GuiGrid((Rectangle){panelContentRec.x, panelContentRec.y, panelContentRec.width, panelContentRec.height}, NULL, 16, 3, NULL);
EndScissorMode();

if (showContentArea) DrawRectangle(panelContentRec.x, panelContentRec.y, panelContentRec.width, panelContentRec.height, Fade(RED, 0.1));

Current state for comparasion

GuiScrollPanel(panelRec, NULL, panelContentRec, &panelScroll, &panelView);

BeginScissorMode(panelView.x, panelView.y, panelView.width, panelView.height);
    GuiGrid((Rectangle){panelRec.x + panelScroll.x, panelRec.y + panelScroll.y, panelContentRec.width, panelContentRec.height}, NULL, 16, 3, NULL);
EndScissorMode();

if (showContentArea) DrawRectangle(panelRec.x + panelScroll.x, panelRec.y + panelScroll.y, panelContentRec.width, panelContentRec.height, Fade(RED, 0.1));

In my opinion this change would make example better by clearly signaling that result panelRec + panelScroll is position of scroll panel content and should be used as such.

I've attached diff file, and can create push request if there's wish to implement such change.

scroll_panel.c.diff.c

Dominant language
C
Stars
5.3k
Forks
410
Avg merge
1d 22h
Merged PRs (30d)
1

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from raysan5/raygui

All issues in raysan5/raygui

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.