2011-02-23 10:52:22 +00:00
|
|
|
/*
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
*/
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup edinterface
|
2011-02-27 20:29:51 +00:00
|
|
|
*/
|
|
|
|
|
2020-03-19 09:33:03 +01:00
|
|
|
#include <assert.h>
|
2009-03-13 13:38:41 +00:00
|
|
|
#include <limits.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2010-12-12 18:16:54 +00:00
|
|
|
#include "DNA_armature_types.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_screen_types.h"
|
2009-04-27 18:05:58 +00:00
|
|
|
#include "DNA_userdef_types.h"
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2018-06-09 16:50:05 +02:00
|
|
|
#include "BLI_alloca.h"
|
2009-03-13 13:38:41 +00:00
|
|
|
#include "BLI_listbase.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_math.h"
|
2012-08-21 19:35:06 +00:00
|
|
|
#include "BLI_rect.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_string.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2015-08-16 17:32:01 +10:00
|
|
|
#include "BLT_translation.h"
|
2011-06-15 11:41:15 +00:00
|
|
|
|
2020-04-03 13:07:36 +02:00
|
|
|
#include "BKE_anim_data.h"
|
2009-03-13 13:38:41 +00:00
|
|
|
#include "BKE_context.h"
|
|
|
|
#include "BKE_global.h"
|
|
|
|
#include "BKE_idprop.h"
|
2009-03-29 19:44:39 +00:00
|
|
|
#include "BKE_screen.h"
|
2009-03-13 13:38:41 +00:00
|
|
|
|
|
|
|
#include "RNA_access.h"
|
|
|
|
|
|
|
|
#include "UI_interface.h"
|
|
|
|
|
2013-11-18 16:06:31 +13:00
|
|
|
#include "ED_armature.h"
|
|
|
|
|
2009-03-13 13:38:41 +00:00
|
|
|
#include "WM_api.h"
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
2009-04-02 01:39:33 +00:00
|
|
|
#include "interface_intern.h"
|
|
|
|
|
2018-06-16 14:48:21 +02:00
|
|
|
/* Show an icon button after each RNA button to use to quickly set keyframes,
|
|
|
|
* this is a way to display animation/driven/override status, see T54951. */
|
|
|
|
#define UI_PROP_DECORATE
|
2018-06-25 12:06:31 +02:00
|
|
|
/* Alternate draw mode where some buttons can use single icon width,
|
|
|
|
* giving more room for the text at the expense of nicely aligned text. */
|
|
|
|
#define UI_PROP_SEP_ICON_WIDTH_EXCEPTION
|
2018-06-16 14:48:21 +02:00
|
|
|
|
2019-09-06 16:12:47 +10:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Structs and Defines
|
|
|
|
* \{ */
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
#define UI_OPERATOR_ERROR_RET(_ot, _opname, return_statement) \
|
|
|
|
if (ot == NULL) { \
|
|
|
|
ui_item_disabled(layout, _opname); \
|
|
|
|
RNA_warning("'%s' unknown operator", _opname); \
|
|
|
|
return_statement; \
|
|
|
|
} \
|
|
|
|
(void)0
|
2012-01-22 19:52:41 +00:00
|
|
|
|
UI: Layout changes for new checkbox layout possibilities
Follow-up to previous commit.
Some examples:
{F8473507} {F8473508} {F8473509} {F8473510}
For more screenshots, please see D7430.
We use column or row headings here to bring more structure, and to give
the eye visual anchors which aid eye-scanning. The left-aligned
checkboxes likewise help with this. And we keep the adherence to the
center line, so the alignment matches up between the various buttons and
controls.
* Changes the property split percentage from 50/50% to 40/60%. This is
needed to give enough space for the checkboxes. But in most cases this
looks better anyway - see Transform panel. In some cases it simply
fills out the available space more efficently.
* Fix various hacks where we previously used manually defined splits.
When we did this, the alignment was never quite right, and the layout
code was a mess.
* Adds column headings to many places where a list of checkboxes all
share a common purpose or leading text.
* Add checkbox + value configurations various places where a checkbox
only serves to enable the value slider
* Removes most uses of grid flow layout. The grid flow layouts combine
poorly with column headings, and also they would mess alignment up
badly. The grid flow layouts also often made buttons and controls jump
around on the screen if you would just resize editors slightly,
causing visual confusion, making users lose their place. The logic for
at what time the list of items would re-flow was often flawed, jumping
to multiple columns too fast or too late - and frankly, the grid flow
layouts would often just look bad.
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7430
Reviewed by: Brecht Van Lommel, Pablo Vazquez.
Most work here by William Reynish, few changes by Julian Eisel.
2020-04-17 16:54:03 +02:00
|
|
|
#define UI_ITEM_PROP_SEP_DIVIDE 0.4f
|
2012-01-22 19:52:41 +00:00
|
|
|
|
2009-05-19 17:13:33 +00:00
|
|
|
/* uiLayoutRoot */
|
|
|
|
|
|
|
|
typedef struct uiLayoutRoot {
|
2019-04-17 06:17:24 +02:00
|
|
|
struct uiLayoutRoot *next, *prev;
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
int type;
|
|
|
|
int opcontext;
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
int emw, emh;
|
|
|
|
int padding;
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
uiMenuHandleFunc handlefunc;
|
|
|
|
void *argv;
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2020-03-15 17:32:25 +11:00
|
|
|
const uiStyle *style;
|
2019-04-17 06:17:24 +02:00
|
|
|
uiBlock *block;
|
|
|
|
uiLayout *layout;
|
2009-05-19 17:13:33 +00:00
|
|
|
} uiLayoutRoot;
|
2009-04-22 18:39:44 +00:00
|
|
|
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
/* Item */
|
2009-04-22 18:39:44 +00:00
|
|
|
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
typedef enum uiItemType {
|
2019-04-17 06:17:24 +02:00
|
|
|
ITEM_BUTTON,
|
|
|
|
|
|
|
|
ITEM_LAYOUT_ROW,
|
|
|
|
ITEM_LAYOUT_COLUMN,
|
|
|
|
ITEM_LAYOUT_COLUMN_FLOW,
|
|
|
|
ITEM_LAYOUT_ROW_FLOW,
|
|
|
|
ITEM_LAYOUT_GRID_FLOW,
|
|
|
|
ITEM_LAYOUT_BOX,
|
|
|
|
ITEM_LAYOUT_ABSOLUTE,
|
|
|
|
ITEM_LAYOUT_SPLIT,
|
|
|
|
ITEM_LAYOUT_OVERLAP,
|
|
|
|
ITEM_LAYOUT_RADIAL,
|
|
|
|
|
|
|
|
ITEM_LAYOUT_ROOT
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
#if 0
|
2019-04-17 08:24:14 +02:00
|
|
|
TEMPLATE_COLUMN_FLOW,
|
2019-04-17 06:17:24 +02:00
|
|
|
TEMPLATE_SPLIT,
|
|
|
|
TEMPLATE_BOX,
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
TEMPLATE_HEADER,
|
|
|
|
TEMPLATE_HEADER_ID,
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
#endif
|
|
|
|
} uiItemType;
|
2009-03-13 13:38:41 +00:00
|
|
|
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
typedef struct uiItem {
|
2019-04-17 06:17:24 +02:00
|
|
|
void *next, *prev;
|
|
|
|
uiItemType type;
|
|
|
|
int flag;
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
} uiItem;
|
|
|
|
|
2017-01-10 16:19:10 +01:00
|
|
|
enum {
|
2019-09-19 16:14:47 +02:00
|
|
|
UI_ITEM_AUTO_FIXED_SIZE = 1 << 0,
|
|
|
|
UI_ITEM_FIXED_SIZE = 1 << 1,
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
UI_ITEM_BOX_ITEM = 1 << 2, /* The item is "inside" a box item */
|
|
|
|
UI_ITEM_PROP_SEP = 1 << 3,
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
UI_ITEM_INSIDE_PROP_SEP = 1 << 4,
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Show an icon button next to each property (to set keyframes, show status).
|
|
|
|
* Enabled by default, depends on 'UI_ITEM_PROP_SEP'. */
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
UI_ITEM_PROP_DECORATE = 1 << 5,
|
|
|
|
UI_ITEM_PROP_DECORATE_NO_PAD = 1 << 6,
|
2017-01-10 16:19:10 +01:00
|
|
|
};
|
|
|
|
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
typedef struct uiButtonItem {
|
2019-04-17 06:17:24 +02:00
|
|
|
uiItem item;
|
|
|
|
uiBut *but;
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
} uiButtonItem;
|
|
|
|
|
|
|
|
struct uiLayout {
|
2019-04-17 06:17:24 +02:00
|
|
|
uiItem item;
|
|
|
|
|
|
|
|
uiLayoutRoot *root;
|
|
|
|
bContextStore *context;
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
uiLayout *parent;
|
2019-04-17 06:17:24 +02:00
|
|
|
ListBase items;
|
|
|
|
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
char heading[UI_MAX_NAME_STR];
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/** Sub layout to add child items, if not the layout itself. */
|
|
|
|
uiLayout *child_items_layout;
|
|
|
|
|
|
|
|
int x, y, w, h;
|
|
|
|
float scale[2];
|
|
|
|
short space;
|
|
|
|
bool align;
|
|
|
|
bool active;
|
|
|
|
bool active_default;
|
|
|
|
bool activate_init;
|
|
|
|
bool enabled;
|
|
|
|
bool redalert;
|
|
|
|
bool keepaspect;
|
|
|
|
/** For layouts inside gridflow, they and their items shall never have a fixed maximal size. */
|
|
|
|
bool variable_size;
|
|
|
|
char alignment;
|
|
|
|
char emboss;
|
|
|
|
/** for fixed width or height to avoid UI size changes */
|
|
|
|
float units[2];
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct uiLayoutItemFlow {
|
2019-04-17 06:17:24 +02:00
|
|
|
uiLayout litem;
|
|
|
|
int number;
|
|
|
|
int totcol;
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
} uiLayoutItemFlow;
|
2009-04-11 01:52:27 +00:00
|
|
|
|
2018-06-09 16:50:05 +02:00
|
|
|
typedef struct uiLayoutItemGridFlow {
|
2019-04-17 06:17:24 +02:00
|
|
|
uiLayout litem;
|
|
|
|
|
|
|
|
/* Extra parameters */
|
|
|
|
bool row_major; /* Fill first row first, instead of filling first column first. */
|
|
|
|
bool even_columns; /* Same width for all columns. */
|
|
|
|
bool even_rows; /* Same height for all rows. */
|
|
|
|
/**
|
|
|
|
* - If positive, absolute fixed number of columns.
|
|
|
|
* - If 0, fully automatic (based on available width).
|
|
|
|
* - If negative, automatic but only generates number of columns/rows
|
|
|
|
* multiple of given (absolute) value.
|
|
|
|
*/
|
|
|
|
int columns_len;
|
|
|
|
|
|
|
|
/* Pure internal runtime storage. */
|
|
|
|
int tot_items, tot_columns, tot_rows;
|
2018-06-09 16:50:05 +02:00
|
|
|
} uiLayoutItemGridFlow;
|
|
|
|
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
typedef struct uiLayoutItemBx {
|
2019-04-17 06:17:24 +02:00
|
|
|
uiLayout litem;
|
|
|
|
uiBut *roundbox;
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
} uiLayoutItemBx;
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2011-07-26 20:22:54 +00:00
|
|
|
typedef struct uiLayoutItemSplit {
|
2019-04-17 06:17:24 +02:00
|
|
|
uiLayout litem;
|
|
|
|
float percentage;
|
2011-07-26 20:22:54 +00:00
|
|
|
} uiLayoutItemSplit;
|
2009-06-07 13:20:41 +00:00
|
|
|
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
typedef struct uiLayoutItemRoot {
|
2019-04-17 06:17:24 +02:00
|
|
|
uiLayout litem;
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
} uiLayoutItemRoot;
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-09-06 16:12:47 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Item
|
|
|
|
* \{ */
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2010-11-17 09:45:45 +00:00
|
|
|
static const char *ui_item_name_add_colon(const char *name, char namestr[UI_MAX_NAME_STR])
|
2009-04-27 18:05:58 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int len = strlen(name);
|
|
|
|
|
|
|
|
if (len != 0 && len + 1 < UI_MAX_NAME_STR) {
|
|
|
|
memcpy(namestr, name, len);
|
|
|
|
namestr[len] = ':';
|
|
|
|
namestr[len + 1] = '\0';
|
|
|
|
return namestr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ui_item_fit(
|
|
|
|
int item, int pos, int all, int available, bool is_last, int alignment, float *extra_pixel)
|
|
|
|
{
|
|
|
|
/* available == 0 is unlimited */
|
|
|
|
if (ELEM(0, available, all)) {
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (all > available) {
|
|
|
|
/* contents is bigger than available space */
|
|
|
|
if (is_last) {
|
|
|
|
return available - pos;
|
|
|
|
}
|
2020-07-03 14:20:10 +02:00
|
|
|
|
|
|
|
float width = *extra_pixel + (item * available) / (float)all;
|
|
|
|
*extra_pixel = width - (int)width;
|
|
|
|
return (int)width;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2020-07-03 14:20:10 +02:00
|
|
|
|
|
|
|
/* contents is smaller or equal to available space */
|
|
|
|
if (alignment == UI_LAYOUT_ALIGN_EXPAND) {
|
|
|
|
if (is_last) {
|
|
|
|
return available - pos;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2020-07-03 14:20:10 +02:00
|
|
|
|
|
|
|
float width = *extra_pixel + (item * available) / (float)all;
|
|
|
|
*extra_pixel = width - (int)width;
|
|
|
|
return (int)width;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2020-07-03 14:20:10 +02:00
|
|
|
return item;
|
2009-03-13 13:38:41 +00:00
|
|
|
}
|
|
|
|
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
/* variable button size in which direction? */
|
2019-04-17 06:17:24 +02:00
|
|
|
#define UI_ITEM_VARY_X 1
|
|
|
|
#define UI_ITEM_VARY_Y 2
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
|
2015-02-13 09:10:53 +01:00
|
|
|
static int ui_layout_vary_direction(uiLayout *layout)
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return ((ELEM(layout->root->type, UI_LAYOUT_HEADER, UI_LAYOUT_PIEMENU) ||
|
|
|
|
(layout->alignment != UI_LAYOUT_ALIGN_EXPAND)) ?
|
|
|
|
UI_ITEM_VARY_X :
|
|
|
|
UI_ITEM_VARY_Y);
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
}
|
|
|
|
|
2018-06-09 16:50:05 +02:00
|
|
|
static bool ui_layout_variable_size(uiLayout *layout)
|
|
|
|
{
|
2019-06-16 13:37:21 +10:00
|
|
|
/* Note that this code is probably a bit flakey, we'd probably want to know whether it's
|
2019-04-17 06:17:24 +02:00
|
|
|
* variable in X and/or Y, etc. But for now it mimics previous one,
|
2019-06-16 13:37:21 +10:00
|
|
|
* with addition of variable flag set for children of grid-flow layouts. */
|
2019-04-17 06:17:24 +02:00
|
|
|
return ui_layout_vary_direction(layout) == UI_ITEM_VARY_X || layout->variable_size;
|
2018-06-09 16:50:05 +02:00
|
|
|
}
|
|
|
|
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
/* estimated size of text + icon */
|
2014-02-27 15:50:30 +11:00
|
|
|
static int ui_text_icon_width(uiLayout *layout, const char *name, int icon, bool compact)
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bool variable;
|
|
|
|
const int unit_x = UI_UNIT_X * (layout->scale[0] ? layout->scale[0] : 1.0f);
|
|
|
|
|
|
|
|
if (icon && !name[0]) {
|
|
|
|
return unit_x; /* icon only */
|
|
|
|
}
|
|
|
|
|
|
|
|
variable = ui_layout_variable_size(layout);
|
|
|
|
|
|
|
|
if (variable) {
|
|
|
|
if (!icon && !name[0]) {
|
|
|
|
return unit_x; /* No icon or name. */
|
|
|
|
}
|
|
|
|
if (layout->alignment != UI_LAYOUT_ALIGN_EXPAND) {
|
2019-09-19 16:14:47 +02:00
|
|
|
layout->item.flag |= UI_ITEM_FIXED_SIZE;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
|
2019-05-03 16:15:11 +03:00
|
|
|
float margin = compact ? 1.25 : 1.50;
|
|
|
|
if (icon) {
|
|
|
|
/* It may seem odd that the icon only adds (unit_x / 4)
|
|
|
|
* but taking margins into account its fine, except
|
|
|
|
* in compact mode a bit more margin is required. */
|
|
|
|
margin += compact ? 0.35 : 0.25;
|
|
|
|
}
|
|
|
|
return UI_fontstyle_string_width(fstyle, name) + (unit_x * margin);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2020-07-03 14:20:10 +02:00
|
|
|
return unit_x * 10;
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ui_item_size(uiItem *item, int *r_w, int *r_h)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (item->type == ITEM_BUTTON) {
|
|
|
|
uiButtonItem *bitem = (uiButtonItem *)item;
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (r_w) {
|
|
|
|
*r_w = BLI_rctf_size_x(&bitem->but->rect);
|
|
|
|
}
|
|
|
|
if (r_h) {
|
|
|
|
*r_h = BLI_rctf_size_y(&bitem->but->rect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
uiLayout *litem = (uiLayout *)item;
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (r_w) {
|
|
|
|
*r_w = litem->w;
|
|
|
|
}
|
|
|
|
if (r_h) {
|
|
|
|
*r_h = litem->h;
|
|
|
|
}
|
|
|
|
}
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ui_item_offset(uiItem *item, int *r_x, int *r_y)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (item->type == ITEM_BUTTON) {
|
|
|
|
uiButtonItem *bitem = (uiButtonItem *)item;
|
|
|
|
|
|
|
|
if (r_x) {
|
|
|
|
*r_x = bitem->but->rect.xmin;
|
|
|
|
}
|
|
|
|
if (r_y) {
|
|
|
|
*r_y = bitem->but->rect.ymin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (r_x) {
|
|
|
|
*r_x = 0;
|
|
|
|
}
|
|
|
|
if (r_y) {
|
|
|
|
*r_y = 0;
|
|
|
|
}
|
|
|
|
}
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ui_item_position(uiItem *item, int x, int y, int w, int h)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (item->type == ITEM_BUTTON) {
|
|
|
|
uiButtonItem *bitem = (uiButtonItem *)item;
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
bitem->but->rect.xmin = x;
|
|
|
|
bitem->but->rect.ymin = y;
|
|
|
|
bitem->but->rect.xmax = x + w;
|
|
|
|
bitem->but->rect.ymax = y + h;
|
2018-05-23 10:47:12 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ui_but_update(bitem->but); /* for strlen */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
uiLayout *litem = (uiLayout *)item;
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
litem->x = x;
|
|
|
|
litem->y = y + h;
|
|
|
|
litem->w = w;
|
|
|
|
litem->h = h;
|
|
|
|
}
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
}
|
|
|
|
|
2017-02-25 13:18:41 +03:00
|
|
|
static void ui_item_move(uiItem *item, int delta_xmin, int delta_xmax)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (item->type == ITEM_BUTTON) {
|
|
|
|
uiButtonItem *bitem = (uiButtonItem *)item;
|
2017-02-25 13:18:41 +03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
bitem->but->rect.xmin += delta_xmin;
|
|
|
|
bitem->but->rect.xmax += delta_xmax;
|
2018-05-23 10:47:12 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ui_but_update(bitem->but); /* for strlen */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
uiLayout *litem = (uiLayout *)item;
|
2017-02-25 13:18:41 +03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (delta_xmin > 0) {
|
|
|
|
litem->x += delta_xmin;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
litem->w += delta_xmax;
|
|
|
|
}
|
|
|
|
}
|
2017-02-25 13:18:41 +03:00
|
|
|
}
|
|
|
|
|
2019-09-06 16:12:47 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Special RNA Items
|
|
|
|
* \{ */
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
|
2018-12-20 11:59:31 +11:00
|
|
|
int uiLayoutGetLocalDir(const uiLayout *layout)
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
switch (layout->item.type) {
|
|
|
|
case ITEM_LAYOUT_ROW:
|
|
|
|
case ITEM_LAYOUT_ROOT:
|
|
|
|
case ITEM_LAYOUT_OVERLAP:
|
|
|
|
return UI_LAYOUT_HORIZONTAL;
|
|
|
|
case ITEM_LAYOUT_COLUMN:
|
|
|
|
case ITEM_LAYOUT_COLUMN_FLOW:
|
|
|
|
case ITEM_LAYOUT_GRID_FLOW:
|
|
|
|
case ITEM_LAYOUT_SPLIT:
|
|
|
|
case ITEM_LAYOUT_ABSOLUTE:
|
|
|
|
case ITEM_LAYOUT_BOX:
|
|
|
|
default:
|
|
|
|
return UI_LAYOUT_VERTICAL;
|
|
|
|
}
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
}
|
|
|
|
|
2018-07-01 15:47:09 +02:00
|
|
|
static uiLayout *ui_item_local_sublayout(uiLayout *test, uiLayout *layout, bool align)
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiLayout *sub;
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (uiLayoutGetLocalDir(test) == UI_LAYOUT_HORIZONTAL) {
|
|
|
|
sub = uiLayoutRow(layout, align);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sub = uiLayoutColumn(layout, align);
|
|
|
|
}
|
2018-05-23 10:47:12 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
sub->space = 0;
|
|
|
|
return sub;
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
}
|
|
|
|
|
2009-09-09 17:39:19 +00:00
|
|
|
static void ui_layer_but_cb(bContext *C, void *arg_but, void *arg_index)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
wmWindow *win = CTX_wm_window(C);
|
|
|
|
uiBut *but = arg_but, *cbut;
|
|
|
|
PointerRNA *ptr = &but->rnapoin;
|
|
|
|
PropertyRNA *prop = but->rnaprop;
|
|
|
|
int i, index = POINTER_AS_INT(arg_index);
|
|
|
|
int shift = win->eventstate->shift;
|
|
|
|
int len = RNA_property_array_length(ptr, prop);
|
2009-09-09 17:39:19 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (!shift) {
|
|
|
|
RNA_property_boolean_set_index(ptr, prop, index, true);
|
2009-09-09 17:39:19 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
if (i != index) {
|
|
|
|
RNA_property_boolean_set_index(ptr, prop, i, 0);
|
|
|
|
}
|
|
|
|
}
|
2009-09-09 17:39:19 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
RNA_property_update(C, ptr, prop);
|
2009-09-09 17:39:19 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (cbut = but->block->buttons.first; cbut; cbut = cbut->next) {
|
|
|
|
ui_but_update(cbut);
|
|
|
|
}
|
|
|
|
}
|
2009-09-09 17:39:19 +00:00
|
|
|
}
|
|
|
|
|
2009-03-13 13:38:41 +00:00
|
|
|
/* create buttons for an item with an RNA array */
|
2019-04-17 06:17:24 +02:00
|
|
|
static void ui_item_array(uiLayout *layout,
|
|
|
|
uiBlock *block,
|
|
|
|
const char *name,
|
|
|
|
int icon,
|
|
|
|
PointerRNA *ptr,
|
|
|
|
PropertyRNA *prop,
|
|
|
|
int len,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int w,
|
|
|
|
int UNUSED(h),
|
|
|
|
bool expand,
|
|
|
|
bool slider,
|
2019-05-21 14:39:09 +10:00
|
|
|
int toggle,
|
2019-04-17 06:17:24 +02:00
|
|
|
bool icon_only,
|
|
|
|
bool compact,
|
|
|
|
bool show_text)
|
|
|
|
{
|
2020-03-15 17:32:25 +11:00
|
|
|
const uiStyle *style = layout->root->style;
|
2019-04-17 06:17:24 +02:00
|
|
|
uiBut *but;
|
|
|
|
PropertyType type;
|
|
|
|
PropertySubType subtype;
|
|
|
|
uiLayout *sub;
|
|
|
|
uint a, b;
|
|
|
|
|
|
|
|
/* retrieve type and subtype */
|
|
|
|
type = RNA_property_type(prop);
|
|
|
|
subtype = RNA_property_subtype(prop);
|
|
|
|
|
|
|
|
sub = ui_item_local_sublayout(layout, layout, 1);
|
|
|
|
UI_block_layout_set_current(block, sub);
|
|
|
|
|
|
|
|
/* create label */
|
|
|
|
if (name[0] && show_text) {
|
|
|
|
uiDefBut(block, UI_BTYPE_LABEL, 0, name, 0, 0, w, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create buttons */
|
|
|
|
if (type == PROP_BOOLEAN && ELEM(subtype, PROP_LAYER, PROP_LAYER_MEMBER)) {
|
|
|
|
/* special check for layer layout */
|
|
|
|
int butw, buth, unit;
|
|
|
|
int cols = (len >= 20) ? 2 : 1;
|
|
|
|
const uint colbuts = len / (2 * cols);
|
|
|
|
uint layer_used = 0;
|
|
|
|
uint layer_active = 0;
|
|
|
|
|
|
|
|
UI_block_layout_set_current(block, uiLayoutAbsolute(layout, false));
|
|
|
|
|
|
|
|
unit = UI_UNIT_X * 0.75;
|
|
|
|
butw = unit;
|
|
|
|
buth = unit;
|
|
|
|
|
|
|
|
if (ptr->type == &RNA_Armature) {
|
2020-03-05 08:33:26 +11:00
|
|
|
bArmature *arm = ptr->data;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
layer_used = arm->layer_used;
|
|
|
|
|
|
|
|
if (arm->edbo) {
|
|
|
|
if (arm->act_edbone) {
|
|
|
|
layer_active |= arm->act_edbone->layer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (arm->act_bone) {
|
|
|
|
layer_active |= arm->act_bone->layer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (b = 0; b < cols; b++) {
|
|
|
|
UI_block_align_begin(block);
|
|
|
|
|
|
|
|
for (a = 0; a < colbuts; a++) {
|
|
|
|
const int layer_num = a + b * colbuts;
|
|
|
|
const uint layer_flag = (1u << layer_num);
|
|
|
|
|
|
|
|
if (layer_used & layer_flag) {
|
|
|
|
if (layer_active & layer_flag) {
|
|
|
|
icon = ICON_LAYER_ACTIVE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
icon = ICON_LAYER_USED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
icon = ICON_BLANK1;
|
|
|
|
}
|
|
|
|
|
|
|
|
but = uiDefAutoButR(
|
|
|
|
block, ptr, prop, layer_num, "", icon, x + butw * a, y + buth, butw, buth);
|
|
|
|
if (subtype == PROP_LAYER_MEMBER) {
|
|
|
|
UI_but_func_set(but, ui_layer_but_cb, but, POINTER_FROM_INT(layer_num));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (a = 0; a < colbuts; a++) {
|
|
|
|
const int layer_num = a + len / 2 + b * colbuts;
|
|
|
|
const uint layer_flag = (1u << layer_num);
|
|
|
|
|
|
|
|
if (layer_used & layer_flag) {
|
|
|
|
if (layer_active & layer_flag) {
|
|
|
|
icon = ICON_LAYER_ACTIVE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
icon = ICON_LAYER_USED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
icon = ICON_BLANK1;
|
|
|
|
}
|
|
|
|
|
|
|
|
but = uiDefAutoButR(block, ptr, prop, layer_num, "", icon, x + butw * a, y, butw, buth);
|
|
|
|
if (subtype == PROP_LAYER_MEMBER) {
|
|
|
|
UI_but_func_set(but, ui_layer_but_cb, but, POINTER_FROM_INT(layer_num));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UI_block_align_end(block);
|
|
|
|
|
|
|
|
x += colbuts * butw + style->buttonspacex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (subtype == PROP_MATRIX) {
|
|
|
|
int totdim, dim_size[3]; /* 3 == RNA_MAX_ARRAY_DIMENSION */
|
|
|
|
int row, col;
|
|
|
|
|
|
|
|
UI_block_layout_set_current(block, uiLayoutAbsolute(layout, true));
|
|
|
|
|
|
|
|
totdim = RNA_property_array_dimension(ptr, prop, dim_size);
|
|
|
|
if (totdim != 2) {
|
|
|
|
/* Only 2D matrices supported in UI so far. */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
w /= dim_size[0];
|
|
|
|
/* h /= dim_size[1]; */ /* UNUSED */
|
|
|
|
|
|
|
|
for (a = 0; a < len; a++) {
|
|
|
|
col = a % dim_size[0];
|
|
|
|
row = a / dim_size[0];
|
|
|
|
|
|
|
|
but = uiDefAutoButR(block,
|
|
|
|
ptr,
|
|
|
|
prop,
|
|
|
|
a,
|
|
|
|
"",
|
|
|
|
ICON_NONE,
|
|
|
|
x + w * col,
|
|
|
|
y + (dim_size[1] * UI_UNIT_Y) - (row * UI_UNIT_Y),
|
|
|
|
w,
|
|
|
|
UI_UNIT_Y);
|
|
|
|
if (slider && but->type == UI_BTYPE_NUM) {
|
|
|
|
but->type = UI_BTYPE_NUM_SLIDER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (subtype == PROP_DIRECTION && !expand) {
|
|
|
|
uiDefButR_prop(block,
|
|
|
|
UI_BTYPE_UNITVEC,
|
|
|
|
0,
|
|
|
|
name,
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
UI_UNIT_X * 3,
|
|
|
|
UI_UNIT_Y * 3,
|
|
|
|
ptr,
|
|
|
|
prop,
|
|
|
|
-1,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
-1,
|
|
|
|
-1,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* note, this block of code is a bit arbitrary and has just been made
|
|
|
|
* to work with common cases, but may need to be re-worked */
|
|
|
|
|
|
|
|
/* special case, boolean array in a menu, this could be used in a more generic way too */
|
2019-08-13 19:45:20 +03:00
|
|
|
if (ELEM(subtype, PROP_COLOR, PROP_COLOR_GAMMA) && !expand && ELEM(len, 3, 4)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
uiDefAutoButR(block, ptr, prop, -1, "", ICON_NONE, 0, 0, w, UI_UNIT_Y);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bool *boolarr = NULL;
|
|
|
|
|
|
|
|
/* even if 'expand' is fale, expanding anyway */
|
|
|
|
|
|
|
|
/* layout for known array subtypes */
|
|
|
|
char str[3] = {'\0'};
|
|
|
|
|
|
|
|
if (!icon_only && show_text) {
|
|
|
|
if (type != PROP_BOOLEAN) {
|
|
|
|
str[1] = ':';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* show checkboxes for rna on a non-emboss block (menu for eg) */
|
|
|
|
if (type == PROP_BOOLEAN &&
|
2020-07-29 12:05:27 +10:00
|
|
|
ELEM(layout->root->block->emboss, UI_EMBOSS_NONE, UI_EMBOSS_PULLDOWN)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
boolarr = MEM_callocN(sizeof(bool) * len, __func__);
|
|
|
|
RNA_property_boolean_get_array(ptr, prop, boolarr);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *str_buf = show_text ? str : "";
|
|
|
|
for (a = 0; a < len; a++) {
|
|
|
|
int width_item;
|
|
|
|
|
|
|
|
if (!icon_only && show_text) {
|
|
|
|
str[0] = RNA_property_array_item_char(prop, a);
|
|
|
|
}
|
|
|
|
if (boolarr) {
|
|
|
|
icon = boolarr[a] ? ICON_CHECKBOX_HLT : ICON_CHECKBOX_DEHLT;
|
|
|
|
}
|
|
|
|
|
|
|
|
width_item = ((compact && type == PROP_BOOLEAN) ?
|
|
|
|
min_ii(w, ui_text_icon_width(layout, str_buf, icon, false)) :
|
|
|
|
w);
|
|
|
|
|
|
|
|
but = uiDefAutoButR(block, ptr, prop, a, str_buf, icon, 0, 0, width_item, UI_UNIT_Y);
|
|
|
|
if (slider && but->type == UI_BTYPE_NUM) {
|
|
|
|
but->type = UI_BTYPE_NUM_SLIDER;
|
|
|
|
}
|
2019-05-21 14:39:09 +10:00
|
|
|
if ((toggle == 1) && but->type == UI_BTYPE_CHECKBOX) {
|
2019-04-17 06:17:24 +02:00
|
|
|
but->type = UI_BTYPE_TOGGLE;
|
|
|
|
}
|
|
|
|
if ((a == 0) && (subtype == PROP_AXISANGLE)) {
|
|
|
|
UI_but_unit_type_set(but, PROP_UNIT_ROTATION);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (boolarr) {
|
|
|
|
MEM_freeN(boolarr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UI_block_layout_set_current(block, layout);
|
2009-03-13 13:38:41 +00:00
|
|
|
}
|
|
|
|
|
Fix for [#35224] Transform Orientation - order inconsistency
Fix turned out to remove as much "manual UI" from 3D view header as possible. Mode selector and all transform manipulators/orientations stuff are now RNA-based UI (leaving basically only edit mesh select modes with custom handlers, as they have some quite specific features).
To achieve this, four main modifications were done:
* enum-operator-generated menus are now MENU (i.e. dropdown lists) in headers too.
* All bit-flag enums expanded in ROW buttons now have a handling consistent with e.g. layers, or what we already have for transform manipulators, i.e. clicking select only one element, shift-click to select multiple ones.
* Consequently, the three RNA booleans manipulators flags are merged into a single bit-flag enum (yes, this is also an API change, though I doubt many scripts use it).
* Now the width of enum-based dropdown lists is computed from longest item name in enum, no more from a dummy place holder string (when no label/name is given).
All this allows to remove some code from 3DView/transform areas, that was actually mostly duplicating RNA/operator one.
Also done a few optimizations here and there (among others, do not pass &numitems to RNA_property_enum_items() when you do not need it, saves at least an iteration over enum items to count them).
Many thanks to Brecht for the reviews!
2013-05-12 13:16:11 +00:00
|
|
|
static void ui_item_enum_expand_handle(bContext *C, void *arg1, void *arg2)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
wmWindow *win = CTX_wm_window(C);
|
|
|
|
|
|
|
|
if (!win->eventstate->shift) {
|
|
|
|
uiBut *but = (uiBut *)arg1;
|
|
|
|
int enum_value = POINTER_AS_INT(arg2);
|
|
|
|
|
|
|
|
int current_value = RNA_property_enum_get(&but->rnapoin, but->rnaprop);
|
|
|
|
if (!(current_value & enum_value)) {
|
|
|
|
current_value = enum_value;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
current_value &= enum_value;
|
|
|
|
}
|
|
|
|
RNA_property_enum_set(&but->rnapoin, but->rnaprop, current_value);
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 15:02:30 +02:00
|
|
|
|
2019-04-18 13:59:59 +02:00
|
|
|
/**
|
|
|
|
* Draw a single enum button, a utility for #ui_item_enum_expand_exec
|
|
|
|
*/
|
2019-04-17 15:02:30 +02:00
|
|
|
static void ui_item_enum_expand_elem_exec(uiLayout *layout,
|
|
|
|
uiBlock *block,
|
|
|
|
PointerRNA *ptr,
|
|
|
|
PropertyRNA *prop,
|
|
|
|
const char *uiname,
|
2019-04-18 13:59:59 +02:00
|
|
|
const int h,
|
|
|
|
const eButType but_type,
|
|
|
|
const bool icon_only,
|
2019-04-17 15:02:30 +02:00
|
|
|
const EnumPropertyItem *item,
|
2019-04-18 13:59:59 +02:00
|
|
|
const bool is_first)
|
2019-04-17 15:02:30 +02:00
|
|
|
{
|
2019-04-18 13:59:59 +02:00
|
|
|
const char *name = (!uiname || uiname[0]) ? item->name : "";
|
|
|
|
const int icon = item->icon;
|
|
|
|
const int value = item->value;
|
|
|
|
const int itemw = ui_text_icon_width(block->curlayout, icon_only ? "" : name, icon, 0);
|
2019-04-17 15:02:30 +02:00
|
|
|
|
2019-04-18 13:59:59 +02:00
|
|
|
uiBut *but;
|
2019-04-17 15:02:30 +02:00
|
|
|
|
|
|
|
if (icon && name[0] && !icon_only) {
|
|
|
|
but = uiDefIconTextButR_prop(
|
|
|
|
block, but_type, 0, icon, name, 0, 0, itemw, h, ptr, prop, -1, 0, value, -1, -1, NULL);
|
|
|
|
}
|
|
|
|
else if (icon) {
|
2019-04-18 13:59:59 +02:00
|
|
|
const int w = (is_first) ? itemw : ceilf(itemw - U.pixelsize);
|
|
|
|
but = uiDefIconButR_prop(
|
|
|
|
block, but_type, 0, icon, 0, 0, w, h, ptr, prop, -1, 0, value, -1, -1, NULL);
|
2019-04-17 15:02:30 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
but = uiDefButR_prop(
|
|
|
|
block, but_type, 0, name, 0, 0, itemw, h, ptr, prop, -1, 0, value, -1, -1, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RNA_property_flag(prop) & PROP_ENUM_FLAG) {
|
|
|
|
/* If this is set, assert since we're clobbering someone elses callback. */
|
2019-05-11 15:35:48 +02:00
|
|
|
/* Buttons get their block's func by default, so we cannot assert in that case either. */
|
|
|
|
BLI_assert(ELEM(but->func, NULL, block->func));
|
2019-04-17 15:02:30 +02:00
|
|
|
UI_but_func_set(but, ui_item_enum_expand_handle, but, POINTER_FROM_INT(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uiLayoutGetLocalDir(layout) != UI_LAYOUT_HORIZONTAL) {
|
|
|
|
but->drawflag |= UI_BUT_TEXT_LEFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allow quick, inaccurate swipe motions to switch tabs
|
2019-04-18 13:59:59 +02:00
|
|
|
* (no need to keep cursor over them). */
|
2019-04-17 15:02:30 +02:00
|
|
|
if (but_type == UI_BTYPE_TAB) {
|
|
|
|
but->flag |= UI_BUT_DRAG_LOCK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static void ui_item_enum_expand_exec(uiLayout *layout,
|
|
|
|
uiBlock *block,
|
|
|
|
PointerRNA *ptr,
|
|
|
|
PropertyRNA *prop,
|
|
|
|
const char *uiname,
|
2019-04-18 13:59:59 +02:00
|
|
|
const int h,
|
|
|
|
const eButType but_type,
|
|
|
|
const bool icon_only)
|
2019-04-17 06:17:24 +02:00
|
|
|
{
|
2019-04-17 08:44:38 +02:00
|
|
|
/* XXX: The way this function currently handles uiname parameter
|
|
|
|
* is insane and inconsistent with general UI API:
|
|
|
|
*
|
|
|
|
* - uiname is the *enum property* label.
|
|
|
|
* - when it is NULL or empty, we do not draw *enum items* labels,
|
|
|
|
* this doubles the icon_only parameter.
|
|
|
|
* - we *never* draw (i.e. really use) the enum label uiname, it is just used as a mere flag!
|
|
|
|
*
|
|
|
|
* Unfortunately, fixing this implies an API "soft break", so better to defer it for later... :/
|
|
|
|
* - mont29
|
2019-04-17 06:17:24 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
const EnumPropertyItem *item, *item_array;
|
|
|
|
bool free;
|
|
|
|
|
|
|
|
BLI_assert(RNA_property_type(prop) == PROP_ENUM);
|
|
|
|
|
2019-04-17 15:02:30 +02:00
|
|
|
uiLayout *layout_radial = NULL;
|
|
|
|
bool radial = (layout->root->type == UI_LAYOUT_PIEMENU);
|
2019-04-17 06:17:24 +02:00
|
|
|
if (radial) {
|
|
|
|
RNA_property_enum_items_gettexted_all(block->evil_C, ptr, prop, &item_array, NULL, &free);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
RNA_property_enum_items_gettexted(block->evil_C, ptr, prop, &item_array, NULL, &free);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we dont want nested rows, cols in menus */
|
|
|
|
if (radial) {
|
|
|
|
if (layout->root->layout == layout) {
|
|
|
|
layout_radial = uiLayoutRadial(layout);
|
|
|
|
UI_block_layout_set_current(block, layout_radial);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (layout->item.type == ITEM_LAYOUT_RADIAL) {
|
|
|
|
layout_radial = layout;
|
|
|
|
}
|
|
|
|
UI_block_layout_set_current(block, layout);
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 15:02:30 +02:00
|
|
|
else if (ELEM(layout->item.type, ITEM_LAYOUT_GRID_FLOW, ITEM_LAYOUT_COLUMN_FLOW) ||
|
|
|
|
layout->root->type == UI_LAYOUT_MENU) {
|
|
|
|
UI_block_layout_set_current(block, layout);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 15:02:30 +02:00
|
|
|
UI_block_layout_set_current(block, ui_item_local_sublayout(layout, layout, 1));
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (item = item_array; item->identifier; item++) {
|
|
|
|
const bool is_first = item == item_array;
|
|
|
|
|
|
|
|
if (!item->identifier[0]) {
|
|
|
|
const EnumPropertyItem *next_item = item + 1;
|
|
|
|
|
|
|
|
/* Separate items, potentially with a label. */
|
|
|
|
if (next_item->identifier) {
|
|
|
|
/* Item without identifier but with name:
|
2019-05-01 11:09:22 +10:00
|
|
|
* Add group label for the following items. */
|
2019-04-17 06:17:24 +02:00
|
|
|
if (item->name) {
|
|
|
|
if (!is_first) {
|
|
|
|
uiItemS(block->curlayout);
|
|
|
|
}
|
|
|
|
uiItemL(block->curlayout, item->name, item->icon);
|
|
|
|
}
|
|
|
|
else if (radial && layout_radial) {
|
|
|
|
uiItemS(layout_radial);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
uiItemS(block->curlayout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-04-17 15:02:30 +02:00
|
|
|
ui_item_enum_expand_elem_exec(
|
|
|
|
layout, block, ptr, prop, uiname, h, but_type, icon_only, item, is_first);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-04-17 15:02:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
UI_block_layout_set_current(block, layout);
|
|
|
|
|
|
|
|
if (free) {
|
|
|
|
MEM_freeN((void *)item_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static void ui_item_enum_expand(uiLayout *layout,
|
|
|
|
uiBlock *block,
|
|
|
|
PointerRNA *ptr,
|
|
|
|
PropertyRNA *prop,
|
|
|
|
const char *uiname,
|
2019-04-18 13:59:59 +02:00
|
|
|
const int h,
|
|
|
|
const bool icon_only)
|
2019-04-17 06:17:24 +02:00
|
|
|
{
|
|
|
|
ui_item_enum_expand_exec(layout, block, ptr, prop, uiname, h, UI_BTYPE_ROW, icon_only);
|
|
|
|
}
|
|
|
|
static void ui_item_enum_expand_tabs(uiLayout *layout,
|
|
|
|
bContext *C,
|
|
|
|
uiBlock *block,
|
|
|
|
PointerRNA *ptr,
|
|
|
|
PropertyRNA *prop,
|
|
|
|
const char *uiname,
|
2019-04-18 13:59:59 +02:00
|
|
|
const int h,
|
|
|
|
const bool icon_only)
|
2019-04-17 06:17:24 +02:00
|
|
|
{
|
|
|
|
uiBut *last = block->buttons.last;
|
|
|
|
|
|
|
|
ui_item_enum_expand_exec(layout, block, ptr, prop, uiname, h, UI_BTYPE_TAB, icon_only);
|
|
|
|
BLI_assert(last != block->buttons.last);
|
|
|
|
for (uiBut *tab = last ? last->next : block->buttons.first; tab; tab = tab->next) {
|
|
|
|
UI_but_drawflag_enable(tab, ui_but_align_opposite_to_area_align_get(CTX_wm_region(C)));
|
|
|
|
}
|
2018-10-29 21:20:58 +01:00
|
|
|
}
|
2009-04-16 12:17:58 +00:00
|
|
|
|
Key Configuration
Keymaps are now saveable and configurable from the user preferences, note
that editing one item in a keymap means the whole keymap is now defined by
the user and will not be updated by Blender, an option for syncing might be
added later. The outliner interface is still there, but I will probably
remove it.
There's actually 3 levels now:
* Default builtin key configuration.
* Key configuration loaded from .py file, for configs like Blender 2.4x
or other 3D applications.
* Keymaps edited by the user and saved in .B.blend. These can be saved
to .py files as well to make creating distributable configurations
easier.
Also, user preferences sections were reorganized a bit, now there is:
Interface, Editing, Input, Files and System.
Implementation notes:
* wmKeyConfig was added which represents a key configuration containing
keymaps.
* wmKeymapItem was renamed to wmKeyMapItem for consistency with wmKeyMap.
* Modal maps are not wrapped yet.
* User preferences DNA file reading did not support newdataadr() yet,
added this now for reading keymaps.
* Key configuration related settings are now RNA wrapped.
* is_property_set and is_property_hidden python methods were added.
2009-10-08 18:40:03 +00:00
|
|
|
/* callback for keymap item change button */
|
2010-10-14 12:24:08 +00:00
|
|
|
static void ui_keymap_but_cb(bContext *UNUSED(C), void *but_v, void *UNUSED(key_v))
|
Key Configuration
Keymaps are now saveable and configurable from the user preferences, note
that editing one item in a keymap means the whole keymap is now defined by
the user and will not be updated by Blender, an option for syncing might be
added later. The outliner interface is still there, but I will probably
remove it.
There's actually 3 levels now:
* Default builtin key configuration.
* Key configuration loaded from .py file, for configs like Blender 2.4x
or other 3D applications.
* Keymaps edited by the user and saved in .B.blend. These can be saved
to .py files as well to make creating distributable configurations
easier.
Also, user preferences sections were reorganized a bit, now there is:
Interface, Editing, Input, Files and System.
Implementation notes:
* wmKeyConfig was added which represents a key configuration containing
keymaps.
* wmKeymapItem was renamed to wmKeyMapItem for consistency with wmKeyMap.
* Modal maps are not wrapped yet.
* User preferences DNA file reading did not support newdataadr() yet,
added this now for reading keymaps.
* Key configuration related settings are now RNA wrapped.
* is_property_set and is_property_hidden python methods were added.
2009-10-08 18:40:03 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiBut *but = but_v;
|
Key Configuration
Keymaps are now saveable and configurable from the user preferences, note
that editing one item in a keymap means the whole keymap is now defined by
the user and will not be updated by Blender, an option for syncing might be
added later. The outliner interface is still there, but I will probably
remove it.
There's actually 3 levels now:
* Default builtin key configuration.
* Key configuration loaded from .py file, for configs like Blender 2.4x
or other 3D applications.
* Keymaps edited by the user and saved in .B.blend. These can be saved
to .py files as well to make creating distributable configurations
easier.
Also, user preferences sections were reorganized a bit, now there is:
Interface, Editing, Input, Files and System.
Implementation notes:
* wmKeyConfig was added which represents a key configuration containing
keymaps.
* wmKeymapItem was renamed to wmKeyMapItem for consistency with wmKeyMap.
* Modal maps are not wrapped yet.
* User preferences DNA file reading did not support newdataadr() yet,
added this now for reading keymaps.
* Key configuration related settings are now RNA wrapped.
* is_property_set and is_property_hidden python methods were added.
2009-10-08 18:40:03 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
RNA_boolean_set(&but->rnapoin, "shift", (but->modifier_key & KM_SHIFT) != 0);
|
|
|
|
RNA_boolean_set(&but->rnapoin, "ctrl", (but->modifier_key & KM_CTRL) != 0);
|
|
|
|
RNA_boolean_set(&but->rnapoin, "alt", (but->modifier_key & KM_ALT) != 0);
|
|
|
|
RNA_boolean_set(&but->rnapoin, "oskey", (but->modifier_key & KM_OSKEY) != 0);
|
Key Configuration
Keymaps are now saveable and configurable from the user preferences, note
that editing one item in a keymap means the whole keymap is now defined by
the user and will not be updated by Blender, an option for syncing might be
added later. The outliner interface is still there, but I will probably
remove it.
There's actually 3 levels now:
* Default builtin key configuration.
* Key configuration loaded from .py file, for configs like Blender 2.4x
or other 3D applications.
* Keymaps edited by the user and saved in .B.blend. These can be saved
to .py files as well to make creating distributable configurations
easier.
Also, user preferences sections were reorganized a bit, now there is:
Interface, Editing, Input, Files and System.
Implementation notes:
* wmKeyConfig was added which represents a key configuration containing
keymaps.
* wmKeymapItem was renamed to wmKeyMapItem for consistency with wmKeyMap.
* Modal maps are not wrapped yet.
* User preferences DNA file reading did not support newdataadr() yet,
added this now for reading keymaps.
* Key configuration related settings are now RNA wrapped.
* is_property_set and is_property_hidden python methods were added.
2009-10-08 18:40:03 +00:00
|
|
|
}
|
|
|
|
|
UI: New Global Top-Bar (WIP)
== Main Features/Changes for Users
* Add horizontal bar at top of all non-temp windows, consisting out of two horizontal sub-bars.
* Upper sub-bar contains global menus (File, Render, etc.), tabs for workspaces and scene selector.
* Lower sub-bar contains object mode selector, screen-layout and render-layer selector. Later operator and/or tool settings will be placed here.
* Individual sections of the topbar are individually scrollable.
* Workspace tabs can be double- or ctrl-clicked for renaming and contain 'x' icon for deleting.
* Top-bar should scale nicely with DPI.
* The lower half of the top-bar can be hided by dragging the lower top-bar edge up. Better hiding options are planned (e.g. hide in fullscreen modes).
* Info editors at the top of the window and using the full window width with be replaced by the top-bar.
* In fullscreen modes, no more info editor is added on top, the top-bar replaces it.
== Technical Features/Changes
* Adds initial support for global areas
A global area is part of the window, not part of the regular screen-layout.
I've added a macro iterator to iterate over both, global and screen-layout level areas. When iterating over areas, from now on developers should always consider if they have to include global areas.
* Adds a TOPBAR editor type
The editor type is hidden in the UI editor type menu.
* Adds a variation of the ID template to display IDs as tab buttons (template_ID_tabs in BPY)
* Does various changes to RNA button creation code to improve their appearance in the horizontal top-bar.
* Adds support for dynamically sized regions. That is, regions that scale automatically to the layout bounds.
The code for this is currently a big hack (it's based on drawing the UI multiple times). This should definitely be improved.
* Adds a template for displaying operator properties optimized for the top-bar. This will probably change a lot still and is in fact disabled in code.
Since the final top-bar design depends a lot on other 2.8 designs (mainly tool-system and workspaces), we decided to not show the operator or tool settings in the top-bar for now. That means most of the lower sub-bar is empty for the time being.
NOTE: Top-bar or global area data is not written to files or SDNA. They are simply added to the window when opening Blender or reading a file. This allows us doing changes to the top-bar without having to care for compatibility.
== ToDo's
It's a bit hard to predict all the ToDo's here are the known main ones:
* Add options for the new active-tool system and for operator redo to the topbar.
* Automatically hide the top-bar in fullscreen modes.
* General visual polish.
* Top-bar drag & drop support (WIP in temp-tab_drag_drop).
* Improve dynamic regions (should also fix some layout glitches).
* Make internal terminology consistent.
* Enable topbar file writing once design is more advanced.
* Address TODO's and XXX's in code :)
Thanks @brecht for the review! And @sergey for the complaining ;)
Differential Revision: D2758
2018-04-20 17:14:03 +02:00
|
|
|
/**
|
|
|
|
* Create label + button for RNA property
|
|
|
|
*
|
|
|
|
* \param w_hint: For varying width layout, this becomes the label width.
|
|
|
|
* Otherwise it's used to fit both items into it.
|
2019-03-19 15:17:46 +11:00
|
|
|
*/
|
2019-04-17 06:17:24 +02:00
|
|
|
static uiBut *ui_item_with_label(uiLayout *layout,
|
|
|
|
uiBlock *block,
|
|
|
|
const char *name,
|
|
|
|
int icon,
|
|
|
|
PointerRNA *ptr,
|
|
|
|
PropertyRNA *prop,
|
|
|
|
int index,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int w_hint,
|
|
|
|
int h,
|
|
|
|
int flag)
|
|
|
|
{
|
2020-08-05 16:50:33 +02:00
|
|
|
uiLayout *sub = layout;
|
2019-04-17 06:17:24 +02:00
|
|
|
uiBut *but = NULL;
|
|
|
|
PropertyType type;
|
|
|
|
PropertySubType subtype;
|
|
|
|
int prop_but_width = w_hint;
|
2020-04-05 14:19:24 +02:00
|
|
|
#ifdef UI_PROP_DECORATE
|
|
|
|
uiLayout *layout_prop_decorate = NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
const bool use_prop_sep = ((layout->item.flag & UI_ITEM_PROP_SEP) != 0);
|
2020-08-05 16:50:33 +02:00
|
|
|
const bool use_prop_decorate = use_prop_sep && (layout->item.flag & UI_ITEM_PROP_DECORATE) &&
|
|
|
|
(layout->item.flag & UI_ITEM_PROP_DECORATE_NO_PAD) == 0;
|
2020-04-05 14:19:24 +02:00
|
|
|
#endif
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-08-05 16:50:33 +02:00
|
|
|
UI_block_layout_set_current(block, layout);
|
|
|
|
|
|
|
|
/* Only add new row if more than 1 item will be added. */
|
|
|
|
if (name[0] || use_prop_decorate) {
|
|
|
|
/* Also avoid setting 'align' if possible. Set the space to zero instead as aligning a large
|
|
|
|
* number of labels can end up aligning thousands of buttons when displaying key-map search (a
|
|
|
|
* heavy operation), see: T78636. */
|
|
|
|
sub = uiLayoutRow(layout, layout->align);
|
|
|
|
sub->space = 0;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-04-05 14:19:24 +02:00
|
|
|
#ifdef UI_PROP_DECORATE
|
2019-04-17 06:17:24 +02:00
|
|
|
if (name[0]) {
|
|
|
|
if (use_prop_sep) {
|
2020-04-05 14:19:24 +02:00
|
|
|
layout_prop_decorate = uiItemL_respect_property_split(layout, name, 0);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2020-04-05 14:19:24 +02:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
int w_label;
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ui_layout_variable_size(layout)) {
|
|
|
|
/* w_hint is width for label in this case.
|
|
|
|
* Use a default width for property button(s) */
|
|
|
|
prop_but_width = UI_UNIT_X * 5;
|
|
|
|
w_label = w_hint;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
w_label = w_hint / 3;
|
|
|
|
}
|
2020-04-05 14:19:24 +02:00
|
|
|
uiDefBut(block, UI_BTYPE_LABEL, 0, name, x, y, w_label, h, NULL, 0.0, 0.0, 0, 0, "");
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type = RNA_property_type(prop);
|
|
|
|
subtype = RNA_property_subtype(prop);
|
|
|
|
|
|
|
|
if (subtype == PROP_FILEPATH || subtype == PROP_DIRPATH) {
|
|
|
|
UI_block_layout_set_current(block, uiLayoutRow(sub, true));
|
|
|
|
but = uiDefAutoButR(block, ptr, prop, index, "", icon, x, y, prop_but_width - UI_UNIT_X, h);
|
|
|
|
|
|
|
|
/* BUTTONS_OT_file_browse calls UI_context_active_but_prop_get_filebrowser */
|
|
|
|
uiDefIconButO(block,
|
|
|
|
UI_BTYPE_BUT,
|
|
|
|
subtype == PROP_DIRPATH ? "BUTTONS_OT_directory_browse" :
|
|
|
|
"BUTTONS_OT_file_browse",
|
|
|
|
WM_OP_INVOKE_DEFAULT,
|
|
|
|
ICON_FILEBROWSER,
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
UI_UNIT_X,
|
|
|
|
h,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
else if (flag & UI_ITEM_R_EVENT) {
|
|
|
|
but = uiDefButR_prop(block,
|
|
|
|
UI_BTYPE_KEY_EVENT,
|
|
|
|
0,
|
|
|
|
name,
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
prop_but_width,
|
|
|
|
h,
|
|
|
|
ptr,
|
|
|
|
prop,
|
|
|
|
index,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
-1,
|
|
|
|
-1,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
else if (flag & UI_ITEM_R_FULL_EVENT) {
|
|
|
|
if (RNA_struct_is_a(ptr->type, &RNA_KeyMapItem)) {
|
|
|
|
char buf[128];
|
|
|
|
|
|
|
|
WM_keymap_item_to_string(ptr->data, false, buf, sizeof(buf));
|
|
|
|
|
|
|
|
but = uiDefButR_prop(block,
|
|
|
|
UI_BTYPE_HOTKEY_EVENT,
|
|
|
|
0,
|
|
|
|
buf,
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
prop_but_width,
|
|
|
|
h,
|
|
|
|
ptr,
|
|
|
|
prop,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
-1,
|
|
|
|
-1,
|
|
|
|
NULL);
|
|
|
|
UI_but_func_set(but, ui_keymap_but_cb, but, NULL);
|
|
|
|
if (flag & UI_ITEM_R_IMMEDIATE) {
|
|
|
|
UI_but_flag_enable(but, UI_BUT_IMMEDIATE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const char *str = (type == PROP_ENUM && !(flag & UI_ITEM_R_ICON_ONLY)) ? NULL : "";
|
|
|
|
but = uiDefAutoButR(block, ptr, prop, index, str, icon, x, y, prop_but_width, h);
|
|
|
|
}
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2018-08-28 00:59:15 +10:00
|
|
|
#ifdef UI_PROP_DECORATE
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Only for alignment. */
|
2020-08-05 16:50:33 +02:00
|
|
|
if (use_prop_decorate) { /* Note that sep flag may have been unset meanwhile. */
|
|
|
|
uiItemL(layout_prop_decorate ? layout_prop_decorate : sub, NULL, ICON_BLANK1);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
#endif /* UI_PROP_DECORATE */
|
|
|
|
|
|
|
|
UI_block_layout_set_current(block, layout);
|
|
|
|
return but;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UI_context_active_but_prop_get_filebrowser(const bContext *C,
|
|
|
|
PointerRNA *r_ptr,
|
|
|
|
PropertyRNA **r_prop,
|
2020-06-11 17:24:00 +10:00
|
|
|
bool *r_is_undo,
|
|
|
|
bool *r_is_userdef)
|
2019-04-17 06:17:24 +02:00
|
|
|
{
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region = CTX_wm_menu(C) ? CTX_wm_menu(C) : CTX_wm_region(C);
|
2019-04-17 06:17:24 +02:00
|
|
|
uiBlock *block;
|
|
|
|
uiBut *but, *prevbut = NULL;
|
|
|
|
|
|
|
|
memset(r_ptr, 0, sizeof(*r_ptr));
|
|
|
|
*r_prop = NULL;
|
|
|
|
*r_is_undo = false;
|
2020-06-11 17:24:00 +10:00
|
|
|
*r_is_userdef = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
if (!region) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
for (block = region->uiblocks.first; block; block = block->next) {
|
2019-04-17 06:17:24 +02:00
|
|
|
for (but = block->buttons.first; but; but = but->next) {
|
|
|
|
if (but && but->rnapoin.data) {
|
|
|
|
if (RNA_property_type(but->rnaprop) == PROP_STRING) {
|
|
|
|
prevbut = but;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find the button before the active one */
|
|
|
|
if ((but->flag & UI_BUT_LAST_ACTIVE) && prevbut) {
|
|
|
|
*r_ptr = prevbut->rnapoin;
|
|
|
|
*r_prop = prevbut->rnaprop;
|
|
|
|
*r_is_undo = (prevbut->flag & UI_BUT_UNDO) != 0;
|
2020-06-11 17:24:00 +10:00
|
|
|
*r_is_userdef = UI_but_is_userdef(prevbut);
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-07-28 18:51:06 +00:00
|
|
|
}
|
|
|
|
|
2019-09-06 16:12:47 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Button Items
|
|
|
|
* \{ */
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2013-02-05 05:39:18 +00:00
|
|
|
/**
|
|
|
|
* Update a buttons tip with an enum's description if possible.
|
|
|
|
*/
|
2016-02-16 14:50:26 +01:00
|
|
|
static void ui_but_tip_from_enum_item(uiBut *but, const EnumPropertyItem *item)
|
2013-02-05 05:39:18 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (but->tip == NULL || but->tip[0] == '\0') {
|
2019-09-09 21:12:47 +03:00
|
|
|
if (item->description && item->description[0] &&
|
|
|
|
!(but->optype && but->optype->get_description)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
but->tip = item->description;
|
|
|
|
}
|
|
|
|
}
|
2013-02-05 05:39:18 +00:00
|
|
|
}
|
|
|
|
|
2009-04-22 18:39:44 +00:00
|
|
|
/* disabled item */
|
2010-11-17 09:45:45 +00:00
|
|
|
static void ui_item_disabled(uiLayout *layout, const char *name)
|
2009-04-22 18:39:44 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiBlock *block = layout->root->block;
|
|
|
|
uiBut *but;
|
|
|
|
int w;
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
UI_block_layout_set_current(block, layout);
|
2009-04-22 18:39:44 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (!name) {
|
|
|
|
name = "";
|
|
|
|
}
|
2009-04-22 18:39:44 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
w = ui_text_icon_width(layout, name, 0, 0);
|
2009-04-22 18:39:44 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
but = uiDefBut(block, UI_BTYPE_LABEL, 0, name, 0, 0, w, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
|
|
|
|
but->flag |= UI_BUT_DISABLED;
|
|
|
|
but->disabled_info = "";
|
2009-04-22 18:39:44 +00:00
|
|
|
}
|
|
|
|
|
2017-10-31 16:58:26 +11:00
|
|
|
/**
|
|
|
|
* Operator Item
|
|
|
|
* \param r_opptr: Optional, initialize with operator properties when not NULL.
|
|
|
|
* Will always be written to even in the case of errors.
|
|
|
|
*/
|
2019-04-17 06:17:24 +02:00
|
|
|
static uiBut *uiItemFullO_ptr_ex(uiLayout *layout,
|
|
|
|
wmOperatorType *ot,
|
|
|
|
const char *name,
|
|
|
|
int icon,
|
|
|
|
IDProperty *properties,
|
|
|
|
int context,
|
|
|
|
int flag,
|
|
|
|
PointerRNA *r_opptr)
|
|
|
|
{
|
|
|
|
/* Take care to fill 'r_opptr' whatever happens. */
|
|
|
|
uiBlock *block = layout->root->block;
|
|
|
|
uiBut *but;
|
|
|
|
int w;
|
|
|
|
|
|
|
|
if (!name) {
|
|
|
|
if (ot && ot->srna && (flag & UI_ITEM_R_ICON_ONLY) == 0) {
|
2019-06-04 15:50:15 +02:00
|
|
|
name = WM_operatortype_name(ot, NULL);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
name = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (layout->root->type == UI_LAYOUT_MENU && !icon) {
|
|
|
|
icon = ICON_BLANK1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create button */
|
|
|
|
UI_block_layout_set_current(block, layout);
|
|
|
|
|
|
|
|
w = ui_text_icon_width(layout, name, icon, 0);
|
|
|
|
|
|
|
|
int prev_emboss = layout->emboss;
|
|
|
|
if (flag & UI_ITEM_R_NO_BG) {
|
|
|
|
layout->emboss = UI_EMBOSS_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create the button */
|
|
|
|
if (icon) {
|
|
|
|
if (name[0]) {
|
|
|
|
but = uiDefIconTextButO_ptr(
|
|
|
|
block, UI_BTYPE_BUT, ot, context, icon, name, 0, 0, w, UI_UNIT_Y, NULL);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
but = uiDefIconButO_ptr(block, UI_BTYPE_BUT, ot, context, icon, 0, 0, w, UI_UNIT_Y, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
but = uiDefButO_ptr(block, UI_BTYPE_BUT, ot, context, name, 0, 0, w, UI_UNIT_Y, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(but->optype != NULL);
|
|
|
|
|
|
|
|
if (flag & UI_ITEM_R_NO_BG) {
|
|
|
|
layout->emboss = prev_emboss;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flag & UI_ITEM_O_DEPRESS) {
|
|
|
|
but->flag |= UI_SELECT_DRAW;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (layout->redalert) {
|
|
|
|
UI_but_flag_enable(but, UI_BUT_REDALERT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (layout->active_default) {
|
|
|
|
UI_but_flag_enable(but, UI_BUT_ACTIVE_DEFAULT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* assign properties */
|
|
|
|
if (properties || r_opptr) {
|
|
|
|
PointerRNA *opptr = UI_but_operator_ptr_get(but);
|
|
|
|
if (properties) {
|
|
|
|
opptr->data = properties;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
IDPropertyTemplate val = {0};
|
|
|
|
opptr->data = IDP_New(IDP_GROUP, &val, "wmOperatorProperties");
|
|
|
|
}
|
|
|
|
if (r_opptr) {
|
|
|
|
*r_opptr = *opptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return but;
|
2017-11-02 04:30:07 +11:00
|
|
|
}
|
|
|
|
|
2017-11-02 23:43:51 +11:00
|
|
|
static void ui_item_menu_hold(struct bContext *C, ARegion *butregion, uiBut *but)
|
2017-11-02 04:30:07 +11:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiPopupMenu *pup = UI_popup_menu_begin(C, "", ICON_NONE);
|
|
|
|
uiLayout *layout = UI_popup_menu_layout(pup);
|
|
|
|
uiBlock *block = layout->root->block;
|
|
|
|
UI_popup_menu_but_set(pup, butregion, but);
|
|
|
|
|
|
|
|
block->flag |= UI_BLOCK_POPUP_HOLD;
|
|
|
|
block->flag |= UI_BLOCK_IS_FLIP;
|
|
|
|
|
|
|
|
char direction = UI_DIR_DOWN;
|
|
|
|
if (!but->drawstr[0]) {
|
2020-01-16 15:55:49 +01:00
|
|
|
switch (RGN_ALIGN_ENUM_FROM_MASK(butregion->alignment)) {
|
|
|
|
case RGN_ALIGN_LEFT:
|
|
|
|
direction = UI_DIR_RIGHT;
|
|
|
|
break;
|
|
|
|
case RGN_ALIGN_RIGHT:
|
|
|
|
direction = UI_DIR_LEFT;
|
|
|
|
break;
|
|
|
|
case RGN_ALIGN_BOTTOM:
|
|
|
|
direction = UI_DIR_UP;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
direction = UI_DIR_DOWN;
|
|
|
|
break;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
UI_block_direction_set(block, direction);
|
|
|
|
|
|
|
|
const char *menu_id = but->hold_argN;
|
|
|
|
MenuType *mt = WM_menutype_find(menu_id, true);
|
|
|
|
if (mt) {
|
|
|
|
uiLayoutSetContextFromBut(layout, but);
|
|
|
|
UI_menutype_draw(C, mt, layout);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
uiItemL(layout, "Menu Missing:", ICON_NONE);
|
|
|
|
uiItemL(layout, menu_id, ICON_NONE);
|
|
|
|
}
|
|
|
|
UI_popup_menu_end(C, pup);
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiItemFullO_ptr(uiLayout *layout,
|
|
|
|
wmOperatorType *ot,
|
|
|
|
const char *name,
|
|
|
|
int icon,
|
|
|
|
IDProperty *properties,
|
|
|
|
int context,
|
|
|
|
int flag,
|
|
|
|
PointerRNA *r_opptr)
|
|
|
|
{
|
|
|
|
uiItemFullO_ptr_ex(layout, ot, name, icon, properties, context, flag, r_opptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiItemFullOMenuHold_ptr(uiLayout *layout,
|
|
|
|
wmOperatorType *ot,
|
|
|
|
const char *name,
|
|
|
|
int icon,
|
|
|
|
IDProperty *properties,
|
|
|
|
int context,
|
|
|
|
int flag,
|
|
|
|
const char *menu_id,
|
|
|
|
PointerRNA *r_opptr)
|
|
|
|
{
|
|
|
|
uiBut *but = uiItemFullO_ptr_ex(layout, ot, name, icon, properties, context, flag, r_opptr);
|
|
|
|
UI_but_func_hold_set(but, ui_item_menu_hold, BLI_strdup(menu_id));
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiItemFullO(uiLayout *layout,
|
|
|
|
const char *opname,
|
|
|
|
const char *name,
|
|
|
|
int icon,
|
|
|
|
IDProperty *properties,
|
|
|
|
int context,
|
|
|
|
int flag,
|
|
|
|
PointerRNA *r_opptr)
|
|
|
|
{
|
|
|
|
wmOperatorType *ot = WM_operatortype_find(opname, 0); /* print error next */
|
|
|
|
|
|
|
|
UI_OPERATOR_ERROR_RET(ot, opname, {
|
|
|
|
if (r_opptr) {
|
|
|
|
*r_opptr = PointerRNA_NULL;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
});
|
|
|
|
|
|
|
|
uiItemFullO_ptr(layout, ot, name, icon, properties, context, flag, r_opptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *ui_menu_enumpropname(uiLayout *layout,
|
|
|
|
PointerRNA *ptr,
|
|
|
|
PropertyRNA *prop,
|
|
|
|
int retval)
|
|
|
|
{
|
|
|
|
const EnumPropertyItem *item;
|
|
|
|
bool free;
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
RNA_property_enum_items(layout->root->block->evil_C, ptr, prop, &item, NULL, &free);
|
|
|
|
if (RNA_enum_name(item, retval, &name)) {
|
|
|
|
name = CTX_IFACE_(RNA_property_translation_context(prop), name);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
name = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (free) {
|
|
|
|
MEM_freeN((void *)item);
|
|
|
|
}
|
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiItemEnumO_ptr(uiLayout *layout,
|
|
|
|
wmOperatorType *ot,
|
|
|
|
const char *name,
|
|
|
|
int icon,
|
|
|
|
const char *propname,
|
|
|
|
int value)
|
|
|
|
{
|
|
|
|
PointerRNA ptr;
|
|
|
|
PropertyRNA *prop;
|
|
|
|
|
|
|
|
WM_operator_properties_create_ptr(&ptr, ot);
|
|
|
|
|
|
|
|
if ((prop = RNA_struct_find_property(&ptr, propname))) {
|
|
|
|
/* pass */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
RNA_warning("%s.%s not found", RNA_struct_identifier(ptr.type), propname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RNA_property_enum_set(&ptr, prop, value);
|
|
|
|
|
|
|
|
if (!name) {
|
|
|
|
name = ui_menu_enumpropname(layout, &ptr, prop, value);
|
|
|
|
}
|
2012-01-22 19:52:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
uiItemFullO_ptr(layout, ot, name, icon, ptr.data, layout->root->opcontext, 0, NULL);
|
2012-01-22 03:30:07 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
void uiItemEnumO(uiLayout *layout,
|
|
|
|
const char *opname,
|
|
|
|
const char *name,
|
|
|
|
int icon,
|
|
|
|
const char *propname,
|
|
|
|
int value)
|
2012-01-22 03:30:07 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
wmOperatorType *ot = WM_operatortype_find(opname, 0); /* print error next */
|
2009-04-22 18:39:44 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ot) {
|
|
|
|
uiItemEnumO_ptr(layout, ot, name, icon, propname, value);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ui_item_disabled(layout, opname);
|
|
|
|
RNA_warning("unknown operator '%s'", opname);
|
|
|
|
}
|
2009-03-13 13:38:41 +00:00
|
|
|
}
|
|
|
|
|
2016-02-16 14:50:26 +01:00
|
|
|
BLI_INLINE bool ui_layout_is_radial(const uiLayout *layout)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return (layout->item.type == ITEM_LAYOUT_RADIAL) ||
|
|
|
|
((layout->item.type == ITEM_LAYOUT_ROOT) && (layout->root->type == UI_LAYOUT_PIEMENU));
|
2016-02-16 14:50:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create ui items for enum items in \a item_array.
|
|
|
|
*
|
|
|
|
* A version of #uiItemsFullEnumO that takes pre-calculated item array.
|
|
|
|
*/
|
2019-04-17 06:17:24 +02:00
|
|
|
void uiItemsFullEnumO_items(uiLayout *layout,
|
|
|
|
wmOperatorType *ot,
|
|
|
|
PointerRNA ptr,
|
|
|
|
PropertyRNA *prop,
|
|
|
|
IDProperty *properties,
|
|
|
|
int context,
|
|
|
|
int flag,
|
|
|
|
const EnumPropertyItem *item_array,
|
|
|
|
int totitem)
|
|
|
|
{
|
|
|
|
const char *propname = RNA_property_identifier(prop);
|
|
|
|
if (RNA_property_type(prop) != PROP_ENUM) {
|
|
|
|
RNA_warning("%s.%s, not an enum type", RNA_struct_identifier(ptr.type), propname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uiLayout *target, *split = NULL;
|
|
|
|
const EnumPropertyItem *item;
|
|
|
|
uiBlock *block = layout->root->block;
|
|
|
|
const bool radial = ui_layout_is_radial(layout);
|
|
|
|
|
|
|
|
if (radial) {
|
|
|
|
target = uiLayoutRadial(layout);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
split = uiLayoutSplit(layout, 0.0f, false);
|
|
|
|
target = uiLayoutColumn(split, layout->align);
|
|
|
|
}
|
|
|
|
|
|
|
|
int i;
|
|
|
|
bool last_iter = false;
|
|
|
|
|
|
|
|
for (i = 1, item = item_array; item->identifier && !last_iter; i++, item++) {
|
|
|
|
/* handle oversized pies */
|
|
|
|
if (radial && (totitem > PIE_MAX_ITEMS) && (i >= PIE_MAX_ITEMS)) {
|
|
|
|
if (item->name) { /* only visible items */
|
|
|
|
const EnumPropertyItem *tmp;
|
|
|
|
|
|
|
|
/* Check if there are more visible items for the next level. If not, we don't
|
|
|
|
* add a new level and add the remaining item instead of the 'more' button. */
|
|
|
|
for (tmp = item + 1; tmp->identifier; tmp++) {
|
|
|
|
if (tmp->name) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tmp->identifier) { /* only true if loop above found item and did early-exit */
|
|
|
|
ui_pie_menu_level_create(
|
|
|
|
block, ot, propname, properties, item_array, totitem, context, flag);
|
|
|
|
/* break since rest of items is handled in new pie level */
|
|
|
|
break;
|
|
|
|
}
|
2020-07-03 14:20:10 +02:00
|
|
|
last_iter = true;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item->identifier[0]) {
|
|
|
|
PointerRNA tptr;
|
|
|
|
|
|
|
|
WM_operator_properties_create_ptr(&tptr, ot);
|
|
|
|
if (properties) {
|
|
|
|
if (tptr.data) {
|
|
|
|
IDP_FreeProperty(tptr.data);
|
|
|
|
}
|
|
|
|
tptr.data = IDP_CopyProperty(properties);
|
|
|
|
}
|
|
|
|
RNA_property_enum_set(&tptr, prop, item->value);
|
|
|
|
|
|
|
|
uiItemFullO_ptr(target, ot, item->name, item->icon, tptr.data, context, flag, NULL);
|
|
|
|
|
|
|
|
ui_but_tip_from_enum_item(block->buttons.last, item);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (item->name) {
|
|
|
|
uiBut *but;
|
|
|
|
|
|
|
|
if (item != item_array && !radial) {
|
|
|
|
target = uiLayoutColumn(split, layout->align);
|
|
|
|
|
|
|
|
/* inconsistent, but menus with labels do not look good flipped */
|
|
|
|
block->flag |= UI_BLOCK_NO_FLIP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item->icon || radial) {
|
|
|
|
uiItemL(target, item->name, item->icon);
|
|
|
|
|
|
|
|
but = block->buttons.last;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Do not use uiItemL here, as our root layout is a menu one,
|
|
|
|
* it will add a fake blank icon! */
|
|
|
|
but = uiDefBut(block,
|
|
|
|
UI_BTYPE_LABEL,
|
|
|
|
0,
|
|
|
|
item->name,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
UI_UNIT_X * 5,
|
|
|
|
UI_UNIT_Y,
|
|
|
|
NULL,
|
|
|
|
0.0,
|
|
|
|
0.0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
"");
|
|
|
|
}
|
|
|
|
ui_but_tip_from_enum_item(but, item);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (radial) {
|
|
|
|
/* invisible dummy button to ensure all items are
|
|
|
|
* always at the same position */
|
|
|
|
uiItemS(target);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* XXX bug here, columns draw bottom item badly */
|
|
|
|
uiItemS(target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiItemsFullEnumO(uiLayout *layout,
|
|
|
|
const char *opname,
|
|
|
|
const char *propname,
|
|
|
|
IDProperty *properties,
|
|
|
|
int context,
|
|
|
|
int flag)
|
|
|
|
{
|
|
|
|
wmOperatorType *ot = WM_operatortype_find(opname, 0); /* print error next */
|
|
|
|
|
|
|
|
PointerRNA ptr;
|
|
|
|
PropertyRNA *prop;
|
|
|
|
uiBlock *block = layout->root->block;
|
|
|
|
|
|
|
|
if (!ot || !ot->srna) {
|
|
|
|
ui_item_disabled(layout, opname);
|
|
|
|
RNA_warning("%s '%s'", ot ? "unknown operator" : "operator missing srna", opname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
WM_operator_properties_create_ptr(&ptr, ot);
|
|
|
|
/* so the context is passed to itemf functions (some need it) */
|
|
|
|
WM_operator_properties_sanitize(&ptr, false);
|
|
|
|
prop = RNA_struct_find_property(&ptr, propname);
|
|
|
|
|
|
|
|
/* don't let bad properties slip through */
|
|
|
|
BLI_assert((prop == NULL) || (RNA_property_type(prop) == PROP_ENUM));
|
|
|
|
|
|
|
|
if (prop && RNA_property_type(prop) == PROP_ENUM) {
|
|
|
|
const EnumPropertyItem *item_array = NULL;
|
|
|
|
int totitem;
|
|
|
|
bool free;
|
|
|
|
|
|
|
|
if (ui_layout_is_radial(layout)) {
|
2019-04-17 08:44:38 +02:00
|
|
|
/* XXX: While "_all()" guarantees spatial stability,
|
|
|
|
* it's bad when an enum has > 8 items total,
|
|
|
|
* but only a small subset will ever be shown at once
|
|
|
|
* (e.g. Mode Switch menu, after the introduction of GP editing modes).
|
2019-04-17 06:17:24 +02:00
|
|
|
*/
|
2018-07-31 10:22:19 +02:00
|
|
|
#if 0
|
2019-04-17 08:24:14 +02:00
|
|
|
RNA_property_enum_items_gettexted_all(
|
|
|
|
block->evil_C, &ptr, prop, &item_array, &totitem, &free);
|
2018-07-31 10:22:19 +02:00
|
|
|
#else
|
2019-04-17 06:17:24 +02:00
|
|
|
RNA_property_enum_items_gettexted(block->evil_C, &ptr, prop, &item_array, &totitem, &free);
|
2018-07-31 10:22:19 +02:00
|
|
|
#endif
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
RNA_property_enum_items_gettexted(block->evil_C, &ptr, prop, &item_array, &totitem, &free);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add items */
|
|
|
|
uiItemsFullEnumO_items(layout, ot, ptr, prop, properties, context, flag, item_array, totitem);
|
|
|
|
|
|
|
|
if (free) {
|
|
|
|
MEM_freeN((void *)item_array);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* intentionally don't touch UI_BLOCK_IS_FLIP here,
|
|
|
|
* we don't know the context this is called in */
|
|
|
|
}
|
|
|
|
else if (prop && RNA_property_type(prop) != PROP_ENUM) {
|
|
|
|
RNA_warning("%s.%s, not an enum type", RNA_struct_identifier(ptr.type), propname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
RNA_warning("%s.%s not found", RNA_struct_identifier(ptr.type), propname);
|
|
|
|
return;
|
|
|
|
}
|
2009-03-13 13:38:41 +00:00
|
|
|
}
|
|
|
|
|
2010-11-17 09:45:45 +00:00
|
|
|
void uiItemsEnumO(uiLayout *layout, const char *opname, const char *propname)
|
2009-12-22 11:59:30 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiItemsFullEnumO(layout, opname, propname, NULL, layout->root->opcontext, 0);
|
2009-12-22 11:59:30 +00:00
|
|
|
}
|
|
|
|
|
2009-06-07 14:53:08 +00:00
|
|
|
/* for use in cases where we have */
|
2019-04-17 06:17:24 +02:00
|
|
|
void uiItemEnumO_value(uiLayout *layout,
|
|
|
|
const char *name,
|
|
|
|
int icon,
|
|
|
|
const char *opname,
|
|
|
|
const char *propname,
|
|
|
|
int value)
|
2011-03-24 12:36:12 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
wmOperatorType *ot = WM_operatortype_find(opname, 0); /* print error next */
|
|
|
|
PointerRNA ptr;
|
|
|
|
PropertyRNA *prop;
|
2011-03-24 12:36:12 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
UI_OPERATOR_ERROR_RET(ot, opname, return );
|
2012-01-22 03:30:07 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
WM_operator_properties_create_ptr(&ptr, ot);
|
2011-03-24 12:36:12 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* enum lookup */
|
|
|
|
if ((prop = RNA_struct_find_property(&ptr, propname))) {
|
|
|
|
/* pass */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
RNA_warning("%s.%s not found", RNA_struct_identifier(ptr.type), propname);
|
|
|
|
return;
|
|
|
|
}
|
2011-03-24 12:36:12 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
RNA_property_enum_set(&ptr, prop, value);
|
2011-03-24 12:36:12 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* same as uiItemEnumO */
|
|
|
|
if (!name) {
|
|
|
|
name = ui_menu_enumpropname(layout, &ptr, prop, value);
|
|
|
|
}
|
2011-03-24 12:36:12 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
uiItemFullO_ptr(layout, ot, name, icon, ptr.data, layout->root->opcontext, 0, NULL);
|
2011-03-24 12:36:12 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void uiItemEnumO_string(uiLayout *layout,
|
|
|
|
const char *name,
|
|
|
|
int icon,
|
|
|
|
const char *opname,
|
|
|
|
const char *propname,
|
|
|
|
const char *value_str)
|
2009-06-07 14:53:08 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
wmOperatorType *ot = WM_operatortype_find(opname, 0); /* print error next */
|
|
|
|
PointerRNA ptr;
|
|
|
|
PropertyRNA *prop;
|
2012-01-22 03:30:07 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
const EnumPropertyItem *item;
|
|
|
|
int value;
|
|
|
|
bool free;
|
2009-06-07 14:53:08 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
UI_OPERATOR_ERROR_RET(ot, opname, return );
|
2012-01-22 03:30:07 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
WM_operator_properties_create_ptr(&ptr, ot);
|
2012-12-18 18:25:48 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* enum lookup */
|
|
|
|
if ((prop = RNA_struct_find_property(&ptr, propname))) {
|
|
|
|
/* no need for translations here */
|
|
|
|
RNA_property_enum_items(layout->root->block->evil_C, &ptr, prop, &item, NULL, &free);
|
|
|
|
if (item == NULL || RNA_enum_value_from_id(item, value_str, &value) == 0) {
|
|
|
|
if (free) {
|
|
|
|
MEM_freeN((void *)item);
|
|
|
|
}
|
|
|
|
RNA_warning(
|
|
|
|
"%s.%s, enum %s not found", RNA_struct_identifier(ptr.type), propname, value_str);
|
|
|
|
return;
|
|
|
|
}
|
RNA
* Enums can now be dynamically created in the _itemf callback,
using RNA_enum_item(s)_add, RNA_enum_item_end. All places asking
for enum items now need to potentially free the items.
* This callback now also gets context, this was added specifically
for operators. This doesn't fit design well at all, needed to do
some ugly hacks, but can't find a good solution at the moment.
* All enums must have a default list of items too, even with an
_itemf callback, for docs and fallback in case there is no context.
* Used by MESH_OT_merge, MESH_OT_select_similar, TFM_OT_select_orientation.
* Also changes some operator properties that were enums to booleas
(unselected, deselect), to make them consistent with other ops.
2009-07-10 19:56:13 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (free) {
|
|
|
|
MEM_freeN((void *)item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
RNA_warning("%s.%s not found", RNA_struct_identifier(ptr.type), propname);
|
|
|
|
return;
|
|
|
|
}
|
2012-12-18 18:25:48 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
RNA_property_enum_set(&ptr, prop, value);
|
2012-12-18 18:25:48 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* same as uiItemEnumO */
|
|
|
|
if (!name) {
|
|
|
|
name = ui_menu_enumpropname(layout, &ptr, prop, value);
|
|
|
|
}
|
2009-06-07 14:53:08 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
uiItemFullO_ptr(layout, ot, name, icon, ptr.data, layout->root->opcontext, 0, NULL);
|
2009-06-07 14:53:08 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void uiItemBooleanO(uiLayout *layout,
|
|
|
|
const char *name,
|
|
|
|
int icon,
|
|
|
|
const char *opname,
|
|
|
|
const char *propname,
|
|
|
|
int value)
|
2009-03-13 13:38:41 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
wmOperatorType *ot = WM_operatortype_find(opname, 0); /* print error next */
|
|
|
|
PointerRNA ptr;
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
UI_OPERATOR_ERROR_RET(ot, opname, return );
|
2012-01-22 03:30:07 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
WM_operator_properties_create_ptr(&ptr, ot);
|
|
|
|
RNA_boolean_set(&ptr, propname, value);
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
uiItemFullO_ptr(layout, ot, name, icon, ptr.data, layout->root->opcontext, 0, NULL);
|
2009-03-13 13:38:41 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void uiItemIntO(uiLayout *layout,
|
|
|
|
const char *name,
|
|
|
|
int icon,
|
|
|
|
const char *opname,
|
|
|
|
const char *propname,
|
|
|
|
int value)
|
2009-03-13 13:38:41 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
wmOperatorType *ot = WM_operatortype_find(opname, 0); /* print error next */
|
|
|
|
PointerRNA ptr;
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
UI_OPERATOR_ERROR_RET(ot, opname, return );
|
2012-01-22 03:30:07 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
WM_operator_properties_create_ptr(&ptr, ot);
|
|
|
|
RNA_int_set(&ptr, propname, value);
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
uiItemFullO_ptr(layout, ot, name, icon, ptr.data, layout->root->opcontext, 0, NULL);
|
2009-03-13 13:38:41 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void uiItemFloatO(uiLayout *layout,
|
|
|
|
const char *name,
|
|
|
|
int icon,
|
|
|
|
const char *opname,
|
|
|
|
const char *propname,
|
|
|
|
float value)
|
2009-03-13 13:38:41 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
wmOperatorType *ot = WM_operatortype_find(opname, 0); /* print error next */
|
|
|
|
PointerRNA ptr;
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
UI_OPERATOR_ERROR_RET(ot, opname, return );
|
2012-01-22 03:30:07 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
WM_operator_properties_create_ptr(&ptr, ot);
|
|
|
|
RNA_float_set(&ptr, propname, value);
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
uiItemFullO_ptr(layout, ot, name, icon, ptr.data, layout->root->opcontext, 0, NULL);
|
2009-03-13 13:38:41 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void uiItemStringO(uiLayout *layout,
|
|
|
|
const char *name,
|
|
|
|
int icon,
|
|
|
|
const char *opname,
|
|
|
|
const char *propname,
|
|
|
|
const char *value)
|
2009-03-13 13:38:41 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
wmOperatorType *ot = WM_operatortype_find(opname, 0); /* print error next */
|
|
|
|
PointerRNA ptr;
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
UI_OPERATOR_ERROR_RET(ot, opname, return );
|
2012-01-22 03:30:07 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
WM_operator_properties_create_ptr(&ptr, ot);
|
|
|
|
RNA_string_set(&ptr, propname, value);
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
uiItemFullO_ptr(layout, ot, name, icon, ptr.data, layout->root->opcontext, 0, NULL);
|
2009-03-13 13:38:41 +00:00
|
|
|
}
|
|
|
|
|
2010-11-17 09:45:45 +00:00
|
|
|
void uiItemO(uiLayout *layout, const char *name, int icon, const char *opname)
|
2009-03-13 13:38:41 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiItemFullO(layout, opname, name, icon, NULL, layout->root->opcontext, 0, NULL);
|
2009-03-13 13:38:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* RNA property items */
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static void ui_item_rna_size(uiLayout *layout,
|
|
|
|
const char *name,
|
|
|
|
int icon,
|
|
|
|
PointerRNA *ptr,
|
|
|
|
PropertyRNA *prop,
|
|
|
|
int index,
|
|
|
|
bool icon_only,
|
|
|
|
bool compact,
|
|
|
|
int *r_w,
|
|
|
|
int *r_h)
|
|
|
|
{
|
|
|
|
PropertyType type;
|
|
|
|
PropertySubType subtype;
|
|
|
|
int len, w = 0, h;
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
bool is_checkbox_only = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* arbitrary extended width by type */
|
|
|
|
type = RNA_property_type(prop);
|
|
|
|
subtype = RNA_property_subtype(prop);
|
|
|
|
len = RNA_property_array_length(ptr, prop);
|
|
|
|
|
|
|
|
if (!name[0] && !icon_only) {
|
|
|
|
if (ELEM(type, PROP_STRING, PROP_POINTER)) {
|
|
|
|
name = "non-empty text";
|
|
|
|
}
|
|
|
|
else if (type == PROP_BOOLEAN) {
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
if (icon == ICON_NONE) {
|
|
|
|
/* Exception for checkboxes, they need a little less space to align nicely. */
|
|
|
|
is_checkbox_only = true;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
icon = ICON_DOT;
|
|
|
|
}
|
|
|
|
else if (type == PROP_ENUM) {
|
|
|
|
/* Find the longest enum item name, instead of using a dummy text! */
|
|
|
|
const EnumPropertyItem *item, *item_array;
|
|
|
|
bool free;
|
|
|
|
|
|
|
|
RNA_property_enum_items_gettexted(
|
|
|
|
layout->root->block->evil_C, ptr, prop, &item_array, NULL, &free);
|
|
|
|
for (item = item_array; item->identifier; item++) {
|
|
|
|
if (item->identifier[0]) {
|
|
|
|
w = max_ii(w, ui_text_icon_width(layout, item->name, item->icon, compact));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (free) {
|
|
|
|
MEM_freeN((void *)item_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!w) {
|
|
|
|
if (type == PROP_ENUM && icon_only) {
|
|
|
|
w = ui_text_icon_width(layout, "", ICON_BLANK1, compact);
|
|
|
|
if (index != RNA_ENUM_VALUE) {
|
|
|
|
w += 0.6f * UI_UNIT_X;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* not compact for float/int buttons, looks too squashed */
|
|
|
|
w = ui_text_icon_width(
|
|
|
|
layout, name, icon, ELEM(type, PROP_FLOAT, PROP_INT) ? false : compact);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
h = UI_UNIT_Y;
|
|
|
|
|
|
|
|
/* increase height for arrays */
|
|
|
|
if (index == RNA_NO_INDEX && len > 0) {
|
|
|
|
if (!name[0] && icon == ICON_NONE) {
|
|
|
|
h = 0;
|
|
|
|
}
|
|
|
|
if (layout->item.flag & UI_ITEM_PROP_SEP) {
|
|
|
|
h = 0;
|
|
|
|
}
|
|
|
|
if (ELEM(subtype, PROP_LAYER, PROP_LAYER_MEMBER)) {
|
|
|
|
h += 2 * UI_UNIT_Y;
|
|
|
|
}
|
|
|
|
else if (subtype == PROP_MATRIX) {
|
|
|
|
h += ceilf(sqrtf(len)) * UI_UNIT_Y;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
h += len * UI_UNIT_Y;
|
|
|
|
}
|
|
|
|
}
|
2019-08-10 14:42:14 +03:00
|
|
|
|
|
|
|
/* Increase width requirement if in a variable size layout. */
|
|
|
|
if (ui_layout_variable_size(layout)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
if (type == PROP_BOOLEAN && name[0]) {
|
|
|
|
w += UI_UNIT_X / 5;
|
|
|
|
}
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
else if (is_checkbox_only) {
|
|
|
|
w -= UI_UNIT_X / 4;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
else if (type == PROP_ENUM && !icon_only) {
|
|
|
|
w += UI_UNIT_X / 4;
|
|
|
|
}
|
|
|
|
else if (type == PROP_FLOAT || type == PROP_INT) {
|
|
|
|
w += UI_UNIT_X * 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*r_w = w;
|
|
|
|
*r_h = h;
|
|
|
|
}
|
|
|
|
|
2020-04-27 13:50:16 +02:00
|
|
|
static bool ui_item_rna_is_expand(PropertyRNA *prop, int index, int item_flag)
|
|
|
|
{
|
|
|
|
const bool is_array = RNA_property_array_check(prop);
|
|
|
|
const int subtype = RNA_property_subtype(prop);
|
|
|
|
return is_array && (index == RNA_NO_INDEX) &&
|
|
|
|
((item_flag & UI_ITEM_R_EXPAND) ||
|
|
|
|
!ELEM(subtype, PROP_COLOR, PROP_COLOR_GAMMA, PROP_DIRECTION));
|
|
|
|
}
|
|
|
|
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
/**
|
|
|
|
* Find first layout ancestor (or self) with a heading set.
|
|
|
|
*
|
|
|
|
* \returns the layout to add the heading to as fallback (i.e. if it can't be placed in a split
|
|
|
|
* layout). Its #uiLayout.heading member can be cleared to mark the heading as added (so
|
|
|
|
* it's not added multiple times). Returns a pointer to the heading
|
|
|
|
*/
|
|
|
|
static uiLayout *ui_layout_heading_find(uiLayout *cur_layout)
|
|
|
|
{
|
|
|
|
for (uiLayout *parent = cur_layout; parent; parent = parent->parent) {
|
|
|
|
if (parent->heading[0]) {
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ui_layout_heading_label_add(uiLayout *layout,
|
|
|
|
uiLayout *heading_layout,
|
|
|
|
bool right_align,
|
|
|
|
bool respect_prop_split)
|
|
|
|
{
|
|
|
|
const int prev_alignment = layout->alignment;
|
|
|
|
|
|
|
|
if (right_align) {
|
|
|
|
uiLayoutSetAlignment(layout, UI_LAYOUT_ALIGN_RIGHT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (respect_prop_split) {
|
|
|
|
uiItemL_respect_property_split(layout, heading_layout->heading, ICON_NONE);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
uiItemL(layout, heading_layout->heading, ICON_NONE);
|
|
|
|
}
|
|
|
|
/* After adding the heading label, we have to mark it somehow as added, so it's not added again
|
|
|
|
* for other items in this layout. For now just clear it. */
|
|
|
|
heading_layout->heading[0] = '\0';
|
|
|
|
|
|
|
|
layout->alignment = prev_alignment;
|
|
|
|
}
|
|
|
|
|
2020-04-05 14:19:24 +02:00
|
|
|
/**
|
|
|
|
* Hack to add further items in a row into the second part of the split layout, so the label part
|
|
|
|
* keeps a fixed size.
|
|
|
|
* \return The layout to place further items in for the split layout.
|
|
|
|
*/
|
|
|
|
static uiLayout *ui_item_prop_split_layout_hack(uiLayout *layout_parent, uiLayout *layout_split)
|
|
|
|
{
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
/* Tag item as using property split layout, this is inherited to children so they can get special
|
|
|
|
* treatment if needed. */
|
|
|
|
layout_parent->item.flag |= UI_ITEM_INSIDE_PROP_SEP;
|
|
|
|
|
2020-04-05 14:19:24 +02:00
|
|
|
if (layout_parent->item.type == ITEM_LAYOUT_ROW) {
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
/* Prevent further splits within the row. */
|
|
|
|
uiLayoutSetPropSep(layout_parent, false);
|
|
|
|
|
2020-04-05 14:19:24 +02:00
|
|
|
layout_parent->child_items_layout = uiLayoutRow(layout_split, true);
|
|
|
|
return layout_parent->child_items_layout;
|
|
|
|
}
|
|
|
|
return layout_split;
|
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void uiItemFullR(uiLayout *layout,
|
|
|
|
PointerRNA *ptr,
|
|
|
|
PropertyRNA *prop,
|
|
|
|
int index,
|
|
|
|
int value,
|
|
|
|
int flag,
|
|
|
|
const char *name,
|
|
|
|
int icon)
|
|
|
|
{
|
|
|
|
uiBlock *block = layout->root->block;
|
|
|
|
char namestr[UI_MAX_NAME_STR];
|
|
|
|
const bool use_prop_sep = ((layout->item.flag & UI_ITEM_PROP_SEP) != 0);
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
const bool inside_prop_sep = ((layout->item.flag & UI_ITEM_INSIDE_PROP_SEP) != 0);
|
|
|
|
/* Columns can define a heading to insert. If the first item added to a split layout doesn't have
|
|
|
|
* a label to display in the first column, the heading is inserted there. Otherwise it's inserted
|
|
|
|
* as a new row before the first item. */
|
|
|
|
uiLayout *heading_layout = ui_layout_heading_find(layout);
|
|
|
|
/* Although checkboxes use the split layout, they are an exception and should only place their
|
|
|
|
* label in the second column, to not make that almost empty.
|
2019-04-17 06:17:24 +02:00
|
|
|
*
|
|
|
|
* Keep using 'use_prop_sep' instead of disabling it entirely because
|
|
|
|
* we need the ability to have decorators still. */
|
|
|
|
bool use_prop_sep_split_label = use_prop_sep;
|
2020-04-27 15:24:25 +02:00
|
|
|
bool use_split_empty_name = (flag & UI_ITEM_R_SPLIT_EMPTY_NAME);
|
2019-03-22 15:29:25 +11:00
|
|
|
|
2018-06-16 14:48:21 +02:00
|
|
|
#ifdef UI_PROP_DECORATE
|
2019-04-17 06:17:24 +02:00
|
|
|
struct {
|
|
|
|
bool use_prop_decorate;
|
|
|
|
int len;
|
|
|
|
uiLayout *layout;
|
|
|
|
uiBut *but;
|
|
|
|
} ui_decorate = {
|
|
|
|
.use_prop_decorate = (((layout->item.flag & UI_ITEM_PROP_DECORATE) != 0) &&
|
2019-08-25 15:59:04 +10:00
|
|
|
(use_prop_sep && ptr->owner_id &&
|
|
|
|
id_can_have_animdata(ptr->owner_id))),
|
2019-04-17 06:17:24 +02:00
|
|
|
};
|
|
|
|
#endif /* UI_PROP_DECORATE */
|
|
|
|
|
|
|
|
UI_block_layout_set_current(block, layout);
|
|
|
|
|
|
|
|
/* retrieve info */
|
2019-05-21 12:30:07 +10:00
|
|
|
const PropertyType type = RNA_property_type(prop);
|
|
|
|
const bool is_array = RNA_property_array_check(prop);
|
|
|
|
const int len = (is_array) ? RNA_property_array_length(ptr, prop) : 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-21 12:30:07 +10:00
|
|
|
const bool icon_only = (flag & UI_ITEM_R_ICON_ONLY) != 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-21 14:39:09 +10:00
|
|
|
/* Boolean with -1 to signify that the value depends on the presence of an icon. */
|
|
|
|
const int toggle = ((flag & UI_ITEM_R_TOGGLE) ? 1 : ((flag & UI_ITEM_R_ICON_NEVER) ? 0 : -1));
|
|
|
|
const bool no_icon = (toggle == 0);
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* set name and icon */
|
|
|
|
if (!name) {
|
|
|
|
if (!icon_only) {
|
|
|
|
name = RNA_property_ui_name(prop);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
name = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-20 12:14:48 +02:00
|
|
|
if (type != PROP_BOOLEAN) {
|
|
|
|
flag &= ~UI_ITEM_R_CHECKBOX_INVERT;
|
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (flag & UI_ITEM_R_ICON_ONLY) {
|
|
|
|
/* pass */
|
|
|
|
}
|
|
|
|
else if (ELEM(type, PROP_INT, PROP_FLOAT, PROP_STRING, PROP_POINTER)) {
|
|
|
|
if (use_prop_sep == false) {
|
|
|
|
name = ui_item_name_add_colon(name, namestr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == PROP_BOOLEAN && is_array && index == RNA_NO_INDEX) {
|
|
|
|
if (use_prop_sep == false) {
|
|
|
|
name = ui_item_name_add_colon(name, namestr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == PROP_ENUM && index != RNA_ENUM_VALUE) {
|
|
|
|
if (flag & UI_ITEM_R_COMPACT) {
|
|
|
|
name = "";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (use_prop_sep == false) {
|
|
|
|
name = ui_item_name_add_colon(name, namestr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
|
2019-05-21 14:39:09 +10:00
|
|
|
if (no_icon == false) {
|
|
|
|
if (icon == ICON_NONE) {
|
|
|
|
icon = RNA_property_ui_icon(prop);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-03-25 07:34:06 +11:00
|
|
|
|
2019-05-21 14:39:09 +10:00
|
|
|
/* Menus and pie-menus don't show checkbox without this. */
|
|
|
|
if ((layout->root->type == UI_LAYOUT_MENU) ||
|
|
|
|
/* Use checkboxes only as a fallback in pie-menu's, when no icon is defined. */
|
|
|
|
((layout->root->type == UI_LAYOUT_PIEMENU) && (icon == ICON_NONE))) {
|
|
|
|
int prop_flag = RNA_property_flag(prop);
|
|
|
|
if (type == PROP_BOOLEAN) {
|
|
|
|
if ((is_array == false) || (index != RNA_NO_INDEX)) {
|
|
|
|
if (prop_flag & PROP_ICONS_CONSECUTIVE) {
|
|
|
|
icon = ICON_CHECKBOX_DEHLT; /* but->iconadd will set to correct icon */
|
|
|
|
}
|
|
|
|
else if (is_array) {
|
|
|
|
icon = (RNA_property_boolean_get_index(ptr, prop, index)) ? ICON_CHECKBOX_HLT :
|
|
|
|
ICON_CHECKBOX_DEHLT;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
icon = (RNA_property_boolean_get(ptr, prop)) ? ICON_CHECKBOX_HLT : ICON_CHECKBOX_DEHLT;
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-05-21 14:39:09 +10:00
|
|
|
else if (type == PROP_ENUM) {
|
|
|
|
if (index == RNA_ENUM_VALUE) {
|
|
|
|
int enum_value = RNA_property_enum_get(ptr, prop);
|
|
|
|
if (prop_flag & PROP_ICONS_CONSECUTIVE) {
|
|
|
|
icon = ICON_CHECKBOX_DEHLT; /* but->iconadd will set to correct icon */
|
|
|
|
}
|
|
|
|
else if (prop_flag & PROP_ENUM_FLAG) {
|
|
|
|
icon = (enum_value & value) ? ICON_CHECKBOX_HLT : ICON_CHECKBOX_DEHLT;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
icon = (enum_value == value) ? ICON_CHECKBOX_HLT : ICON_CHECKBOX_DEHLT;
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
2019-05-21 14:39:09 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef UI_PROP_SEP_ICON_WIDTH_EXCEPTION
|
|
|
|
if (use_prop_sep) {
|
|
|
|
if (type == PROP_BOOLEAN && (icon == ICON_NONE) && !icon_only) {
|
|
|
|
use_prop_sep_split_label = false;
|
2020-05-09 17:15:25 +10:00
|
|
|
/* For check-boxes we make an exception: We allow showing them in a split row even without
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
* label. It typically relates to its neighbor items, so no need for an extra label. */
|
2020-04-27 15:24:25 +02:00
|
|
|
use_split_empty_name = true;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
2019-05-21 14:39:09 +10:00
|
|
|
#endif
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
if ((type == PROP_ENUM) && (RNA_property_flag(prop) & PROP_ENUM_FLAG)) {
|
|
|
|
flag |= UI_ITEM_R_EXPAND;
|
|
|
|
}
|
|
|
|
|
2019-05-21 12:30:07 +10:00
|
|
|
const bool slider = (flag & UI_ITEM_R_SLIDER) != 0;
|
|
|
|
const bool expand = (flag & UI_ITEM_R_EXPAND) != 0;
|
|
|
|
const bool no_bg = (flag & UI_ITEM_R_NO_BG) != 0;
|
|
|
|
const bool compact = (flag & UI_ITEM_R_COMPACT) != 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* get size */
|
2019-05-21 12:30:07 +10:00
|
|
|
int w, h;
|
2019-04-17 06:17:24 +02:00
|
|
|
ui_item_rna_size(layout, name, icon, ptr, prop, index, icon_only, compact, &w, &h);
|
|
|
|
|
|
|
|
int prev_emboss = layout->emboss;
|
|
|
|
if (no_bg) {
|
|
|
|
layout->emboss = UI_EMBOSS_NONE;
|
|
|
|
}
|
|
|
|
|
2019-05-21 12:30:07 +10:00
|
|
|
uiBut *but = NULL;
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Split the label / property. */
|
|
|
|
uiLayout *layout_parent = layout;
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (use_prop_sep) {
|
|
|
|
uiLayout *layout_row = NULL;
|
2018-06-16 14:48:21 +02:00
|
|
|
#ifdef UI_PROP_DECORATE
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ui_decorate.use_prop_decorate) {
|
|
|
|
layout_row = uiLayoutRow(layout, true);
|
|
|
|
layout_row->space = 0;
|
|
|
|
ui_decorate.len = max_ii(1, len);
|
|
|
|
}
|
|
|
|
#endif /* UI_PROP_DECORATE */
|
|
|
|
|
2020-04-27 15:24:25 +02:00
|
|
|
if ((name[0] == '\0') && !use_split_empty_name) {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Ensure we get a column when text is not set. */
|
|
|
|
layout = uiLayoutColumn(layout_row ? layout_row : layout, true);
|
|
|
|
layout->space = 0;
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
if (heading_layout) {
|
|
|
|
ui_layout_heading_label_add(layout, heading_layout, false, false);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
uiLayout *layout_split = uiLayoutSplit(
|
|
|
|
layout_row ? layout_row : layout, UI_ITEM_PROP_SEP_DIVIDE, true);
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
bool label_added = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
layout_split->space = 0;
|
|
|
|
uiLayout *layout_sub = uiLayoutColumn(layout_split, true);
|
|
|
|
layout_sub->space = 0;
|
|
|
|
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
if (!use_prop_sep_split_label) {
|
|
|
|
/* Pass */
|
|
|
|
}
|
2020-04-27 13:50:16 +02:00
|
|
|
else if (ui_item_rna_is_expand(prop, index, flag)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
char name_with_suffix[UI_MAX_DRAW_STR + 2];
|
|
|
|
char str[2] = {'\0'};
|
|
|
|
for (int a = 0; a < len; a++) {
|
|
|
|
str[0] = RNA_property_array_item_char(prop, a);
|
|
|
|
const bool use_prefix = (a == 0 && name && name[0]);
|
|
|
|
if (use_prefix) {
|
|
|
|
char *s = name_with_suffix;
|
|
|
|
s += STRNCPY_RLEN(name_with_suffix, name);
|
|
|
|
*s++ = ' ';
|
|
|
|
*s++ = str[0];
|
|
|
|
*s++ = '\0';
|
|
|
|
}
|
|
|
|
but = uiDefBut(block,
|
|
|
|
UI_BTYPE_LABEL,
|
|
|
|
0,
|
|
|
|
use_prefix ? name_with_suffix : str,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
w,
|
|
|
|
UI_UNIT_Y,
|
|
|
|
NULL,
|
|
|
|
0.0,
|
|
|
|
0.0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
"");
|
|
|
|
but->drawflag |= UI_BUT_TEXT_RIGHT;
|
|
|
|
but->drawflag &= ~UI_BUT_TEXT_LEFT;
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
|
|
|
|
label_added = true;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (name) {
|
|
|
|
but = uiDefBut(
|
|
|
|
block, UI_BTYPE_LABEL, 0, name, 0, 0, w, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
|
|
|
|
but->drawflag |= UI_BUT_TEXT_RIGHT;
|
|
|
|
but->drawflag &= ~UI_BUT_TEXT_LEFT;
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
|
|
|
|
label_added = true;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
if (!label_added && heading_layout) {
|
|
|
|
ui_layout_heading_label_add(layout_sub, heading_layout, true, false);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
layout_split = ui_item_prop_split_layout_hack(layout_parent, layout_split);
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Watch out! We can only write into the new layout now. */
|
|
|
|
if ((type == PROP_ENUM) && (flag & UI_ITEM_R_EXPAND)) {
|
|
|
|
/* Expanded enums each have their own name. */
|
|
|
|
|
|
|
|
/* Often expanded enum's are better arranged into a row,
|
|
|
|
* so check the existing layout. */
|
|
|
|
if (uiLayoutGetLocalDir(layout) == UI_LAYOUT_HORIZONTAL) {
|
|
|
|
layout = uiLayoutRow(layout_split, true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
layout = uiLayoutColumn(layout_split, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
if (use_prop_sep_split_label) {
|
|
|
|
name = "";
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
layout = uiLayoutColumn(layout_split, true);
|
|
|
|
}
|
|
|
|
layout->space = 0;
|
|
|
|
}
|
2018-06-16 14:48:21 +02:00
|
|
|
|
|
|
|
#ifdef UI_PROP_DECORATE
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ui_decorate.use_prop_decorate) {
|
|
|
|
ui_decorate.layout = uiLayoutColumn(layout_row, true);
|
|
|
|
ui_decorate.layout->space = 0;
|
|
|
|
UI_block_layout_set_current(block, layout);
|
|
|
|
ui_decorate.but = block->buttons.last;
|
|
|
|
|
|
|
|
/* Clear after. */
|
|
|
|
layout->item.flag |= UI_ITEM_PROP_DECORATE_NO_PAD;
|
|
|
|
}
|
|
|
|
#endif /* UI_PROP_DECORATE */
|
|
|
|
}
|
|
|
|
/* End split. */
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
else if (heading_layout) {
|
|
|
|
/* Could not add heading to split layout, fallback to inserting it to the layout with the
|
|
|
|
* heading itself. */
|
|
|
|
ui_layout_heading_label_add(heading_layout, heading_layout, false, false);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* array property */
|
|
|
|
if (index == RNA_NO_INDEX && is_array) {
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
if (inside_prop_sep) {
|
|
|
|
/* Within a split row, add array items to a column so they match the column layout of
|
|
|
|
* previous items (e.g. transform vector with lock icon for each item). */
|
|
|
|
layout = uiLayoutColumn(layout, true);
|
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ui_item_array(layout,
|
|
|
|
block,
|
|
|
|
name,
|
|
|
|
icon,
|
|
|
|
ptr,
|
|
|
|
prop,
|
|
|
|
len,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
w,
|
|
|
|
h,
|
|
|
|
expand,
|
|
|
|
slider,
|
|
|
|
toggle,
|
|
|
|
icon_only,
|
|
|
|
compact,
|
|
|
|
!use_prop_sep_split_label);
|
|
|
|
}
|
|
|
|
/* enum item */
|
|
|
|
else if (type == PROP_ENUM && index == RNA_ENUM_VALUE) {
|
|
|
|
if (icon && name[0] && !icon_only) {
|
|
|
|
uiDefIconTextButR_prop(
|
|
|
|
block, UI_BTYPE_ROW, 0, icon, name, 0, 0, w, h, ptr, prop, -1, 0, value, -1, -1, NULL);
|
|
|
|
}
|
|
|
|
else if (icon) {
|
|
|
|
uiDefIconButR_prop(
|
|
|
|
block, UI_BTYPE_ROW, 0, icon, 0, 0, w, h, ptr, prop, -1, 0, value, -1, -1, NULL);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
uiDefButR_prop(
|
|
|
|
block, UI_BTYPE_ROW, 0, name, 0, 0, w, h, ptr, prop, -1, 0, value, -1, -1, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* expanded enum */
|
|
|
|
else if (type == PROP_ENUM && expand) {
|
|
|
|
ui_item_enum_expand(layout, block, ptr, prop, name, h, icon_only);
|
|
|
|
}
|
|
|
|
/* property with separate label */
|
|
|
|
else if (type == PROP_ENUM || type == PROP_STRING || type == PROP_POINTER) {
|
|
|
|
but = ui_item_with_label(layout, block, name, icon, ptr, prop, index, 0, 0, w, h, flag);
|
|
|
|
ui_but_add_search(but, ptr, prop, NULL, NULL);
|
|
|
|
|
|
|
|
if (layout->redalert) {
|
|
|
|
UI_but_flag_enable(but, UI_BUT_REDALERT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (layout->activate_init) {
|
|
|
|
UI_but_flag_enable(but, UI_BUT_ACTIVATE_ON_INIT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* single button */
|
|
|
|
else {
|
|
|
|
but = uiDefAutoButR(block, ptr, prop, index, name, icon, 0, 0, w, h);
|
|
|
|
|
|
|
|
if (slider && but->type == UI_BTYPE_NUM) {
|
|
|
|
but->type = UI_BTYPE_NUM_SLIDER;
|
|
|
|
}
|
|
|
|
|
2019-05-20 12:14:48 +02:00
|
|
|
if (flag & UI_ITEM_R_CHECKBOX_INVERT) {
|
2020-03-09 16:43:47 +01:00
|
|
|
if (ELEM(but->type,
|
|
|
|
UI_BTYPE_CHECKBOX,
|
|
|
|
UI_BTYPE_CHECKBOX_N,
|
|
|
|
UI_BTYPE_ICON_TOGGLE,
|
|
|
|
UI_BTYPE_ICON_TOGGLE_N)) {
|
2019-05-20 12:14:48 +02:00
|
|
|
but->drawflag |= UI_BUT_CHECKBOX_INVERT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-21 14:39:09 +10:00
|
|
|
if ((toggle == 1) && but->type == UI_BTYPE_CHECKBOX) {
|
2019-04-17 06:17:24 +02:00
|
|
|
but->type = UI_BTYPE_TOGGLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (layout->redalert) {
|
|
|
|
UI_but_flag_enable(but, UI_BUT_REDALERT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (layout->activate_init) {
|
|
|
|
UI_but_flag_enable(but, UI_BUT_ACTIVATE_ON_INIT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-21 14:39:09 +10:00
|
|
|
/* The resulting button may have the icon set since boolean button drawing
|
|
|
|
* is being 'helpful' and adding an icon for us.
|
|
|
|
* In this case we want the ability not to have an icon.
|
|
|
|
*
|
|
|
|
* We could pass an argument not to set the icon to begin with however this is the one case
|
|
|
|
* the functionality is needed. */
|
|
|
|
if (but && no_icon) {
|
|
|
|
if ((icon == ICON_NONE) && (but->icon != ICON_NONE)) {
|
|
|
|
ui_def_but_icon_clear(but);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Mark non-embossed textfields inside a listbox. */
|
|
|
|
if (but && (block->flag & UI_BLOCK_LIST_ITEM) && (but->type == UI_BTYPE_TEXT) &&
|
2020-07-29 12:05:27 +10:00
|
|
|
(but->emboss & UI_EMBOSS_NONE)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
UI_but_flag_enable(but, UI_BUT_LIST_ITEM);
|
|
|
|
}
|
2013-11-23 18:43:23 +01:00
|
|
|
|
2018-06-16 14:48:21 +02:00
|
|
|
#ifdef UI_PROP_DECORATE
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ui_decorate.use_prop_decorate) {
|
|
|
|
uiBut *but_decorate = ui_decorate.but ? ui_decorate.but->next : block->buttons.first;
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
const bool use_blank_decorator = (flag & UI_ITEM_R_FORCE_BLANK_DECORATE);
|
2019-04-17 06:17:24 +02:00
|
|
|
uiLayout *layout_col = uiLayoutColumn(ui_decorate.layout, false);
|
|
|
|
layout_col->space = 0;
|
|
|
|
layout_col->emboss = UI_EMBOSS_NONE;
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < ui_decorate.len && but_decorate; i++) {
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
PointerRNA *ptr_dec = use_blank_decorator ? NULL : &but_decorate->rnapoin;
|
|
|
|
PropertyRNA *prop_dec = use_blank_decorator ? NULL : but_decorate->rnaprop;
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* The icons are set in 'ui_but_anim_flag' */
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
uiItemDecoratorR_prop(layout_col, ptr_dec, prop_dec, but_decorate->rnaindex);
|
|
|
|
but = block->buttons.last;
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Order the decorator after the button we decorate, this is used so we can always
|
|
|
|
* do a quick lookup. */
|
|
|
|
BLI_remlink(&block->buttons, but);
|
|
|
|
BLI_insertlinkafter(&block->buttons, but_decorate, but);
|
|
|
|
but_decorate = but->next;
|
|
|
|
}
|
|
|
|
BLI_assert(ELEM(i, 1, ui_decorate.len));
|
|
|
|
|
|
|
|
layout->item.flag &= ~UI_ITEM_PROP_DECORATE_NO_PAD;
|
|
|
|
}
|
|
|
|
#endif /* UI_PROP_DECORATE */
|
|
|
|
|
|
|
|
if (no_bg) {
|
|
|
|
layout->emboss = prev_emboss;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ensure text isn't added to icon_only buttons */
|
|
|
|
if (but && icon_only) {
|
|
|
|
BLI_assert(but->str[0] == '\0');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiItemR(
|
|
|
|
uiLayout *layout, PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
|
|
|
|
{
|
|
|
|
PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
|
|
|
|
|
|
|
|
if (!prop) {
|
|
|
|
ui_item_disabled(layout, propname);
|
|
|
|
RNA_warning("property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uiItemFullR(layout, ptr, prop, RNA_NO_INDEX, 0, flag, name, icon);
|
2009-04-22 18:39:44 +00:00
|
|
|
}
|
|
|
|
|
2019-03-25 18:55:38 +11:00
|
|
|
/**
|
|
|
|
* Use a wrapper function since re-implementing all the logic in this function would be messy.
|
|
|
|
*/
|
2019-04-17 06:17:24 +02:00
|
|
|
void uiItemFullR_with_popover(uiLayout *layout,
|
|
|
|
PointerRNA *ptr,
|
|
|
|
PropertyRNA *prop,
|
|
|
|
int index,
|
|
|
|
int value,
|
|
|
|
int flag,
|
|
|
|
const char *name,
|
|
|
|
int icon,
|
|
|
|
const char *panel_type)
|
|
|
|
{
|
|
|
|
uiBlock *block = layout->root->block;
|
|
|
|
uiBut *but = block->buttons.last;
|
|
|
|
uiItemFullR(layout, ptr, prop, index, value, flag, name, icon);
|
|
|
|
but = but->next;
|
|
|
|
while (but) {
|
2020-03-09 16:27:24 +01:00
|
|
|
if (but->rnaprop == prop && ELEM(but->type, UI_BTYPE_MENU, UI_BTYPE_COLOR)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ui_but_rna_menu_convert_to_panel_type(but, panel_type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
but = but->next;
|
|
|
|
}
|
|
|
|
if (but == NULL) {
|
|
|
|
const char *propname = RNA_property_identifier(prop);
|
|
|
|
ui_item_disabled(layout, panel_type);
|
|
|
|
RNA_warning("property could not use a popover: %s.%s (%s)",
|
|
|
|
RNA_struct_identifier(ptr->type),
|
|
|
|
propname,
|
|
|
|
panel_type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiItemFullR_with_menu(uiLayout *layout,
|
|
|
|
PointerRNA *ptr,
|
|
|
|
PropertyRNA *prop,
|
|
|
|
int index,
|
|
|
|
int value,
|
|
|
|
int flag,
|
|
|
|
const char *name,
|
|
|
|
int icon,
|
|
|
|
const char *menu_type)
|
|
|
|
{
|
|
|
|
uiBlock *block = layout->root->block;
|
|
|
|
uiBut *but = block->buttons.last;
|
|
|
|
uiItemFullR(layout, ptr, prop, index, value, flag, name, icon);
|
|
|
|
but = but->next;
|
|
|
|
while (but) {
|
|
|
|
if (but->rnaprop == prop && but->type == UI_BTYPE_MENU) {
|
|
|
|
ui_but_rna_menu_convert_to_menu_type(but, menu_type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
but = but->next;
|
|
|
|
}
|
|
|
|
if (but == NULL) {
|
|
|
|
const char *propname = RNA_property_identifier(prop);
|
|
|
|
ui_item_disabled(layout, menu_type);
|
|
|
|
RNA_warning("property could not use a menu: %s.%s (%s)",
|
|
|
|
RNA_struct_identifier(ptr->type),
|
|
|
|
propname,
|
|
|
|
menu_type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiItemEnumR_prop(uiLayout *layout,
|
|
|
|
const char *name,
|
|
|
|
int icon,
|
|
|
|
struct PointerRNA *ptr,
|
|
|
|
PropertyRNA *prop,
|
|
|
|
int value)
|
|
|
|
{
|
|
|
|
if (RNA_property_type(prop) != PROP_ENUM) {
|
|
|
|
const char *propname = RNA_property_identifier(prop);
|
|
|
|
ui_item_disabled(layout, propname);
|
|
|
|
RNA_warning("property not an enum: %s.%s", RNA_struct_identifier(ptr->type), propname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uiItemFullR(layout, ptr, prop, RNA_ENUM_VALUE, value, 0, name, icon);
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiItemEnumR(uiLayout *layout,
|
|
|
|
const char *name,
|
|
|
|
int icon,
|
|
|
|
struct PointerRNA *ptr,
|
|
|
|
const char *propname,
|
|
|
|
int value)
|
|
|
|
{
|
|
|
|
PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
|
|
|
|
|
|
|
|
if (prop == NULL) {
|
|
|
|
ui_item_disabled(layout, propname);
|
|
|
|
RNA_warning("property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uiItemFullR(layout, ptr, prop, RNA_ENUM_VALUE, value, 0, name, icon);
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiItemEnumR_string_prop(uiLayout *layout,
|
|
|
|
struct PointerRNA *ptr,
|
|
|
|
PropertyRNA *prop,
|
|
|
|
const char *value,
|
|
|
|
const char *name,
|
|
|
|
int icon)
|
|
|
|
{
|
|
|
|
const EnumPropertyItem *item;
|
|
|
|
int ivalue, a;
|
|
|
|
bool free;
|
|
|
|
|
|
|
|
if (UNLIKELY(RNA_property_type(prop) != PROP_ENUM)) {
|
|
|
|
const char *propname = RNA_property_identifier(prop);
|
|
|
|
ui_item_disabled(layout, propname);
|
|
|
|
RNA_warning("not an enum property: %s.%s", RNA_struct_identifier(ptr->type), propname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RNA_property_enum_items(layout->root->block->evil_C, ptr, prop, &item, NULL, &free);
|
|
|
|
|
|
|
|
if (!RNA_enum_value_from_id(item, value, &ivalue)) {
|
|
|
|
const char *propname = RNA_property_identifier(prop);
|
|
|
|
if (free) {
|
|
|
|
MEM_freeN((void *)item);
|
|
|
|
}
|
|
|
|
ui_item_disabled(layout, propname);
|
|
|
|
RNA_warning("enum property value not found: %s", value);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (a = 0; item[a].identifier; a++) {
|
2020-01-15 16:09:27 +01:00
|
|
|
if (item[a].identifier[0] == '\0') {
|
|
|
|
/* Skip enum item separators. */
|
|
|
|
continue;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
if (item[a].value == ivalue) {
|
|
|
|
const char *item_name = name ?
|
|
|
|
name :
|
|
|
|
CTX_IFACE_(RNA_property_translation_context(prop), item[a].name);
|
|
|
|
const int flag = item_name[0] ? 0 : UI_ITEM_R_ICON_ONLY;
|
|
|
|
|
|
|
|
uiItemFullR(
|
|
|
|
layout, ptr, prop, RNA_ENUM_VALUE, ivalue, flag, item_name, icon ? icon : item[a].icon);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (free) {
|
|
|
|
MEM_freeN((void *)item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiItemEnumR_string(uiLayout *layout,
|
|
|
|
struct PointerRNA *ptr,
|
|
|
|
const char *propname,
|
|
|
|
const char *value,
|
|
|
|
const char *name,
|
|
|
|
int icon)
|
|
|
|
{
|
|
|
|
PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
|
|
|
|
if (UNLIKELY(prop == NULL)) {
|
|
|
|
ui_item_disabled(layout, propname);
|
|
|
|
RNA_warning("enum property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uiItemEnumR_string_prop(layout, ptr, prop, value, name, icon);
|
2018-08-24 11:44:28 +10:00
|
|
|
}
|
|
|
|
|
2010-11-17 09:45:45 +00:00
|
|
|
void uiItemsEnumR(uiLayout *layout, struct PointerRNA *ptr, const char *propname)
|
2009-04-22 18:39:44 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PropertyRNA *prop;
|
|
|
|
uiBlock *block = layout->root->block;
|
|
|
|
uiBut *bt;
|
|
|
|
|
|
|
|
prop = RNA_struct_find_property(ptr, propname);
|
|
|
|
|
|
|
|
if (!prop) {
|
|
|
|
ui_item_disabled(layout, propname);
|
|
|
|
RNA_warning("enum property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RNA_property_type(prop) != PROP_ENUM) {
|
|
|
|
RNA_warning("not an enum property: %s.%s", RNA_struct_identifier(ptr->type), propname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-03 14:20:10 +02:00
|
|
|
const EnumPropertyItem *item;
|
|
|
|
int totitem, i;
|
|
|
|
bool free;
|
|
|
|
uiLayout *split = uiLayoutSplit(layout, 0.0f, false);
|
|
|
|
uiLayout *column = uiLayoutColumn(split, false);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-07-03 14:20:10 +02:00
|
|
|
RNA_property_enum_items_gettexted(block->evil_C, ptr, prop, &item, &totitem, &free);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-07-03 14:20:10 +02:00
|
|
|
for (i = 0; i < totitem; i++) {
|
|
|
|
if (item[i].identifier[0]) {
|
|
|
|
uiItemEnumR_prop(column, item[i].name, item[i].icon, ptr, prop, item[i].value);
|
|
|
|
ui_but_tip_from_enum_item(block->buttons.last, &item[i]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (item[i].name) {
|
|
|
|
if (i != 0) {
|
|
|
|
column = uiLayoutColumn(split, false);
|
|
|
|
/* inconsistent, but menus with labels do not look good flipped */
|
|
|
|
block->flag |= UI_BLOCK_NO_FLIP;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2020-07-03 14:20:10 +02:00
|
|
|
|
|
|
|
uiItemL(column, item[i].name, ICON_NONE);
|
|
|
|
bt = block->buttons.last;
|
|
|
|
bt->drawflag = UI_BUT_TEXT_LEFT;
|
|
|
|
|
|
|
|
ui_but_tip_from_enum_item(bt, &item[i]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
uiItemS(column);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
2020-07-03 14:20:10 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-07-03 14:20:10 +02:00
|
|
|
if (free) {
|
|
|
|
MEM_freeN((void *)item);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* intentionally don't touch UI_BLOCK_IS_FLIP here,
|
|
|
|
* we don't know the context this is called in */
|
2009-03-13 13:38:41 +00:00
|
|
|
}
|
|
|
|
|
2009-06-27 01:15:31 +00:00
|
|
|
/* Pointer RNA button with search */
|
|
|
|
|
2019-03-25 12:19:55 +11:00
|
|
|
static void search_id_collection(StructRNA *ptype, PointerRNA *r_ptr, PropertyRNA **r_prop)
|
2009-06-27 01:15:31 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
StructRNA *srna;
|
|
|
|
|
|
|
|
/* look for collection property in Main */
|
|
|
|
/* Note: using global Main is OK-ish here, UI shall not access other Mains anyay... */
|
|
|
|
RNA_main_pointer_create(G_MAIN, r_ptr);
|
|
|
|
|
|
|
|
*r_prop = NULL;
|
|
|
|
|
|
|
|
RNA_STRUCT_BEGIN (r_ptr, iprop) {
|
|
|
|
/* if it's a collection and has same pointer type, we've got it */
|
|
|
|
if (RNA_property_type(iprop) == PROP_COLLECTION) {
|
|
|
|
srna = RNA_property_pointer_type(r_ptr, iprop);
|
|
|
|
|
|
|
|
if (ptype == srna) {
|
|
|
|
*r_prop = iprop;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RNA_STRUCT_END;
|
|
|
|
}
|
|
|
|
|
2020-05-08 12:01:35 +10:00
|
|
|
static void ui_rna_collection_search_arg_free_fn(void *ptr)
|
2020-04-08 23:08:32 +02:00
|
|
|
{
|
|
|
|
uiRNACollectionSearch *coll_search = ptr;
|
|
|
|
UI_butstore_free(coll_search->butstore_block, coll_search->butstore);
|
|
|
|
MEM_freeN(ptr);
|
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void ui_but_add_search(
|
|
|
|
uiBut *but, PointerRNA *ptr, PropertyRNA *prop, PointerRNA *searchptr, PropertyRNA *searchprop)
|
|
|
|
{
|
|
|
|
StructRNA *ptype;
|
|
|
|
PointerRNA sptr;
|
|
|
|
|
|
|
|
/* for ID's we do automatic lookup */
|
|
|
|
if (!searchprop) {
|
|
|
|
if (RNA_property_type(prop) == PROP_POINTER) {
|
|
|
|
ptype = RNA_property_pointer_type(ptr, prop);
|
|
|
|
search_id_collection(ptype, &sptr, &searchprop);
|
|
|
|
searchptr = &sptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* turn button into search button */
|
|
|
|
if (searchprop) {
|
|
|
|
uiRNACollectionSearch *coll_search = MEM_mallocN(sizeof(*coll_search), __func__);
|
|
|
|
|
|
|
|
but->type = UI_BTYPE_SEARCH_MENU;
|
|
|
|
but->hardmax = MAX2(but->hardmax, 256.0f);
|
|
|
|
but->rnasearchpoin = *searchptr;
|
|
|
|
but->rnasearchprop = searchprop;
|
|
|
|
but->drawflag |= UI_BUT_ICON_LEFT | UI_BUT_TEXT_LEFT;
|
|
|
|
if (RNA_property_is_unlink(prop)) {
|
|
|
|
but->flag |= UI_BUT_VALUE_CLEAR;
|
|
|
|
}
|
|
|
|
|
|
|
|
coll_search->target_ptr = *ptr;
|
|
|
|
coll_search->target_prop = prop;
|
|
|
|
coll_search->search_ptr = *searchptr;
|
|
|
|
coll_search->search_prop = searchprop;
|
2020-04-08 23:08:32 +02:00
|
|
|
coll_search->search_but = but;
|
|
|
|
coll_search->butstore_block = but->block;
|
|
|
|
coll_search->butstore = UI_butstore_create(coll_search->butstore_block);
|
|
|
|
UI_butstore_register(coll_search->butstore, &coll_search->search_but);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
if (RNA_property_type(prop) == PROP_ENUM) {
|
|
|
|
/* XXX, this will have a menu string,
|
|
|
|
* but in this case we just want the text */
|
|
|
|
but->str[0] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
UI_but_func_search_set(but,
|
|
|
|
ui_searchbox_create_generic,
|
2020-05-07 23:16:05 +10:00
|
|
|
ui_rna_collection_search_update_fn,
|
2019-04-17 06:17:24 +02:00
|
|
|
coll_search,
|
2020-05-08 12:01:35 +10:00
|
|
|
ui_rna_collection_search_arg_free_fn,
|
2019-04-17 06:17:24 +02:00
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
else if (but->type == UI_BTYPE_SEARCH_MENU) {
|
|
|
|
/* In case we fail to find proper searchprop,
|
|
|
|
* so other code might have already set but->type to search menu... */
|
|
|
|
but->flag |= UI_BUT_DISABLED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiItemPointerR_prop(uiLayout *layout,
|
|
|
|
PointerRNA *ptr,
|
|
|
|
PropertyRNA *prop,
|
|
|
|
PointerRNA *searchptr,
|
|
|
|
PropertyRNA *searchprop,
|
|
|
|
const char *name,
|
|
|
|
int icon)
|
|
|
|
{
|
|
|
|
PropertyType type;
|
|
|
|
uiBut *but;
|
|
|
|
uiBlock *block;
|
|
|
|
StructRNA *icontype;
|
|
|
|
int w, h;
|
|
|
|
char namestr[UI_MAX_NAME_STR];
|
|
|
|
const bool use_prop_sep = ((layout->item.flag & UI_ITEM_PROP_SEP) != 0);
|
|
|
|
|
|
|
|
type = RNA_property_type(prop);
|
|
|
|
if (!ELEM(type, PROP_POINTER, PROP_STRING, PROP_ENUM)) {
|
|
|
|
RNA_warning("Property %s.%s must be a pointer, string or enum",
|
|
|
|
RNA_struct_identifier(ptr->type),
|
|
|
|
RNA_property_identifier(prop));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (RNA_property_type(searchprop) != PROP_COLLECTION) {
|
|
|
|
RNA_warning("search collection property is not a collection type: %s.%s",
|
|
|
|
RNA_struct_identifier(searchptr->type),
|
|
|
|
RNA_property_identifier(searchprop));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get icon & name */
|
|
|
|
if (icon == ICON_NONE) {
|
|
|
|
if (type == PROP_POINTER) {
|
|
|
|
icontype = RNA_property_pointer_type(ptr, prop);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
icontype = RNA_property_pointer_type(searchptr, searchprop);
|
|
|
|
}
|
|
|
|
|
|
|
|
icon = RNA_struct_ui_icon(icontype);
|
|
|
|
}
|
|
|
|
if (!name) {
|
|
|
|
name = RNA_property_ui_name(prop);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (use_prop_sep == false) {
|
|
|
|
name = ui_item_name_add_colon(name, namestr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create button */
|
|
|
|
block = uiLayoutGetBlock(layout);
|
|
|
|
|
|
|
|
ui_item_rna_size(layout, name, icon, ptr, prop, 0, 0, false, &w, &h);
|
|
|
|
w += UI_UNIT_X; /* X icon needs more space */
|
|
|
|
but = ui_item_with_label(layout, block, name, icon, ptr, prop, 0, 0, 0, w, h, 0);
|
|
|
|
|
|
|
|
ui_but_add_search(but, ptr, prop, searchptr, searchprop);
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiItemPointerR(uiLayout *layout,
|
|
|
|
PointerRNA *ptr,
|
|
|
|
const char *propname,
|
|
|
|
PointerRNA *searchptr,
|
|
|
|
const char *searchpropname,
|
|
|
|
const char *name,
|
|
|
|
int icon)
|
|
|
|
{
|
|
|
|
PropertyRNA *prop, *searchprop;
|
|
|
|
|
|
|
|
/* validate arguments */
|
|
|
|
prop = RNA_struct_find_property(ptr, propname);
|
|
|
|
if (!prop) {
|
|
|
|
RNA_warning("property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
searchprop = RNA_struct_find_property(searchptr, searchpropname);
|
|
|
|
if (!searchprop) {
|
|
|
|
RNA_warning("search collection property not found: %s.%s",
|
|
|
|
RNA_struct_identifier(searchptr->type),
|
|
|
|
searchpropname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uiItemPointerR_prop(layout, ptr, prop, searchptr, searchprop, name, icon);
|
2018-08-24 11:44:28 +10:00
|
|
|
}
|
|
|
|
|
2009-03-13 13:38:41 +00:00
|
|
|
/* menu item */
|
2019-03-25 20:31:06 +11:00
|
|
|
void ui_item_menutype_func(bContext *C, uiLayout *layout, void *arg_mt)
|
2009-04-22 18:39:44 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
MenuType *mt = (MenuType *)arg_mt;
|
2009-04-22 18:39:44 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
UI_menutype_draw(C, mt, layout);
|
2014-11-15 14:32:23 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* menus are created flipped (from event handling pov) */
|
|
|
|
layout->root->block->flag ^= UI_BLOCK_IS_FLIP;
|
2009-04-22 18:39:44 +00:00
|
|
|
}
|
|
|
|
|
2018-05-25 15:46:22 +02:00
|
|
|
void ui_item_paneltype_func(bContext *C, uiLayout *layout, void *arg_pt)
|
2018-04-22 17:16:39 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PanelType *pt = (PanelType *)arg_pt;
|
|
|
|
UI_paneltype_draw(C, pt, layout);
|
|
|
|
|
|
|
|
/* panels are created flipped (from event handling pov) */
|
|
|
|
layout->root->block->flag ^= UI_BLOCK_IS_FLIP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uiBut *ui_item_menu(uiLayout *layout,
|
|
|
|
const char *name,
|
|
|
|
int icon,
|
|
|
|
uiMenuCreateFunc func,
|
|
|
|
void *arg,
|
|
|
|
void *argN,
|
|
|
|
const char *tip,
|
|
|
|
bool force_menu)
|
|
|
|
{
|
|
|
|
uiBlock *block = layout->root->block;
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
uiLayout *heading_layout = ui_layout_heading_find(layout);
|
2019-04-17 06:17:24 +02:00
|
|
|
uiBut *but;
|
|
|
|
int w, h;
|
|
|
|
|
|
|
|
UI_block_layout_set_current(block, layout);
|
|
|
|
|
|
|
|
if (!name) {
|
|
|
|
name = "";
|
|
|
|
}
|
|
|
|
if (layout->root->type == UI_LAYOUT_MENU && !icon) {
|
|
|
|
icon = ICON_BLANK1;
|
|
|
|
}
|
|
|
|
|
|
|
|
w = ui_text_icon_width(layout, name, icon, 1);
|
|
|
|
h = UI_UNIT_Y;
|
|
|
|
|
|
|
|
if (layout->root->type == UI_LAYOUT_HEADER) { /* ugly .. */
|
|
|
|
if (icon == ICON_NONE && force_menu) {
|
|
|
|
/* pass */
|
|
|
|
}
|
|
|
|
else if (force_menu) {
|
|
|
|
w += 0.6f * UI_UNIT_X;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (name[0]) {
|
|
|
|
w -= UI_UNIT_X / 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
if (heading_layout) {
|
|
|
|
ui_layout_heading_label_add(layout, heading_layout, true, true);
|
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (name[0] && icon) {
|
|
|
|
but = uiDefIconTextMenuBut(block, func, arg, icon, name, 0, 0, w, h, tip);
|
|
|
|
}
|
|
|
|
else if (icon) {
|
|
|
|
but = uiDefIconMenuBut(block, func, arg, icon, 0, 0, w, h, tip);
|
2020-03-30 14:43:17 +11:00
|
|
|
if (force_menu && name[0]) {
|
2019-04-17 06:17:24 +02:00
|
|
|
UI_but_drawflag_enable(but, UI_BUT_ICON_LEFT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
but = uiDefMenuBut(block, func, arg, name, 0, 0, w, h, tip);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argN) {
|
|
|
|
/* ugly .. */
|
|
|
|
if (arg != argN) {
|
|
|
|
but->poin = (char *)but;
|
|
|
|
}
|
|
|
|
but->func_argN = argN;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ELEM(layout->root->type, UI_LAYOUT_PANEL, UI_LAYOUT_TOOLBAR) ||
|
|
|
|
/* We never want a dropdown in menu! */
|
|
|
|
(force_menu && layout->root->type != UI_LAYOUT_MENU)) {
|
|
|
|
UI_but_type_set_menu_from_pulldown(but);
|
|
|
|
}
|
|
|
|
|
|
|
|
return but;
|
2009-03-13 13:38:41 +00:00
|
|
|
}
|
|
|
|
|
2019-05-27 15:30:48 +10:00
|
|
|
void uiItemM_ptr(uiLayout *layout, MenuType *mt, const char *name, int icon)
|
2009-04-22 18:39:44 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (!name) {
|
|
|
|
name = CTX_IFACE_(mt->translation_context, mt->label);
|
|
|
|
}
|
2011-09-15 13:20:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (layout->root->type == UI_LAYOUT_MENU && !icon) {
|
|
|
|
icon = ICON_BLANK1;
|
|
|
|
}
|
2009-10-06 13:04:31 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ui_item_menu(layout,
|
|
|
|
name,
|
|
|
|
icon,
|
|
|
|
ui_item_menutype_func,
|
|
|
|
mt,
|
|
|
|
NULL,
|
|
|
|
mt->description ? TIP_(mt->description) : "",
|
|
|
|
false);
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
}
|
2009-04-22 18:39:44 +00:00
|
|
|
|
2019-05-27 15:30:48 +10:00
|
|
|
void uiItemM(uiLayout *layout, const char *menuname, const char *name, int icon)
|
|
|
|
{
|
|
|
|
MenuType *mt = WM_menutype_find(menuname, false);
|
|
|
|
if (mt == NULL) {
|
|
|
|
RNA_warning("not found %s", menuname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uiItemM_ptr(layout, mt, name, icon);
|
|
|
|
}
|
|
|
|
|
2018-12-20 11:33:08 +11:00
|
|
|
void uiItemMContents(uiLayout *layout, const char *menuname)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
MenuType *mt = WM_menutype_find(menuname, false);
|
|
|
|
if (mt == NULL) {
|
|
|
|
RNA_warning("not found %s", menuname);
|
|
|
|
return;
|
|
|
|
}
|
2018-12-20 11:33:08 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
uiBlock *block = layout->root->block;
|
|
|
|
bContext *C = block->evil_C;
|
|
|
|
UI_menutype_draw(C, mt, layout);
|
2018-12-20 11:33:08 +11:00
|
|
|
}
|
|
|
|
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
/**
|
|
|
|
* Insert a decorator item for a button with the same property as \a prop.
|
|
|
|
* To force inserting a blank dummy element, NULL can be passed for \a ptr and \a prop.
|
|
|
|
*/
|
|
|
|
void uiItemDecoratorR_prop(uiLayout *layout, PointerRNA *ptr, PropertyRNA *prop, int index)
|
|
|
|
{
|
|
|
|
uiBlock *block = layout->root->block;
|
|
|
|
uiBut *but = NULL;
|
|
|
|
|
2020-04-27 13:50:16 +02:00
|
|
|
uiLayout *col;
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
UI_block_layout_set_current(block, layout);
|
2020-04-27 13:50:16 +02:00
|
|
|
col = uiLayoutColumn(layout, false);
|
|
|
|
col->space = 0;
|
|
|
|
col->emboss = UI_EMBOSS_NONE;
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
|
2020-04-27 13:50:16 +02:00
|
|
|
if (ELEM(NULL, ptr, prop) || !RNA_property_animateable(ptr, prop)) {
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
but = uiDefIconBut(block,
|
|
|
|
UI_BTYPE_BUT,
|
|
|
|
0,
|
2020-04-27 13:50:16 +02:00
|
|
|
ICON_BLANK1,
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
UI_UNIT_X,
|
|
|
|
UI_UNIT_Y,
|
|
|
|
NULL,
|
|
|
|
0.0,
|
|
|
|
0.0,
|
|
|
|
0.0,
|
|
|
|
0.0,
|
2020-04-27 13:50:16 +02:00
|
|
|
"");
|
|
|
|
but->flag |= UI_BUT_DISABLED;
|
|
|
|
return;
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
}
|
2020-04-27 13:50:16 +02:00
|
|
|
|
|
|
|
const bool is_expand = ui_item_rna_is_expand(prop, index, 0);
|
|
|
|
const bool is_array = RNA_property_array_check(prop);
|
|
|
|
|
|
|
|
/* Loop for the array-case, but only do in case of an expanded array. */
|
|
|
|
for (int i = 0; i < (is_expand ? RNA_property_array_length(ptr, prop) : 1); i++) {
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
but = uiDefIconBut(block,
|
|
|
|
UI_BTYPE_BUT,
|
|
|
|
0,
|
2020-04-27 13:50:16 +02:00
|
|
|
ICON_DOT,
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
UI_UNIT_X,
|
|
|
|
UI_UNIT_Y,
|
|
|
|
NULL,
|
|
|
|
0.0,
|
|
|
|
0.0,
|
|
|
|
0.0,
|
|
|
|
0.0,
|
2020-04-27 13:50:16 +02:00
|
|
|
TIP_("Animate property"));
|
|
|
|
UI_but_func_set(but, ui_but_anim_decorate_cb, but, NULL);
|
|
|
|
but->flag |= UI_BUT_UNDO | UI_BUT_DRAG_LOCK;
|
|
|
|
/* Reusing RNA search members, setting actual RNA data has many side-effects. */
|
|
|
|
but->rnasearchpoin = *ptr;
|
|
|
|
but->rnasearchprop = prop;
|
|
|
|
/* ui_def_but_rna() sets non-array buttons to have a RNA index of 0. */
|
|
|
|
but->custom_data = POINTER_FROM_INT((!is_array || is_expand) ? i : index);
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-27 13:50:16 +02:00
|
|
|
/**
|
|
|
|
* Insert a decorator item for a button with the same property as \a prop.
|
|
|
|
* To force inserting a blank dummy element, NULL can be passed for \a ptr and \a propname.
|
|
|
|
*/
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
void uiItemDecoratorR(uiLayout *layout, PointerRNA *ptr, const char *propname, int index)
|
|
|
|
{
|
2020-04-27 13:50:16 +02:00
|
|
|
PropertyRNA *prop = NULL;
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
|
2020-04-27 13:50:16 +02:00
|
|
|
if (ptr && propname) {
|
|
|
|
/* validate arguments */
|
|
|
|
prop = RNA_struct_find_property(ptr, propname);
|
|
|
|
if (!prop) {
|
|
|
|
ui_item_disabled(layout, propname);
|
|
|
|
RNA_warning("property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
|
|
|
|
return;
|
|
|
|
}
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
}
|
|
|
|
|
2020-04-27 13:50:16 +02:00
|
|
|
/* ptr and prop are allowed to be NULL here. */
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
uiItemDecoratorR_prop(layout, ptr, prop, index);
|
|
|
|
}
|
|
|
|
|
2018-04-22 17:16:39 +02:00
|
|
|
/* popover */
|
2019-04-17 06:17:24 +02:00
|
|
|
void uiItemPopoverPanel_ptr(
|
|
|
|
uiLayout *layout, bContext *C, PanelType *pt, const char *name, int icon)
|
|
|
|
{
|
|
|
|
if (!name) {
|
|
|
|
name = CTX_IFACE_(pt->translation_context, pt->label);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (layout->root->type == UI_LAYOUT_MENU && !icon) {
|
|
|
|
icon = ICON_BLANK1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool ok = (pt->poll == NULL) || pt->poll(C, pt);
|
|
|
|
if (ok && (pt->draw_header != NULL)) {
|
|
|
|
layout = uiLayoutRow(layout, true);
|
|
|
|
Panel panel = {
|
|
|
|
.type = pt,
|
|
|
|
.layout = layout,
|
|
|
|
.flag = PNL_POPOVER,
|
|
|
|
};
|
|
|
|
pt->draw_header(C, &panel);
|
|
|
|
}
|
|
|
|
uiBut *but = ui_item_menu(layout, name, icon, ui_item_paneltype_func, pt, NULL, NULL, true);
|
|
|
|
but->type = UI_BTYPE_POPOVER;
|
|
|
|
if (!ok) {
|
|
|
|
but->flag |= UI_BUT_DISABLED;
|
|
|
|
}
|
2018-04-22 17:16:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void uiItemPopoverPanel(
|
2019-04-17 06:17:24 +02:00
|
|
|
uiLayout *layout, bContext *C, const char *panel_type, const char *name, int icon)
|
|
|
|
{
|
|
|
|
PanelType *pt = WM_paneltype_find(panel_type, true);
|
|
|
|
if (pt == NULL) {
|
|
|
|
RNA_warning("Panel type not found '%s'", panel_type);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uiItemPopoverPanel_ptr(layout, C, pt, name, icon);
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiItemPopoverPanelFromGroup(uiLayout *layout,
|
|
|
|
bContext *C,
|
|
|
|
int space_id,
|
|
|
|
int region_id,
|
|
|
|
const char *context,
|
|
|
|
const char *category)
|
|
|
|
{
|
|
|
|
SpaceType *st = BKE_spacetype_from_id(space_id);
|
|
|
|
if (st == NULL) {
|
|
|
|
RNA_warning("space type not found %d", space_id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ARegionType *art = BKE_regiontype_from_id(st, region_id);
|
|
|
|
if (art == NULL) {
|
|
|
|
RNA_warning("region type not found %d", region_id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (PanelType *, pt, &art->paneltypes) {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Causes too many panels, check context. */
|
|
|
|
if (pt->parent_id[0] == '\0') {
|
|
|
|
if (/* (*context == '\0') || */ STREQ(pt->context, context)) {
|
|
|
|
if ((*category == '\0') || STREQ(pt->category, category)) {
|
|
|
|
if (pt->poll == NULL || pt->poll(C, pt)) {
|
|
|
|
uiItemPopoverPanel_ptr(layout, C, pt, NULL, ICON_NONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-04-22 17:16:39 +02:00
|
|
|
}
|
|
|
|
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
/* label item */
|
2010-11-17 09:45:45 +00:00
|
|
|
static uiBut *uiItemL_(uiLayout *layout, const char *name, int icon)
|
2009-04-22 18:39:44 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiBlock *block = layout->root->block;
|
|
|
|
uiBut *but;
|
|
|
|
int w;
|
|
|
|
|
|
|
|
UI_block_layout_set_current(block, layout);
|
|
|
|
|
|
|
|
if (!name) {
|
|
|
|
name = "";
|
|
|
|
}
|
|
|
|
if (layout->root->type == UI_LAYOUT_MENU && !icon) {
|
|
|
|
icon = ICON_BLANK1;
|
|
|
|
}
|
|
|
|
|
|
|
|
w = ui_text_icon_width(layout, name, icon, 0);
|
|
|
|
|
|
|
|
if (icon && name[0]) {
|
|
|
|
but = uiDefIconTextBut(
|
|
|
|
block, UI_BTYPE_LABEL, 0, icon, name, 0, 0, w, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, NULL);
|
|
|
|
}
|
|
|
|
else if (icon) {
|
|
|
|
but = uiDefIconBut(
|
|
|
|
block, UI_BTYPE_LABEL, 0, icon, 0, 0, w, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, NULL);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
but = uiDefBut(block, UI_BTYPE_LABEL, 0, name, 0, 0, w, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* to compensate for string size padding in ui_text_icon_width,
|
|
|
|
* make text aligned right if the layout is aligned right.
|
|
|
|
*/
|
|
|
|
if (uiLayoutGetAlignment(layout) == UI_LAYOUT_ALIGN_RIGHT) {
|
|
|
|
but->drawflag &= ~UI_BUT_TEXT_LEFT; /* default, needs to be unset */
|
|
|
|
but->drawflag |= UI_BUT_TEXT_RIGHT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Mark as a label inside a listbox. */
|
|
|
|
if (block->flag & UI_BLOCK_LIST_ITEM) {
|
|
|
|
but->flag |= UI_BUT_LIST_ITEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (layout->redalert) {
|
|
|
|
UI_but_flag_enable(but, UI_BUT_REDALERT);
|
|
|
|
}
|
|
|
|
|
|
|
|
return but;
|
Drag and drop 2.5 integration! Finally, slashdot regulars can use
Blender too now! :)
** Drag works as follows:
- drag-able items are defined by the standard interface ui toolkit
- each button can get this feature, via uiButSetDragXXX(but, ...).
There are calls to define drag-able images, ID blocks, RNA paths,
file paths, and so on. By default you drag an icon, exceptionally
an ImBuf
- Drag items are registered centrally in the WM, it allows more drag
items simultaneous too, but not implemented
** Drop works as follows:
- On mouse release, and if drag items exist in the WM, it converts
the mouse event to an EVT_DROP type. This event then gets the full
drag info as customdata
- drop regions are defined with WM_dropbox_add(), similar to keymaps
you can make a "drop map" this way, which become 'drop map handlers'
in the queues.
- next to that the UI kit handles some common button types (like
accepting ID or names) to be catching a drop event too.
- Every "drop box" has two callbacks:
- poll() = check if the event drag data is relevant for this box
- copy() = fill in custom properties in the dropbox to initialize
an operator
- The dropbox handler then calls its standard Operator with its
dropbox properties.
** Currently implemented
Drag items:
- ID icons in browse buttons
- ID icons in context menu of properties region
- ID icons in outliner and rna viewer
- FileBrowser icons
- FileBrowser preview images
Drag-able icons are subtly visualized by making them brighter a bit
on mouse-over. In case the icon is a button or UI element too (most
cases), the drag-able feature will make the item react to
mouse-release instead of mouse-press.
Drop options:
- UI buttons: ID and text buttons (paste name)
- View3d: Object ID drop copies object
- View3d: Material ID drop assigns to object under cursor
- View3d: Image ID drop assigns to object UV texture under cursor
- Sequencer: Path drop will add either Image or Movie strip
- Image window: Path drop will open image
** Drag and drop Notes:
- Dropping into another Blender window (from same application) works
too. I've added code that passes on mousemoves and clicks to other
windows, without activating them though. This does make using multi-window
Blender a bit friendler.
- Dropping a file path to an image, is not the same as dropping an
Image ID... keep this in mind. Sequencer for example wants paths to
be dropped, textures in 3d window wants an Image ID.
- Although drop boxes could be defined via Python, I suggest they're
part of the UI and editor design (= how we want an editor to work), and
not default offered configurable like keymaps.
- At the moment only one item can be dragged at a time. This is for
several reasons.... For one, Blender doesn't have a well defined
uniform way to define "what is selected" (files, outliner items, etc).
Secondly there's potential conflicts on what todo when you drop mixed
drag sets on spots. All undefined stuff... nice for later.
- Example to bypass the above: a collection of images that form a strip,
should be represented in filewindow as a single sequence anyway.
This then will fit well and gets handled neatly by design.
- Another option to check is to allow multiple options per drop... it
could show the operator as a sort of menu, allowing arrow or scrollwheel
to choose. For time being I'd prefer to try to design a singular drop
though, just offer only one drop action per data type on given spots.
- What does work already, but a tad slow, is to use a function that
detects an object (type) under cursor, so a drag item's option can be
further refined (like drop object on object = parent). (disabled)
** More notes
- Added saving for Region layouts (like split points for toolbar)
- Label buttons now handle mouse over
- File list: added full path entry for drop feature.
- Filesel bugfix: wm_operator_exec() got called there and fully handled,
while WM event code tried same. Added new OPERATOR_HANDLED flag for this.
Maybe python needs it too?
- Cocoa: added window move event, so multi-win setups work OK (didnt save).
- Interface_handlers.c: removed win->active
- Severe area copy bug: area handlers were not set to NULL
- Filesel bugfix: next/prev folder list was not copied on area copies
** Leftover todos
- Cocoa windows seem to hang on cases still... needs check
- Cocoa 'draw overlap' swap doesn't work
- Cocoa window loses focus permanently on using Spotlight
(for these reasons, makefile building has Carbon as default atm)
- ListView templates in UI cannot become dragged yet, needs review...
it consists of two overlapping UI elements, preventing handling icon clicks.
- There's already Ghost library code to handle dropping from OS
into Blender window. I've noticed this code is unfinished for Macs, but
seems to be complete for Windows. Needs test... currently, an external
drop event will print in console when succesfully delivered to Blender's WM.
2010-01-26 18:18:21 +00:00
|
|
|
}
|
|
|
|
|
2020-02-28 13:51:40 +01:00
|
|
|
void uiItemL_ex(
|
|
|
|
uiLayout *layout, const char *name, int icon, const bool highlight, const bool redalert)
|
|
|
|
{
|
|
|
|
uiBut *but = uiItemL_(layout, name, icon);
|
|
|
|
|
|
|
|
if (highlight) {
|
|
|
|
/* TODO: add another flag for this. */
|
|
|
|
UI_but_flag_enable(but, UI_SELECT_DRAW);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (redalert) {
|
|
|
|
UI_but_flag_enable(but, UI_BUT_REDALERT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-17 09:45:45 +00:00
|
|
|
void uiItemL(uiLayout *layout, const char *name, int icon)
|
Drag and drop 2.5 integration! Finally, slashdot regulars can use
Blender too now! :)
** Drag works as follows:
- drag-able items are defined by the standard interface ui toolkit
- each button can get this feature, via uiButSetDragXXX(but, ...).
There are calls to define drag-able images, ID blocks, RNA paths,
file paths, and so on. By default you drag an icon, exceptionally
an ImBuf
- Drag items are registered centrally in the WM, it allows more drag
items simultaneous too, but not implemented
** Drop works as follows:
- On mouse release, and if drag items exist in the WM, it converts
the mouse event to an EVT_DROP type. This event then gets the full
drag info as customdata
- drop regions are defined with WM_dropbox_add(), similar to keymaps
you can make a "drop map" this way, which become 'drop map handlers'
in the queues.
- next to that the UI kit handles some common button types (like
accepting ID or names) to be catching a drop event too.
- Every "drop box" has two callbacks:
- poll() = check if the event drag data is relevant for this box
- copy() = fill in custom properties in the dropbox to initialize
an operator
- The dropbox handler then calls its standard Operator with its
dropbox properties.
** Currently implemented
Drag items:
- ID icons in browse buttons
- ID icons in context menu of properties region
- ID icons in outliner and rna viewer
- FileBrowser icons
- FileBrowser preview images
Drag-able icons are subtly visualized by making them brighter a bit
on mouse-over. In case the icon is a button or UI element too (most
cases), the drag-able feature will make the item react to
mouse-release instead of mouse-press.
Drop options:
- UI buttons: ID and text buttons (paste name)
- View3d: Object ID drop copies object
- View3d: Material ID drop assigns to object under cursor
- View3d: Image ID drop assigns to object UV texture under cursor
- Sequencer: Path drop will add either Image or Movie strip
- Image window: Path drop will open image
** Drag and drop Notes:
- Dropping into another Blender window (from same application) works
too. I've added code that passes on mousemoves and clicks to other
windows, without activating them though. This does make using multi-window
Blender a bit friendler.
- Dropping a file path to an image, is not the same as dropping an
Image ID... keep this in mind. Sequencer for example wants paths to
be dropped, textures in 3d window wants an Image ID.
- Although drop boxes could be defined via Python, I suggest they're
part of the UI and editor design (= how we want an editor to work), and
not default offered configurable like keymaps.
- At the moment only one item can be dragged at a time. This is for
several reasons.... For one, Blender doesn't have a well defined
uniform way to define "what is selected" (files, outliner items, etc).
Secondly there's potential conflicts on what todo when you drop mixed
drag sets on spots. All undefined stuff... nice for later.
- Example to bypass the above: a collection of images that form a strip,
should be represented in filewindow as a single sequence anyway.
This then will fit well and gets handled neatly by design.
- Another option to check is to allow multiple options per drop... it
could show the operator as a sort of menu, allowing arrow or scrollwheel
to choose. For time being I'd prefer to try to design a singular drop
though, just offer only one drop action per data type on given spots.
- What does work already, but a tad slow, is to use a function that
detects an object (type) under cursor, so a drag item's option can be
further refined (like drop object on object = parent). (disabled)
** More notes
- Added saving for Region layouts (like split points for toolbar)
- Label buttons now handle mouse over
- File list: added full path entry for drop feature.
- Filesel bugfix: wm_operator_exec() got called there and fully handled,
while WM event code tried same. Added new OPERATOR_HANDLED flag for this.
Maybe python needs it too?
- Cocoa: added window move event, so multi-win setups work OK (didnt save).
- Interface_handlers.c: removed win->active
- Severe area copy bug: area handlers were not set to NULL
- Filesel bugfix: next/prev folder list was not copied on area copies
** Leftover todos
- Cocoa windows seem to hang on cases still... needs check
- Cocoa 'draw overlap' swap doesn't work
- Cocoa window loses focus permanently on using Spotlight
(for these reasons, makefile building has Carbon as default atm)
- ListView templates in UI cannot become dragged yet, needs review...
it consists of two overlapping UI elements, preventing handling icon clicks.
- There's already Ghost library code to handle dropping from OS
into Blender window. I've noticed this code is unfinished for Macs, but
seems to be complete for Windows. Needs test... currently, an external
drop event will print in console when succesfully delivered to Blender's WM.
2010-01-26 18:18:21 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiItemL_(layout, name, icon);
|
Drag and drop 2.5 integration! Finally, slashdot regulars can use
Blender too now! :)
** Drag works as follows:
- drag-able items are defined by the standard interface ui toolkit
- each button can get this feature, via uiButSetDragXXX(but, ...).
There are calls to define drag-able images, ID blocks, RNA paths,
file paths, and so on. By default you drag an icon, exceptionally
an ImBuf
- Drag items are registered centrally in the WM, it allows more drag
items simultaneous too, but not implemented
** Drop works as follows:
- On mouse release, and if drag items exist in the WM, it converts
the mouse event to an EVT_DROP type. This event then gets the full
drag info as customdata
- drop regions are defined with WM_dropbox_add(), similar to keymaps
you can make a "drop map" this way, which become 'drop map handlers'
in the queues.
- next to that the UI kit handles some common button types (like
accepting ID or names) to be catching a drop event too.
- Every "drop box" has two callbacks:
- poll() = check if the event drag data is relevant for this box
- copy() = fill in custom properties in the dropbox to initialize
an operator
- The dropbox handler then calls its standard Operator with its
dropbox properties.
** Currently implemented
Drag items:
- ID icons in browse buttons
- ID icons in context menu of properties region
- ID icons in outliner and rna viewer
- FileBrowser icons
- FileBrowser preview images
Drag-able icons are subtly visualized by making them brighter a bit
on mouse-over. In case the icon is a button or UI element too (most
cases), the drag-able feature will make the item react to
mouse-release instead of mouse-press.
Drop options:
- UI buttons: ID and text buttons (paste name)
- View3d: Object ID drop copies object
- View3d: Material ID drop assigns to object under cursor
- View3d: Image ID drop assigns to object UV texture under cursor
- Sequencer: Path drop will add either Image or Movie strip
- Image window: Path drop will open image
** Drag and drop Notes:
- Dropping into another Blender window (from same application) works
too. I've added code that passes on mousemoves and clicks to other
windows, without activating them though. This does make using multi-window
Blender a bit friendler.
- Dropping a file path to an image, is not the same as dropping an
Image ID... keep this in mind. Sequencer for example wants paths to
be dropped, textures in 3d window wants an Image ID.
- Although drop boxes could be defined via Python, I suggest they're
part of the UI and editor design (= how we want an editor to work), and
not default offered configurable like keymaps.
- At the moment only one item can be dragged at a time. This is for
several reasons.... For one, Blender doesn't have a well defined
uniform way to define "what is selected" (files, outliner items, etc).
Secondly there's potential conflicts on what todo when you drop mixed
drag sets on spots. All undefined stuff... nice for later.
- Example to bypass the above: a collection of images that form a strip,
should be represented in filewindow as a single sequence anyway.
This then will fit well and gets handled neatly by design.
- Another option to check is to allow multiple options per drop... it
could show the operator as a sort of menu, allowing arrow or scrollwheel
to choose. For time being I'd prefer to try to design a singular drop
though, just offer only one drop action per data type on given spots.
- What does work already, but a tad slow, is to use a function that
detects an object (type) under cursor, so a drag item's option can be
further refined (like drop object on object = parent). (disabled)
** More notes
- Added saving for Region layouts (like split points for toolbar)
- Label buttons now handle mouse over
- File list: added full path entry for drop feature.
- Filesel bugfix: wm_operator_exec() got called there and fully handled,
while WM event code tried same. Added new OPERATOR_HANDLED flag for this.
Maybe python needs it too?
- Cocoa: added window move event, so multi-win setups work OK (didnt save).
- Interface_handlers.c: removed win->active
- Severe area copy bug: area handlers were not set to NULL
- Filesel bugfix: next/prev folder list was not copied on area copies
** Leftover todos
- Cocoa windows seem to hang on cases still... needs check
- Cocoa 'draw overlap' swap doesn't work
- Cocoa window loses focus permanently on using Spotlight
(for these reasons, makefile building has Carbon as default atm)
- ListView templates in UI cannot become dragged yet, needs review...
it consists of two overlapping UI elements, preventing handling icon clicks.
- There's already Ghost library code to handle dropping from OS
into Blender window. I've noticed this code is unfinished for Macs, but
seems to be complete for Windows. Needs test... currently, an external
drop event will print in console when succesfully delivered to Blender's WM.
2010-01-26 18:18:21 +00:00
|
|
|
}
|
|
|
|
|
2019-11-25 19:41:30 +01:00
|
|
|
/**
|
2020-04-27 16:43:36 +02:00
|
|
|
* Normally, we handle the split layout in #uiItemFullR(), but there are other cases where the
|
|
|
|
* logic is needed. Ideally, #uiItemFullR() could just call this, but it currently has too many
|
|
|
|
* special needs.
|
2019-11-25 19:41:30 +01:00
|
|
|
*/
|
2020-04-27 16:43:36 +02:00
|
|
|
uiPropertySplitWrapper uiItemPropertySplitWrapperCreate(uiLayout *parent_layout)
|
2019-11-25 19:41:30 +01:00
|
|
|
{
|
2020-04-27 16:43:36 +02:00
|
|
|
uiPropertySplitWrapper split_wrapper = {NULL};
|
|
|
|
|
|
|
|
uiLayout *layout_row = uiLayoutRow(parent_layout, true);
|
|
|
|
uiLayout *layout_split = uiLayoutSplit(layout_row, UI_ITEM_PROP_SEP_DIVIDE, true);
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
|
2020-04-27 16:43:36 +02:00
|
|
|
layout_split->space = 0;
|
|
|
|
split_wrapper.label_column = uiLayoutColumn(layout_split, true);
|
|
|
|
split_wrapper.label_column->alignment = UI_LAYOUT_ALIGN_RIGHT;
|
|
|
|
split_wrapper.property_row = ui_item_prop_split_layout_hack(parent_layout, layout_split);
|
|
|
|
split_wrapper.decorate_column = uiLayoutColumn(layout_row, true);
|
2019-11-25 19:41:30 +01:00
|
|
|
|
2020-04-27 16:43:36 +02:00
|
|
|
return split_wrapper;
|
|
|
|
}
|
2019-11-25 19:41:30 +01:00
|
|
|
|
2020-04-27 16:43:36 +02:00
|
|
|
/*
|
|
|
|
* Helper to add a label and creates a property split layout if needed.
|
|
|
|
*/
|
|
|
|
uiLayout *uiItemL_respect_property_split(uiLayout *layout, const char *text, int icon)
|
|
|
|
{
|
|
|
|
if (layout->item.flag & UI_ITEM_PROP_SEP) {
|
|
|
|
uiBlock *block = uiLayoutGetBlock(layout);
|
|
|
|
uiPropertySplitWrapper split_wrapper = uiItemPropertySplitWrapperCreate(layout);
|
|
|
|
/* Further items added to 'layout' will automatically be added to split_wrapper.property_row */
|
2019-11-25 19:41:30 +01:00
|
|
|
|
2020-04-27 16:43:36 +02:00
|
|
|
uiItemL_(split_wrapper.label_column, text, icon);
|
|
|
|
UI_block_layout_set_current(block, split_wrapper.property_row);
|
2020-04-05 14:19:24 +02:00
|
|
|
|
2020-04-27 16:43:36 +02:00
|
|
|
return split_wrapper.decorate_column;
|
2019-11-25 19:41:30 +01:00
|
|
|
}
|
|
|
|
|
2020-07-03 14:20:10 +02:00
|
|
|
char namestr[UI_MAX_NAME_STR];
|
|
|
|
if (text) {
|
|
|
|
text = ui_item_name_add_colon(text, namestr);
|
2019-11-25 19:41:30 +01:00
|
|
|
}
|
2020-07-03 14:20:10 +02:00
|
|
|
uiItemL_(layout, text, icon);
|
|
|
|
|
|
|
|
return layout;
|
2019-11-25 19:41:30 +01:00
|
|
|
}
|
|
|
|
|
2010-12-03 17:05:21 +00:00
|
|
|
void uiItemLDrag(uiLayout *layout, PointerRNA *ptr, const char *name, int icon)
|
Drag and drop 2.5 integration! Finally, slashdot regulars can use
Blender too now! :)
** Drag works as follows:
- drag-able items are defined by the standard interface ui toolkit
- each button can get this feature, via uiButSetDragXXX(but, ...).
There are calls to define drag-able images, ID blocks, RNA paths,
file paths, and so on. By default you drag an icon, exceptionally
an ImBuf
- Drag items are registered centrally in the WM, it allows more drag
items simultaneous too, but not implemented
** Drop works as follows:
- On mouse release, and if drag items exist in the WM, it converts
the mouse event to an EVT_DROP type. This event then gets the full
drag info as customdata
- drop regions are defined with WM_dropbox_add(), similar to keymaps
you can make a "drop map" this way, which become 'drop map handlers'
in the queues.
- next to that the UI kit handles some common button types (like
accepting ID or names) to be catching a drop event too.
- Every "drop box" has two callbacks:
- poll() = check if the event drag data is relevant for this box
- copy() = fill in custom properties in the dropbox to initialize
an operator
- The dropbox handler then calls its standard Operator with its
dropbox properties.
** Currently implemented
Drag items:
- ID icons in browse buttons
- ID icons in context menu of properties region
- ID icons in outliner and rna viewer
- FileBrowser icons
- FileBrowser preview images
Drag-able icons are subtly visualized by making them brighter a bit
on mouse-over. In case the icon is a button or UI element too (most
cases), the drag-able feature will make the item react to
mouse-release instead of mouse-press.
Drop options:
- UI buttons: ID and text buttons (paste name)
- View3d: Object ID drop copies object
- View3d: Material ID drop assigns to object under cursor
- View3d: Image ID drop assigns to object UV texture under cursor
- Sequencer: Path drop will add either Image or Movie strip
- Image window: Path drop will open image
** Drag and drop Notes:
- Dropping into another Blender window (from same application) works
too. I've added code that passes on mousemoves and clicks to other
windows, without activating them though. This does make using multi-window
Blender a bit friendler.
- Dropping a file path to an image, is not the same as dropping an
Image ID... keep this in mind. Sequencer for example wants paths to
be dropped, textures in 3d window wants an Image ID.
- Although drop boxes could be defined via Python, I suggest they're
part of the UI and editor design (= how we want an editor to work), and
not default offered configurable like keymaps.
- At the moment only one item can be dragged at a time. This is for
several reasons.... For one, Blender doesn't have a well defined
uniform way to define "what is selected" (files, outliner items, etc).
Secondly there's potential conflicts on what todo when you drop mixed
drag sets on spots. All undefined stuff... nice for later.
- Example to bypass the above: a collection of images that form a strip,
should be represented in filewindow as a single sequence anyway.
This then will fit well and gets handled neatly by design.
- Another option to check is to allow multiple options per drop... it
could show the operator as a sort of menu, allowing arrow or scrollwheel
to choose. For time being I'd prefer to try to design a singular drop
though, just offer only one drop action per data type on given spots.
- What does work already, but a tad slow, is to use a function that
detects an object (type) under cursor, so a drag item's option can be
further refined (like drop object on object = parent). (disabled)
** More notes
- Added saving for Region layouts (like split points for toolbar)
- Label buttons now handle mouse over
- File list: added full path entry for drop feature.
- Filesel bugfix: wm_operator_exec() got called there and fully handled,
while WM event code tried same. Added new OPERATOR_HANDLED flag for this.
Maybe python needs it too?
- Cocoa: added window move event, so multi-win setups work OK (didnt save).
- Interface_handlers.c: removed win->active
- Severe area copy bug: area handlers were not set to NULL
- Filesel bugfix: next/prev folder list was not copied on area copies
** Leftover todos
- Cocoa windows seem to hang on cases still... needs check
- Cocoa 'draw overlap' swap doesn't work
- Cocoa window loses focus permanently on using Spotlight
(for these reasons, makefile building has Carbon as default atm)
- ListView templates in UI cannot become dragged yet, needs review...
it consists of two overlapping UI elements, preventing handling icon clicks.
- There's already Ghost library code to handle dropping from OS
into Blender window. I've noticed this code is unfinished for Macs, but
seems to be complete for Windows. Needs test... currently, an external
drop event will print in console when succesfully delivered to Blender's WM.
2010-01-26 18:18:21 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiBut *but = uiItemL_(layout, name, icon);
|
Drag and drop 2.5 integration! Finally, slashdot regulars can use
Blender too now! :)
** Drag works as follows:
- drag-able items are defined by the standard interface ui toolkit
- each button can get this feature, via uiButSetDragXXX(but, ...).
There are calls to define drag-able images, ID blocks, RNA paths,
file paths, and so on. By default you drag an icon, exceptionally
an ImBuf
- Drag items are registered centrally in the WM, it allows more drag
items simultaneous too, but not implemented
** Drop works as follows:
- On mouse release, and if drag items exist in the WM, it converts
the mouse event to an EVT_DROP type. This event then gets the full
drag info as customdata
- drop regions are defined with WM_dropbox_add(), similar to keymaps
you can make a "drop map" this way, which become 'drop map handlers'
in the queues.
- next to that the UI kit handles some common button types (like
accepting ID or names) to be catching a drop event too.
- Every "drop box" has two callbacks:
- poll() = check if the event drag data is relevant for this box
- copy() = fill in custom properties in the dropbox to initialize
an operator
- The dropbox handler then calls its standard Operator with its
dropbox properties.
** Currently implemented
Drag items:
- ID icons in browse buttons
- ID icons in context menu of properties region
- ID icons in outliner and rna viewer
- FileBrowser icons
- FileBrowser preview images
Drag-able icons are subtly visualized by making them brighter a bit
on mouse-over. In case the icon is a button or UI element too (most
cases), the drag-able feature will make the item react to
mouse-release instead of mouse-press.
Drop options:
- UI buttons: ID and text buttons (paste name)
- View3d: Object ID drop copies object
- View3d: Material ID drop assigns to object under cursor
- View3d: Image ID drop assigns to object UV texture under cursor
- Sequencer: Path drop will add either Image or Movie strip
- Image window: Path drop will open image
** Drag and drop Notes:
- Dropping into another Blender window (from same application) works
too. I've added code that passes on mousemoves and clicks to other
windows, without activating them though. This does make using multi-window
Blender a bit friendler.
- Dropping a file path to an image, is not the same as dropping an
Image ID... keep this in mind. Sequencer for example wants paths to
be dropped, textures in 3d window wants an Image ID.
- Although drop boxes could be defined via Python, I suggest they're
part of the UI and editor design (= how we want an editor to work), and
not default offered configurable like keymaps.
- At the moment only one item can be dragged at a time. This is for
several reasons.... For one, Blender doesn't have a well defined
uniform way to define "what is selected" (files, outliner items, etc).
Secondly there's potential conflicts on what todo when you drop mixed
drag sets on spots. All undefined stuff... nice for later.
- Example to bypass the above: a collection of images that form a strip,
should be represented in filewindow as a single sequence anyway.
This then will fit well and gets handled neatly by design.
- Another option to check is to allow multiple options per drop... it
could show the operator as a sort of menu, allowing arrow or scrollwheel
to choose. For time being I'd prefer to try to design a singular drop
though, just offer only one drop action per data type on given spots.
- What does work already, but a tad slow, is to use a function that
detects an object (type) under cursor, so a drag item's option can be
further refined (like drop object on object = parent). (disabled)
** More notes
- Added saving for Region layouts (like split points for toolbar)
- Label buttons now handle mouse over
- File list: added full path entry for drop feature.
- Filesel bugfix: wm_operator_exec() got called there and fully handled,
while WM event code tried same. Added new OPERATOR_HANDLED flag for this.
Maybe python needs it too?
- Cocoa: added window move event, so multi-win setups work OK (didnt save).
- Interface_handlers.c: removed win->active
- Severe area copy bug: area handlers were not set to NULL
- Filesel bugfix: next/prev folder list was not copied on area copies
** Leftover todos
- Cocoa windows seem to hang on cases still... needs check
- Cocoa 'draw overlap' swap doesn't work
- Cocoa window loses focus permanently on using Spotlight
(for these reasons, makefile building has Carbon as default atm)
- ListView templates in UI cannot become dragged yet, needs review...
it consists of two overlapping UI elements, preventing handling icon clicks.
- There's already Ghost library code to handle dropping from OS
into Blender window. I've noticed this code is unfinished for Macs, but
seems to be complete for Windows. Needs test... currently, an external
drop event will print in console when succesfully delivered to Blender's WM.
2010-01-26 18:18:21 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ptr && ptr->type) {
|
|
|
|
if (RNA_struct_is_ID(ptr->type)) {
|
2019-08-23 09:52:12 +02:00
|
|
|
UI_but_drag_set_id(but, ptr->owner_id);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* value item */
|
2010-12-03 17:05:21 +00:00
|
|
|
void uiItemV(uiLayout *layout, const char *name, int icon, int argval)
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* label */
|
|
|
|
uiBlock *block = layout->root->block;
|
|
|
|
int *retvalue = (block->handle) ? &block->handle->retvalue : NULL;
|
|
|
|
int w;
|
|
|
|
|
|
|
|
UI_block_layout_set_current(block, layout);
|
|
|
|
|
|
|
|
if (!name) {
|
|
|
|
name = "";
|
|
|
|
}
|
|
|
|
if (layout->root->type == UI_LAYOUT_MENU && !icon) {
|
|
|
|
icon = ICON_BLANK1;
|
|
|
|
}
|
|
|
|
|
|
|
|
w = ui_text_icon_width(layout, name, icon, 0);
|
|
|
|
|
|
|
|
if (icon && name[0]) {
|
|
|
|
uiDefIconTextButI(block,
|
|
|
|
UI_BTYPE_BUT,
|
|
|
|
argval,
|
|
|
|
icon,
|
|
|
|
name,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
w,
|
|
|
|
UI_UNIT_Y,
|
|
|
|
retvalue,
|
|
|
|
0.0,
|
|
|
|
0.0,
|
|
|
|
0,
|
|
|
|
-1,
|
|
|
|
"");
|
|
|
|
}
|
|
|
|
else if (icon) {
|
|
|
|
uiDefIconButI(
|
|
|
|
block, UI_BTYPE_BUT, argval, icon, 0, 0, w, UI_UNIT_Y, retvalue, 0.0, 0.0, 0, -1, "");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
uiDefButI(
|
|
|
|
block, UI_BTYPE_BUT, argval, name, 0, 0, w, UI_UNIT_Y, retvalue, 0.0, 0.0, 0, -1, "");
|
|
|
|
}
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* separator item */
|
2018-11-02 16:32:31 +01:00
|
|
|
void uiItemS_ex(uiLayout *layout, float factor)
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiBlock *block = layout->root->block;
|
|
|
|
bool is_menu = ui_block_is_menu(block);
|
2019-04-25 14:40:53 +02:00
|
|
|
if (is_menu && !UI_block_can_add_separator(block)) {
|
|
|
|
return;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
int space = (is_menu) ? 0.45f * UI_UNIT_X : 0.3f * UI_UNIT_X;
|
|
|
|
space *= factor;
|
|
|
|
|
|
|
|
UI_block_layout_set_current(block, layout);
|
|
|
|
uiDefBut(block,
|
|
|
|
(is_menu) ? UI_BTYPE_SEPR_LINE : UI_BTYPE_SEPR,
|
|
|
|
0,
|
|
|
|
"",
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
space,
|
|
|
|
space,
|
|
|
|
NULL,
|
|
|
|
0.0,
|
|
|
|
0.0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
"");
|
2009-04-22 18:39:44 +00:00
|
|
|
}
|
|
|
|
|
2018-11-02 16:32:31 +01:00
|
|
|
/* separator item */
|
|
|
|
void uiItemS(uiLayout *layout)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiItemS_ex(layout, 1.0f);
|
2018-11-02 16:32:31 +01:00
|
|
|
}
|
|
|
|
|
2018-06-11 14:33:53 +02:00
|
|
|
/* Flexible spacing. */
|
|
|
|
void uiItemSpacer(uiLayout *layout)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiBlock *block = layout->root->block;
|
|
|
|
const bool is_popup = ui_block_is_popup_any(block);
|
|
|
|
|
|
|
|
if (is_popup) {
|
|
|
|
printf("Error: separator_spacer() not supported in popups.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (block->direction & UI_DIR_RIGHT) {
|
|
|
|
printf("Error: separator_spacer() only supported in horizontal blocks.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
UI_block_layout_set_current(block, layout);
|
|
|
|
uiDefBut(block,
|
|
|
|
UI_BTYPE_SEPR_SPACER,
|
|
|
|
0,
|
|
|
|
"",
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0.3f * UI_UNIT_X,
|
|
|
|
UI_UNIT_Y,
|
|
|
|
NULL,
|
|
|
|
0.0,
|
|
|
|
0.0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
"");
|
2018-06-11 14:33:53 +02:00
|
|
|
}
|
|
|
|
|
2009-04-22 18:39:44 +00:00
|
|
|
/* level items */
|
2010-11-17 09:45:45 +00:00
|
|
|
void uiItemMenuF(uiLayout *layout, const char *name, int icon, uiMenuCreateFunc func, void *arg)
|
2009-04-22 18:39:44 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (!func) {
|
|
|
|
return;
|
|
|
|
}
|
2009-04-22 18:39:44 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ui_item_menu(layout, name, icon, func, arg, NULL, "", false);
|
2009-04-22 18:39:44 +00:00
|
|
|
}
|
|
|
|
|
2018-10-30 10:46:29 +11:00
|
|
|
/**
|
|
|
|
* Version of #uiItemMenuF that free's `argN`.
|
|
|
|
*/
|
|
|
|
void uiItemMenuFN(uiLayout *layout, const char *name, int icon, uiMenuCreateFunc func, void *argN)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (!func) {
|
|
|
|
return;
|
|
|
|
}
|
2018-10-30 10:46:29 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Second 'argN' only ensures it gets freed. */
|
|
|
|
ui_item_menu(layout, name, icon, func, argN, argN, "", false);
|
2018-10-30 10:46:29 +11:00
|
|
|
}
|
|
|
|
|
2009-04-22 18:39:44 +00:00
|
|
|
typedef struct MenuItemLevel {
|
2019-04-17 06:17:24 +02:00
|
|
|
int opcontext;
|
|
|
|
/* don't use pointers to the strings because python can dynamically
|
|
|
|
* allocate strings and free before the menu draws, see [#27304] */
|
|
|
|
char opname[OP_MAX_TYPENAME];
|
|
|
|
char propname[MAX_IDPROP_NAME];
|
|
|
|
PointerRNA rnapoin;
|
2009-04-22 18:39:44 +00:00
|
|
|
} MenuItemLevel;
|
|
|
|
|
2010-10-14 12:24:08 +00:00
|
|
|
static void menu_item_enum_opname_menu(bContext *UNUSED(C), uiLayout *layout, void *arg)
|
2009-04-22 18:39:44 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
MenuItemLevel *lvl = (MenuItemLevel *)(((uiBut *)arg)->func_argN);
|
2009-04-22 18:39:44 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
uiLayoutSetOperatorContext(layout, lvl->opcontext);
|
|
|
|
uiItemsEnumO(layout, lvl->opname, lvl->propname);
|
2014-02-12 10:29:15 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
layout->root->block->flag |= UI_BLOCK_IS_FLIP;
|
2014-11-16 17:40:46 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* override default, needed since this was assumed pre 2.70 */
|
|
|
|
UI_block_direction_set(layout->root->block, UI_DIR_DOWN);
|
2009-04-22 18:39:44 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void uiItemMenuEnumO_ptr(uiLayout *layout,
|
|
|
|
bContext *C,
|
|
|
|
wmOperatorType *ot,
|
|
|
|
const char *propname,
|
|
|
|
const char *name,
|
|
|
|
int icon)
|
2009-04-22 18:39:44 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
MenuItemLevel *lvl;
|
|
|
|
uiBut *but;
|
2009-04-22 18:39:44 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Caller must check */
|
|
|
|
BLI_assert(ot->srna != NULL);
|
2009-04-22 18:39:44 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (name == NULL) {
|
2019-06-04 15:50:15 +02:00
|
|
|
name = WM_operatortype_name(ot, NULL);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2013-05-10 23:41:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (layout->root->type == UI_LAYOUT_MENU && !icon) {
|
|
|
|
icon = ICON_BLANK1;
|
|
|
|
}
|
2009-04-22 18:39:44 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
lvl = MEM_callocN(sizeof(MenuItemLevel), "MenuItemLevel");
|
|
|
|
BLI_strncpy(lvl->opname, ot->idname, sizeof(lvl->opname));
|
|
|
|
BLI_strncpy(lvl->propname, propname, sizeof(lvl->propname));
|
|
|
|
lvl->opcontext = layout->root->opcontext;
|
2009-04-22 18:39:44 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
but = ui_item_menu(layout,
|
|
|
|
name,
|
|
|
|
icon,
|
|
|
|
menu_item_enum_opname_menu,
|
|
|
|
NULL,
|
|
|
|
lvl,
|
|
|
|
RNA_struct_ui_description(ot->srna),
|
|
|
|
true);
|
2014-05-06 18:11:28 +10:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* add hotkey here, lower UI code can't detect it */
|
|
|
|
if ((layout->root->block->flag & UI_BLOCK_LOOP) && (ot->prop && ot->invoke)) {
|
|
|
|
char keybuf[128];
|
|
|
|
if (WM_key_event_operator_string(
|
|
|
|
C, ot->idname, layout->root->opcontext, NULL, false, keybuf, sizeof(keybuf))) {
|
|
|
|
ui_but_add_shortcut(but, keybuf, false);
|
|
|
|
}
|
|
|
|
}
|
2009-04-22 18:39:44 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void uiItemMenuEnumO(uiLayout *layout,
|
|
|
|
bContext *C,
|
|
|
|
const char *opname,
|
|
|
|
const char *propname,
|
|
|
|
const char *name,
|
|
|
|
int icon)
|
2017-10-31 12:44:41 +11:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
wmOperatorType *ot = WM_operatortype_find(opname, 0); /* print error next */
|
2017-10-31 12:44:41 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
UI_OPERATOR_ERROR_RET(ot, opname, return );
|
2017-10-31 12:44:41 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (!ot->srna) {
|
|
|
|
ui_item_disabled(layout, opname);
|
|
|
|
RNA_warning("operator missing srna '%s'", opname);
|
|
|
|
return;
|
|
|
|
}
|
2017-10-31 12:44:41 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
uiItemMenuEnumO_ptr(layout, C, ot, propname, name, icon);
|
2017-10-31 12:44:41 +11:00
|
|
|
}
|
|
|
|
|
2010-10-14 12:24:08 +00:00
|
|
|
static void menu_item_enum_rna_menu(bContext *UNUSED(C), uiLayout *layout, void *arg)
|
2009-04-22 18:39:44 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
MenuItemLevel *lvl = (MenuItemLevel *)(((uiBut *)arg)->func_argN);
|
2009-04-22 18:39:44 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
uiLayoutSetOperatorContext(layout, lvl->opcontext);
|
|
|
|
uiItemsEnumR(layout, &lvl->rnapoin, lvl->propname);
|
|
|
|
layout->root->block->flag |= UI_BLOCK_IS_FLIP;
|
2009-04-22 18:39:44 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void uiItemMenuEnumR_prop(
|
|
|
|
uiLayout *layout, struct PointerRNA *ptr, PropertyRNA *prop, const char *name, int icon)
|
2009-04-22 18:39:44 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
MenuItemLevel *lvl;
|
2009-04-22 18:39:44 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (!name) {
|
|
|
|
name = RNA_property_ui_name(prop);
|
|
|
|
}
|
|
|
|
if (layout->root->type == UI_LAYOUT_MENU && !icon) {
|
|
|
|
icon = ICON_BLANK1;
|
|
|
|
}
|
2009-04-22 18:39:44 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
lvl = MEM_callocN(sizeof(MenuItemLevel), "MenuItemLevel");
|
|
|
|
lvl->rnapoin = *ptr;
|
|
|
|
BLI_strncpy(lvl->propname, RNA_property_identifier(prop), sizeof(lvl->propname));
|
|
|
|
lvl->opcontext = layout->root->opcontext;
|
2009-04-22 18:39:44 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ui_item_menu(layout,
|
|
|
|
name,
|
|
|
|
icon,
|
|
|
|
menu_item_enum_rna_menu,
|
|
|
|
NULL,
|
|
|
|
lvl,
|
|
|
|
RNA_property_description(prop),
|
|
|
|
false);
|
2009-04-22 18:39:44 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void uiItemMenuEnumR(
|
|
|
|
uiLayout *layout, struct PointerRNA *ptr, const char *propname, const char *name, int icon)
|
2014-11-24 21:03:00 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PropertyRNA *prop;
|
2014-11-24 21:03:00 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
prop = RNA_struct_find_property(ptr, propname);
|
|
|
|
if (!prop) {
|
|
|
|
ui_item_disabled(layout, propname);
|
|
|
|
RNA_warning("property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
|
|
|
|
return;
|
|
|
|
}
|
2014-11-24 21:03:00 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
uiItemMenuEnumR_prop(layout, ptr, prop, name, icon);
|
2014-11-24 21:03:00 +01:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void uiItemTabsEnumR_prop(
|
|
|
|
uiLayout *layout, bContext *C, PointerRNA *ptr, PropertyRNA *prop, bool icon_only)
|
2018-10-29 21:20:58 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiBlock *block = layout->root->block;
|
2018-10-29 21:20:58 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
UI_block_layout_set_current(block, layout);
|
|
|
|
ui_item_enum_expand_tabs(layout, C, block, ptr, prop, NULL, UI_UNIT_Y, icon_only);
|
2018-10-29 21:20:58 +01:00
|
|
|
}
|
|
|
|
|
2019-09-06 16:12:47 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Layout Items
|
|
|
|
* \{ */
|
2009-03-13 13:38:41 +00:00
|
|
|
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
/* single-row layout */
|
|
|
|
static void ui_litem_estimate_row(uiLayout *litem)
|
2009-04-16 12:17:58 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiItem *item;
|
|
|
|
int itemw, itemh;
|
|
|
|
bool min_size_flag = true;
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
litem->w = 0;
|
|
|
|
litem->h = 0;
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (item = litem->items.first; item; item = item->next) {
|
|
|
|
ui_item_size(item, &itemw, &itemh);
|
2009-04-16 12:17:58 +00:00
|
|
|
|
2019-09-19 16:14:47 +02:00
|
|
|
min_size_flag = min_size_flag && (item->flag & UI_ITEM_FIXED_SIZE);
|
2017-01-10 16:19:10 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
litem->w += itemw;
|
|
|
|
litem->h = MAX2(itemh, litem->h);
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (item->next) {
|
|
|
|
litem->w += litem->space;
|
|
|
|
}
|
|
|
|
}
|
2017-01-10 16:19:10 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (min_size_flag) {
|
2019-09-19 16:14:47 +02:00
|
|
|
litem->item.flag |= UI_ITEM_FIXED_SIZE;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
}
|
|
|
|
|
2009-06-03 00:04:48 +00:00
|
|
|
static int ui_litem_min_width(int itemw)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return MIN2(2 * UI_UNIT_X, itemw);
|
2009-06-03 00:04:48 +00:00
|
|
|
}
|
|
|
|
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
static void ui_litem_layout_row(uiLayout *litem)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiItem *item, *last_free_item = NULL;
|
|
|
|
int x, y, w, tot, totw, neww, newtotw, itemw, minw, itemh, offset;
|
|
|
|
int fixedw, freew, fixedx, freex, flag = 0, lastw = 0;
|
|
|
|
float extra_pixel;
|
|
|
|
|
|
|
|
/* x = litem->x; */ /* UNUSED */
|
|
|
|
y = litem->y;
|
|
|
|
w = litem->w;
|
|
|
|
totw = 0;
|
|
|
|
tot = 0;
|
|
|
|
|
|
|
|
for (item = litem->items.first; item; item = item->next) {
|
|
|
|
ui_item_size(item, &itemw, &itemh);
|
|
|
|
totw += itemw;
|
|
|
|
tot++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (totw == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (w != 0) {
|
|
|
|
w -= (tot - 1) * litem->space;
|
|
|
|
}
|
|
|
|
fixedw = 0;
|
|
|
|
|
|
|
|
/* keep clamping items to fixed minimum size until all are done */
|
|
|
|
do {
|
|
|
|
freew = 0;
|
|
|
|
x = 0;
|
|
|
|
flag = 0;
|
|
|
|
newtotw = totw;
|
|
|
|
extra_pixel = 0.0f;
|
|
|
|
|
|
|
|
for (item = litem->items.first; item; item = item->next) {
|
2019-09-19 16:14:47 +02:00
|
|
|
if (item->flag & UI_ITEM_AUTO_FIXED_SIZE) {
|
2019-04-17 06:17:24 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ui_item_size(item, &itemw, &itemh);
|
|
|
|
minw = ui_litem_min_width(itemw);
|
|
|
|
|
|
|
|
if (w - lastw > 0) {
|
|
|
|
neww = ui_item_fit(itemw, x, totw, w - lastw, !item->next, litem->alignment, &extra_pixel);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
neww = 0; /* no space left, all will need clamping to minimum size */
|
|
|
|
}
|
|
|
|
|
|
|
|
x += neww;
|
|
|
|
|
2019-09-19 16:14:47 +02:00
|
|
|
bool min_flag = item->flag & UI_ITEM_FIXED_SIZE;
|
2019-04-17 06:17:24 +02:00
|
|
|
/* ignore min flag for rows with right or center alignment */
|
|
|
|
if (item->type != ITEM_BUTTON &&
|
|
|
|
ELEM(((uiLayout *)item)->alignment, UI_LAYOUT_ALIGN_RIGHT, UI_LAYOUT_ALIGN_CENTER) &&
|
2019-09-19 16:14:47 +02:00
|
|
|
litem->alignment == UI_LAYOUT_ALIGN_EXPAND &&
|
|
|
|
((uiItem *)litem)->flag & UI_ITEM_FIXED_SIZE) {
|
2019-04-17 06:17:24 +02:00
|
|
|
min_flag = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((neww < minw || min_flag) && w != 0) {
|
|
|
|
/* fixed size */
|
2019-09-19 16:14:47 +02:00
|
|
|
item->flag |= UI_ITEM_AUTO_FIXED_SIZE;
|
|
|
|
if (item->type != ITEM_BUTTON && item->flag & UI_ITEM_FIXED_SIZE) {
|
2019-04-17 06:17:24 +02:00
|
|
|
minw = itemw;
|
|
|
|
}
|
|
|
|
fixedw += minw;
|
|
|
|
flag = 1;
|
|
|
|
newtotw -= itemw;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* keep free size */
|
2019-09-19 16:14:47 +02:00
|
|
|
item->flag &= ~UI_ITEM_AUTO_FIXED_SIZE;
|
2019-04-17 06:17:24 +02:00
|
|
|
freew += itemw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
totw = newtotw;
|
|
|
|
lastw = fixedw;
|
|
|
|
} while (flag);
|
|
|
|
|
|
|
|
freex = 0;
|
|
|
|
fixedx = 0;
|
|
|
|
extra_pixel = 0.0f;
|
|
|
|
x = litem->x;
|
|
|
|
|
|
|
|
for (item = litem->items.first; item; item = item->next) {
|
|
|
|
ui_item_size(item, &itemw, &itemh);
|
|
|
|
minw = ui_litem_min_width(itemw);
|
|
|
|
|
2019-09-19 16:14:47 +02:00
|
|
|
if (item->flag & UI_ITEM_AUTO_FIXED_SIZE) {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* fixed minimum size items */
|
2019-09-19 16:14:47 +02:00
|
|
|
if (item->type != ITEM_BUTTON && item->flag & UI_ITEM_FIXED_SIZE) {
|
2019-04-17 06:17:24 +02:00
|
|
|
minw = itemw;
|
|
|
|
}
|
|
|
|
itemw = ui_item_fit(
|
|
|
|
minw, fixedx, fixedw, min_ii(w, fixedw), !item->next, litem->alignment, &extra_pixel);
|
|
|
|
fixedx += itemw;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* free size item */
|
|
|
|
itemw = ui_item_fit(
|
|
|
|
itemw, freex, freew, w - fixedw, !item->next, litem->alignment, &extra_pixel);
|
|
|
|
freex += itemw;
|
|
|
|
last_free_item = item;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* align right/center */
|
|
|
|
offset = 0;
|
|
|
|
if (litem->alignment == UI_LAYOUT_ALIGN_RIGHT) {
|
|
|
|
if (freew + fixedw > 0 && freew + fixedw < w) {
|
|
|
|
offset = w - (fixedw + freew);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (litem->alignment == UI_LAYOUT_ALIGN_CENTER) {
|
|
|
|
if (freew + fixedw > 0 && freew + fixedw < w) {
|
|
|
|
offset = (w - (fixedw + freew)) / 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* position item */
|
|
|
|
ui_item_position(item, x + offset, y - itemh, itemw, itemh);
|
|
|
|
|
|
|
|
x += itemw;
|
|
|
|
if (item->next) {
|
|
|
|
x += litem->space;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add extra pixel */
|
|
|
|
uiItem *last_item = litem->items.last;
|
|
|
|
extra_pixel = litem->w - (x - litem->x);
|
|
|
|
if (extra_pixel > 0 && litem->alignment == UI_LAYOUT_ALIGN_EXPAND && last_free_item &&
|
2019-09-19 16:14:47 +02:00
|
|
|
last_item && last_item->flag & UI_ITEM_AUTO_FIXED_SIZE) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ui_item_move(last_free_item, 0, extra_pixel);
|
|
|
|
for (item = last_free_item->next; item; item = item->next) {
|
|
|
|
ui_item_move(item, extra_pixel, extra_pixel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
litem->w = x - litem->x;
|
|
|
|
litem->h = litem->y - y;
|
|
|
|
litem->x = x;
|
|
|
|
litem->y = y;
|
2009-04-16 12:17:58 +00:00
|
|
|
}
|
|
|
|
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
/* single-column layout */
|
2017-03-26 18:02:11 +03:00
|
|
|
static void ui_litem_estimate_column(uiLayout *litem, bool is_box)
|
2009-03-13 13:38:41 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiItem *item;
|
|
|
|
int itemw, itemh;
|
|
|
|
bool min_size_flag = true;
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
litem->w = 0;
|
|
|
|
litem->h = 0;
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (item = litem->items.first; item; item = item->next) {
|
|
|
|
ui_item_size(item, &itemw, &itemh);
|
2009-04-16 12:17:58 +00:00
|
|
|
|
2019-09-19 16:14:47 +02:00
|
|
|
min_size_flag = min_size_flag && (item->flag & UI_ITEM_FIXED_SIZE);
|
2017-03-28 00:07:31 +03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
litem->w = MAX2(litem->w, itemw);
|
|
|
|
litem->h += itemh;
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (item->next && (!is_box || item != litem->items.first)) {
|
|
|
|
litem->h += litem->space;
|
|
|
|
}
|
|
|
|
}
|
2018-05-23 10:47:12 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (min_size_flag) {
|
2019-09-19 16:14:47 +02:00
|
|
|
litem->item.flag |= UI_ITEM_FIXED_SIZE;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
}
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2017-03-26 18:02:11 +03:00
|
|
|
static void ui_litem_layout_column(uiLayout *litem, bool is_box)
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiItem *item;
|
|
|
|
int itemh, x, y;
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
x = litem->x;
|
|
|
|
y = litem->y;
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (item = litem->items.first; item; item = item->next) {
|
|
|
|
ui_item_size(item, NULL, &itemh);
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
y -= itemh;
|
|
|
|
ui_item_position(item, x, y, litem->w, itemh);
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (item->next && (!is_box || item != litem->items.first)) {
|
|
|
|
y -= litem->space;
|
|
|
|
}
|
2017-07-27 10:27:29 +03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (is_box) {
|
|
|
|
item->flag |= UI_ITEM_BOX_ITEM;
|
|
|
|
}
|
|
|
|
}
|
2009-04-15 15:09:36 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
litem->h = litem->y - y;
|
|
|
|
litem->x = x;
|
|
|
|
litem->y = y;
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
}
|
|
|
|
|
Pie Menus C code backend.
This commit merges the code in the pie-menu branch.
As per decisions taken the last few days, there are no pie menus
included and there will be an official add-on including overrides of
some keys with pie menus. However, people will now be able to use the
new code in python.
Full Documentation is in http://wiki.blender.org/index.php/Dev:Ref/
Thanks:
Campbell Barton, Dalai Felinto and Ton Roosendaal for the code review
and design comments
Jonathan Williamson, Pawel Lyczkowski, Pablo Vazquez among others for
suggestions during the development.
Special Thanks to Sean Olson, for his support, suggestions, testing and
merciless bugging so that I would finish the pie menu code. Without him
we wouldn't be here. Also to the rest of the developers of the original
python add-on, Patrick Moore and Dan Eicher and finally to Matt Ebb, who
did the research and first implementation and whose code I used to get
started.
2014-08-11 10:39:59 +02:00
|
|
|
/* calculates the angle of a specified button in a radial menu,
|
|
|
|
* stores a float vector in unit circle */
|
|
|
|
static RadialDirection ui_get_radialbut_vec(float vec[2], short itemnum)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
RadialDirection dir;
|
2015-05-26 12:08:29 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (itemnum >= PIE_MAX_ITEMS) {
|
|
|
|
itemnum %= PIE_MAX_ITEMS;
|
|
|
|
printf("Warning: Pie menus with more than %i items are currently unsupported\n",
|
|
|
|
PIE_MAX_ITEMS);
|
|
|
|
}
|
Pie Menus C code backend.
This commit merges the code in the pie-menu branch.
As per decisions taken the last few days, there are no pie menus
included and there will be an official add-on including overrides of
some keys with pie menus. However, people will now be able to use the
new code in python.
Full Documentation is in http://wiki.blender.org/index.php/Dev:Ref/
Thanks:
Campbell Barton, Dalai Felinto and Ton Roosendaal for the code review
and design comments
Jonathan Williamson, Pawel Lyczkowski, Pablo Vazquez among others for
suggestions during the development.
Special Thanks to Sean Olson, for his support, suggestions, testing and
merciless bugging so that I would finish the pie menu code. Without him
we wouldn't be here. Also to the rest of the developers of the original
python add-on, Patrick Moore and Dan Eicher and finally to Matt Ebb, who
did the research and first implementation and whose code I used to get
started.
2014-08-11 10:39:59 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
dir = ui_radial_dir_order[itemnum];
|
|
|
|
ui_but_pie_dir(dir, vec);
|
Pie Menus C code backend.
This commit merges the code in the pie-menu branch.
As per decisions taken the last few days, there are no pie menus
included and there will be an official add-on including overrides of
some keys with pie menus. However, people will now be able to use the
new code in python.
Full Documentation is in http://wiki.blender.org/index.php/Dev:Ref/
Thanks:
Campbell Barton, Dalai Felinto and Ton Roosendaal for the code review
and design comments
Jonathan Williamson, Pawel Lyczkowski, Pablo Vazquez among others for
suggestions during the development.
Special Thanks to Sean Olson, for his support, suggestions, testing and
merciless bugging so that I would finish the pie menu code. Without him
we wouldn't be here. Also to the rest of the developers of the original
python add-on, Patrick Moore and Dan Eicher and finally to Matt Ebb, who
did the research and first implementation and whose code I used to get
started.
2014-08-11 10:39:59 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return dir;
|
Pie Menus C code backend.
This commit merges the code in the pie-menu branch.
As per decisions taken the last few days, there are no pie menus
included and there will be an official add-on including overrides of
some keys with pie menus. However, people will now be able to use the
new code in python.
Full Documentation is in http://wiki.blender.org/index.php/Dev:Ref/
Thanks:
Campbell Barton, Dalai Felinto and Ton Roosendaal for the code review
and design comments
Jonathan Williamson, Pawel Lyczkowski, Pablo Vazquez among others for
suggestions during the development.
Special Thanks to Sean Olson, for his support, suggestions, testing and
merciless bugging so that I would finish the pie menu code. Without him
we wouldn't be here. Also to the rest of the developers of the original
python add-on, Patrick Moore and Dan Eicher and finally to Matt Ebb, who
did the research and first implementation and whose code I used to get
started.
2014-08-11 10:39:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool ui_item_is_radial_displayable(uiItem *item)
|
|
|
|
{
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if ((item->type == ITEM_BUTTON) && (((uiButtonItem *)item)->but->type == UI_BTYPE_LABEL)) {
|
|
|
|
return false;
|
|
|
|
}
|
Pie Menus C code backend.
This commit merges the code in the pie-menu branch.
As per decisions taken the last few days, there are no pie menus
included and there will be an official add-on including overrides of
some keys with pie menus. However, people will now be able to use the
new code in python.
Full Documentation is in http://wiki.blender.org/index.php/Dev:Ref/
Thanks:
Campbell Barton, Dalai Felinto and Ton Roosendaal for the code review
and design comments
Jonathan Williamson, Pawel Lyczkowski, Pablo Vazquez among others for
suggestions during the development.
Special Thanks to Sean Olson, for his support, suggestions, testing and
merciless bugging so that I would finish the pie menu code. Without him
we wouldn't be here. Also to the rest of the developers of the original
python add-on, Patrick Moore and Dan Eicher and finally to Matt Ebb, who
did the research and first implementation and whose code I used to get
started.
2014-08-11 10:39:59 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
Pie Menus C code backend.
This commit merges the code in the pie-menu branch.
As per decisions taken the last few days, there are no pie menus
included and there will be an official add-on including overrides of
some keys with pie menus. However, people will now be able to use the
new code in python.
Full Documentation is in http://wiki.blender.org/index.php/Dev:Ref/
Thanks:
Campbell Barton, Dalai Felinto and Ton Roosendaal for the code review
and design comments
Jonathan Williamson, Pawel Lyczkowski, Pablo Vazquez among others for
suggestions during the development.
Special Thanks to Sean Olson, for his support, suggestions, testing and
merciless bugging so that I would finish the pie menu code. Without him
we wouldn't be here. Also to the rest of the developers of the original
python add-on, Patrick Moore and Dan Eicher and finally to Matt Ebb, who
did the research and first implementation and whose code I used to get
started.
2014-08-11 10:39:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool ui_item_is_radial_drawable(uiButtonItem *bitem)
|
|
|
|
{
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ELEM(bitem->but->type, UI_BTYPE_SEPR, UI_BTYPE_SEPR_LINE, UI_BTYPE_SEPR_SPACER)) {
|
|
|
|
return false;
|
|
|
|
}
|
Pie Menus C code backend.
This commit merges the code in the pie-menu branch.
As per decisions taken the last few days, there are no pie menus
included and there will be an official add-on including overrides of
some keys with pie menus. However, people will now be able to use the
new code in python.
Full Documentation is in http://wiki.blender.org/index.php/Dev:Ref/
Thanks:
Campbell Barton, Dalai Felinto and Ton Roosendaal for the code review
and design comments
Jonathan Williamson, Pawel Lyczkowski, Pablo Vazquez among others for
suggestions during the development.
Special Thanks to Sean Olson, for his support, suggestions, testing and
merciless bugging so that I would finish the pie menu code. Without him
we wouldn't be here. Also to the rest of the developers of the original
python add-on, Patrick Moore and Dan Eicher and finally to Matt Ebb, who
did the research and first implementation and whose code I used to get
started.
2014-08-11 10:39:59 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
Pie Menus C code backend.
This commit merges the code in the pie-menu branch.
As per decisions taken the last few days, there are no pie menus
included and there will be an official add-on including overrides of
some keys with pie menus. However, people will now be able to use the
new code in python.
Full Documentation is in http://wiki.blender.org/index.php/Dev:Ref/
Thanks:
Campbell Barton, Dalai Felinto and Ton Roosendaal for the code review
and design comments
Jonathan Williamson, Pawel Lyczkowski, Pablo Vazquez among others for
suggestions during the development.
Special Thanks to Sean Olson, for his support, suggestions, testing and
merciless bugging so that I would finish the pie menu code. Without him
we wouldn't be here. Also to the rest of the developers of the original
python add-on, Patrick Moore and Dan Eicher and finally to Matt Ebb, who
did the research and first implementation and whose code I used to get
started.
2014-08-11 10:39:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ui_litem_layout_radial(uiLayout *litem)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiItem *item;
|
|
|
|
int itemh, itemw, x, y;
|
|
|
|
int itemnum = 0;
|
|
|
|
int totitems = 0;
|
|
|
|
|
|
|
|
/* For the radial layout we will use Matt Ebb's design
|
|
|
|
* for radiation, see http://mattebb.com/weblog/radiation/
|
|
|
|
* also the old code at http://developer.blender.org/T5103
|
|
|
|
*/
|
|
|
|
|
|
|
|
int pie_radius = U.pie_menu_radius * UI_DPI_FAC;
|
|
|
|
|
|
|
|
x = litem->x;
|
|
|
|
y = litem->y;
|
|
|
|
|
|
|
|
int minx = x, miny = y, maxx = x, maxy = y;
|
|
|
|
|
|
|
|
/* first count total items */
|
|
|
|
for (item = litem->items.first; item; item = item->next) {
|
|
|
|
totitems++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (totitems < 5) {
|
|
|
|
litem->root->block->pie_data.flags |= UI_PIE_DEGREES_RANGE_LARGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (item = litem->items.first; item; item = item->next) {
|
|
|
|
/* not all button types are drawn in a radial menu, do filtering here */
|
|
|
|
if (ui_item_is_radial_displayable(item)) {
|
|
|
|
RadialDirection dir;
|
|
|
|
float vec[2];
|
|
|
|
float factor[2];
|
|
|
|
|
|
|
|
dir = ui_get_radialbut_vec(vec, itemnum);
|
|
|
|
factor[0] = (vec[0] > 0.01f) ? 0.0f : ((vec[0] < -0.01f) ? -1.0f : -0.5f);
|
|
|
|
factor[1] = (vec[1] > 0.99f) ? 0.0f : ((vec[1] < -0.99f) ? -1.0f : -0.5f);
|
|
|
|
|
|
|
|
itemnum++;
|
|
|
|
|
|
|
|
if (item->type == ITEM_BUTTON) {
|
|
|
|
uiButtonItem *bitem = (uiButtonItem *)item;
|
|
|
|
|
|
|
|
bitem->but->pie_dir = dir;
|
|
|
|
/* scale the buttons */
|
|
|
|
bitem->but->rect.ymax *= 1.5f;
|
|
|
|
/* add a little bit more here to include number */
|
|
|
|
bitem->but->rect.xmax += 1.5f * UI_UNIT_X;
|
|
|
|
/* enable drawing as pie item if supported by widget */
|
|
|
|
if (ui_item_is_radial_drawable(bitem)) {
|
2020-07-29 12:05:27 +10:00
|
|
|
bitem->but->emboss = UI_EMBOSS_RADIAL;
|
2019-04-17 06:17:24 +02:00
|
|
|
bitem->but->drawflag |= UI_BUT_ICON_LEFT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ui_item_size(item, &itemw, &itemh);
|
|
|
|
|
|
|
|
ui_item_position(item,
|
|
|
|
x + vec[0] * pie_radius + factor[0] * itemw,
|
|
|
|
y + vec[1] * pie_radius + factor[1] * itemh,
|
|
|
|
itemw,
|
|
|
|
itemh);
|
|
|
|
|
|
|
|
minx = min_ii(minx, x + vec[0] * pie_radius - itemw / 2);
|
|
|
|
maxx = max_ii(maxx, x + vec[0] * pie_radius + itemw / 2);
|
|
|
|
miny = min_ii(miny, y + vec[1] * pie_radius - itemh / 2);
|
|
|
|
maxy = max_ii(maxy, y + vec[1] * pie_radius + itemh / 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
litem->x = minx;
|
|
|
|
litem->y = miny;
|
|
|
|
litem->w = maxx - minx;
|
|
|
|
litem->h = maxy - miny;
|
Pie Menus C code backend.
This commit merges the code in the pie-menu branch.
As per decisions taken the last few days, there are no pie menus
included and there will be an official add-on including overrides of
some keys with pie menus. However, people will now be able to use the
new code in python.
Full Documentation is in http://wiki.blender.org/index.php/Dev:Ref/
Thanks:
Campbell Barton, Dalai Felinto and Ton Roosendaal for the code review
and design comments
Jonathan Williamson, Pawel Lyczkowski, Pablo Vazquez among others for
suggestions during the development.
Special Thanks to Sean Olson, for his support, suggestions, testing and
merciless bugging so that I would finish the pie menu code. Without him
we wouldn't be here. Also to the rest of the developers of the original
python add-on, Patrick Moore and Dan Eicher and finally to Matt Ebb, who
did the research and first implementation and whose code I used to get
started.
2014-08-11 10:39:59 +02:00
|
|
|
}
|
|
|
|
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
/* root layout */
|
2010-10-14 12:24:08 +00:00
|
|
|
static void ui_litem_estimate_root(uiLayout *UNUSED(litem))
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* nothing to do */
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
}
|
|
|
|
|
Pie Menus C code backend.
This commit merges the code in the pie-menu branch.
As per decisions taken the last few days, there are no pie menus
included and there will be an official add-on including overrides of
some keys with pie menus. However, people will now be able to use the
new code in python.
Full Documentation is in http://wiki.blender.org/index.php/Dev:Ref/
Thanks:
Campbell Barton, Dalai Felinto and Ton Roosendaal for the code review
and design comments
Jonathan Williamson, Pawel Lyczkowski, Pablo Vazquez among others for
suggestions during the development.
Special Thanks to Sean Olson, for his support, suggestions, testing and
merciless bugging so that I would finish the pie menu code. Without him
we wouldn't be here. Also to the rest of the developers of the original
python add-on, Patrick Moore and Dan Eicher and finally to Matt Ebb, who
did the research and first implementation and whose code I used to get
started.
2014-08-11 10:39:59 +02:00
|
|
|
static void ui_litem_layout_root_radial(uiLayout *litem)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* first item is pie menu title, align on center of menu */
|
|
|
|
uiItem *item = litem->items.first;
|
Pie Menus C code backend.
This commit merges the code in the pie-menu branch.
As per decisions taken the last few days, there are no pie menus
included and there will be an official add-on including overrides of
some keys with pie menus. However, people will now be able to use the
new code in python.
Full Documentation is in http://wiki.blender.org/index.php/Dev:Ref/
Thanks:
Campbell Barton, Dalai Felinto and Ton Roosendaal for the code review
and design comments
Jonathan Williamson, Pawel Lyczkowski, Pablo Vazquez among others for
suggestions during the development.
Special Thanks to Sean Olson, for his support, suggestions, testing and
merciless bugging so that I would finish the pie menu code. Without him
we wouldn't be here. Also to the rest of the developers of the original
python add-on, Patrick Moore and Dan Eicher and finally to Matt Ebb, who
did the research and first implementation and whose code I used to get
started.
2014-08-11 10:39:59 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (item->type == ITEM_BUTTON) {
|
|
|
|
int itemh, itemw, x, y;
|
|
|
|
x = litem->x;
|
|
|
|
y = litem->y;
|
Pie Menus C code backend.
This commit merges the code in the pie-menu branch.
As per decisions taken the last few days, there are no pie menus
included and there will be an official add-on including overrides of
some keys with pie menus. However, people will now be able to use the
new code in python.
Full Documentation is in http://wiki.blender.org/index.php/Dev:Ref/
Thanks:
Campbell Barton, Dalai Felinto and Ton Roosendaal for the code review
and design comments
Jonathan Williamson, Pawel Lyczkowski, Pablo Vazquez among others for
suggestions during the development.
Special Thanks to Sean Olson, for his support, suggestions, testing and
merciless bugging so that I would finish the pie menu code. Without him
we wouldn't be here. Also to the rest of the developers of the original
python add-on, Patrick Moore and Dan Eicher and finally to Matt Ebb, who
did the research and first implementation and whose code I used to get
started.
2014-08-11 10:39:59 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ui_item_size(item, &itemw, &itemh);
|
Pie Menus C code backend.
This commit merges the code in the pie-menu branch.
As per decisions taken the last few days, there are no pie menus
included and there will be an official add-on including overrides of
some keys with pie menus. However, people will now be able to use the
new code in python.
Full Documentation is in http://wiki.blender.org/index.php/Dev:Ref/
Thanks:
Campbell Barton, Dalai Felinto and Ton Roosendaal for the code review
and design comments
Jonathan Williamson, Pawel Lyczkowski, Pablo Vazquez among others for
suggestions during the development.
Special Thanks to Sean Olson, for his support, suggestions, testing and
merciless bugging so that I would finish the pie menu code. Without him
we wouldn't be here. Also to the rest of the developers of the original
python add-on, Patrick Moore and Dan Eicher and finally to Matt Ebb, who
did the research and first implementation and whose code I used to get
started.
2014-08-11 10:39:59 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ui_item_position(
|
|
|
|
item, x - itemw / 2, y + U.dpi_fac * (U.pie_menu_threshold + 9.0f), itemw, itemh);
|
|
|
|
}
|
Pie Menus C code backend.
This commit merges the code in the pie-menu branch.
As per decisions taken the last few days, there are no pie menus
included and there will be an official add-on including overrides of
some keys with pie menus. However, people will now be able to use the
new code in python.
Full Documentation is in http://wiki.blender.org/index.php/Dev:Ref/
Thanks:
Campbell Barton, Dalai Felinto and Ton Roosendaal for the code review
and design comments
Jonathan Williamson, Pawel Lyczkowski, Pablo Vazquez among others for
suggestions during the development.
Special Thanks to Sean Olson, for his support, suggestions, testing and
merciless bugging so that I would finish the pie menu code. Without him
we wouldn't be here. Also to the rest of the developers of the original
python add-on, Patrick Moore and Dan Eicher and finally to Matt Ebb, who
did the research and first implementation and whose code I used to get
started.
2014-08-11 10:39:59 +02:00
|
|
|
}
|
|
|
|
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
static void ui_litem_layout_root(uiLayout *litem)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (litem->root->type == UI_LAYOUT_HEADER) {
|
|
|
|
ui_litem_layout_row(litem);
|
|
|
|
}
|
|
|
|
else if (litem->root->type == UI_LAYOUT_PIEMENU) {
|
|
|
|
ui_litem_layout_root_radial(litem);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ui_litem_layout_column(litem, false);
|
|
|
|
}
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* box layout */
|
|
|
|
static void ui_litem_estimate_box(uiLayout *litem)
|
|
|
|
{
|
2020-03-15 17:32:25 +11:00
|
|
|
const uiStyle *style = litem->root->style;
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ui_litem_estimate_column(litem, true);
|
2019-10-28 05:00:56 +11:00
|
|
|
|
|
|
|
int boxspace = style->boxspace;
|
|
|
|
if (litem->root->type == UI_LAYOUT_HEADER) {
|
|
|
|
boxspace = 0;
|
|
|
|
}
|
|
|
|
litem->w += 2 * boxspace;
|
|
|
|
litem->h += 2 * boxspace;
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ui_litem_layout_box(uiLayout *litem)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiLayoutItemBx *box = (uiLayoutItemBx *)litem;
|
2020-03-15 17:32:25 +11:00
|
|
|
const uiStyle *style = litem->root->style;
|
2019-04-17 06:17:24 +02:00
|
|
|
uiBut *but;
|
|
|
|
int w, h;
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
|
2019-10-28 05:00:56 +11:00
|
|
|
int boxspace = style->boxspace;
|
|
|
|
if (litem->root->type == UI_LAYOUT_HEADER) {
|
|
|
|
boxspace = 0;
|
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
w = litem->w;
|
|
|
|
h = litem->h;
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
|
2019-10-28 05:00:56 +11:00
|
|
|
litem->x += boxspace;
|
|
|
|
litem->y -= boxspace;
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (w != 0) {
|
2019-10-28 05:00:56 +11:00
|
|
|
litem->w -= 2 * boxspace;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
if (h != 0) {
|
2019-10-28 05:00:56 +11:00
|
|
|
litem->h -= 2 * boxspace;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ui_litem_layout_column(litem, true);
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
|
2019-10-28 05:00:56 +11:00
|
|
|
litem->x -= boxspace;
|
|
|
|
litem->y -= boxspace;
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (w != 0) {
|
2019-10-28 05:00:56 +11:00
|
|
|
litem->w += 2 * boxspace;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
if (h != 0) {
|
2019-10-28 05:00:56 +11:00
|
|
|
litem->h += 2 * boxspace;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* roundbox around the sublayout */
|
|
|
|
but = box->roundbox;
|
|
|
|
but->rect.xmin = litem->x;
|
|
|
|
but->rect.ymin = litem->y;
|
|
|
|
but->rect.xmax = litem->x + litem->w;
|
|
|
|
but->rect.ymax = litem->y + litem->h;
|
2009-04-15 15:09:36 +00:00
|
|
|
}
|
|
|
|
|
2009-04-11 01:52:27 +00:00
|
|
|
/* multi-column layout, automatically flowing to the next */
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
static void ui_litem_estimate_column_flow(uiLayout *litem)
|
2009-04-11 01:52:27 +00:00
|
|
|
{
|
2020-03-15 17:32:25 +11:00
|
|
|
const uiStyle *style = litem->root->style;
|
2019-04-17 06:17:24 +02:00
|
|
|
uiLayoutItemFlow *flow = (uiLayoutItemFlow *)litem;
|
|
|
|
uiItem *item;
|
|
|
|
int col, x, y, emh, emy, miny, itemw, itemh, maxw = 0;
|
|
|
|
int toth, totitem;
|
|
|
|
|
|
|
|
/* compute max needed width and total height */
|
|
|
|
toth = 0;
|
|
|
|
totitem = 0;
|
|
|
|
for (item = litem->items.first; item; item = item->next) {
|
|
|
|
ui_item_size(item, &itemw, &itemh);
|
|
|
|
maxw = MAX2(maxw, itemw);
|
|
|
|
toth += itemh;
|
|
|
|
totitem++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flow->number <= 0) {
|
|
|
|
/* auto compute number of columns, not very good */
|
|
|
|
if (maxw == 0) {
|
|
|
|
flow->totcol = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
flow->totcol = max_ii(litem->root->emw / maxw, 1);
|
|
|
|
flow->totcol = min_ii(flow->totcol, totitem);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
flow->totcol = flow->number;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* compute sizes */
|
|
|
|
x = 0;
|
|
|
|
y = 0;
|
|
|
|
emy = 0;
|
|
|
|
miny = 0;
|
|
|
|
|
|
|
|
maxw = 0;
|
|
|
|
emh = toth / flow->totcol;
|
|
|
|
|
|
|
|
/* create column per column */
|
|
|
|
col = 0;
|
|
|
|
for (item = litem->items.first; item; item = item->next) {
|
|
|
|
ui_item_size(item, &itemw, &itemh);
|
|
|
|
|
|
|
|
y -= itemh + style->buttonspacey;
|
|
|
|
miny = min_ii(miny, y);
|
|
|
|
emy -= itemh;
|
|
|
|
maxw = max_ii(itemw, maxw);
|
|
|
|
|
|
|
|
/* decide to go to next one */
|
|
|
|
if (col < flow->totcol - 1 && emy <= -emh) {
|
|
|
|
x += maxw + litem->space;
|
|
|
|
maxw = 0;
|
|
|
|
y = 0;
|
|
|
|
emy = 0; /* need to reset height again for next column */
|
|
|
|
col++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
litem->w = x;
|
|
|
|
litem->h = litem->y - miny;
|
2009-04-11 01:52:27 +00:00
|
|
|
}
|
|
|
|
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
static void ui_litem_layout_column_flow(uiLayout *litem)
|
2009-03-13 13:38:41 +00:00
|
|
|
{
|
2020-03-15 17:32:25 +11:00
|
|
|
const uiStyle *style = litem->root->style;
|
2019-04-17 06:17:24 +02:00
|
|
|
uiLayoutItemFlow *flow = (uiLayoutItemFlow *)litem;
|
|
|
|
uiItem *item;
|
|
|
|
int col, x, y, w, emh, emy, miny, itemw, itemh;
|
|
|
|
int toth, totitem;
|
|
|
|
|
|
|
|
/* compute max needed width and total height */
|
|
|
|
toth = 0;
|
|
|
|
totitem = 0;
|
|
|
|
for (item = litem->items.first; item; item = item->next) {
|
|
|
|
ui_item_size(item, &itemw, &itemh);
|
|
|
|
toth += itemh;
|
|
|
|
totitem++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* compute sizes */
|
|
|
|
x = litem->x;
|
|
|
|
y = litem->y;
|
|
|
|
emy = 0;
|
|
|
|
miny = 0;
|
|
|
|
|
|
|
|
w = litem->w - (flow->totcol - 1) * style->columnspace;
|
|
|
|
emh = toth / flow->totcol;
|
|
|
|
|
|
|
|
/* create column per column */
|
|
|
|
col = 0;
|
|
|
|
w = (litem->w - (flow->totcol - 1) * style->columnspace) / flow->totcol;
|
|
|
|
for (item = litem->items.first; item; item = item->next) {
|
|
|
|
ui_item_size(item, &itemw, &itemh);
|
|
|
|
|
|
|
|
itemw = (litem->alignment == UI_LAYOUT_ALIGN_EXPAND) ? w : min_ii(w, itemw);
|
|
|
|
|
|
|
|
y -= itemh;
|
|
|
|
emy -= itemh;
|
|
|
|
ui_item_position(item, x, y, itemw, itemh);
|
|
|
|
y -= style->buttonspacey;
|
|
|
|
miny = min_ii(miny, y);
|
|
|
|
|
|
|
|
/* decide to go to next one */
|
|
|
|
if (col < flow->totcol - 1 && emy <= -emh) {
|
|
|
|
x += w + style->columnspace;
|
|
|
|
y = litem->y;
|
|
|
|
emy = 0; /* need to reset height again for next column */
|
|
|
|
col++;
|
|
|
|
|
2019-04-17 09:05:56 +02:00
|
|
|
const int remaining_width = litem->w - (x - litem->x);
|
|
|
|
const int remaining_width_between_columns = (flow->totcol - col - 1) * style->columnspace;
|
|
|
|
const int remaining_columns = flow->totcol - col;
|
|
|
|
w = (remaining_width - remaining_width_between_columns) / remaining_columns;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
litem->h = litem->y - miny;
|
|
|
|
litem->x = x;
|
|
|
|
litem->y = miny;
|
2009-03-13 13:38:41 +00:00
|
|
|
}
|
|
|
|
|
2018-06-09 16:50:05 +02:00
|
|
|
/* multi-column and multi-row layout. */
|
|
|
|
typedef struct UILayoutGridFlowInput {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* General layout control settings. */
|
|
|
|
const bool row_major : 1; /* Fill rows before columns */
|
|
|
|
const bool even_columns : 1; /* All columns will have same width. */
|
|
|
|
const bool even_rows : 1; /* All rows will have same height. */
|
|
|
|
const int space_x; /* Space between columns. */
|
|
|
|
const int space_y; /* Space between rows. */
|
|
|
|
/* Real data about current position and size of this layout item
|
|
|
|
* (either estimated, or final values). */
|
|
|
|
const int litem_w; /* Layout item width. */
|
|
|
|
const int litem_x; /* Layout item X position. */
|
|
|
|
const int litem_y; /* Layout item Y position. */
|
|
|
|
/* Actual number of columns and rows to generate (computed from first pass usually). */
|
|
|
|
const int tot_columns; /* Number of columns. */
|
|
|
|
const int tot_rows; /* Number of rows. */
|
2018-06-09 16:50:05 +02:00
|
|
|
} UILayoutGridFlowInput;
|
|
|
|
|
|
|
|
typedef struct UILayoutGridFlowOutput {
|
2019-04-17 06:17:24 +02:00
|
|
|
int *tot_items; /* Total number of items in this grid layout. */
|
|
|
|
/* Width / X pos data. */
|
|
|
|
float *global_avg_w; /* Computed average width of the columns. */
|
|
|
|
int *cos_x_array; /* Computed X coordinate of each column. */
|
|
|
|
int *widths_array; /* Computed width of each column. */
|
|
|
|
int *tot_w; /* Computed total width. */
|
|
|
|
/* Height / Y pos data. */
|
|
|
|
int *global_max_h; /* Computed height of the tallest item in the grid. */
|
|
|
|
int *cos_y_array; /* Computed Y coordinate of each column. */
|
|
|
|
int *heights_array; /* Computed height of each column. */
|
|
|
|
int *tot_h; /* Computed total height. */
|
2018-06-09 16:50:05 +02:00
|
|
|
} UILayoutGridFlowOutput;
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static void ui_litem_grid_flow_compute(ListBase *items,
|
|
|
|
UILayoutGridFlowInput *parameters,
|
|
|
|
UILayoutGridFlowOutput *results)
|
|
|
|
{
|
|
|
|
uiItem *item;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
float tot_w = 0.0f, tot_h = 0.0f;
|
|
|
|
float global_avg_w = 0.0f, global_totweight_w = 0.0f;
|
|
|
|
int global_max_h = 0;
|
|
|
|
|
|
|
|
float *avg_w = NULL, *totweight_w = NULL;
|
|
|
|
int *max_h = NULL;
|
|
|
|
|
|
|
|
BLI_assert(
|
|
|
|
parameters->tot_columns != 0 ||
|
|
|
|
(results->cos_x_array == NULL && results->widths_array == NULL && results->tot_w == NULL));
|
|
|
|
BLI_assert(
|
|
|
|
parameters->tot_rows != 0 ||
|
|
|
|
(results->cos_y_array == NULL && results->heights_array == NULL && results->tot_h == NULL));
|
|
|
|
|
|
|
|
if (results->tot_items) {
|
|
|
|
*results->tot_items = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (items->first == NULL) {
|
|
|
|
if (results->global_avg_w) {
|
|
|
|
*results->global_avg_w = 0.0f;
|
|
|
|
}
|
|
|
|
if (results->global_max_h) {
|
|
|
|
*results->global_max_h = 0;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parameters->tot_columns != 0) {
|
|
|
|
avg_w = BLI_array_alloca(avg_w, parameters->tot_columns);
|
|
|
|
totweight_w = BLI_array_alloca(totweight_w, parameters->tot_columns);
|
|
|
|
memset(avg_w, 0, sizeof(*avg_w) * parameters->tot_columns);
|
|
|
|
memset(totweight_w, 0, sizeof(*totweight_w) * parameters->tot_columns);
|
|
|
|
}
|
|
|
|
if (parameters->tot_rows != 0) {
|
|
|
|
max_h = BLI_array_alloca(max_h, parameters->tot_rows);
|
|
|
|
memset(max_h, 0, sizeof(*max_h) * parameters->tot_rows);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0, item = items->first; item; item = item->next, i++) {
|
|
|
|
int item_w, item_h;
|
|
|
|
ui_item_size(item, &item_w, &item_h);
|
|
|
|
|
|
|
|
global_avg_w += (float)(item_w * item_w);
|
|
|
|
global_totweight_w += (float)item_w;
|
|
|
|
global_max_h = max_ii(global_max_h, item_h);
|
|
|
|
|
|
|
|
if (parameters->tot_rows != 0 && parameters->tot_columns != 0) {
|
|
|
|
const int index_col = parameters->row_major ? i % parameters->tot_columns :
|
|
|
|
i / parameters->tot_rows;
|
|
|
|
const int index_row = parameters->row_major ? i / parameters->tot_columns :
|
|
|
|
i % parameters->tot_rows;
|
|
|
|
|
|
|
|
avg_w[index_col] += (float)(item_w * item_w);
|
|
|
|
totweight_w[index_col] += (float)item_w;
|
|
|
|
|
|
|
|
max_h[index_row] = max_ii(max_h[index_row], item_h);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (results->tot_items) {
|
|
|
|
(*results->tot_items)++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Finalize computing of column average sizes */
|
|
|
|
global_avg_w /= global_totweight_w;
|
|
|
|
if (parameters->tot_columns != 0) {
|
|
|
|
for (i = 0; i < parameters->tot_columns; i++) {
|
|
|
|
avg_w[i] /= totweight_w[i];
|
|
|
|
tot_w += avg_w[i];
|
|
|
|
}
|
|
|
|
if (parameters->even_columns) {
|
|
|
|
tot_w = ceilf(global_avg_w) * parameters->tot_columns;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Finalize computing of rows max sizes */
|
|
|
|
if (parameters->tot_rows != 0) {
|
|
|
|
for (i = 0; i < parameters->tot_rows; i++) {
|
|
|
|
tot_h += max_h[i];
|
|
|
|
}
|
|
|
|
if (parameters->even_rows) {
|
|
|
|
tot_h = global_max_h * parameters->tot_columns;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Compute positions and sizes of all cells. */
|
|
|
|
if (results->cos_x_array != NULL && results->widths_array != NULL) {
|
|
|
|
/* We enlarge/narrow columns evenly to match available width. */
|
|
|
|
const float wfac = (float)(parameters->litem_w -
|
|
|
|
(parameters->tot_columns - 1) * parameters->space_x) /
|
|
|
|
tot_w;
|
|
|
|
|
|
|
|
for (int col = 0; col < parameters->tot_columns; col++) {
|
|
|
|
results->cos_x_array[col] = (col ? results->cos_x_array[col - 1] +
|
|
|
|
results->widths_array[col - 1] + parameters->space_x :
|
|
|
|
parameters->litem_x);
|
|
|
|
if (parameters->even_columns) {
|
|
|
|
/* (< remaining width > - < space between remaining columns >) / < remaining columns > */
|
|
|
|
results->widths_array[col] = (((parameters->litem_w -
|
|
|
|
(results->cos_x_array[col] - parameters->litem_x)) -
|
|
|
|
(parameters->tot_columns - col - 1) * parameters->space_x) /
|
|
|
|
(parameters->tot_columns - col));
|
|
|
|
}
|
|
|
|
else if (col == parameters->tot_columns - 1) {
|
|
|
|
/* Last column copes width rounding errors... */
|
|
|
|
results->widths_array[col] = parameters->litem_w -
|
|
|
|
(results->cos_x_array[col] - parameters->litem_x);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
results->widths_array[col] = (int)(avg_w[col] * wfac);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (results->cos_y_array != NULL && results->heights_array != NULL) {
|
|
|
|
for (int row = 0; row < parameters->tot_rows; row++) {
|
|
|
|
if (parameters->even_rows) {
|
|
|
|
results->heights_array[row] = global_max_h;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
results->heights_array[row] = max_h[row];
|
|
|
|
}
|
|
|
|
results->cos_y_array[row] = (row ? results->cos_y_array[row - 1] - parameters->space_y -
|
|
|
|
results->heights_array[row] :
|
|
|
|
parameters->litem_y - results->heights_array[row]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (results->global_avg_w) {
|
|
|
|
*results->global_avg_w = global_avg_w;
|
|
|
|
}
|
|
|
|
if (results->global_max_h) {
|
|
|
|
*results->global_max_h = global_max_h;
|
|
|
|
}
|
|
|
|
if (results->tot_w) {
|
|
|
|
*results->tot_w = (int)tot_w + parameters->space_x * (parameters->tot_columns - 1);
|
|
|
|
}
|
|
|
|
if (results->tot_h) {
|
|
|
|
*results->tot_h = tot_h + parameters->space_y * (parameters->tot_rows - 1);
|
|
|
|
}
|
2018-06-09 16:50:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ui_litem_estimate_grid_flow(uiLayout *litem)
|
|
|
|
{
|
2020-03-15 17:32:25 +11:00
|
|
|
const uiStyle *style = litem->root->style;
|
2019-04-17 06:17:24 +02:00
|
|
|
uiLayoutItemGridFlow *gflow = (uiLayoutItemGridFlow *)litem;
|
|
|
|
|
|
|
|
const int space_x = style->columnspace;
|
|
|
|
const int space_y = style->buttonspacey;
|
|
|
|
|
|
|
|
/* Estimate average needed width and height per item. */
|
|
|
|
{
|
|
|
|
float avg_w;
|
|
|
|
int max_h;
|
|
|
|
|
|
|
|
ui_litem_grid_flow_compute(&litem->items,
|
|
|
|
&((UILayoutGridFlowInput){
|
|
|
|
.row_major = gflow->row_major,
|
|
|
|
.even_columns = gflow->even_columns,
|
|
|
|
.even_rows = gflow->even_rows,
|
|
|
|
.litem_w = litem->w,
|
|
|
|
.litem_x = litem->x,
|
|
|
|
.litem_y = litem->y,
|
|
|
|
.space_x = space_x,
|
|
|
|
.space_y = space_y,
|
|
|
|
}),
|
|
|
|
&((UILayoutGridFlowOutput){
|
|
|
|
.tot_items = &gflow->tot_items,
|
|
|
|
.global_avg_w = &avg_w,
|
|
|
|
.global_max_h = &max_h,
|
|
|
|
}));
|
|
|
|
|
|
|
|
if (gflow->tot_items == 0) {
|
|
|
|
litem->w = litem->h = 0;
|
|
|
|
gflow->tot_columns = gflow->tot_rows = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-17 08:44:38 +02:00
|
|
|
/* Even in varying column width case,
|
|
|
|
* we fix our columns number from weighted average width of items,
|
|
|
|
* a proper solving of required width would be too costly,
|
|
|
|
* and this should give reasonably good results in all reasonable cases. */
|
2019-04-17 06:17:24 +02:00
|
|
|
if (gflow->columns_len > 0) {
|
|
|
|
gflow->tot_columns = gflow->columns_len;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (avg_w == 0.0f) {
|
|
|
|
gflow->tot_columns = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
gflow->tot_columns = min_ii(max_ii((int)(litem->w / avg_w), 1), gflow->tot_items);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gflow->tot_rows = (int)ceilf((float)gflow->tot_items / gflow->tot_columns);
|
|
|
|
|
|
|
|
/* Try to tweak number of columns and rows to get better filling of last column or row,
|
|
|
|
* and apply 'modulo' value to number of columns or rows.
|
|
|
|
* Note that modulo does not prevent ending with fewer columns/rows than modulo, if mandatory
|
|
|
|
* to avoid empty column/row. */
|
|
|
|
{
|
|
|
|
const int modulo = (gflow->columns_len < -1) ? -gflow->columns_len : 0;
|
|
|
|
const int step = modulo ? modulo : 1;
|
|
|
|
|
|
|
|
if (gflow->row_major) {
|
|
|
|
/* Adjust number of columns to be multiple of given modulo. */
|
|
|
|
if (modulo && gflow->tot_columns % modulo != 0 && gflow->tot_columns > modulo) {
|
|
|
|
gflow->tot_columns = gflow->tot_columns - (gflow->tot_columns % modulo);
|
|
|
|
}
|
|
|
|
/* Find smallest number of columns conserving computed optimal number of rows. */
|
|
|
|
for (gflow->tot_rows = (int)ceilf((float)gflow->tot_items / gflow->tot_columns);
|
|
|
|
(gflow->tot_columns - step) > 0 &&
|
|
|
|
(int)ceilf((float)gflow->tot_items / (gflow->tot_columns - step)) <= gflow->tot_rows;
|
|
|
|
gflow->tot_columns -= step) {
|
|
|
|
/* pass */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Adjust number of rows to be multiple of given modulo. */
|
|
|
|
if (modulo && gflow->tot_rows % modulo != 0) {
|
|
|
|
gflow->tot_rows = min_ii(gflow->tot_rows + modulo - (gflow->tot_rows % modulo),
|
|
|
|
gflow->tot_items);
|
|
|
|
}
|
|
|
|
/* Find smallest number of rows conserving computed optimal number of columns. */
|
|
|
|
for (gflow->tot_columns = (int)ceilf((float)gflow->tot_items / gflow->tot_rows);
|
|
|
|
(gflow->tot_rows - step) > 0 &&
|
|
|
|
(int)ceilf((float)gflow->tot_items / (gflow->tot_rows - step)) <= gflow->tot_columns;
|
|
|
|
gflow->tot_rows -= step) {
|
|
|
|
/* pass */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set evenly-spaced axes size
|
|
|
|
* (quick optimization in case we have even columns and rows). */
|
|
|
|
if (gflow->even_columns && gflow->even_rows) {
|
|
|
|
litem->w = (int)(gflow->tot_columns * avg_w) + space_x * (gflow->tot_columns - 1);
|
|
|
|
litem->h = (int)(gflow->tot_rows * max_h) + space_y * (gflow->tot_rows - 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now that we have our final number of columns and rows,
|
|
|
|
* we can compute actual needed space for non-evenly sized axes. */
|
|
|
|
{
|
|
|
|
int tot_w, tot_h;
|
|
|
|
|
|
|
|
ui_litem_grid_flow_compute(&litem->items,
|
|
|
|
&((UILayoutGridFlowInput){
|
|
|
|
.row_major = gflow->row_major,
|
|
|
|
.even_columns = gflow->even_columns,
|
|
|
|
.even_rows = gflow->even_rows,
|
|
|
|
.litem_w = litem->w,
|
|
|
|
.litem_x = litem->x,
|
|
|
|
.litem_y = litem->y,
|
|
|
|
.space_x = space_x,
|
|
|
|
.space_y = space_y,
|
|
|
|
.tot_columns = gflow->tot_columns,
|
|
|
|
.tot_rows = gflow->tot_rows,
|
|
|
|
}),
|
|
|
|
&((UILayoutGridFlowOutput){
|
|
|
|
.tot_w = &tot_w,
|
|
|
|
.tot_h = &tot_h,
|
|
|
|
}));
|
|
|
|
|
|
|
|
litem->w = tot_w;
|
|
|
|
litem->h = tot_h;
|
|
|
|
}
|
2018-06-09 16:50:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ui_litem_layout_grid_flow(uiLayout *litem)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int i;
|
2020-03-15 17:32:25 +11:00
|
|
|
const uiStyle *style = litem->root->style;
|
2019-04-17 06:17:24 +02:00
|
|
|
uiLayoutItemGridFlow *gflow = (uiLayoutItemGridFlow *)litem;
|
|
|
|
uiItem *item;
|
|
|
|
|
|
|
|
if (gflow->tot_items == 0) {
|
|
|
|
litem->w = litem->h = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_assert(gflow->tot_columns > 0);
|
|
|
|
BLI_assert(gflow->tot_rows > 0);
|
|
|
|
|
|
|
|
const int space_x = style->columnspace;
|
|
|
|
const int space_y = style->buttonspacey;
|
|
|
|
|
|
|
|
int *widths = BLI_array_alloca(widths, gflow->tot_columns);
|
|
|
|
int *heights = BLI_array_alloca(heights, gflow->tot_rows);
|
|
|
|
int *cos_x = BLI_array_alloca(cos_x, gflow->tot_columns);
|
|
|
|
int *cos_y = BLI_array_alloca(cos_y, gflow->tot_rows);
|
|
|
|
|
|
|
|
/* This time we directly compute coordinates and sizes of all cells. */
|
|
|
|
ui_litem_grid_flow_compute(&litem->items,
|
|
|
|
&((UILayoutGridFlowInput){
|
|
|
|
.row_major = gflow->row_major,
|
|
|
|
.even_columns = gflow->even_columns,
|
|
|
|
.even_rows = gflow->even_rows,
|
|
|
|
.litem_w = litem->w,
|
|
|
|
.litem_x = litem->x,
|
|
|
|
.litem_y = litem->y,
|
|
|
|
.space_x = space_x,
|
|
|
|
.space_y = space_y,
|
|
|
|
.tot_columns = gflow->tot_columns,
|
|
|
|
.tot_rows = gflow->tot_rows,
|
|
|
|
}),
|
|
|
|
&((UILayoutGridFlowOutput){
|
|
|
|
.cos_x_array = cos_x,
|
|
|
|
.cos_y_array = cos_y,
|
|
|
|
.widths_array = widths,
|
|
|
|
.heights_array = heights,
|
|
|
|
}));
|
|
|
|
|
|
|
|
for (item = litem->items.first, i = 0; item; item = item->next, i++) {
|
|
|
|
const int col = gflow->row_major ? i % gflow->tot_columns : i / gflow->tot_rows;
|
|
|
|
const int row = gflow->row_major ? i / gflow->tot_columns : i % gflow->tot_rows;
|
|
|
|
int item_w, item_h;
|
|
|
|
ui_item_size(item, &item_w, &item_h);
|
|
|
|
|
|
|
|
const int w = widths[col];
|
|
|
|
const int h = heights[row];
|
|
|
|
|
|
|
|
item_w = (litem->alignment == UI_LAYOUT_ALIGN_EXPAND) ? w : min_ii(w, item_w);
|
|
|
|
item_h = (litem->alignment == UI_LAYOUT_ALIGN_EXPAND) ? h : min_ii(h, item_h);
|
|
|
|
|
|
|
|
ui_item_position(item, cos_x[col], cos_y[row], item_w, item_h);
|
|
|
|
}
|
|
|
|
|
|
|
|
litem->h = litem->y - cos_y[gflow->tot_rows - 1];
|
|
|
|
litem->x = (cos_x[gflow->tot_columns - 1] - litem->x) + widths[gflow->tot_columns - 1];
|
|
|
|
litem->y = litem->y - litem->h;
|
2018-06-09 16:50:05 +02:00
|
|
|
}
|
|
|
|
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
/* free layout */
|
2009-10-09 10:45:11 +00:00
|
|
|
static void ui_litem_estimate_absolute(uiLayout *litem)
|
2009-03-13 13:38:41 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiItem *item;
|
|
|
|
int itemx, itemy, itemw, itemh, minx, miny;
|
2009-04-16 12:17:58 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
minx = 1e6;
|
|
|
|
miny = 1e6;
|
|
|
|
litem->w = 0;
|
|
|
|
litem->h = 0;
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (item = litem->items.first; item; item = item->next) {
|
|
|
|
ui_item_offset(item, &itemx, &itemy);
|
|
|
|
ui_item_size(item, &itemw, &itemh);
|
2009-04-16 12:17:58 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
minx = min_ii(minx, itemx);
|
|
|
|
miny = min_ii(miny, itemy);
|
2009-04-16 12:17:58 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
litem->w = MAX2(litem->w, itemx + itemw);
|
|
|
|
litem->h = MAX2(litem->h, itemy + itemh);
|
|
|
|
}
|
2009-04-16 12:17:58 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
litem->w -= minx;
|
|
|
|
litem->h -= miny;
|
2009-04-16 12:17:58 +00:00
|
|
|
}
|
|
|
|
|
2009-10-09 10:45:11 +00:00
|
|
|
static void ui_litem_layout_absolute(uiLayout *litem)
|
2009-04-16 12:17:58 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiItem *item;
|
|
|
|
float scalex = 1.0f, scaley = 1.0f;
|
|
|
|
int x, y, newx, newy, itemx, itemy, itemh, itemw, minx, miny, totw, toth;
|
2009-04-16 12:17:58 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
minx = 1e6;
|
|
|
|
miny = 1e6;
|
|
|
|
totw = 0;
|
|
|
|
toth = 0;
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (item = litem->items.first; item; item = item->next) {
|
|
|
|
ui_item_offset(item, &itemx, &itemy);
|
|
|
|
ui_item_size(item, &itemw, &itemh);
|
2009-04-16 12:17:58 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
minx = min_ii(minx, itemx);
|
|
|
|
miny = min_ii(miny, itemy);
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
totw = max_ii(totw, itemx + itemw);
|
|
|
|
toth = max_ii(toth, itemy + itemh);
|
|
|
|
}
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
totw -= minx;
|
|
|
|
toth -= miny;
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (litem->w && totw > 0) {
|
|
|
|
scalex = (float)litem->w / (float)totw;
|
|
|
|
}
|
|
|
|
if (litem->h && toth > 0) {
|
|
|
|
scaley = (float)litem->h / (float)toth;
|
|
|
|
}
|
2018-05-23 10:47:12 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
x = litem->x;
|
|
|
|
y = litem->y - scaley * toth;
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (item = litem->items.first; item; item = item->next) {
|
|
|
|
ui_item_offset(item, &itemx, &itemy);
|
|
|
|
ui_item_size(item, &itemw, &itemh);
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (scalex != 1.0f) {
|
|
|
|
newx = (itemx - minx) * scalex;
|
|
|
|
itemw = (itemx - minx + itemw) * scalex - newx;
|
|
|
|
itemx = minx + newx;
|
|
|
|
}
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (scaley != 1.0f) {
|
|
|
|
newy = (itemy - miny) * scaley;
|
|
|
|
itemh = (itemy - miny + itemh) * scaley - newy;
|
|
|
|
itemy = miny + newy;
|
|
|
|
}
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ui_item_position(item, x + itemx - minx, y + itemy - miny, itemw, itemh);
|
|
|
|
}
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
litem->w = scalex * totw;
|
|
|
|
litem->h = litem->y - y;
|
|
|
|
litem->x = x + litem->w;
|
|
|
|
litem->y = y;
|
2009-03-13 13:38:41 +00:00
|
|
|
}
|
|
|
|
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
/* split layout */
|
|
|
|
static void ui_litem_estimate_split(uiLayout *litem)
|
2009-04-22 18:39:44 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ui_litem_estimate_row(litem);
|
2019-09-19 16:14:47 +02:00
|
|
|
litem->item.flag &= ~UI_ITEM_FIXED_SIZE;
|
2009-04-22 18:39:44 +00:00
|
|
|
}
|
|
|
|
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
static void ui_litem_layout_split(uiLayout *litem)
|
2009-03-13 13:38:41 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiLayoutItemSplit *split = (uiLayoutItemSplit *)litem;
|
|
|
|
uiItem *item;
|
|
|
|
float percentage, extra_pixel = 0.0f;
|
|
|
|
const int tot = BLI_listbase_count(&litem->items);
|
|
|
|
int itemh, x, y, w, colw = 0;
|
2011-03-19 05:06:06 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (tot == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
x = litem->x;
|
|
|
|
y = litem->y;
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
percentage = (split->percentage == 0.0f) ? 1.0f / (float)tot : split->percentage;
|
2018-05-23 10:47:12 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
w = (litem->w - (tot - 1) * litem->space);
|
|
|
|
colw = w * percentage;
|
|
|
|
colw = MAX2(colw, 0);
|
2009-04-22 18:39:44 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (item = litem->items.first; item; item = item->next) {
|
|
|
|
ui_item_size(item, NULL, &itemh);
|
2009-04-22 18:39:44 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ui_item_position(item, x, y - itemh, colw, itemh);
|
|
|
|
x += colw;
|
2009-04-22 18:39:44 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (item->next) {
|
|
|
|
const float width = extra_pixel + (w - (int)(w * percentage)) / ((float)tot - 1);
|
|
|
|
extra_pixel = width - (int)width;
|
|
|
|
colw = (int)width;
|
|
|
|
colw = MAX2(colw, 0);
|
2009-06-07 13:20:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
x += litem->space;
|
|
|
|
}
|
|
|
|
}
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
litem->w = x - litem->x;
|
|
|
|
litem->h = litem->y - y;
|
|
|
|
litem->x = x;
|
|
|
|
litem->y = y;
|
2009-03-13 13:38:41 +00:00
|
|
|
}
|
|
|
|
|
2009-10-21 20:58:10 +00:00
|
|
|
/* overlap layout */
|
|
|
|
static void ui_litem_estimate_overlap(uiLayout *litem)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiItem *item;
|
|
|
|
int itemw, itemh;
|
2009-10-21 20:58:10 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
litem->w = 0;
|
|
|
|
litem->h = 0;
|
2009-10-21 20:58:10 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (item = litem->items.first; item; item = item->next) {
|
|
|
|
ui_item_size(item, &itemw, &itemh);
|
2009-10-21 20:58:10 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
litem->w = MAX2(itemw, litem->w);
|
|
|
|
litem->h = MAX2(itemh, litem->h);
|
|
|
|
}
|
2009-10-21 20:58:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ui_litem_layout_overlap(uiLayout *litem)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiItem *item;
|
|
|
|
int itemw, itemh, x, y;
|
2009-10-21 20:58:10 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
x = litem->x;
|
|
|
|
y = litem->y;
|
2009-10-21 20:58:10 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (item = litem->items.first; item; item = item->next) {
|
|
|
|
ui_item_size(item, &itemw, &itemh);
|
|
|
|
ui_item_position(item, x, y - itemh, litem->w, itemh);
|
2009-10-21 20:58:10 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
litem->h = MAX2(litem->h, itemh);
|
|
|
|
}
|
2009-10-21 20:58:10 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
litem->x = x;
|
|
|
|
litem->y = y - litem->h;
|
2009-10-21 20:58:10 +00:00
|
|
|
}
|
|
|
|
|
2018-05-13 12:28:35 +02:00
|
|
|
static void ui_litem_init_from_parent(uiLayout *litem, uiLayout *layout, int align)
|
2009-03-13 13:38:41 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
litem->root = layout->root;
|
|
|
|
litem->align = align;
|
|
|
|
/* Children of gridflow layout shall never have "ideal big size" returned as estimated size. */
|
|
|
|
litem->variable_size = layout->variable_size || layout->item.type == ITEM_LAYOUT_GRID_FLOW;
|
|
|
|
litem->active = true;
|
|
|
|
litem->enabled = true;
|
|
|
|
litem->context = layout->context;
|
|
|
|
litem->redalert = layout->redalert;
|
|
|
|
litem->w = layout->w;
|
|
|
|
litem->emboss = layout->emboss;
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
litem->item.flag = (layout->item.flag &
|
|
|
|
(UI_ITEM_PROP_SEP | UI_ITEM_PROP_DECORATE | UI_ITEM_INSIDE_PROP_SEP));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
if (layout->child_items_layout) {
|
|
|
|
BLI_addtail(&layout->child_items_layout->items, litem);
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
litem->parent = layout->child_items_layout;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
BLI_addtail(&layout->items, litem);
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
litem->parent = layout;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ui_layout_heading_set(uiLayout *layout, const char *heading)
|
|
|
|
{
|
|
|
|
BLI_assert(layout->heading[0] == '\0');
|
|
|
|
if (heading) {
|
|
|
|
STRNCPY(layout->heading, heading);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-05-13 12:28:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* layout create functions */
|
2018-07-01 16:22:06 +02:00
|
|
|
uiLayout *uiLayoutRow(uiLayout *layout, bool align)
|
2018-05-13 12:28:35 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiLayout *litem;
|
2018-05-13 12:28:35 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
litem = MEM_callocN(sizeof(uiLayout), "uiLayoutRow");
|
|
|
|
ui_litem_init_from_parent(litem, layout, align);
|
2018-05-13 12:28:35 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
litem->item.type = ITEM_LAYOUT_ROW;
|
|
|
|
litem->space = (align) ? 0 : layout->root->style->buttonspacex;
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
UI_block_layout_set_current(layout->root->block, litem);
|
2009-05-19 17:13:33 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return litem;
|
2009-03-13 13:38:41 +00:00
|
|
|
}
|
|
|
|
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
/**
|
|
|
|
* See #uiLayoutColumnWithHeading().
|
|
|
|
*/
|
|
|
|
uiLayout *uiLayoutRowWithHeading(uiLayout *layout, bool align, const char *heading)
|
|
|
|
{
|
|
|
|
uiLayout *litem = uiLayoutRow(layout, align);
|
|
|
|
ui_layout_heading_set(litem, heading);
|
|
|
|
return litem;
|
|
|
|
}
|
|
|
|
|
2018-07-01 15:47:09 +02:00
|
|
|
uiLayout *uiLayoutColumn(uiLayout *layout, bool align)
|
2009-04-15 15:09:36 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiLayout *litem;
|
2009-04-15 15:09:36 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
litem = MEM_callocN(sizeof(uiLayout), "uiLayoutColumn");
|
|
|
|
ui_litem_init_from_parent(litem, layout, align);
|
2018-05-13 12:28:35 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
litem->item.type = ITEM_LAYOUT_COLUMN;
|
|
|
|
litem->space = (align) ? 0 : layout->root->style->buttonspacey;
|
2009-04-15 15:09:36 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
UI_block_layout_set_current(layout->root->block, litem);
|
2009-05-19 17:13:33 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return litem;
|
2009-04-15 15:09:36 +00:00
|
|
|
}
|
|
|
|
|
UI: Better split layout support for checkboxes
Makes the following layout changes possible:
{F8473498} {F8473499} {F8473502}
The next commit will contain many layout changes to make good use of
these new possibilities. The result should be more consistent, easier to
read and should give a more organized impression. Additionally, it
should be possible to replace many sub-panels with compacter layouts.
Main changes:
* Checkboxes now respect the property split layouts
* Add support for row and column headers (i.e.
`uiLayout.column(heading="Foo")`, `uiLayout.row(heading="Bar")`). If the
first property added to this layout doesn't insert anything into the label
split column, the heading is inserted there. Otherwise, it's inserted as own
item.
* Add support for manually inserting decorators for an existing item
(`uiLayout.prop_decorator()`). That way layout creators can manually insert
this, which was the only way I saw to support property split layouts with a
checkbox before the actual property. {F8471883}
* Autogenerated layouts for operator properties look bad if there are only
checkboxes (which only use half the region width). So before creating the
layout, we iterate over visible properties and disable split layout if all
are booleans. I think this is fine, if needed we could also add layout hints
to operators.
* `uiTemplateOperatorPropertyButs()` now handles macros itself, the caller
used to be responsible for this. Code that didn't handle these so far never
used macros I think, so this change should be invisible.
* Remove manual property split layout from autogenerated operator properties
layout.
* Padding of checkboxes is tweaked to make their label visually more connected
to the checkboxes.
* Support split layout for menus (should work for `uiLayout.menu()`,
`.operator_menu_enum()`, `.prop_menu_enum()`, maybe more)
Maniphest Task: https://developer.blender.org/T65965
Differential Revision: https://developer.blender.org/D7427
Reviewed by: Brecht Van Lommel, William Reynish, Pablo Vazques
2020-04-17 16:40:25 +02:00
|
|
|
/**
|
|
|
|
* Variant of #uiLayoutColumn() that sets a heading label for the layout if the first item is
|
|
|
|
* added through #uiItemFullR(). If split layout is used and the item has no string to add to the
|
|
|
|
* first split-column, the heading is added there instead. Otherwise the heading inserted with a
|
|
|
|
* new row.
|
|
|
|
*/
|
|
|
|
uiLayout *uiLayoutColumnWithHeading(uiLayout *layout, bool align, const char *heading)
|
|
|
|
{
|
|
|
|
uiLayout *litem = uiLayoutColumn(layout, align);
|
|
|
|
ui_layout_heading_set(litem, heading);
|
|
|
|
return litem;
|
|
|
|
}
|
|
|
|
|
2018-07-01 15:47:09 +02:00
|
|
|
uiLayout *uiLayoutColumnFlow(uiLayout *layout, int number, bool align)
|
2009-03-13 13:38:41 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiLayoutItemFlow *flow;
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
flow = MEM_callocN(sizeof(uiLayoutItemFlow), "uiLayoutItemFlow");
|
|
|
|
ui_litem_init_from_parent(&flow->litem, layout, align);
|
2018-05-13 12:28:35 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
flow->litem.item.type = ITEM_LAYOUT_COLUMN_FLOW;
|
|
|
|
flow->litem.space = (flow->litem.align) ? 0 : layout->root->style->columnspace;
|
|
|
|
flow->number = number;
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
UI_block_layout_set_current(layout->root->block, &flow->litem);
|
2009-05-19 17:13:33 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return &flow->litem;
|
2009-03-13 13:38:41 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
uiLayout *uiLayoutGridFlow(uiLayout *layout,
|
|
|
|
bool row_major,
|
|
|
|
int columns_len,
|
|
|
|
bool even_columns,
|
|
|
|
bool even_rows,
|
|
|
|
bool align)
|
2018-06-09 16:50:05 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiLayoutItemGridFlow *flow;
|
2018-06-09 16:50:05 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
flow = MEM_callocN(sizeof(uiLayoutItemGridFlow), __func__);
|
|
|
|
flow->litem.item.type = ITEM_LAYOUT_GRID_FLOW;
|
|
|
|
ui_litem_init_from_parent(&flow->litem, layout, align);
|
2018-06-09 16:50:05 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
flow->litem.space = (flow->litem.align) ? 0 : layout->root->style->columnspace;
|
|
|
|
flow->row_major = row_major;
|
|
|
|
flow->columns_len = columns_len;
|
|
|
|
flow->even_columns = even_columns;
|
|
|
|
flow->even_rows = even_rows;
|
2018-06-09 16:50:05 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
UI_block_layout_set_current(layout->root->block, &flow->litem);
|
2018-06-09 16:50:05 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return &flow->litem;
|
2018-06-09 16:50:05 +02:00
|
|
|
}
|
|
|
|
|
2009-10-21 20:58:10 +00:00
|
|
|
static uiLayoutItemBx *ui_layout_box(uiLayout *layout, int type)
|
2009-04-11 01:52:27 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiLayoutItemBx *box;
|
2009-04-11 01:52:27 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
box = MEM_callocN(sizeof(uiLayoutItemBx), "uiLayoutItemBx");
|
|
|
|
ui_litem_init_from_parent(&box->litem, layout, false);
|
2018-05-13 12:28:35 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
box->litem.item.type = ITEM_LAYOUT_BOX;
|
|
|
|
box->litem.space = layout->root->style->columnspace;
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
UI_block_layout_set_current(layout->root->block, &box->litem);
|
2009-05-19 17:13:33 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
box->roundbox = uiDefBut(layout->root->block, type, 0, "", 0, 0, 0, 0, NULL, 0.0, 0.0, 0, 0, "");
|
2009-05-21 15:34:09 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return box;
|
2009-04-11 01:52:27 +00:00
|
|
|
}
|
2009-03-13 13:38:41 +00:00
|
|
|
|
Pie Menus C code backend.
This commit merges the code in the pie-menu branch.
As per decisions taken the last few days, there are no pie menus
included and there will be an official add-on including overrides of
some keys with pie menus. However, people will now be able to use the
new code in python.
Full Documentation is in http://wiki.blender.org/index.php/Dev:Ref/
Thanks:
Campbell Barton, Dalai Felinto and Ton Roosendaal for the code review
and design comments
Jonathan Williamson, Pawel Lyczkowski, Pablo Vazquez among others for
suggestions during the development.
Special Thanks to Sean Olson, for his support, suggestions, testing and
merciless bugging so that I would finish the pie menu code. Without him
we wouldn't be here. Also to the rest of the developers of the original
python add-on, Patrick Moore and Dan Eicher and finally to Matt Ebb, who
did the research and first implementation and whose code I used to get
started.
2014-08-11 10:39:59 +02:00
|
|
|
uiLayout *uiLayoutRadial(uiLayout *layout)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiLayout *litem;
|
|
|
|
uiItem *item;
|
Pie Menus C code backend.
This commit merges the code in the pie-menu branch.
As per decisions taken the last few days, there are no pie menus
included and there will be an official add-on including overrides of
some keys with pie menus. However, people will now be able to use the
new code in python.
Full Documentation is in http://wiki.blender.org/index.php/Dev:Ref/
Thanks:
Campbell Barton, Dalai Felinto and Ton Roosendaal for the code review
and design comments
Jonathan Williamson, Pawel Lyczkowski, Pablo Vazquez among others for
suggestions during the development.
Special Thanks to Sean Olson, for his support, suggestions, testing and
merciless bugging so that I would finish the pie menu code. Without him
we wouldn't be here. Also to the rest of the developers of the original
python add-on, Patrick Moore and Dan Eicher and finally to Matt Ebb, who
did the research and first implementation and whose code I used to get
started.
2014-08-11 10:39:59 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* radial layouts are only valid for radial menus */
|
|
|
|
if (layout->root->type != UI_LAYOUT_PIEMENU) {
|
|
|
|
return ui_item_local_sublayout(layout, layout, 0);
|
|
|
|
}
|
Pie Menus C code backend.
This commit merges the code in the pie-menu branch.
As per decisions taken the last few days, there are no pie menus
included and there will be an official add-on including overrides of
some keys with pie menus. However, people will now be able to use the
new code in python.
Full Documentation is in http://wiki.blender.org/index.php/Dev:Ref/
Thanks:
Campbell Barton, Dalai Felinto and Ton Roosendaal for the code review
and design comments
Jonathan Williamson, Pawel Lyczkowski, Pablo Vazquez among others for
suggestions during the development.
Special Thanks to Sean Olson, for his support, suggestions, testing and
merciless bugging so that I would finish the pie menu code. Without him
we wouldn't be here. Also to the rest of the developers of the original
python add-on, Patrick Moore and Dan Eicher and finally to Matt Ebb, who
did the research and first implementation and whose code I used to get
started.
2014-08-11 10:39:59 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* only one radial wheel per root layout is allowed, so check and return that, if it exists */
|
|
|
|
for (item = layout->root->layout->items.first; item; item = item->next) {
|
|
|
|
litem = (uiLayout *)item;
|
|
|
|
if (litem->item.type == ITEM_LAYOUT_RADIAL) {
|
|
|
|
UI_block_layout_set_current(layout->root->block, litem);
|
|
|
|
return litem;
|
|
|
|
}
|
|
|
|
}
|
Pie Menus C code backend.
This commit merges the code in the pie-menu branch.
As per decisions taken the last few days, there are no pie menus
included and there will be an official add-on including overrides of
some keys with pie menus. However, people will now be able to use the
new code in python.
Full Documentation is in http://wiki.blender.org/index.php/Dev:Ref/
Thanks:
Campbell Barton, Dalai Felinto and Ton Roosendaal for the code review
and design comments
Jonathan Williamson, Pawel Lyczkowski, Pablo Vazquez among others for
suggestions during the development.
Special Thanks to Sean Olson, for his support, suggestions, testing and
merciless bugging so that I would finish the pie menu code. Without him
we wouldn't be here. Also to the rest of the developers of the original
python add-on, Patrick Moore and Dan Eicher and finally to Matt Ebb, who
did the research and first implementation and whose code I used to get
started.
2014-08-11 10:39:59 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
litem = MEM_callocN(sizeof(uiLayout), "uiLayoutRadial");
|
|
|
|
ui_litem_init_from_parent(litem, layout, false);
|
2018-05-13 12:28:35 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
litem->item.type = ITEM_LAYOUT_RADIAL;
|
Pie Menus C code backend.
This commit merges the code in the pie-menu branch.
As per decisions taken the last few days, there are no pie menus
included and there will be an official add-on including overrides of
some keys with pie menus. However, people will now be able to use the
new code in python.
Full Documentation is in http://wiki.blender.org/index.php/Dev:Ref/
Thanks:
Campbell Barton, Dalai Felinto and Ton Roosendaal for the code review
and design comments
Jonathan Williamson, Pawel Lyczkowski, Pablo Vazquez among others for
suggestions during the development.
Special Thanks to Sean Olson, for his support, suggestions, testing and
merciless bugging so that I would finish the pie menu code. Without him
we wouldn't be here. Also to the rest of the developers of the original
python add-on, Patrick Moore and Dan Eicher and finally to Matt Ebb, who
did the research and first implementation and whose code I used to get
started.
2014-08-11 10:39:59 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
UI_block_layout_set_current(layout->root->block, litem);
|
Pie Menus C code backend.
This commit merges the code in the pie-menu branch.
As per decisions taken the last few days, there are no pie menus
included and there will be an official add-on including overrides of
some keys with pie menus. However, people will now be able to use the
new code in python.
Full Documentation is in http://wiki.blender.org/index.php/Dev:Ref/
Thanks:
Campbell Barton, Dalai Felinto and Ton Roosendaal for the code review
and design comments
Jonathan Williamson, Pawel Lyczkowski, Pablo Vazquez among others for
suggestions during the development.
Special Thanks to Sean Olson, for his support, suggestions, testing and
merciless bugging so that I would finish the pie menu code. Without him
we wouldn't be here. Also to the rest of the developers of the original
python add-on, Patrick Moore and Dan Eicher and finally to Matt Ebb, who
did the research and first implementation and whose code I used to get
started.
2014-08-11 10:39:59 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return litem;
|
Pie Menus C code backend.
This commit merges the code in the pie-menu branch.
As per decisions taken the last few days, there are no pie menus
included and there will be an official add-on including overrides of
some keys with pie menus. However, people will now be able to use the
new code in python.
Full Documentation is in http://wiki.blender.org/index.php/Dev:Ref/
Thanks:
Campbell Barton, Dalai Felinto and Ton Roosendaal for the code review
and design comments
Jonathan Williamson, Pawel Lyczkowski, Pablo Vazquez among others for
suggestions during the development.
Special Thanks to Sean Olson, for his support, suggestions, testing and
merciless bugging so that I would finish the pie menu code. Without him
we wouldn't be here. Also to the rest of the developers of the original
python add-on, Patrick Moore and Dan Eicher and finally to Matt Ebb, who
did the research and first implementation and whose code I used to get
started.
2014-08-11 10:39:59 +02:00
|
|
|
}
|
|
|
|
|
2009-07-21 01:26:17 +00:00
|
|
|
uiLayout *uiLayoutBox(uiLayout *layout)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return (uiLayout *)ui_layout_box(layout, UI_BTYPE_ROUNDBOX);
|
2009-07-21 01:26:17 +00:00
|
|
|
}
|
|
|
|
|
2015-05-31 14:20:03 +10:00
|
|
|
/**
|
2019-04-17 08:44:38 +02:00
|
|
|
* Check all buttons defined in this layout,
|
|
|
|
* and set any button flagged as UI_BUT_LIST_ITEM as active/selected.
|
2013-11-23 18:43:23 +01:00
|
|
|
* Needed to handle correctly text colors of active (selected) list item.
|
|
|
|
*/
|
Fix [#35750] list items in properties editor (text colors not following list item theme).
Issue goes back since we stopped using LISTROW button to draw item's name (i.e. since we have custom buttons in list items!).
This commit:
* Adds a new flag to uiBlock, UI_BLOCK_LIST_ITEM, to mark blocks used for each list item.
* Adds a new button type, LISTLABEL, which basically behaves exactly as LABEL, but uses wcol_list_item color set.
* When uiItemL is called, it checks whether current block has UI_BLOCK_LIST_ITEM set, and if so, switch produced button to LISTLABEL type.
* Adds a new helper func, ui_layout_list_set_labels_active, called after the active list item has been "drawn", to set all LISTLABEL buttons as UI_SELECT.
Note custom widget_state_label() was removed, in interface_widgets.c, as it did nothing more than default widget_state().
Thanks to Brecht for the review and advices.
2013-06-26 07:28:55 +00:00
|
|
|
void ui_layout_list_set_labels_active(uiLayout *layout)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiButtonItem *bitem;
|
|
|
|
for (bitem = layout->items.first; bitem; bitem = bitem->item.next) {
|
|
|
|
if (bitem->item.type != ITEM_BUTTON) {
|
|
|
|
ui_layout_list_set_labels_active((uiLayout *)(&bitem->item));
|
|
|
|
}
|
|
|
|
else if (bitem->but->flag & UI_BUT_LIST_ITEM) {
|
|
|
|
UI_but_flag_enable(bitem->but, UI_SELECT);
|
|
|
|
}
|
|
|
|
}
|
Fix [#35750] list items in properties editor (text colors not following list item theme).
Issue goes back since we stopped using LISTROW button to draw item's name (i.e. since we have custom buttons in list items!).
This commit:
* Adds a new flag to uiBlock, UI_BLOCK_LIST_ITEM, to mark blocks used for each list item.
* Adds a new button type, LISTLABEL, which basically behaves exactly as LABEL, but uses wcol_list_item color set.
* When uiItemL is called, it checks whether current block has UI_BLOCK_LIST_ITEM set, and if so, switch produced button to LISTLABEL type.
* Adds a new helper func, ui_layout_list_set_labels_active, called after the active list item has been "drawn", to set all LISTLABEL buttons as UI_SELECT.
Note custom widget_state_label() was removed, in interface_widgets.c, as it did nothing more than default widget_state().
Thanks to Brecht for the review and advices.
2013-06-26 07:28:55 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
uiLayout *uiLayoutListBox(uiLayout *layout,
|
|
|
|
uiList *ui_list,
|
|
|
|
PointerRNA *ptr,
|
|
|
|
PropertyRNA *prop,
|
|
|
|
PointerRNA *actptr,
|
|
|
|
PropertyRNA *actprop)
|
2009-07-21 01:26:17 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiLayoutItemBx *box = ui_layout_box(layout, UI_BTYPE_LISTBOX);
|
|
|
|
uiBut *but = box->roundbox;
|
2009-07-21 01:26:17 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
but->custom_data = ui_list;
|
This commit frees list ui items from their dependencies to Panel, and hence from all the limitations this implied (mostly, the "only one list per panel" one).
It introduces a new (py-extendable and registrable) RNA type, UIList (roughly similar to Panel one), which currently contains only "standard" list's scroll pos and size (but may be expended to include e.g. some filtering data, etc.). This now makes lists completely independent from Panels!
This UIList has a draw_item callback which allows to customize items' drawing from python, that all addons can now use. Incidentally, this also greatly simplifies the C code of this widget, as we do not code any "special case" here anymore!
To make all this work, other changes were also necessary:
* Now all buttons (uiBut struct) have a 'custom_data' void pointer, used currently to store the uiList struct associated with a given uiLayoutListBox.
* DynamicPaintSurface now exposes a new bool, use_color_preview (readonly), saying whether that surface has some 3D view preview data or not.
* UILayout class has now four new (static) functions, to get the actual icon of any RNA object (important e.g. with materials or textures), and to get an enum item's UI name, description and icon.
* UILayout's label() func now takes an optional 'icon_value' integer parameter, which if not zero will override the 'icon' one (mandatory to use "custom" icons as generated for material/texture/... previews).
Note: not sure whether we should add that one to all UILayout's prop funcs?
Note: will update addons using template list asap.
2012-12-28 09:20:16 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
but->rnasearchpoin = *ptr;
|
|
|
|
but->rnasearchprop = prop;
|
|
|
|
but->rnapoin = *actptr;
|
|
|
|
but->rnaprop = actprop;
|
2009-10-21 20:58:10 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* only for the undo string */
|
|
|
|
if (but->flag & UI_BUT_UNDO) {
|
|
|
|
but->tip = RNA_property_description(actprop);
|
|
|
|
}
|
2013-07-09 23:40:53 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return (uiLayout *)box;
|
2009-07-21 01:26:17 +00:00
|
|
|
}
|
|
|
|
|
2018-07-01 15:47:09 +02:00
|
|
|
uiLayout *uiLayoutAbsolute(uiLayout *layout, bool align)
|
2009-03-13 13:38:41 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiLayout *litem;
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
litem = MEM_callocN(sizeof(uiLayout), "uiLayoutAbsolute");
|
|
|
|
ui_litem_init_from_parent(litem, layout, align);
|
2018-05-13 12:28:35 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
litem->item.type = ITEM_LAYOUT_ABSOLUTE;
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
UI_block_layout_set_current(layout->root->block, litem);
|
2009-05-19 17:13:33 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return litem;
|
2009-04-16 12:17:58 +00:00
|
|
|
}
|
|
|
|
|
2009-10-09 10:45:11 +00:00
|
|
|
uiBlock *uiLayoutAbsoluteBlock(uiLayout *layout)
|
2009-05-19 17:13:33 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiBlock *block;
|
2009-05-19 17:13:33 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
block = uiLayoutGetBlock(layout);
|
|
|
|
uiLayoutAbsolute(layout, false);
|
2009-05-19 17:13:33 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return block;
|
2009-05-19 17:13:33 +00:00
|
|
|
}
|
|
|
|
|
2009-10-21 20:58:10 +00:00
|
|
|
uiLayout *uiLayoutOverlap(uiLayout *layout)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiLayout *litem;
|
2009-10-21 20:58:10 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
litem = MEM_callocN(sizeof(uiLayout), "uiLayoutOverlap");
|
|
|
|
ui_litem_init_from_parent(litem, layout, false);
|
2018-05-13 12:28:35 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
litem->item.type = ITEM_LAYOUT_OVERLAP;
|
2009-10-21 20:58:10 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
UI_block_layout_set_current(layout->root->block, litem);
|
2009-10-21 20:58:10 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return litem;
|
2009-10-21 20:58:10 +00:00
|
|
|
}
|
|
|
|
|
2018-07-01 15:47:09 +02:00
|
|
|
uiLayout *uiLayoutSplit(uiLayout *layout, float percentage, bool align)
|
2009-04-16 12:17:58 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiLayoutItemSplit *split;
|
2009-04-16 12:17:58 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
split = MEM_callocN(sizeof(uiLayoutItemSplit), "uiLayoutItemSplit");
|
|
|
|
ui_litem_init_from_parent(&split->litem, layout, align);
|
2018-05-13 12:28:35 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
split->litem.item.type = ITEM_LAYOUT_SPLIT;
|
|
|
|
split->litem.space = layout->root->style->columnspace;
|
|
|
|
split->percentage = percentage;
|
2009-05-19 17:13:33 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
UI_block_layout_set_current(layout->root->block, &split->litem);
|
2009-04-16 12:17:58 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return &split->litem;
|
2009-03-13 13:38:41 +00:00
|
|
|
}
|
|
|
|
|
2013-04-04 02:05:11 +00:00
|
|
|
void uiLayoutSetActive(uiLayout *layout, bool active)
|
2009-05-28 23:37:55 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
layout->active = active;
|
2009-05-28 23:37:55 +00:00
|
|
|
}
|
|
|
|
|
2019-03-27 21:39:44 +11:00
|
|
|
void uiLayoutSetActiveDefault(uiLayout *layout, bool active_default)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
layout->active_default = active_default;
|
2019-03-27 21:39:44 +11:00
|
|
|
}
|
|
|
|
|
2019-03-20 22:40:38 +11:00
|
|
|
void uiLayoutSetActivateInit(uiLayout *layout, bool activate_init)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
layout->activate_init = activate_init;
|
2019-03-20 22:40:38 +11:00
|
|
|
}
|
|
|
|
|
2013-04-04 02:05:11 +00:00
|
|
|
void uiLayoutSetEnabled(uiLayout *layout, bool enabled)
|
2009-05-28 23:37:55 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
layout->enabled = enabled;
|
2009-05-28 23:37:55 +00:00
|
|
|
}
|
|
|
|
|
2013-04-04 02:05:11 +00:00
|
|
|
void uiLayoutSetRedAlert(uiLayout *layout, bool redalert)
|
2009-05-28 23:37:55 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
layout->redalert = redalert;
|
2009-05-28 23:37:55 +00:00
|
|
|
}
|
|
|
|
|
2013-04-04 02:05:11 +00:00
|
|
|
void uiLayoutSetKeepAspect(uiLayout *layout, bool keepaspect)
|
2009-05-28 23:37:55 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
layout->keepaspect = keepaspect;
|
2009-05-28 23:37:55 +00:00
|
|
|
}
|
|
|
|
|
2013-04-04 02:05:11 +00:00
|
|
|
void uiLayoutSetAlignment(uiLayout *layout, char alignment)
|
2009-05-28 23:37:55 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
layout->alignment = alignment;
|
2009-05-28 23:37:55 +00:00
|
|
|
}
|
|
|
|
|
2009-06-03 00:04:48 +00:00
|
|
|
void uiLayoutSetScaleX(uiLayout *layout, float scale)
|
2009-05-28 23:37:55 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
layout->scale[0] = scale;
|
2009-06-03 00:04:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void uiLayoutSetScaleY(uiLayout *layout, float scale)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
layout->scale[1] = scale;
|
2009-05-28 23:37:55 +00:00
|
|
|
}
|
|
|
|
|
2018-09-26 17:44:35 +02:00
|
|
|
void uiLayoutSetUnitsX(uiLayout *layout, float unit)
|
2018-09-25 20:59:04 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
layout->units[0] = unit;
|
2018-09-25 20:59:04 +02:00
|
|
|
}
|
|
|
|
|
2018-09-26 17:44:35 +02:00
|
|
|
void uiLayoutSetUnitsY(uiLayout *layout, float unit)
|
2018-09-25 20:59:04 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
layout->units[1] = unit;
|
2018-09-25 20:59:04 +02:00
|
|
|
}
|
|
|
|
|
2018-05-13 12:57:31 +02:00
|
|
|
void uiLayoutSetEmboss(uiLayout *layout, char emboss)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
layout->emboss = emboss;
|
2018-05-13 12:57:31 +02:00
|
|
|
}
|
|
|
|
|
2018-05-28 16:40:27 +02:00
|
|
|
bool uiLayoutGetPropSep(uiLayout *layout)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return (layout->item.flag & UI_ITEM_PROP_SEP) != 0;
|
2018-05-28 16:40:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void uiLayoutSetPropSep(uiLayout *layout, bool is_sep)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
SET_FLAG_FROM_TEST(layout->item.flag, is_sep, UI_ITEM_PROP_SEP);
|
2018-05-28 16:40:27 +02:00
|
|
|
}
|
|
|
|
|
2018-06-16 14:48:21 +02:00
|
|
|
bool uiLayoutGetPropDecorate(uiLayout *layout)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return (layout->item.flag & UI_ITEM_PROP_DECORATE) != 0;
|
2018-06-16 14:48:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void uiLayoutSetPropDecorate(uiLayout *layout, bool is_sep)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
SET_FLAG_FROM_TEST(layout->item.flag, is_sep, UI_ITEM_PROP_DECORATE);
|
2018-06-16 14:48:21 +02:00
|
|
|
}
|
|
|
|
|
2013-04-04 02:05:11 +00:00
|
|
|
bool uiLayoutGetActive(uiLayout *layout)
|
2009-05-28 23:37:55 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return layout->active;
|
2009-05-28 23:37:55 +00:00
|
|
|
}
|
|
|
|
|
2019-03-27 21:39:44 +11:00
|
|
|
bool uiLayoutGetActiveDefault(uiLayout *layout)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return layout->active_default;
|
2019-03-27 21:39:44 +11:00
|
|
|
}
|
|
|
|
|
2019-03-20 22:40:38 +11:00
|
|
|
bool uiLayoutGetActivateInit(uiLayout *layout)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return layout->activate_init;
|
2019-03-20 22:40:38 +11:00
|
|
|
}
|
|
|
|
|
2013-04-04 02:05:11 +00:00
|
|
|
bool uiLayoutGetEnabled(uiLayout *layout)
|
2009-05-28 23:37:55 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return layout->enabled;
|
2009-05-28 23:37:55 +00:00
|
|
|
}
|
|
|
|
|
2013-04-04 02:05:11 +00:00
|
|
|
bool uiLayoutGetRedAlert(uiLayout *layout)
|
2009-05-28 23:37:55 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return layout->redalert;
|
2009-05-28 23:37:55 +00:00
|
|
|
}
|
|
|
|
|
2013-04-04 02:05:11 +00:00
|
|
|
bool uiLayoutGetKeepAspect(uiLayout *layout)
|
2009-05-28 23:37:55 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return layout->keepaspect;
|
2009-05-28 23:37:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int uiLayoutGetAlignment(uiLayout *layout)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return layout->alignment;
|
2009-05-28 23:37:55 +00:00
|
|
|
}
|
|
|
|
|
2009-08-16 13:01:40 +00:00
|
|
|
int uiLayoutGetWidth(uiLayout *layout)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return layout->w;
|
2009-08-16 13:01:40 +00:00
|
|
|
}
|
|
|
|
|
2009-06-03 00:04:48 +00:00
|
|
|
float uiLayoutGetScaleX(uiLayout *layout)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return layout->scale[0];
|
2009-06-03 00:04:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float uiLayoutGetScaleY(uiLayout *layout)
|
2009-05-28 23:37:55 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return layout->scale[1];
|
2009-05-28 23:37:55 +00:00
|
|
|
}
|
|
|
|
|
2018-09-26 17:44:35 +02:00
|
|
|
float uiLayoutGetUnitsX(uiLayout *layout)
|
2018-09-25 20:59:04 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return layout->units[0];
|
2018-09-25 20:59:04 +02:00
|
|
|
}
|
|
|
|
|
2018-09-26 17:44:35 +02:00
|
|
|
float uiLayoutGetUnitsY(uiLayout *layout)
|
2018-09-25 20:59:04 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return layout->units[1];
|
2018-09-25 20:59:04 +02:00
|
|
|
}
|
|
|
|
|
2018-05-13 12:57:31 +02:00
|
|
|
int uiLayoutGetEmboss(uiLayout *layout)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (layout->emboss == UI_EMBOSS_UNDEFINED) {
|
2020-07-29 12:05:27 +10:00
|
|
|
return layout->root->block->emboss;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2020-07-03 14:20:10 +02:00
|
|
|
return layout->emboss;
|
2018-05-13 12:57:31 +02:00
|
|
|
}
|
|
|
|
|
2019-09-06 16:12:47 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Layout
|
|
|
|
* \{ */
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
|
2013-05-08 12:54:33 +00:00
|
|
|
static void ui_item_scale(uiLayout *litem, const float scale[2])
|
2009-06-03 00:04:48 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiItem *item;
|
|
|
|
int x, y, w, h;
|
2009-06-03 00:04:48 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (item = litem->items.last; item; item = item->prev) {
|
|
|
|
if (item->type != ITEM_BUTTON) {
|
|
|
|
uiLayout *subitem = (uiLayout *)item;
|
|
|
|
ui_item_scale(subitem, scale);
|
|
|
|
}
|
2018-06-26 11:57:22 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ui_item_size(item, &w, &h);
|
|
|
|
ui_item_offset(item, &x, &y);
|
2009-06-03 00:04:48 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (scale[0] != 0.0f) {
|
|
|
|
x *= scale[0];
|
|
|
|
w *= scale[0];
|
|
|
|
}
|
2009-06-03 00:04:48 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (scale[1] != 0.0f) {
|
|
|
|
y *= scale[1];
|
|
|
|
h *= scale[1];
|
|
|
|
}
|
2009-06-03 00:04:48 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ui_item_position(item, x, y, w, h);
|
|
|
|
}
|
2009-06-03 00:04:48 +00:00
|
|
|
}
|
|
|
|
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
static void ui_item_estimate(uiItem *item)
|
2009-03-13 13:38:41 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiItem *subitem;
|
|
|
|
|
|
|
|
if (item->type != ITEM_BUTTON) {
|
|
|
|
uiLayout *litem = (uiLayout *)item;
|
|
|
|
|
|
|
|
for (subitem = litem->items.first; subitem; subitem = subitem->next) {
|
|
|
|
ui_item_estimate(subitem);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (BLI_listbase_is_empty(&litem->items)) {
|
|
|
|
litem->w = 0;
|
|
|
|
litem->h = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (litem->scale[0] != 0.0f || litem->scale[1] != 0.0f) {
|
|
|
|
ui_item_scale(litem, litem->scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (litem->item.type) {
|
|
|
|
case ITEM_LAYOUT_COLUMN:
|
|
|
|
ui_litem_estimate_column(litem, false);
|
|
|
|
break;
|
|
|
|
case ITEM_LAYOUT_COLUMN_FLOW:
|
|
|
|
ui_litem_estimate_column_flow(litem);
|
|
|
|
break;
|
|
|
|
case ITEM_LAYOUT_GRID_FLOW:
|
|
|
|
ui_litem_estimate_grid_flow(litem);
|
|
|
|
break;
|
|
|
|
case ITEM_LAYOUT_ROW:
|
|
|
|
ui_litem_estimate_row(litem);
|
|
|
|
break;
|
|
|
|
case ITEM_LAYOUT_BOX:
|
|
|
|
ui_litem_estimate_box(litem);
|
|
|
|
break;
|
|
|
|
case ITEM_LAYOUT_ROOT:
|
|
|
|
ui_litem_estimate_root(litem);
|
|
|
|
break;
|
|
|
|
case ITEM_LAYOUT_ABSOLUTE:
|
|
|
|
ui_litem_estimate_absolute(litem);
|
|
|
|
break;
|
|
|
|
case ITEM_LAYOUT_SPLIT:
|
|
|
|
ui_litem_estimate_split(litem);
|
|
|
|
break;
|
|
|
|
case ITEM_LAYOUT_OVERLAP:
|
|
|
|
ui_litem_estimate_overlap(litem);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Force fixed size. */
|
|
|
|
if (litem->units[0] > 0) {
|
|
|
|
litem->w = UI_UNIT_X * litem->units[0];
|
|
|
|
}
|
|
|
|
if (litem->units[1] > 0) {
|
|
|
|
litem->h = UI_UNIT_Y * litem->units[1];
|
|
|
|
}
|
|
|
|
}
|
2009-03-13 13:38:41 +00:00
|
|
|
}
|
|
|
|
|
2011-10-03 01:01:01 +00:00
|
|
|
static void ui_item_align(uiLayout *litem, short nr)
|
2009-03-13 13:38:41 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiItem *item;
|
|
|
|
uiButtonItem *bitem;
|
|
|
|
uiLayoutItemBx *box;
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (item = litem->items.last; item; item = item->prev) {
|
|
|
|
if (item->type == ITEM_BUTTON) {
|
|
|
|
bitem = (uiButtonItem *)item;
|
2015-11-06 18:39:56 +01:00
|
|
|
#ifndef USE_UIBUT_SPATIAL_ALIGN
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ui_but_can_align(bitem->but))
|
2015-11-06 18:39:56 +01:00
|
|
|
#endif
|
2019-04-17 06:17:24 +02:00
|
|
|
{
|
|
|
|
if (!bitem->but->alignnr) {
|
|
|
|
bitem->but->alignnr = nr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (item->type == ITEM_LAYOUT_ABSOLUTE) {
|
|
|
|
/* pass */
|
|
|
|
}
|
|
|
|
else if (item->type == ITEM_LAYOUT_OVERLAP) {
|
|
|
|
/* pass */
|
|
|
|
}
|
|
|
|
else if (item->type == ITEM_LAYOUT_BOX) {
|
|
|
|
box = (uiLayoutItemBx *)item;
|
|
|
|
if (!box->roundbox->alignnr) {
|
|
|
|
box->roundbox->alignnr = nr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (((uiLayout *)item)->align) {
|
|
|
|
ui_item_align((uiLayout *)item, nr);
|
|
|
|
}
|
|
|
|
}
|
2009-03-13 13:38:41 +00:00
|
|
|
}
|
|
|
|
|
2009-05-28 23:37:55 +00:00
|
|
|
static void ui_item_flag(uiLayout *litem, int flag)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiItem *item;
|
|
|
|
uiButtonItem *bitem;
|
2009-05-28 23:37:55 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (item = litem->items.last; item; item = item->prev) {
|
|
|
|
if (item->type == ITEM_BUTTON) {
|
|
|
|
bitem = (uiButtonItem *)item;
|
|
|
|
bitem->but->flag |= flag;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ui_item_flag((uiLayout *)item, flag);
|
|
|
|
}
|
|
|
|
}
|
2009-05-28 23:37:55 +00:00
|
|
|
}
|
|
|
|
|
2009-05-27 00:03:49 +00:00
|
|
|
static void ui_item_layout(uiItem *item)
|
2009-03-13 13:38:41 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiItem *subitem;
|
|
|
|
|
|
|
|
if (item->type != ITEM_BUTTON) {
|
|
|
|
uiLayout *litem = (uiLayout *)item;
|
|
|
|
|
|
|
|
if (BLI_listbase_is_empty(&litem->items)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (litem->align) {
|
|
|
|
ui_item_align(litem, ++litem->root->block->alignnr);
|
|
|
|
}
|
|
|
|
if (!litem->active) {
|
|
|
|
ui_item_flag(litem, UI_BUT_INACTIVE);
|
|
|
|
}
|
|
|
|
if (!litem->enabled) {
|
|
|
|
ui_item_flag(litem, UI_BUT_DISABLED);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (litem->item.type) {
|
|
|
|
case ITEM_LAYOUT_COLUMN:
|
|
|
|
ui_litem_layout_column(litem, false);
|
|
|
|
break;
|
|
|
|
case ITEM_LAYOUT_COLUMN_FLOW:
|
|
|
|
ui_litem_layout_column_flow(litem);
|
|
|
|
break;
|
|
|
|
case ITEM_LAYOUT_GRID_FLOW:
|
|
|
|
ui_litem_layout_grid_flow(litem);
|
|
|
|
break;
|
|
|
|
case ITEM_LAYOUT_ROW:
|
|
|
|
ui_litem_layout_row(litem);
|
|
|
|
break;
|
|
|
|
case ITEM_LAYOUT_BOX:
|
|
|
|
ui_litem_layout_box(litem);
|
|
|
|
break;
|
|
|
|
case ITEM_LAYOUT_ROOT:
|
|
|
|
ui_litem_layout_root(litem);
|
|
|
|
break;
|
|
|
|
case ITEM_LAYOUT_ABSOLUTE:
|
|
|
|
ui_litem_layout_absolute(litem);
|
|
|
|
break;
|
|
|
|
case ITEM_LAYOUT_SPLIT:
|
|
|
|
ui_litem_layout_split(litem);
|
|
|
|
break;
|
|
|
|
case ITEM_LAYOUT_OVERLAP:
|
|
|
|
ui_litem_layout_overlap(litem);
|
|
|
|
break;
|
|
|
|
case ITEM_LAYOUT_RADIAL:
|
|
|
|
ui_litem_layout_radial(litem);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (subitem = litem->items.first; subitem; subitem = subitem->next) {
|
|
|
|
if (item->flag & UI_ITEM_BOX_ITEM) {
|
|
|
|
subitem->flag |= UI_ITEM_BOX_ITEM;
|
|
|
|
}
|
|
|
|
ui_item_layout(subitem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (item->flag & UI_ITEM_BOX_ITEM) {
|
|
|
|
uiButtonItem *bitem = (uiButtonItem *)item;
|
|
|
|
bitem->but->drawflag |= UI_BUT_BOX_ITEM;
|
|
|
|
}
|
|
|
|
}
|
2009-04-11 01:52:27 +00:00
|
|
|
}
|
|
|
|
|
2019-03-25 12:19:55 +11:00
|
|
|
static void ui_layout_end(uiBlock *block, uiLayout *layout, int *r_x, int *r_y)
|
2009-04-22 18:39:44 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (layout->root->handlefunc) {
|
|
|
|
UI_block_func_handle_set(block, layout->root->handlefunc, layout->root->argv);
|
|
|
|
}
|
2009-04-22 18:39:44 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ui_item_estimate(&layout->item);
|
|
|
|
ui_item_layout(&layout->item);
|
2009-04-22 18:39:44 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (r_x) {
|
|
|
|
*r_x = layout->x;
|
|
|
|
}
|
|
|
|
if (r_y) {
|
|
|
|
*r_y = layout->y;
|
|
|
|
}
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
}
|
2009-04-22 18:39:44 +00:00
|
|
|
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
static void ui_layout_free(uiLayout *layout)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiItem *item, *next;
|
2009-04-22 18:39:44 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (item = layout->items.first; item; item = next) {
|
|
|
|
next = item->next;
|
2009-04-22 18:39:44 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (item->type == ITEM_BUTTON) {
|
|
|
|
MEM_freeN(item);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ui_layout_free((uiLayout *)item);
|
|
|
|
}
|
|
|
|
}
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(layout);
|
2009-04-22 18:39:44 +00:00
|
|
|
}
|
|
|
|
|
2014-01-17 00:23:00 +01:00
|
|
|
static void ui_layout_add_padding_button(uiLayoutRoot *root)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (root->padding) {
|
|
|
|
/* add an invisible button for padding */
|
|
|
|
uiBlock *block = root->block;
|
|
|
|
uiLayout *prev_layout = block->curlayout;
|
2014-01-17 00:23:00 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
block->curlayout = root->layout;
|
|
|
|
uiDefBut(
|
|
|
|
block, UI_BTYPE_SEPR, 0, "", 0, 0, root->padding, root->padding, NULL, 0.0, 0.0, 0, 0, "");
|
|
|
|
block->curlayout = prev_layout;
|
|
|
|
}
|
2014-01-17 00:23:00 +01:00
|
|
|
}
|
|
|
|
|
2020-03-15 17:32:25 +11:00
|
|
|
uiLayout *UI_block_layout(uiBlock *block,
|
|
|
|
int dir,
|
|
|
|
int type,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int size,
|
|
|
|
int em,
|
|
|
|
int padding,
|
|
|
|
const uiStyle *style)
|
2009-03-13 13:38:41 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiLayout *layout;
|
|
|
|
uiLayoutRoot *root;
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
root = MEM_callocN(sizeof(uiLayoutRoot), "uiLayoutRoot");
|
|
|
|
root->type = type;
|
|
|
|
root->style = style;
|
|
|
|
root->block = block;
|
|
|
|
root->padding = padding;
|
|
|
|
root->opcontext = WM_OP_INVOKE_REGION_WIN;
|
2009-04-22 18:39:44 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
layout = MEM_callocN(sizeof(uiLayout), "uiLayout");
|
|
|
|
layout->item.type = (type == UI_LAYOUT_VERT_BAR) ? ITEM_LAYOUT_COLUMN : ITEM_LAYOUT_ROOT;
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Only used when 'UI_ITEM_PROP_SEP' is set. */
|
|
|
|
layout->item.flag = UI_ITEM_PROP_DECORATE;
|
2018-06-16 14:48:21 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
layout->x = x;
|
|
|
|
layout->y = y;
|
|
|
|
layout->root = root;
|
|
|
|
layout->space = style->templatespace;
|
|
|
|
layout->active = 1;
|
|
|
|
layout->enabled = 1;
|
|
|
|
layout->context = NULL;
|
|
|
|
layout->emboss = UI_EMBOSS_UNDEFINED;
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (type == UI_LAYOUT_MENU || type == UI_LAYOUT_PIEMENU) {
|
|
|
|
layout->space = 0;
|
|
|
|
}
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (dir == UI_LAYOUT_HORIZONTAL) {
|
|
|
|
layout->h = size;
|
|
|
|
layout->root->emh = em * UI_UNIT_Y;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
layout->w = size;
|
|
|
|
layout->root->emw = em * UI_UNIT_X;
|
|
|
|
}
|
2009-05-19 17:13:33 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
block->curlayout = layout;
|
|
|
|
root->layout = layout;
|
|
|
|
BLI_addtail(&block->layouts, root);
|
2014-01-17 00:23:00 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ui_layout_add_padding_button(root);
|
2018-05-23 10:47:12 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return layout;
|
2009-03-13 13:38:41 +00:00
|
|
|
}
|
|
|
|
|
2009-05-28 23:37:55 +00:00
|
|
|
uiBlock *uiLayoutGetBlock(uiLayout *layout)
|
2009-03-13 13:38:41 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return layout->root->block;
|
2009-03-13 13:38:41 +00:00
|
|
|
}
|
|
|
|
|
2009-06-09 10:30:11 +00:00
|
|
|
int uiLayoutGetOperatorContext(uiLayout *layout)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return layout->root->opcontext;
|
2009-06-09 10:30:11 +00:00
|
|
|
}
|
|
|
|
|
2014-11-09 21:20:40 +01:00
|
|
|
void UI_block_layout_set_current(uiBlock *block, uiLayout *layout)
|
2009-03-13 13:38:41 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
block->curlayout = layout;
|
2009-03-13 13:38:41 +00:00
|
|
|
}
|
|
|
|
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
void ui_layout_add_but(uiLayout *layout, uiBut *but)
|
2009-03-13 13:38:41 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiButtonItem *bitem;
|
2018-05-23 10:47:12 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
bitem = MEM_callocN(sizeof(uiButtonItem), "uiButtonItem");
|
|
|
|
bitem->item.type = ITEM_BUTTON;
|
|
|
|
bitem->but = but;
|
2017-02-02 17:30:50 +03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
int w, h;
|
|
|
|
ui_item_size((uiItem *)bitem, &w, &h);
|
|
|
|
/* XXX uiBut hasn't scaled yet
|
|
|
|
* we can flag the button as not expandable, depending on its size */
|
|
|
|
if (w <= 2 * UI_UNIT_X && (!but->str || but->str[0] == '\0')) {
|
2019-09-19 16:14:47 +02:00
|
|
|
bitem->item.flag |= UI_ITEM_FIXED_SIZE;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2017-02-02 17:30:50 +03:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (layout->child_items_layout) {
|
|
|
|
BLI_addtail(&layout->child_items_layout->items, bitem);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BLI_addtail(&layout->items, bitem);
|
|
|
|
}
|
2009-05-28 23:13:42 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (layout->context) {
|
|
|
|
but->context = layout->context;
|
|
|
|
but->context->used = true;
|
|
|
|
}
|
2018-05-13 12:57:31 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (layout->emboss != UI_EMBOSS_UNDEFINED) {
|
2020-07-29 12:05:27 +10:00
|
|
|
but->emboss = layout->emboss;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2009-03-13 13:38:41 +00:00
|
|
|
}
|
|
|
|
|
2019-09-19 16:14:47 +02:00
|
|
|
void uiLayoutSetFixedSize(uiLayout *layout, bool fixed_size)
|
|
|
|
{
|
|
|
|
if (fixed_size) {
|
|
|
|
layout->item.flag |= UI_ITEM_FIXED_SIZE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
layout->item.flag &= ~UI_ITEM_FIXED_SIZE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool uiLayoutGetFixedSize(uiLayout *layout)
|
|
|
|
{
|
|
|
|
return (layout->item.flag & UI_ITEM_FIXED_SIZE) != 0;
|
|
|
|
}
|
|
|
|
|
2009-05-28 23:37:55 +00:00
|
|
|
void uiLayoutSetOperatorContext(uiLayout *layout, int opcontext)
|
2009-03-13 13:38:41 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
layout->root->opcontext = opcontext;
|
2009-03-13 13:38:41 +00:00
|
|
|
}
|
|
|
|
|
2009-05-28 23:37:55 +00:00
|
|
|
void uiLayoutSetFunc(uiLayout *layout, uiMenuHandleFunc handlefunc, void *argv)
|
2009-04-22 18:39:44 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
layout->root->handlefunc = handlefunc;
|
|
|
|
layout->root->argv = argv;
|
2009-04-22 18:39:44 +00:00
|
|
|
}
|
|
|
|
|
2019-03-25 12:19:55 +11:00
|
|
|
void UI_block_layout_resolve(uiBlock *block, int *r_x, int *r_y)
|
2009-03-13 13:38:41 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiLayoutRoot *root;
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(block->active);
|
2014-06-15 01:40:15 +10:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (r_x) {
|
|
|
|
*r_x = 0;
|
|
|
|
}
|
|
|
|
if (r_y) {
|
|
|
|
*r_y = 0;
|
|
|
|
}
|
2009-03-13 13:38:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
block->curlayout = NULL;
|
2009-05-19 17:13:33 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (root = block->layouts.first; root; root = root->next) {
|
|
|
|
ui_layout_add_padding_button(root);
|
2014-01-17 00:23:00 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* NULL in advance so we don't interfere when adding button */
|
|
|
|
ui_layout_end(block, root->layout, r_x, r_y);
|
|
|
|
ui_layout_free(root->layout);
|
|
|
|
}
|
2009-03-29 19:44:39 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_freelistN(&block->layouts);
|
2009-05-19 17:13:33 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* XXX silly trick, interface_templates.c doesn't get linked
|
|
|
|
* because it's not used by other files in this module? */
|
|
|
|
{
|
|
|
|
UI_template_fix_linking();
|
|
|
|
}
|
2009-03-13 13:38:41 +00:00
|
|
|
}
|
|
|
|
|
2010-11-17 09:45:45 +00:00
|
|
|
void uiLayoutSetContextPointer(uiLayout *layout, const char *name, PointerRNA *ptr)
|
2009-03-13 13:38:41 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiBlock *block = layout->root->block;
|
|
|
|
layout->context = CTX_store_add(&block->contexts, name, ptr);
|
2009-03-29 19:44:39 +00:00
|
|
|
}
|
2009-03-25 14:34:17 +00:00
|
|
|
|
2012-04-03 15:18:59 +00:00
|
|
|
void uiLayoutContextCopy(uiLayout *layout, bContextStore *context)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
uiBlock *block = layout->root->block;
|
|
|
|
layout->context = CTX_store_add_all(&block->contexts, context);
|
2012-04-03 15:18:59 +00:00
|
|
|
}
|
|
|
|
|
2017-11-02 18:19:11 +11:00
|
|
|
void uiLayoutSetContextFromBut(uiLayout *layout, uiBut *but)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (but->opptr) {
|
|
|
|
uiLayoutSetContextPointer(layout, "button_operator", but->opptr);
|
|
|
|
}
|
2017-11-02 18:19:11 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (but->rnapoin.data && but->rnaprop) {
|
|
|
|
/* TODO: index could be supported as well */
|
|
|
|
PointerRNA ptr_prop;
|
|
|
|
RNA_pointer_create(NULL, &RNA_Property, but->rnaprop, &ptr_prop);
|
|
|
|
uiLayoutSetContextPointer(layout, "button_prop", &ptr_prop);
|
|
|
|
uiLayoutSetContextPointer(layout, "button_pointer", &but->rnapoin);
|
|
|
|
}
|
2017-11-02 18:19:11 +11:00
|
|
|
}
|
2009-11-28 17:45:23 +00:00
|
|
|
|
2011-11-14 14:42:47 +00:00
|
|
|
/* this is a bit of a hack but best keep it in one place at least */
|
2014-11-09 21:20:40 +01:00
|
|
|
MenuType *UI_but_menutype_get(uiBut *but)
|
2011-11-14 14:42:47 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (but->menu_create_func == ui_item_menutype_func) {
|
|
|
|
return (MenuType *)but->poin;
|
|
|
|
}
|
2020-07-03 14:20:10 +02:00
|
|
|
return NULL;
|
2011-11-14 14:42:47 +00:00
|
|
|
}
|
2017-11-02 18:19:11 +11:00
|
|
|
|
2018-04-22 17:16:39 +02:00
|
|
|
/* this is a bit of a hack but best keep it in one place at least */
|
|
|
|
PanelType *UI_but_paneltype_get(uiBut *but)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (but->menu_create_func == ui_item_paneltype_func) {
|
|
|
|
return (PanelType *)but->poin;
|
|
|
|
}
|
2020-07-03 14:20:10 +02:00
|
|
|
return NULL;
|
2018-04-22 17:16:39 +02:00
|
|
|
}
|
|
|
|
|
2017-11-02 18:19:11 +11:00
|
|
|
void UI_menutype_draw(bContext *C, MenuType *mt, struct uiLayout *layout)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Menu menu = {
|
|
|
|
.layout = layout,
|
|
|
|
.type = mt,
|
|
|
|
};
|
2017-11-02 18:19:11 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (G.debug & G_DEBUG_WM) {
|
|
|
|
printf("%s: opening menu \"%s\"\n", __func__, mt->idname);
|
|
|
|
}
|
2017-11-02 18:19:11 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (layout->context) {
|
|
|
|
CTX_store_set(C, layout->context);
|
|
|
|
}
|
2017-11-02 18:19:11 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
mt->draw(C, &menu);
|
2017-11-02 18:19:11 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (layout->context) {
|
|
|
|
CTX_store_set(C, NULL);
|
|
|
|
}
|
2017-11-02 18:19:11 +11:00
|
|
|
}
|
2018-05-25 12:19:04 +02:00
|
|
|
|
2020-07-20 19:46:08 +02:00
|
|
|
static bool ui_layout_has_panel_label(const uiLayout *layout, const PanelType *pt)
|
|
|
|
{
|
|
|
|
LISTBASE_FOREACH (uiItem *, subitem, &layout->items) {
|
|
|
|
if (subitem->type == ITEM_BUTTON) {
|
|
|
|
uiButtonItem *bitem = (uiButtonItem *)subitem;
|
|
|
|
if (!(bitem->but->flag & UI_HIDDEN) && STREQ(bitem->but->str, pt->label)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
uiLayout *litem = (uiLayout *)subitem;
|
|
|
|
if (ui_layout_has_panel_label(litem, pt)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static void ui_paneltype_draw_impl(bContext *C, PanelType *pt, uiLayout *layout, bool show_header)
|
2018-05-25 12:19:04 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Panel *panel = MEM_callocN(sizeof(Panel), "popover panel");
|
|
|
|
panel->type = pt;
|
|
|
|
panel->flag = PNL_POPOVER;
|
2018-06-09 17:36:28 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
uiLayout *last_item = layout->items.last;
|
2018-06-29 17:46:16 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Draw main panel. */
|
|
|
|
if (show_header) {
|
|
|
|
uiLayout *row = uiLayoutRow(layout, false);
|
|
|
|
if (pt->draw_header) {
|
|
|
|
panel->layout = row;
|
|
|
|
pt->draw_header(C, panel);
|
|
|
|
panel->layout = NULL;
|
|
|
|
}
|
2020-07-20 19:46:08 +02:00
|
|
|
|
|
|
|
/* draw_header() is often used to add a checkbox to the header. If we add the label like below
|
|
|
|
* the label is disconnected from the checkbox, adding a weird looking gap. As workaround, let
|
|
|
|
* the checkbox add the label instead. */
|
|
|
|
if (!ui_layout_has_panel_label(row, pt)) {
|
|
|
|
uiItemL(row, CTX_IFACE_(pt->translation_context, pt->label), ICON_NONE);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-05-25 12:19:04 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
panel->layout = layout;
|
|
|
|
pt->draw(C, panel);
|
|
|
|
panel->layout = NULL;
|
2020-06-30 10:47:49 +02:00
|
|
|
BLI_assert(panel->runtime.custom_data_ptr == NULL);
|
2018-05-25 12:19:04 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(panel);
|
2018-06-09 14:21:39 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Draw child panels. */
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (LinkData *, link, &pt->children) {
|
2019-04-17 06:17:24 +02:00
|
|
|
PanelType *child_pt = link->data;
|
2018-06-29 17:46:16 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (child_pt->poll == NULL || child_pt->poll(C, child_pt)) {
|
|
|
|
/* Add space if something was added to the layout. */
|
|
|
|
if (last_item != layout->items.last) {
|
|
|
|
uiItemS(layout);
|
|
|
|
last_item = layout->items.last;
|
|
|
|
}
|
2018-06-29 17:46:16 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
uiLayout *col = uiLayoutColumn(layout, false);
|
|
|
|
ui_paneltype_draw_impl(C, child_pt, col, true);
|
|
|
|
}
|
|
|
|
}
|
2018-06-09 14:21:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used for popup panels only.
|
|
|
|
*/
|
|
|
|
void UI_paneltype_draw(bContext *C, PanelType *pt, uiLayout *layout)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (layout->context) {
|
|
|
|
CTX_store_set(C, layout->context);
|
|
|
|
}
|
2018-06-09 14:21:39 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ui_paneltype_draw_impl(C, pt, layout, false);
|
2018-05-25 12:19:04 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (layout->context) {
|
|
|
|
CTX_store_set(C, NULL);
|
|
|
|
}
|
2018-05-25 12:19:04 +02:00
|
|
|
}
|
2019-09-06 16:12:47 +10:00
|
|
|
|
|
|
|
/** \} */
|