3 #ifdef windex_has_boost
4 #include <boost/property_tree/ptree.hpp>
5 #include <boost/property_tree/json_parser.hpp>
18 const std::string &name,
19 const std::string &value)
21 myLabel(wex::maker::make<wex::label>(*parent)),
22 myEditbox(wex::maker::make<editbox>(*parent)),
23 myCombobox(wex::maker::make<choice>(*parent)),
24 myCheckbox(wex::maker::make<checkbox>(*parent)),
25 myCategoryExpanded(wex::maker::make<checkbox>(*parent)),
27 myType(eType::string),
34 myLabelClicked =
true;
38 myEditbox.text(myValue);
42 const std::string &name,
44 : myName(name), myValue(std::to_string((
int)value)), W(
windex::get()),
45 myLabel(wex::maker::make<label>(*parent)), myEditbox(wex::maker::make<editbox>(*parent)), myCombobox(wex::maker::make<choice>(*parent)), myCheckbox(wex::maker::make<checkbox>(*parent)), myCategoryExpanded(wex::maker::make<checkbox>(*parent)), myLabelWidth(100), myType(eType::check)
48 myCheckbox.check(value);
56 const std::string &name,
57 const std::vector<std::string> &value)
58 : myName(name), myValue(
""), W(
windex::get()), myLabel(wex::maker::make<label>(*parent)), myEditbox(wex::maker::make<editbox>(*parent)), myCombobox(wex::maker::make<choice>(*parent)), myCheckbox(wex::maker::make<checkbox>(*parent)), myCategoryExpanded(wex::maker::make<checkbox>(*parent)), myLabelWidth(100), myType(eType::choice)
70 const std::string &name)
73 myCategoryExpanded.text(myName);
74 myCategoryExpanded.
plus();
75 myCategoryExpanded.check();
84 myCategoryExpanded.~checkbox();
87 void move(
const std::vector<int> &r)
89 std::vector<int> rl(r);
94 std::vector<int> re(r);
96 re[0] += myLabelWidth;
98 re[2] -= myLabelWidth + 25;
103 myCategoryExpanded.
move({0, 0, 0, 0});
107 re[3] *= myCombobox.
count();
108 myCombobox.
move(re[0], re[1], re[2], re[3]);
113 case eType::category:
115 re[1] += 0.5 * re[3];
117 myCategoryExpanded.
move(re);
118 myLabel.
move({0, 0, 0, 0});
122 void labelWidth(
int w)
126 void bgcolor(
int color)
131 bool labelClicked()
const
133 return myLabelClicked;
135 void labelClicked(
bool f)
139 std::string labeltext()
const
141 return myLabel.text();
144 void tabList(
bool f =
true)
146 if (myType != eType::string)
148 auto s = GetWindowLongPtr(myEditbox.
handle(), GWL_STYLE);
164 property &
tooltip(
const std::string &tip,
int width = 0)
189 void show(
bool f =
true)
203 case eType::category:
205 myCategoryExpanded.
show(f);
220 myCategoryExpanded.
update();
223 const std::string &name()
const
227 const std::string value()
const
232 return myEditbox.text();
238 return std::to_string((
int)myCheckbox.isChecked());
241 case eType::category:
244 return std::string(
"");
249 if (myType == eType::check)
250 return myCheckbox.isChecked();
254 property &
value(
const std::string v)
277 void value_bool(
bool v)
282 myValue = std::to_string((
int)v);
296 myValue = myEditbox.text();
302 myValue = std::to_string((
int)myCheckbox.isChecked());
304 case eType::category:
310 const std::string savedValue()
const
315 bool isCategory()
const
317 return myType == eType::category;
319 bool isExpanded()
const
323 return myCategoryExpanded.isChecked();
327 myCategoryExpanded.check(f);
345 #ifdef windex_has_boost
346 void BoostPropertyTree(
347 boost::property_tree::ptree &tree,
348 const std::string &catname)
351 if (myType == eType::choice)
353 catname + myName +
".value",
357 catname + myName +
".value",
360 catname + myName +
".type",
361 std::to_string((
int)myType));
362 if (myType == eType::choice)
364 for (
int k = 0; k < myCombobox.
count(); k++)
366 catname + myName +
".choice" + std::to_string(k),
398 typedef std::shared_ptr<property> prop_t;
401 :
gui(parent,
"windex", WS_CHILD, WS_EX_CONTROLPARENT), myHeight(25), myHeightCategory(2), myWidth(300), myLabelWidth(100), myBGColor(0xc8c8c8), myfScroll(
false), myftabstop(
false)
427 const std::string &name,
428 const std::string &
value)
430 myProperty.push_back(prop_t(
new property(
this, name,
value)));
431 CommonConstruction();
432 return *myProperty.back().get();
440 const std::string &name,
441 const std::vector<std::string> &
choice)
444 CommonConstruction();
445 return *myProperty.back().get();
453 const std::string &name,
456 myProperty.push_back(prop_t(
new property(
this, name, f)));
457 CommonConstruction();
458 return *myProperty.back().get();
462 const std::string &name)
464 myProperty.push_back(prop_t(
new property(
this, name)));
465 CommonConstruction();
468 #ifdef windex_has_boost
475 void add(boost::property_tree::ptree &pt)
483 for (
auto prop : cat.second)
485 int type = pt.get<
int>(cat.first +
"." + prop.first +
"." +
"type", 0);
493 std::vector<std::string> vc;
494 for (
auto ch : prop.second)
496 if (ch.first.find(
"choice") == 0)
498 vc.push_back(ch.second.data());
501 choice(prop.first, vc).value(pt.get<std::string>(cat.first +
"." + prop.first +
"." +
"value"));
511 pt.get<std::string>(cat.first +
"." + prop.first +
"." +
"value",
"missing"));
519 boost::property_tree::ptree
525 boost::property_tree::ptree tree;
527 for (
auto p : myProperty)
531 catname = p->name() +
".";
535 p->BoostPropertyTree(tree, catname);
544 std::stringstream ss;
545 write_json(ss, BoostPropertyTree());
554 void addjson(
const std::string &json)
556 std::cout <<
"->addjson\n";
557 std::stringstream ss(json);
558 boost::property_tree::ptree tree;
560 std::cout <<
"<-read\n";
562 std::cout <<
"<-addjson\n";
575 const std::string name,
578 for (
auto &p : myProperty)
580 if (p->name() == name &&
592 for (
auto &p : myProperty)
601 void move(
const std::vector<int> &r)
606 void labelWidth(
int w)
614 for (
auto &p : myProperty)
620 property *
find(
const std::string &name)
622 for (
auto &p : myProperty)
625 if (p->name() == name)
634 const std::string &name)
636 for (
auto p = myProperty.begin();
637 p != myProperty.end();
640 if ((*p)->isCategory())
645 p != myProperty.end();
648 if ((*p)->isCategory())
650 if ((*p)->name() == name)
660 const std::string
value(
const std::string &name)
663 property *p =
find(name);
666 static std::string
null;
669 std::string v = p->value();
673 bool isChecked(
const std::string &name)
675 property *p =
find(name);
678 return p->isChecked();
684 for (
auto &p : myProperty)
690 int propHeight()
const
705 myHeightCategory = 1;
707 myHeightCategory = 2;
713 int propCount()
const
715 return (
int)myProperty.size();
723 void nameClick(std::function<
void(
const std::string &)> f)
739 for (
auto p : myProperty)
744 std::vector<prop_t> myProperty;
746 int myHeightCategory;
752 std::function<void()> onChange;
753 std::function<void(
const std::string &)> onName;
755 void CommonConstruction()
757 prop_t P = myProperty.back();
758 P->labelWidth(myLabelWidth);
759 P->bgcolor(myBGColor);
765 ((
int)myProperty.size() + 1) * myHeight);
779 for (
auto P : myProperty)
781 if (P->labelClicked())
785 onName(P->labeltext());
788 P->labelClicked(
false);
797 for (
auto P : myProperty)
801 bool expanded =
true;
803 for (
auto P : myProperty)
808 P->move({0, index * myHeight, myWidth, myHeightCategory * myHeight});
810 index += myHeightCategory;
811 expanded = P->isExpanded();
816 P->move({0, index * myHeight, myWidth, myHeight});
823 P->move({0, 0, 0, 0});
A widget that user can click to toggle a true/false value.
Definition: wex.h:2473
void plus(bool f=true)
set type to plus, useful to indicate expanded or collapsed property categories
Definition: wex.h:2493
A widget where user can choose from a dropdown list of strings.
Definition: wex.h:2715
std::string text(int i)
get text by index
Definition: wex.h:2799
void itemHeight(int h)
set item height in drop doown list
Definition: wex.h:2730
void add(const std::string &s)
Add an option.
Definition: wex.h:2746
void select(int i)
Select by index.
Definition: wex.h:2765
void move(int x, int y, int w, int h)
Override move to ensure height is sufficient to allow dropdown to apprear.
Definition: wex.h:2723
int count()
get count of items
Definition: wex.h:2810
std::string selectedText()
get text of selected item
Definition: wex.h:2791
A widget where user can enter a single line string.
Definition: wex.h:2635
void readonly(bool f=true)
disable ( or enable ) user editing
Definition: wex.h:2671
void clickPropogate(bool f=true)
specify that click event should propogate to parent window after currently registered click event han...
Definition: wex.h:296
void change(int id, std::function< void(void)> f)
register function to call when control changes
Definition: wex.h:351
void click(std::function< void(void)> f, bool propogate=false)
register click event handler
Definition: wex.h:276
The base class for all windex gui elements.
Definition: wex.h:824
void update()
force widget to redraw completely
Definition: wex.h:1575
void tooltip(const std::string &text, int width=0)
Add tooltip that pops up helpfully when mouse cursor hovers over widget.
Definition: wex.h:1222
void scrollRange(int width, int height)
Set the scrolling range.
Definition: wex.h:1135
eventhandler & events()
Get event handler.
Definition: wex.h:1649
void move(const std::vector< int > &r)
Move the window.
Definition: wex.h:1587
HWND handle()
get window handle
Definition: wex.h:1655
void enable(bool f=true)
Enable/Disable, default enable.
Definition: wex.h:963
void bgcolor(int color)
Change background color.
Definition: wex.h:949
virtual void show(bool f=true)
Show window and all children.
Definition: wex.h:1490
gui()
Construct top level window with no parent.
Definition: wex.h:831
void scroll(bool fHoriz=true)
Add scrollbars.
Definition: wex.h:1044
A widget that displays a string.
Definition: wex.h:2583
A class for making windex objects.
Definition: wex.h:3237
A grid of properties.
Definition: propertygrid.h:396
void change(std::function< void()> f)
Register function to call when property value has changed.
Definition: propertygrid.h:718
void expand(const std::string name, bool fexpand=true)
Expand, or contract, category of properties.
Definition: propertygrid.h:574
property & check(const std::string &name, bool f)
Add boolean property.
Definition: propertygrid.h:452
void update()
force every property to redraw its label
Definition: propertygrid.h:612
property & string(const std::string &name, const std::string &value)
Add string property.
Definition: propertygrid.h:426
void saveValues()
save values in all property textboxes in the property's myValue attribute
Definition: propertygrid.h:682
property & choice(const std::string &name, const std::vector< std::string > &choice)
Add choice property.
Definition: propertygrid.h:439
void tabList(bool f=true)
Enable tab stepping through the properties.
Definition: propertygrid.h:733
void scroll()
Add vertical scrollbar.
Definition: propertygrid.h:568
const std::string value(const std::string &name)
get value in editbox of property with name
Definition: propertygrid.h:660
property * find(const std::string &category, const std::string &name)
get pointer to first property with name in a category
Definition: propertygrid.h:632
void category(const std::string &name)
Add categoty.
Definition: propertygrid.h:461
void propHeight(int h)
set property display height in pixels. Default 25
Definition: propertygrid.h:696
property * find(const std::string &name)
get pointer to first property with name, ignoring categories
Definition: propertygrid.h:620
void nameClick(std::function< void(const std::string &)> f)
Register function to call when property name is clicked.
Definition: propertygrid.h:723
void categoryHeightLow(bool f=true)
set category height low i.e. just one property height, rather than 2x prop height
Definition: propertygrid.h:702
A name value pair.
Definition: propertygrid.h:14
property(gui *parent, const std::string &name)
construct a category
Definition: propertygrid.h:68
void update()
Update ( redraw ) property child widgets.
Definition: propertygrid.h:216
void change(std::function< void()> f)
register function to call when property value changes
Definition: propertygrid.h:330
property & value(const std::string v)
set property value
Definition: propertygrid.h:254
property & tooltip(const std::string &tip, int width=0)
Add pop help message when mouse hovers over property label.
Definition: propertygrid.h:164
void saveValue()
copy value from gui into myValue attribute
Definition: propertygrid.h:291
~property()
destructor
Definition: propertygrid.h:80
property & readonly(bool f=true)
Set property to be readonly.
Definition: propertygrid.h:175
A class containing a database of the current gui elements.
Definition: wex.h:2940
static windex & get()
get reference to windex gui framework ( singleton )
Definition: wex.h:2950