From d7b69ead8e7e959b01cf615c5f363fd2a0a6590f Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 22 Jan 2025 18:42:15 -0500 Subject: Simplify initial position code and place children at the origin The code to find the initial size and position for a view had a lot of duplication, and was inconsistent between platforms. Flaky positioning and attempting to center embedded children has historically caused a bunch of problems in general, particularly since windows can be resized. So, factor out all the initial size and position code so that the logic is in one centralized place used by all platforms, and always position embedded children within their parent at the top/left origin. For top-level windows, the view is centered on its transient parent or the screen (as before). A new platform function puglGetAncestorCenter() is used to do this in general code. Also towards a total separation of position and size, towards support for Wayland, where applications don't dictate their own positions. --- src/internal.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/internal.h') diff --git a/src/internal.h b/src/internal.h index 8497c50..7387494 100644 --- a/src/internal.h +++ b/src/internal.h @@ -30,6 +30,18 @@ puglIsValidSize(unsigned x, unsigned y); bool puglIsValidArea(PuglArea size); +/// Return the center point of some "soft" ancestor (parent window or screen) +PuglPoint +puglGetAncestorCenter(const PuglView* view); + +/// Return the initial size of a view +PuglArea +puglGetInitialSize(const PuglView* view); + +/// Return the initial position of a view if known, or an invalid position +PuglPoint +puglGetInitialPosition(const PuglView* view, PuglArea size); + /// Set hint to a default value if it is unset (PUGL_DONT_CARE) void puglEnsureHint(PuglView* view, PuglViewHint hint, int value); -- cgit v1.2.1