Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
drop-down-list.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
6/*
7 * Authors:
8 * Mike Kowalski
9 *
10 * Copyright (C) 2024 Authors
11 *
12 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
13 */
14
15#include <glibmm/ustring.h>
16#include <gtkmm/builder.h>
17#include <gtkmm/dropdown.h>
18#include <gtkmm/signallistitemfactory.h>
19#include <gtkmm/stringlist.h>
20
21#ifndef INCLUDE_DROP_DOWN_LIST_H
22#define INCLUDE_DROP_DOWN_LIST_H
23
24namespace Inkscape::UI::Widget {
25
26class DropDownList : public Gtk::DropDown {
27public:
29
30 // GtkBuilder constructor
31 DropDownList(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& builder);
32
33 // append a new item to the dropdown list, return its position
34 unsigned int append(const Glib::ustring& item);
35 // get n-th item
36 Glib::ustring get_string(unsigned int position) const { return _model->get_string(position); }
37 // get number of items
38 unsigned int get_item_count() const { return _model->get_n_items(); }
39 // delete all items
40 void remove_all() { _model->splice(0, _model->get_n_items(), {}); }
41
42 // selected item changed signal
43 Glib::SignalProxyProperty signal_changed() { return property_selected().signal_changed(); }
44
45 // enable searching in a popup list
46 void enable_search(bool enable = true);
47
48 // if set, this callback will be invoked for each item position - returning true will
49 // insert a separator on top of that item
50 void set_row_separator_func(std::function<bool (unsigned int)> callback);
51
52private:
53 void _init();
54 Glib::RefPtr<Gtk::StringList> _model = Gtk::StringList::create({});
55 Glib::RefPtr<Gtk::SignalListItemFactory> _factory = Gtk::SignalListItemFactory::create();
56 std::function<bool (unsigned int)> _separator_callback;
57};
58
59} // namespace
60
61#endif // INCLUDE_DROP_DOWN_LIST_H
unsigned int append(const Glib::ustring &item)
unsigned int get_item_count() const
Glib::RefPtr< Gtk::SignalListItemFactory > _factory
Glib::SignalProxyProperty signal_changed()
Glib::RefPtr< Gtk::StringList > _model
std::function< bool(unsigned int)> _separator_callback
void set_row_separator_func(std::function< bool(unsigned int)> callback)
Glib::ustring get_string(unsigned int position) const
void enable_search(bool enable=true)
SPItem * item
Custom widgets.
Definition desktop.h:126
Glib::RefPtr< Gtk::Builder > builder