WINDEX
inputbox.h
1 #pragma once
2 #include "propertygrid.h"
3 namespace wex
4 {
5 
25 class inputbox : public gui
26 {
27 public:
30 
31  inputbox( gui& AppWindow )
32  : myGrid( propertyGrid( this ))
33  , myOKButton( maker::make<button>(*this) )
34  , myAppWindow( AppWindow )
35  {
36  windex::get().Add( this );
37  text("inputbox");
38  move( {100,100,300,300} );
39  myGrid.move( { 50,50, 200, 60});
40  myGrid.labelWidth( 50 );
41  myGrid.bgcolor( 0xFFFFFF );
42  myGrid.tabList();
43  //myOKButton.move( { 100,300, 50, 40 } );
44  myOKButton.text("OK");
45  myOKButton.events().click([this]
46  {
47  //std::cout << "destroying inputbox " << myHandle << "\n";
48 
49  // before destroying the window extract values from gui into property attributes
50  myGrid.saveValues();
51 
52  endModal();
53  });
54  }
55  void clear()
56  {
57  myGrid.clear();
58  }
59  wex::property& add(
60  const std::string& name,
61  const std::string& def )
62  {
63  ExpandForAdditionalProperty();
64  return myGrid.string( name, def );
65  }
66  wex::property& choice(
67  const std::string& name,
68  const std::vector<std::string>& choice )
69  {
70  ExpandForAdditionalProperty();
71  return myGrid.choice( name, choice );
72  }
73  wex::property& check(
74  const std::string& name,
75  bool def )
76  {
77  ExpandForAdditionalProperty();
78  return myGrid.check( name, def );
79  }
80 
86  void show()
87  {
89  auto wh = myGrid.size();
90  move( {100,100,wh[0]+100,wh[1]+200} );
91  myOKButton.move( { 100,wh[1]+80, 50, 40 } );
92 
93  // base class showModal
94  gui::showModal(myAppWindow);
95  }
101  void showModal()
102  {
103  show();
104  }
109  std::string value ( const std::string& name )
110  {
111  auto p = myGrid.find( name );
112  if( p == nullptr )
113  return "property not found";
114  return p->savedValue();
115  }
116  bool isChecked( const std::string& name )
117  {
118  return myGrid.isChecked( name );
119  }
120  void gridWidth( int w )
121  {
122  myGrid.move( { 50,50, w, 60});
123  }
124  void labelWidth( int w )
125  {
126  myGrid.labelWidth( w );
127  }
128 private:
129  propertyGrid myGrid;
130  button& myOKButton;
131  gui& myAppWindow;
132 
133  void ExpandForAdditionalProperty()
134  {
135  myGrid.move( { 50, 50,
136  myGrid.width(),
137  ( myGrid.propCount() + 1 ) * myGrid.propHeight()
138  } );
139  }
140 };
141 }
A widget that user can click to start an action.
Definition: wex.h:2113
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 showModal(gui &appWindow)
Show this window and suspend all other windows interactions until this is closed.
Definition: wex.h:1505
void endModal()
Stop modal interaction and close window.
Definition: wex.h:1558
eventhandler & events()
Get event handler.
Definition: wex.h:1649
void move(const std::vector< int > &r)
Move the window.
Definition: wex.h:1587
void size(int w, int h)
Change size without moving top left corner.
Definition: wex.h:1598
void bgcolor(int color)
Change background color.
Definition: wex.h:949
gui()
Construct top level window with no parent.
Definition: wex.h:831
A popup window where user can edit a set of values.
Definition: inputbox.h:26
void showModal()
Redirect calls to ShowModal to Show instead Inputbox is a popup handling the modal dialog itself This...
Definition: inputbox.h:101
std::string value(const std::string &name)
get value saved in property attribute
Definition: inputbox.h:109
inputbox(gui &AppWindow)
Construct input box modal dialog.
Definition: inputbox.h:31
void show()
Show inputbox and suspend all other windows interactions until this is closed.
Definition: inputbox.h:86
A class for making windex objects.
Definition: wex.h:3237
A grid of properties.
Definition: propertygrid.h:396
property & check(const std::string &name, bool f)
Add boolean property.
Definition: propertygrid.h:452
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
property * find(const std::string &name)
get pointer to first property with name, ignoring categories
Definition: propertygrid.h:620
A name value pair.
Definition: propertygrid.h:14
gui * Add(gui *g)
Add new gui element.
Definition: wex.h:2978
static windex & get()
get reference to windex gui framework ( singleton )
Definition: wex.h:2950