The project is hosted on
Welcome to the cursive source documentation and project homepage, generated with doxygen.
include "crs/cursive.h"
include "crs/group_box.h"
include "crs/edit_ctrl.h"
include <string>
int main() {
crs::group_box grpbox( "I'm a groupbox", crs::crsv.getScreen(), 1, 1, 20, 20 );
grpbox.visible = true;
std::string edit_text;
crs::edit_ctrl<std::string> edit( &grpbox, 0, 2, 4, 13, &edit_text, 0, crs::style::bubble );
edit.visible = true;
crs::crsv.mainloop();
}
include "base_control.h"
class group_box: public base_control {
private:
std::string caption;
public:
group_box( const std::string &caption, base_control *Parent,
const unsigned int Left=0, const unsigned int Top=0, const unsigned int Width=3, const unsigned int Height=3 );
virtual void draw();
};
Implementation:
group_box::group_box( const std::string &Caption, base_control *Parent,
const unsigned int Left, const unsigned int Top, const unsigned int Width, const unsigned int Height ):
base_control( Parent, 0, Left, Top, Width, Height ), caption( Caption ) {
}
void group_box::draw() {
base_control::draw();
buffer.drawHLine( 1, 0, mWidth - 2, sc::HorizontalLine ); // upper border
buffer.drawHLine( 1, mHeight - 1, mWidth - 2, sc::HorizontalLine ); // lower border
buffer[ 0 ] = sc::UpperLeftCorner; // upper left corner
buffer[ mWidth - 1 ] = sc::UpperRightCorner; // upper right corner
buffer[ ( mHeight - 1 ) * mWidth ] = sc::LowerLeftCorner; // lower left corner
buffer[ mHeight * mWidth - 1 ] = sc::LowerRightCorner; // lower right corner
buffer.drawVLine( 0, 1, mHeight - 2, sc::VerticalLine ); // left border
buffer.drawVLine( mWidth - 1, 1, mHeight - 2, sc::VerticalLine ); // right border
buffer.setText( caption, 1, 0 );
}
If you need control over keyboard input (what will be the case most of the time), you need to override the keyPress virtual function. If the control shall be focusable, derive the class from crs::focused_ctrl instead of crs::base_control. Thats all.
1.2.18