Blender  V3.3
Classes | Macros | Typedefs | Enumerations | Functions
interface_align.c File Reference
#include "DNA_screen_types.h"
#include "DNA_userdef_types.h"
#include "BLI_listbase.h"
#include "BLI_math.h"
#include "BLI_rect.h"
#include "UI_interface.h"
#include "interface_intern.h"
#include "MEM_guardedalloc.h"

Go to the source code of this file.

Classes

struct  ButAlign
 

Macros

#define SIDE_TO_UI_BUT_ALIGN
 
#define SIDE1(_s)   (((_s) + 1) % TOTSIDES)
 
#define OPPOSITE(_s)   (((_s) + 2) % TOTSIDES)
 
#define SIDE2(_s)   (((_s) + 3) % TOTSIDES)
 
#define IS_COLUMN(_s)   ((_s) % 2)
 
#define STITCH(_s)   (1 << (_s))
 
#define MAX_DELTA   0.45f * max_ii(UI_UNIT_Y, UI_UNIT_X)
 

Typedefs

typedef struct ButAlign ButAlign
 

Enumerations

enum  {
  LEFT = 0 , TOP = 1 , RIGHT = 2 , DOWN = 3 ,
  TOTSIDES = 4 , STITCH_LEFT = 1 << LEFT , STITCH_TOP = 1 << TOP , STITCH_RIGHT = 1 << RIGHT ,
  STITCH_DOWN = 1 << DOWN
}
 

Functions

bool ui_but_can_align (const uiBut *but)
 
static void block_align_proximity_compute (ButAlign *butal, ButAlign *butal_other)
 
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)
 
static int ui_block_align_butal_cmp (const void *a, const void *b)
 
static void ui_block_align_but_to_region (uiBut *but, const ARegion *region)
 
void ui_block_align_calc (uiBlock *block, const ARegion *region)
 
int ui_but_align_opposite_to_area_align_get (const ARegion *region)
 

Macro Definition Documentation

◆ IS_COLUMN

#define IS_COLUMN (   _s)    ((_s) % 2)

Definition at line 90 of file interface_align.c.

◆ MAX_DELTA

#define MAX_DELTA   0.45f * max_ii(UI_UNIT_Y, UI_UNIT_X)

Definition at line 96 of file interface_align.c.

◆ OPPOSITE

#define OPPOSITE (   _s)    (((_s) + 2) % TOTSIDES)

Definition at line 86 of file interface_align.c.

◆ SIDE1

#define SIDE1 (   _s)    (((_s) + 1) % TOTSIDES)

Definition at line 85 of file interface_align.c.

◆ SIDE2

#define SIDE2 (   _s)    (((_s) + 3) % TOTSIDES)

Definition at line 87 of file interface_align.c.

◆ SIDE_TO_UI_BUT_ALIGN

#define SIDE_TO_UI_BUT_ALIGN
Value:
{ \
}
@ UI_BUT_ALIGN_DOWN
Definition: UI_interface.h:272
@ UI_BUT_ALIGN_TOP
Definition: UI_interface.h:269
@ UI_BUT_ALIGN_RIGHT
Definition: UI_interface.h:271

Definition at line 79 of file interface_align.c.

◆ STITCH

#define STITCH (   _s)    (1 << (_s))

Definition at line 93 of file interface_align.c.

Typedef Documentation

◆ ButAlign

typedef struct ButAlign ButAlign

This struct stores a (simplified) 2D representation of all buttons of a same align group, with their immediate neighbors (if found), and needed value to compute 'stitching' of aligned buttons.

Note
This simplistic struct cannot fully represent complex layouts where buttons share some 'align space' with several others (see schema below), we'd need linked list and more complex code to handle that. However, looks like we can do without that for now, which is rather lucky!
      +--------+-------+
      | BUT 1  | BUT 2 |      BUT 3 has two 'top' neighbors...
      |----------------|  =>  In practice, we only store one of BUT 1 or 2 (which ones is not
      |      BUT 3     |      really deterministic), and assume the other stores a ref to BUT 3.
      +----------------+
      

This will probably not work in all possible cases, but not sure we want to support such exotic cases anyway.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
LEFT 
TOP 
RIGHT 
DOWN 
TOTSIDES 
STITCH_LEFT 
STITCH_TOP 
STITCH_RIGHT 
STITCH_DOWN 

Definition at line 62 of file interface_align.c.

Function Documentation

◆ block_align_proximity_compute()

static void block_align_proximity_compute ( ButAlign butal,
ButAlign butal_other 
)
static

This function checks a pair of buttons (assumed in a same align group), and if they are neighbors, set needed data accordingly.

Note
It is designed to be called in total random order of buttons. Order-based optimizations are done by caller.

Definition at line 119 of file interface_align.c.

References ButAlign::borders, ButAlign::but, ButAlign::dists, DOWN, fabsf, ButAlign::flags, IS_COLUMN, LEFT, MAX_DELTA, max_ff(), ButAlign::neighbors, NULL, OPPOSITE, RIGHT, SIDE1, SIDE2, STITCH, SWAP, TOP, and ui_but_can_align().

Referenced by ui_block_align_calc().

◆ block_align_stitch_neighbors()

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 
)
static

This function takes care of case described in this schema:

+-----------+-----------+
|   BUT 1   |   BUT 2   |
|-----------------------+
|   BUT 3   |
+-----------+

Here, BUT 3 RIGHT side would not get 'dragged' to align with BUT 1 RIGHT side, since BUT 3 has not RIGHT neighbor. So, this function, when called with BUT 1, will 'walk' the whole column in side_s1 direction (TOP or DOWN when called for RIGHT side), and force buttons like BUT 3 to align as needed, if BUT 1 and BUT 3 were detected as needing top-right corner stitching in block_align_proximity_compute() step.

Note
To avoid doing this twice, some stitching flags are cleared to break the 'stitching connection' between neighbors.

Definition at line 253 of file interface_align.c.

References ButAlign::borders, ButAlign::but, ButAlign::dists, uiBut::drawflag, ButAlign::flags, LEFT, ButAlign::neighbors, STITCH, TOP, UI_BUT_ALIGN_STITCH_LEFT, and UI_BUT_ALIGN_STITCH_TOP.

Referenced by ui_block_align_calc().

◆ ui_block_align_but_to_region()

static void ui_block_align_but_to_region ( uiBut but,
const ARegion region 
)
static

◆ ui_block_align_butal_cmp()

static int ui_block_align_butal_cmp ( const void a,
const void b 
)
static

Helper to sort ButAlign items by:

  • Their align group.
  • Their vertical position.
  • Their horizontal position.

Definition at line 305 of file interface_align.c.

References Freestyle::a, uiBut::alignnr, usdtokens::b(), ButAlign::borders, ButAlign::but, LEFT, and TOP.

Referenced by ui_block_align_calc().

◆ ui_block_align_calc()

void ui_block_align_calc ( uiBlock block,
const ARegion region 
)

◆ ui_but_align_opposite_to_area_align_get()

int ui_but_align_opposite_to_area_align_get ( const ARegion region)

◆ ui_but_can_align()

bool ui_but_can_align ( const uiBut but)