Introducing Zinzala - page 3

We will modify the constructor of our class cCalcWindow as follows:

01 cCalcWindow::cCalcWindow() 02 : cWindow(uRect(250,100),"calc",eWinNormal, 03 0, 04 kCurrentWorkspace) 05 { 06 cGroupView *lFrame; 07 cFloatEntryView *lDistance; 08 cFloatEntryView *lWeight; 09 cComboBoxView *lDistanceUnit; 10 cComboBoxView *lWeightUnit; 11 cStringView *lResult; 12 13 // Set some settings of the window 14 SetTitle("Calorie burner Calculator"); 15 MoveTo(10,10); 16 17 // Create widget to group all the widgets to put on the window 18 lFrame = new cGroupView(uRect(0,0),NULL,eHorizontal,0, 19 kFlgForceEqualSize | kFlgResizeToFit); 20 lFrame->SetSlicing(3); 21 lFrame->SetSpacing(5,5); 22 23 // Create and set widget to enter the distance 24 lDistance = new cFloatEntryView(uRect(60,20),NULL,0,NULL,0,kFlgUpDown); 25 lDistance->SetPrecision(1); 26 27 // Create and set widget to enter weight 28 lWeight = new cFloatEntryView(uRect(60,20),NULL,0,NULL,0,kFlgUpDown); 29 lWeight->SetPrecision(1); 30 31 // Create and set widget to select distance unit 32 lDistanceUnit = new cComboBoxView(uRect(60,20),NULL,NULL,0,kFlgNotEditable); 33 34 // Create and set widget to select weight unit 35 lWeightUnit = new cComboBoxView(uRect(60,20),NULL,NULL,0,kFlgNotEditable); 36 37 // Create and set widget to display the computation result 38 lResult = new cStringView(uRect(0,0),NULL,"a string",0,0); 39 lResult->SetFGColor(kColorBlue); 40 lResult->SetAlignment(eCenter); 41 42 // Add all the widget to the group 43 lFrame->AddChild(new cStringView(uRect(0,0),NULL,"Distance run",0,0)); 44 lFrame->AddChild(lDistance); 45 lFrame->AddChild(lDistanceUnit); 46 lFrame->AddChild(new cStringView(uRect(0,0),NULL,"Weight",0,0)); 47 lFrame->AddChild(lWeight); 48 lFrame->AddChild(lWeightUnit); 49 lFrame->AddChild(new cButtonView(uRect(0,0),NULL,"Compute",NULL,0,0)); 50 lFrame->AddChild(lResult); 51 52 // Add the group to the window 53 AddChild(lFrame); 54 }

The source code can be downloaded here. This result is shown below:

step3 - calories burned calculator

A couple of things can be done to improve the appearance and behavior of the application. First, specifying a size for the window is not always elegant. It is best to let the window decide on its own based on its contents. Secondly, for a simple application such as this calculator, we don't want the user to resize the window.

Implementing this can be easily done in the call to the cWindow constructor in the cCalcWindow constructor:

01 cCalcWindow::cCalcWindow() 02 : cWindow(uRect(0,0),"calc",eWinNormal, 03 kFlgResizeToFit | kFlgNotResizable | kFlgNotZoomable, 04 kCurrentWorkspace) 05 { 06 cGroupView *lFrame; 07 cFloatEntryView *lDistance; 08 cFloatEntryView *lWeight; 09 cComboBoxView *lDistanceUnit; 10 cComboBoxView *lWeightUnit; 11 cStringView *lResult; 12 13 // Set some settings of the window 14 SetPadding(5,5); 15 SetTitle("Calorie burner Calculator"); 16 MoveTo(10,10); 17 18 // Create widget to group all the widgets to put on the window 19 lFrame = new cGroupView(uRect(0,0),NULL,eHorizontal,0, 20 kFlgForceEqualSize | kFlgResizeToFit); 21 lFrame->SetSlicing(3); 22 lFrame->SetSpacing(5,5); 23 24 // Create and set widget to enter the distance 25 lDistance = new cFloatEntryView(uRect(60,20),NULL,0,NULL,0,kFlgUpDown); 26 lDistance->SetPrecision(1); 27 28 // Create and set widget to enter weight 29 lWeight = new cFloatEntryView(uRect(60,20),NULL,0,NULL,0,kFlgUpDown); 30 lWeight->SetPrecision(1); 31 32 // Create and set widget to select distance unit 33 lDistanceUnit = new cComboBoxView(uRect(60,20),NULL,NULL,0,kFlgNotEditable); 34 35 // Create and set widget to select weight unit 36 lWeightUnit = new cComboBoxView(uRect(60,20),NULL,NULL,0,kFlgNotEditable); 37 38 // Create and set widget to display the computation result 39 lResult = new cStringView(uRect(0,0),NULL,"a string",0,0); 40 lResult->SetFGColor(kColorBlue); 41 lResult->SetAlignment(eCenter); 42 43 // Add all the widget to the group 44 lFrame->AddChild(new cStringView(uRect(0,0),NULL,"Distance run",0,0)); 45 lFrame->AddChild(lDistance); 46 lFrame->AddChild(lDistanceUnit); 47 lFrame->AddChild(new cStringView(uRect(0,0),NULL,"Weight",0,0)); 48 lFrame->AddChild(lWeight); 49 lFrame->AddChild(lWeightUnit); 50 lFrame->AddChild(new cButtonView(uRect(0,0),NULL,"Compute",NULL,0,0)); 51 lFrame->AddChild(lResult); 52 53 // Add the group to the window 54 AddChild(lFrame); 55 }

Print version

All content © 2004-2007, hexaZen - Vancouver BC, Canada