Let's write a toy UI library
nakst.gitlab.io·1d
✏️Code Editors
Preview
Report Post

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...