29 items_.append(std::move(item));
40 for (
const auto &item_ptr :
items_) {
52 return match ? *match :
nullptr;
55 void AbstractGridView::change_state_delayed()
59 "These state changes are supposed to be delayed until reconstruction is completed");
63 void AbstractGridView::update_children_from_old(
const AbstractView &old_view)
69 if (!matching_old_item) {
73 new_item.update_from_old(*matching_old_item);
103 void AbstractGridViewItem::grid_tile_click_fn(
struct bContext * ,
114 void AbstractGridViewItem::add_grid_tile_button(
uiBlock &block)
146 void AbstractGridViewItem::change_state_delayed()
157 "Item activation can't be done until reconstruction is completed");
179 throw std::runtime_error(
180 "Invalid state, item must be added through AbstractGridView::add_item()");
207 const int cols_per_row_ = 0;
222 void add_spacer_button(
uiBlock &block,
int row_count)
const;
227 const int cols_per_row)
228 : v2d_(v2d), grid_view_(grid_view), style_(grid_view.get_style()), cols_per_row_(cols_per_row)
230 visible_items_range_ = get_visible_range();
233 IndexRange BuildOnlyVisibleButtonsHelper::get_visible_range()
const
235 int first_idx_in_view = 0;
236 int max_items_in_view = 0;
239 if (!
IS_EQF(scroll_ofs_y, 0)) {
240 const int scrolled_away_rows = (int)scroll_ofs_y / style_.
tile_height;
242 first_idx_in_view = scrolled_away_rows * cols_per_row_;
247 max_items_in_view = (count_rows_in_view + 1) * cols_per_row_;
250 return IndexRange(first_idx_in_view, max_items_in_view);
255 return visible_items_range_.
contains(item_idx);
262 if (
IS_EQF(scroll_ofs_y, 0)) {
266 const int scrolled_away_rows = (int)scroll_ofs_y / style_.
tile_height;
267 add_spacer_button(block, scrolled_away_rows);
273 const int last_visible_idx = visible_items_range_.
last();
275 if (last_item_idx > last_visible_idx) {
276 const int remaining_rows = (cols_per_row_ > 0) ?
277 (last_item_idx - last_visible_idx) / cols_per_row_ :
279 BuildOnlyVisibleButtonsHelper::add_spacer_button(block, remaining_rows);
283 void BuildOnlyVisibleButtonsHelper::add_spacer_button(
uiBlock &block,
const int row_count)
const
287 for (
int remaining_rows = row_count; remaining_rows > 0;) {
288 const short row_count_this_iter =
std::min(
305 remaining_rows -= row_count_this_iter;
331 void GridViewLayoutBuilder::build_grid_tile(
uiLayout &grid_layout,
336 item.add_grid_tile_button(block_);
343 uiLayout *prev_layout = current_layout();
367 build_grid_tile(*grid_layout, item);
374 for (
int padding_item_idx = 0; padding_item_idx < (cols_per_row - grid_view.
get_item_count());
375 padding_item_idx++) {
385 uiLayout *GridViewLayoutBuilder::current_layout()
const
400 grid_view.change_state_delayed();
448 void PreviewGridItem::on_activate()
455 std::optional<bool> PreviewGridItem::should_be_active()
const
#define BLI_assert_msg(a, msg)
MINLINE int round_fl_to_int(float a)
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
uiBlock * uiLayoutGetBlock(uiLayout *layout)
uiLayout * uiLayoutColumn(uiLayout *layout, bool align)
uiLayout * uiLayoutGridFlow(uiLayout *layout, bool row_major, int columns_len, bool even_columns, bool even_rows, bool align)
uiLayout * uiLayoutOverlap(uiLayout *layout)
uiBut * uiDefBut(uiBlock *block, int type, int retval, const char *str, int x, int y, short width, short height, void *poin, float min, float max, float a1, float a2, const char *tip)
void uiItemS(uiLayout *layout)
uiLayout * uiLayoutRow(uiLayout *layout, bool align)
int UI_preview_tile_size_x(void)
void UI_but_func_set(uiBut *but, uiButHandleFunc func, void *arg1, void *arg2)
int uiLayoutGetWidth(uiLayout *layout)
int UI_preview_tile_size_y(void)
void UI_block_layout_set_current(uiBlock *block, uiLayout *layout)
struct uiViewItemHandle uiViewItemHandle
constexpr int64_t last(const int64_t n=0) const
constexpr bool contains(int64_t value) const
virtual void on_activate()
virtual std::optional< bool > should_be_active() const
AbstractGridViewItem(StringRef identifier)
virtual void build_grid_tile(uiLayout &layout) const =0
uiButViewItem * view_item_but_
const AbstractGridView & get_view() const
virtual bool matches(const AbstractViewItem &other) const override
Map< StringRef, AbstractGridViewItem * > item_map_
ItemT & add_item(Args &&...args)
int get_item_count() const
void foreach_item(ItemIterFn iter_fn) const
const GridViewStyle & get_style() const
friend class AbstractGridViewItem
virtual void build_items()=0
Vector< std::unique_ptr< AbstractGridViewItem > > items_
bool is_reconstructed() const
void update_from_old(uiBlock &new_block)
void register_item(AbstractViewItem &item)
GridViewBuilder(uiBlock &block)
void build_grid_view(AbstractGridView &grid_view, const View2D &v2d)
GridViewLayoutBuilder(uiBlock &block)
void build_from_view(const AbstractGridView &grid_view, const View2D &v2d) const
std::function< void(PreviewGridItem &new_active)> ActivateFn
PreviewGridItem(StringRef identifier, StringRef label, int preview_icon_id)
void build_grid_tile(uiLayout &layout) const override
void set_is_active_fn(IsActiveFn fn)
void set_on_activate_fn(ActivateFn fn)
std::function< bool()> IsActiveFn
void ui_def_but_icon(uiBut *but, const int icon, const int flag)
GridViewStyle(int width, int height)
struct uiLayout * curlayout
uiViewItemHandle * view_item