summaryrefslogtreecommitdiffstats
path: root/src/ui/widget/spin-button-tool-item.cpp
diff options
context:
space:
mode:
authorAlexander Valavanis <valavanisalex@gmail.com>2019-01-27 14:09:16 +0000
committerAlexander Valavanis <valavanisalex@gmail.com>2019-01-27 14:09:16 +0000
commit544202e9a0a16f66f64206e049298f8f1a9dad9c (patch)
tree54fb47f09a488c039a07e772ff337b4e4ed6ef0b /src/ui/widget/spin-button-tool-item.cpp
parentSpinButtonToolItem: Allow labels on numeric menu (diff)
downloadinkscape-544202e9a0a16f66f64206e049298f8f1a9dad9c.tar.gz
inkscape-544202e9a0a16f66f64206e049298f8f1a9dad9c.zip
SpinButtonToolItem: Allow custom numeric menu items
Diffstat (limited to 'src/ui/widget/spin-button-tool-item.cpp')
-rw-r--r--src/ui/widget/spin-button-tool-item.cpp34
1 files changed, 29 insertions, 5 deletions
diff --git a/src/ui/widget/spin-button-tool-item.cpp b/src/ui/widget/spin-button-tool-item.cpp
index 7f7ed99e3..ecca051a4 100644
--- a/src/ui/widget/spin-button-tool-item.cpp
+++ b/src/ui/widget/spin-button-tool-item.cpp
@@ -10,8 +10,6 @@
#include "spinbutton.h"
-typedef std::vector< std::pair<double, Glib::ustring> > NumericMenuData;
-
namespace Inkscape {
namespace UI {
namespace Widget {
@@ -292,10 +290,8 @@ SpinButtonToolItem::create_numeric_menu()
// For digits = 2, we get epsilon = 0.9 * 10^-2 = 0.009 etc...
auto epsilon = 0.9 * pow(10.0, -float(digits));
- // For now, set some fixed values based on the adjustment's
+ // Start by setting some fixed values based on the adjustment's
// parameters.
- //
- // TODO: Allow custom values for the list to be specified
NumericMenuData values;
values.push_back(std::make_pair(upper, ""));
values.push_back(std::make_pair(adj_value + page, ""));
@@ -305,6 +301,15 @@ SpinButtonToolItem::create_numeric_menu()
values.push_back(std::make_pair(adj_value - page, ""));
values.push_back(std::make_pair(lower, ""));
+ // Now add any custom items
+ for (auto custom_data : _custom_menu_data) {
+ values.push_back(custom_data);
+ }
+
+ // Sort the numeric menu items into reverse numerical order (largest at top of menu)
+ std::sort (begin(values), end(values));
+ std::reverse(begin(values), end(values));
+
for (auto value : values)
{
auto numeric_menu_item = create_numeric_menu_item(&group, value.first, value.second);
@@ -477,6 +482,25 @@ SpinButtonToolItem::grab_button_focus()
{
_btn->grab_focus();
}
+
+void
+SpinButtonToolItem::set_custom_numeric_menu_items(std::vector<double>& values,
+ std::vector<Glib::ustring>& labels)
+{
+ if(values.size() != labels.size()) {
+ g_warning("Cannot add custom menu items. Value and label arrays are different sizes");
+ return;
+ }
+
+ _custom_menu_data.clear();
+
+ int i = 0;
+
+ for (auto value : values) {
+ _custom_menu_data.push_back(std::make_pair(value, labels[i++]));
+ }
+}
+
} // namespace Widget
} // namespace UI
} // namespace Inkscape