[Bf-blender-cvs] [4c7c8efd0b5] panel-list-patch-2: Patch 1

Hans Goudey noreply at git.blender.org
Mon Apr 27 02:31:47 CEST 2020


Commit: 4c7c8efd0b52cae01275b7896f86c47c9322183e
Author: Hans Goudey
Date:   Tue Apr 21 21:59:36 2020 -0500
Branches: panel-list-patch-2
https://developer.blender.org/rB4c7c8efd0b52cae01275b7896f86c47c9322183e

Patch 1

===================================================================

M	source/blender/blenkernel/BKE_screen.h
M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface.c
M	source/blender/editors/interface/interface_align.c
M	source/blender/editors/interface/interface_intern.h
M	source/blender/editors/interface/interface_panel.c
M	source/blender/editors/interface/interface_region_popup.c
M	source/blender/editors/interface/interface_widgets.c
M	source/blender/editors/screen/area.c
M	source/blender/makesdna/DNA_screen_types.h
M	source/blender/makesrna/intern/rna_ui.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h
index c49b6e27bba..41afa50497d 100644
--- a/source/blender/blenkernel/BKE_screen.h
+++ b/source/blender/blenkernel/BKE_screen.h
@@ -228,6 +228,25 @@ typedef struct PanelType {
   /* draw entirely, view changes should be handled here */
   void (*draw)(const struct bContext *C, struct Panel *panel);
 
+  /* For panels corresponding to a list: */
+
+  /** Reorder function, called when drag and drop finishes. */
+  void (*reorder)(struct bContext *C, struct Panel *pa, int new_index);
+  /**
+   * Set the panel and subpanel's expansion state from the corresponding expansion flag. Called
+   * on draw updates.
+   * \note Subpanels are indexed in depth first order, the visual order you would see if all panels
+   * were expanded.
+   */
+  short (*get_list_data_expand_flag)(const struct bContext *C, struct Panel *pa);
+  /**
+   * Set the expand bitfield from the closed / open state of this panel and its subpanels. Called
+   * when the expansion state of the panel changes by user input.
+   * \note Subpanels are indexed in depth first order, the visual order you would see if all panels
+   * were expanded.
+   */
+  void (*set_list_data_expand_flag)(const struct bContext *C, struct Panel *pa, short expand_flag);
+
   /* sub panels */
   struct PanelType *parent;
   ListBase children;
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index cd2e2794192..968c53c5876 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -239,6 +239,8 @@ enum {
 
 #define UI_PANEL_CATEGORY_MARGIN_WIDTH (U.widget_unit * 1.0f)
 
+#define UI_LIST_PANEL_MARGIN (U.widget_unit * 0.15f)
+
 /* but->drawflag - these flags should only affect how the button is drawn. */
 /* Note: currently, these flags _are not passed_ to the widget's state() or draw() functions
  *       (except for the 'align' ones)!
@@ -672,7 +674,7 @@ void UI_block_emboss_set(uiBlock *block, char dt);
 
 void UI_block_free(const struct bContext *C, uiBlock *block);
 void UI_blocklist_free(const struct bContext *C, struct ListBase *lb);
-void UI_blocklist_free_inactive(const struct bContext *C, struct ListBase *lb);
+void UI_blocklist_free_inactive(const struct bContext *C, struct ARegion *region);
 void UI_screen_free_active_but(const struct bContext *C, struct bScreen *screen);
 
 void UI_block_region_set(uiBlock *block, struct ARegion *region);
@@ -1669,6 +1671,7 @@ void UI_panel_end(const struct ScrArea *area,
                   int width,
                   int height,
                   bool open);
+
 void UI_panels_scale(struct ARegion *region, float new_width);
 void UI_panel_label_offset(struct uiBlock *block, int *r_x, int *r_y);
 int UI_panel_size_y(const struct Panel *panel);
@@ -1691,6 +1694,26 @@ void UI_panel_category_draw_all(struct ARegion *region, const char *category_id_
 
 struct PanelType *UI_paneltype_find(int space_id, int region_id, const char *idname);
 
+/* Recreated list panels for representing a list. */
+struct Panel *UI_panel_add_list(struct ScrArea *sa,
+                                struct ARegion *region,
+                                struct ListBase *panels,
+                                struct PanelType *panel_type,
+                                int modifier_index);
+void UI_panel_delete(struct ARegion *region, struct ListBase *panels, struct Panel *panel);
+void UI_panels_free_list(struct bContext *C, struct ARegion *region);
+
+#define LIST_PANEL_UNIQUE_STR_LEN 4
+void UI_list_panel_unique_str(struct Panel *panel, char *r_name);
+
+void UI_panel_set_expand_from_list_data(const struct bContext *C, struct Panel *panel);
+
+typedef struct PanelType *(*uiListPanelTypeFromDataFunc)(struct ARegion *region,
+                                                         struct Link *data_link);
+bool UI_panel_list_matches_data(struct ARegion *region,
+                                struct ListBase *data,
+                                uiListPanelTypeFromDataFunc get_panel_type);
+
 /* Handlers
  *
  * Handlers that can be registered in regions, areas and windows for
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 8ff3dc11dc7..e84cdbce3c0 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -3321,16 +3321,16 @@ void UI_blocklist_free(const bContext *C, ListBase *lb)
   }
 }
 
-void UI_blocklist_free_inactive(const bContext *C, ListBase *lb)
+void UI_blocklist_free_inactive(const bContext *C, ARegion *region)
 {
   uiBlock *block, *nextblock;
 
-  for (block = lb->first; block; block = nextblock) {
+  for (block = region->uiblocks.first; block; block = nextblock) {
     nextblock = block->next;
 
     if (!block->handle) {
       if (!block->active) {
-        BLI_remlink(lb, block);
+        BLI_remlink(&region->uiblocks, block);
         UI_block_free(C, block);
       }
       else {
diff --git a/source/blender/editors/interface/interface_align.c b/source/blender/editors/interface/interface_align.c
index 09811fab52d..6529bf8fc5d 100644
--- a/source/blender/editors/interface/interface_align.c
+++ b/source/blender/editors/interface/interface_align.c
@@ -502,7 +502,7 @@ void ui_block_align_calc(uiBlock *block, const ARegion *region)
 
         butal->but->drawflag |= align;
         butal_other->but->drawflag |= align_opp;
-        if (butal->dists[side]) {
+        if (!IS_EQF(butal->dists[side], 0.0f)) {
           float *delta = &butal->dists[side];
 
           if (*butal->borders[side] < *butal_other->borders[side_opp]) {
@@ -513,7 +513,7 @@ void ui_block_align_calc(uiBlock *block, const ARegion *region)
           }
           co = (*butal->borders[side] += *delta);
 
-          if (butal_other->dists[side_opp]) {
+          if (!IS_EQF(butal_other->dists[side_opp], 0.0f)) {
             BLI_assert(butal_other->dists[side_opp] * 0.5f == fabsf(*delta));
             *butal_other->borders[side_opp] = co;
             butal_other->dists[side_opp] = 0.0f;
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index c2417c86086..fba59877d68 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -841,6 +841,7 @@ struct GPUBatch *ui_batch_roundbox_shadow_get(void);
 
 void ui_draw_anti_tria_rect(const rctf *rect, char dir, const float color[4]);
 void ui_draw_menu_back(struct uiStyle *style, uiBlock *block, rcti *rect);
+void ui_draw_box_opaque(rcti *rect, int roundboxalign);
 void ui_draw_popover_back(ARegion *region, struct uiStyle *style, uiBlock *block, rcti *rect);
 void ui_draw_pie_center(uiBlock *block);
 const struct uiWidgetColors *ui_tooltip_get_theme(void);
diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c
index f824670cc57..bf9f1ebbe7e 100644
--- a/source/blender/editors/interface/interface_panel.c
+++ b/source/blender/editors/interface/interface_panel.c
@@ -39,6 +39,7 @@
 
 #include "BLT_translation.h"
 
+#include "DNA_screen_types.h"
 #include "DNA_userdef_types.h"
 
 #include "BKE_context.h"
@@ -68,6 +69,11 @@
 #define ANIMATION_TIME 0.30
 #define ANIMATION_INTERVAL 0.02
 
+/** Discance to scroll per second when panel dragged to boundary. */
+#define PNL_DRAG_SCROLL_SPEED (10.0 * U.widget_unit)
+/** Delay before drag scrolling in seconds. */
+#define PNL_DRAG_SCROLL_DELAY 0.25
+
 #define PNL_LAST_ADDED 1
 #define PNL_ACTIVE 2
 #define PNL_WAS_ACTIVE 4
@@ -102,13 +108,19 @@ typedef struct uiHandlePanelData {
   double starttime;
 
   /* dragging */
+  bool is_drag_drop;
   int startx, starty;
   int startofsx, startofsy;
   int startsizex, startsizey;
 } uiHandlePanelData;
 
+typedef struct PanelSort {
+  Panel *panel, *orig;
+} PanelSort;
+
 static int get_panel_real_size_y(const Panel *panel);
 static void panel_activate_state(const bContext *C, Panel *panel, uiHandlePanelState state);
+static int compare_panel(const void *a1, const void *a2);
 
 static void panel_title_color_get(bool show_background, uchar color[4])
 {
@@ -234,9 +246,339 @@ static bool panels_need_realign(ScrArea *area, ARegion *region, Panel **r_panel_
   return false;
 }
 
+/***** Functions for recreate list panels. ***********/
+
+/**
+ * Called in situations where panels need to be added dynamically rather than having only one panel
+ * corresponding to each PanelType.
+ */
+Panel *UI_panel_add_list(
+    ScrArea *sa, ARegion *region, ListBase *panels, PanelType *panel_type, int list_index)
+{
+  Panel *panel = MEM_callocN(sizeof(Panel), "list panel");
+  panel->type = panel_type;
+  BLI_strncpy(panel->panelname, panel_type->idname, sizeof(panel->panelname));
+
+  panel->ofsx = 0;
+  panel->ofsy = 0;
+  panel->sizex = 0;
+  panel->sizey = 0;
+  panel->blocksizex = 0;
+  panel->blocksizey = 0;
+
+  panel->runtime.list_index = list_index;
+
+  /* Add the panel's children too. Although they aren't list panels, we can still use this
+   * function to creat them, as UI_panel_begin does other things we don't need to do. */
+  for (LinkData *link = panel_type->children.first; link; link = link->next) {
+    PanelType *child = link->data;
+    UI_panel_add_list(sa, region, &panel->children, child, list_index);
+  }
+
+  /* If we're adding a recreate list panel, make sure it's added to the end of the list. Check the
+   * context string to make sure we add to the right list.
+   *
+   * We can the panel list is also the display order because the list panel list is rebuild
+   * when the order changes. */
+  if (panel_type->flag & PNL_LIST) {
+    Panel *last_list_panel = NULL;
+
+    for (Panel *list_panel = panels->first; list_panel; list_panel = list_panel->next) {
+      if (list_panel->type == NULL) {
+        continue;
+      }
+      if (list_panel->type->flag & (PNL_LIST_START | PNL_LIST)) {
+        last_list_panel = list_panel;
+      }
+    }
+
+    /* There should always be a list panel or a list panel start before this panel. */
+    BLI_assert(last_list_panel);


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list