Loading...
Searching...
No Matches
Anchor.h
Go to the documentation of this file.
1// Copyright (c) 2025 Dave R. Smith.
2// Malena Framework — Licensed under PolyForm Noncommercial 1.0.0; commercial use requires a paid license. See LICENSE.
3
4//
5// Anchor.h — a single retained relational-placement constraint.
6//
7// An Anchor records "keep me <op> <reference> by <spacing>". The reference is a
8// live Positionable (re-read each solve) or the window (ref == nullptr). Anchors
9// are stored per-object by AnchorManager and re-solved on window resize, so a
10// layout expressed with the Align verbs stays correct when the window changes.
11//
12
13#ifndef MALENA_ANCHOR_H
14#define MALENA_ANCHOR_H
15
16#pragma once
17
18namespace ml
19{
20 class Positionable;
21
24 enum class AnchorOp
25 {
33 // Window inside-edge ops (ref is always the window; spacing = inward margin).
38 };
39
42 inline bool anchorTouchesX(AnchorOp op)
43 {
44 return op == AnchorOp::LeftOf || op == AnchorOp::RightOf
47 }
48 inline bool anchorTouchesY(AnchorOp op)
49 {
50 return op == AnchorOp::Above || op == AnchorOp::Below
53 }
54
55 struct Anchor
56 {
59 float spacing;
60 };
61
62} // namespace ml
63
64#endif // MALENA_ANCHOR_H
Trait that provides position, bounds, and animated movement.
Definition Animate.h:25
bool anchorTouchesY(AnchorOp op)
Definition Anchor.h:48
AnchorOp
Definition Anchor.h:25
@ WindowTop
my top edge at window top + margin (y)
Definition Anchor.h:36
@ CenterY
center within ref vertically, + spacing offset (y)
Definition Anchor.h:31
@ CenterX
center within ref horizontally, + spacing offset (x)
Definition Anchor.h:30
@ Above
my bottom edge to ref's top edge (y)
Definition Anchor.h:28
@ WindowRight
my right edge at window right − margin (x)
Definition Anchor.h:35
@ WindowBottom
my bottom edge at window bottom − margin (y)
Definition Anchor.h:37
@ RightOf
my left edge to ref's right edge (x)
Definition Anchor.h:27
@ CenterOn
center within ref both axes (x + y)
Definition Anchor.h:32
@ LeftOf
my right edge to ref's left edge (x)
Definition Anchor.h:26
@ WindowLeft
my left edge at window left + margin (x)
Definition Anchor.h:34
@ Below
my top edge to ref's bottom edge (y)
Definition Anchor.h:29
bool anchorTouchesX(AnchorOp op)
Definition Anchor.h:42
const Positionable * ref
live reference; nullptr == the window
Definition Anchor.h:58
AnchorOp op
Definition Anchor.h:57
float spacing
gap / offset in pixels
Definition Anchor.h:59