Jerfov2
Jerfov2

Reputation: 5534

C GLFW How would I set a minimum size for a window?

The title explains everything. Using the library GLFW from C, how could I keep the window width from going lower than 20 pixels across, or 10. How could I keep the height from reaching no more then 100? I tried making a callback function for when the window resizes that looks like this:

void windowResizeCallback(GLFWwindow* window, int width, int height) {
    glfwSetWindowSize(window, max(width, 50), max(height, 50));
}

However, when I reach the boundaries, my Mac throws a segmentation fault at my program. How can I fix this?

Upvotes: 4

Views: 2232

Answers (1)

Joe Cool
Joe Cool

Reputation: 235

GLFW documentation has a solution using glfwSetWindowSizeLimits which sets the minimum and maximum size the window content area can reach.

Usage:

glfwSetWindowSizeLimits(window, 200, 200, 400, 400);
// min area is 200 by 200
// max area is 400 by 400

glfwSetWindowSizeLimits(window, 200, 200, GLFW_DONT_CARE, GLFW_DONT_CARE);
// min area is 200 by 200
// there is no maximum size

This function was added in GLFW 3.2.

Upvotes: 5

Related Questions