WINDEX
inputbox.h
1 #pragma once
2 #include "propertygrid.h"
3 namespace wex
4 {
5 
25 class inputbox : public gui
26 {
27 public:
30  // @param width, default 300
31 
32  inputbox( gui& AppWindow, int width = 300 )
33  : myGrid( propertyGrid( this ))
34  , myOKButton( maker::make<button>(*this) )
35  , myAppWindow( AppWindow )
36  {
37  windex::get().Add( this );
38  text("inputbox");
39  move( {100,100,width,300} );
40  myGrid.move( { 50,50, width-100, 60});
41  myGrid.labelWidth( width / 4 );
42  myGrid.bgcolor( 0xFFFFFF );
43  myGrid.tabList();
44  //myOKButton.move( { 100,300, 50, 40 } );
45  myOKButton.text("OK");
46  myOKButton.events().click([this]
47  {
48  //std::cout << "destroying inputbox " << myHandle << "\n";
49 
50  // before destroying the window extract values from gui into property attributes
51  myGrid.saveValues();
52 
53  endModal();
54  });
55  }
56  void clear()
57  {
58  myGrid.clear();
59  }
60  wex::property& add(
61  const std::string& name,
62  const std::string& def )
63  {
64  ExpandForAdditionalProperty();
65  return myGrid.string( name, def );
66  }
67  wex::property& choice(
68  const std::string& name,
69  const std::vector<std::string>& choice )
70  {
71  ExpandForAdditionalProperty();
72  return myGrid.choice( name, choice );
73  }
74  wex::property& check(
75  const std::string& name,
76  bool def )
77  {
78  ExpandForAdditionalProperty();
79  return myGrid.check( name, def );
80  }
81 
87  void show()
88  {
90  auto wh = myGrid.size();
91  move( {100,100,wh[0]+100,wh[1]+200} );
92  myOKButton.move( { 100,wh[1]+80, 50, 40 } );
93 
94  // base class showModal
95  gui::showModal(myAppWindow);
96  }
102  void showModal()
103  {
104  show();
105  }
110  std::string value ( const std::string& name )
111  {
112  auto p = myGrid.find( name );
113  if( p == nullptr )
114  return "property not found";
115  return p->savedValue();
116  }
117  bool isChecked( const std::string& name )
118  {
119  return myGrid.isChecked( name );
120  }
121  void gridWidth( int w )
122  {
123  myGrid.move( { 50,50, w, 60});
124  }
125  void labelWidth( int w )
126  {
127  myGrid.labelWidth( w );
128  }
129 private:
130  propertyGrid myGrid;
131  button& myOKButton;
132  gui& myAppWindow;
133 
134  void ExpandForAdditionalProperty()
135  {
136  myGrid.move( { 50, 50,
137  myGrid.width(),
138  ( myGrid.propCount() + 1 ) * myGrid.propHeight()
139  } );
140  }
141 };
142 }
A widget that user can click to start an action.
Definition: wex.h:2206
void click(std::function< void(void)> f, bool propogate=false)
register click event handler
Definition: wex.h:280
The base class for all windex gui elements.
Definition: wex.h:900
void showModal(gui &appWindow)
Show this window and suspend all other windows interactions until this is closed.
Definition: wex.h:1599
void endModal()
Stop modal interaction and close window.
Definition: wex.h:1651
eventhandler & events()
Get event handler.
Definition: wex.h:1742
void move(const std::vector< int > &r)
Move the window.
Definition: wex.h:1680
void size(int w, int h)
Change size without moving top left corner.
Definition: wex.h:1691
void bgcolor(int color)
Change background color.
Definition: wex.h:1025
gui()
Construct top level window with no parent.
Definition: wex.h:907
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:102
std::string value(const std::string &name)
get value saved in property attribute
Definition: inputbox.h:110
inputbox(gui &AppWindow, int width=300)
Construct input box modal dialog.
Definition: inputbox.h:32
void show()
Show inputbox and suspend all other windows interactions until this is closed.
Definition: inputbox.h:87
A class for making windex objects.
Definition: wex.h:3338
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:3071
static windex & get()
get reference to windex gui framework ( singleton )
Definition: wex.h:3043