Good afternoon! Let’s write a toy UI library.

We begin by writing a few helper functions that will invariably prove useful to us later. We will be dealing with a lot of rectangular regions on the screen, so it makes sense to start by defining a rectangle structure and write some code to manipulate it.

typedef struct Rectangle {
int l, r, t, b;
} Rectangle;

My preferred method of encoding rectangles is as a quartet comprising the left, right, top and bottom sides.

Here are the helper functions we’ll implement that deal with rectangles.

Rectangle RectangleMake(int l, int r, int t, int b); // Initialise a Rectangle structure with the provided values.
bool RectangleValid(Rectangle a); // Returns true if the rectangle is 'valid', which I define to mean it has positive w...

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help