80#define SIDE_TO_BUT_ALIGN {BUT_ALIGN_LEFT, BUT_ALIGN_TOP, BUT_ALIGN_RIGHT, BUT_ALIGN_DOWN}
83#define SIDE1(_s) (((_s) + 1) % TOTSIDES)
84#define OPPOSITE(_s) (((_s) + 2) % TOTSIDES)
85#define SIDE2(_s) (((_s) + 3) % TOTSIDES)
88#define IS_COLUMN(_s) ((_s) % 2)
91#define STITCH(_s) (1 << (_s))
94#define MAX_DELTA 0.45f * max_ii(UI_UNIT_Y, UI_UNIT_X)
98 const bool btype_can_align = !
ELEM(but->
type,
120 float delta, delta_side_opp;
126 const bool buts_share[2] = {
136 if (!(buts_share[0] || buts_share[1]) || !(butal_can_align || butal_other_can_align)) {
140 for (side = 0; side <
RIGHT; side++) {
155 if (delta_side_opp < delta) {
156 std::swap(side, side_opp);
157 delta = delta_side_opp;
160 if (delta < max_delta) {
163 if (delta <= butal->dists[side]) {
176 if (butal_can_align && butal_other_can_align) {
178 butal_other->
neighbors[side_opp] = butal;
180 else if (butal_can_align && (delta < butal->dists[side])) {
183 else if (butal_other_can_align && (delta < butal_other->dists[side_opp])) {
184 butal_other->
neighbors[side_opp] =
nullptr;
186 butal->
dists[side] = butal_other->
dists[side_opp] = delta;
189 if (butal_can_align && butal_other_can_align) {
190 const int side_s1 =
SIDE1(side);
191 const int side_s2 =
SIDE2(side);
193 const int stitch =
STITCH(side);
194 const int stitch_opp =
STITCH(side_opp);
199 if (butal_other->
neighbors[side_opp] ==
nullptr) {
200 butal_other->
neighbors[side_opp] = butal;
210 if (delta < max_delta) {
211 butal->
flags[side_s1] |= stitch;
212 butal_other->
flags[side_s1] |= stitch_opp;
215 if (delta < max_delta) {
216 butal->
flags[side_s2] |= stitch;
217 butal_other->
flags[side_s2] |= stitch_opp;
261 const int stitch_s1 =
STITCH(side_s1);
262 const int stitch_s2 =
STITCH(side_s2);
269 while ((butal->
flags[side] & stitch_s1) && (butal = butal->
neighbors[side_s1]) &&
270 (butal->
flags[side] & stitch_s2))
276 if (butal_neighbor) {
279 *butal_neighbor->
borders[side_opp] = co;
280 butal_neighbor->
dists[side_opp] = 0.0f;
283 else if (side ==
LEFT) {
286 else if (side ==
TOP) {
290 butal->
dists[side] = 0.0f;
293 butal->
flags[side] &= ~stitch_s2;
330 const float outline_px =
U.pixelsize;
334 rect->
ymax = region->
winy + outline_px;
338 rect->
ymin = -outline_px;
339 rect->
ymax = rect->
ymin + but_height;
342 rect->
xmin = -outline_px;
343 rect->
xmax = rect->
xmin + but_width;
346 rect->
xmax = region->
winx + outline_px;
347 rect->
xmin = rect->
xmax - but_width;
377 if (but.alignnr == 0) {
391 if (butal_array.
size() < 2) {
414 if (butal_other.but->alignnr != alignnr) {
421 if ((*butal.
borders[
DOWN] - *butal_other.borders[
TOP]) > max_delta) {
433 for (
ButAlign &butal : butal_array) {
435 for (
int side = 0; side <
TOTSIDES; side++) {
439 const int side_opp =
OPPOSITE(side);
440 const int side_s1 =
SIDE1(side);
441 const int side_s2 =
SIDE2(side);
443 const int align = sides_to_ui_but_align_flags[side];
444 const int align_opp = sides_to_ui_but_align_flags[side_opp];
448 butal.but->drawflag |= align;
450 if (!
IS_EQF(butal.dists[side], 0.0f)) {
451 float *delta = &butal.dists[side];
453 if (*butal.borders[side] < *butal_other->
borders[side_opp]) {
459 co = (*butal.borders[side] += *delta);
463 *butal_other->
borders[side_opp] = co;
464 butal_other->
dists[side_opp] = 0.0f;
469 co = *butal.borders[side];
473 &butal, side, side_opp, side_s1, side_s2, align, align_opp, co);
475 &butal, side, side_opp, side_s2, side_s1, align, align_opp, co);
481#undef SIDE_TO_BUT_ALIGN
#define RGN_ALIGN_ENUM_FROM_MASK(align)
Read Blender memory allocation and freeing.
IndexRange index_range() const
void resize(const int64_t new_size)
MutableSpan< T > as_mutable_span()
#define SIDE_TO_BUT_ALIGN
static void block_align_but_to_region(Button *but, const ARegion *region)
void block_align_calc(Block *block, const ARegion *region)
static bool block_align_butal_cmp(const ButAlign &butal, const ButAlign &butal_other)
static void block_align_proximity_compute(ButAlign *butal, ButAlign *butal_other)
bool button_can_align(const Button *but)
int button_align_opposite_to_area_align_get(const ARegion *region)
static void block_align_stitch_neighbors(ButAlign *butal, const int side, const int side_opp, const int side_s1, const int side_s2, const int align, const int align_opp, const float co)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
VecBase< int8_t, 4 > char4
VecBase< float, 4 > float4
bool BLI_rctf_is_empty(const struct rctf *rect)
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
MINLINE float max_ff(float a, float b)
eRegion_Alignment alignment
Vector< std::unique_ptr< Button > > buttons_ptrs
std::ranges::transform_view< std::ranges::ref_view< const Vector< std::unique_ptr< Button > > >, Button &(*)(const std::unique_ptr< Button > &)> buttons() const
std::array< float *, 4 > borders