The calculator application demonstrates some of the available widgets in the Widget toolkit. More...
|
Data Structures | |
| struct | calc_context |
| Calculator application context. More... | |
Enumerations | |
| enum | command_id { RADIO_DEC_ID = 123, RADIO_HEX_ID, BUTTON_EXIT_ID, DUMMY_ID, SLIDER_ID, CHECK_BOX_ID, RADIO_BUTTON_1_ID, RADIO_BUTTON_2_ID, BUTTON_QUIT_ID } |
| enum | calc_mode { CALC_DEC, CALC_HEX } |
The calculator modes. More... | |
Functions | |
| static void | calc_update_display (struct calc_context *calc) |
| Update calculator display. | |
| static bool | calc_frame_command_handler (struct wtk_basic_frame *frame, win_command_t command_data) |
| Frame handler for calculator. | |
| void | app_calc_launch (struct workqueue_task *task) |
| Start calculator app. | |
Keypad configuration | |
|
| |
| #define | POS_X 10 |
| Start position for keypad. | |
| #define | POS_Y 50 |
| Start position for keypad. | |
| #define | SIZE_X 45 |
| Size of each key. | |
| #define | SIZE_Y 35 |
| Size of each key. | |
| #define | SPACE_X (SIZE_X + 10) |
| Size of each key including space to next key. | |
| #define | SPACE_Y (SIZE_Y + 10) |
| Size of each key including space to next key. | |
| #define | KEYS_PR_ROW 4 |
| Number of keys pr row. | |
Calculator display configuration | |
|
| |
| #define | MAX_VALUE 999999 |
| Max value to display. | |
| #define | MAX_DIGITS (10+1) |
| Max digits needed to store display value and terminating null byte. | |
The calculator application demonstrates some of the available widgets in the Widget toolkit.
The application allows the user to enter numbers and perform the arithmetic operations addition, subtraction, multiplication and division on them. The user has the choice between decimal and hexadecimal representation of the values.
| #define KEYS_PR_ROW 4 |
Number of keys pr row.
Definition at line 80 of file app_calc.c.
| #define MAX_DIGITS (10+1) |
Max digits needed to store display value and terminating null byte.
Definition at line 93 of file app_calc.c.
Referenced by calc_update_display().
| #define MAX_VALUE 999999 |
Max value to display.
Definition at line 91 of file app_calc.c.
Referenced by calc_frame_command_handler().
| #define POS_X 10 |
Start position for keypad.
Definition at line 68 of file app_calc.c.
| #define POS_Y 50 |
Start position for keypad.
Definition at line 70 of file app_calc.c.
| #define SIZE_X 45 |
Size of each key.
Definition at line 72 of file app_calc.c.
| #define SIZE_Y 35 |
Size of each key.
Definition at line 74 of file app_calc.c.
| #define SPACE_X (SIZE_X + 10) |
Size of each key including space to next key.
Definition at line 76 of file app_calc.c.
| #define SPACE_Y (SIZE_Y + 10) |
Size of each key including space to next key.
Definition at line 78 of file app_calc.c.
| enum calc_mode |
The calculator modes.
Definition at line 116 of file app_calc.c.
| enum command_id |
Command event IDs
Definition at line 106 of file app_calc.c.
| void app_calc_launch | ( | struct workqueue_task * | task | ) |
Start calculator app.
Allocates the application context and creates all widgets for it.
The command event IDs of the keypad button widgets correspond to ASCII character codes that correspond to their value or function.
If memory allocation or widget creation fails, the application exits immediately.
| task | Workqueue task used to start the calculator. |
| static bool calc_frame_command_handler | ( | struct wtk_basic_frame * | frame, | |
| win_command_t | command_data | |||
| ) | [static] |
Frame handler for calculator.
Handle all the command events of the calculator, i.e., the keypad and radio buttons.
| frame | Pointer to the application frame | |
| command_data | The command event ID |
Definition at line 184 of file app_calc.c.
References app_desktop_restart(), BUTTON_EXIT_ID, CALC_DEC, CALC_HEX, calc_update_display(), calc_context::disp_value, max_s, MAX_VALUE, membag_free(), memcpy(), min_s, calc_context::mode, calc_context::old_sysfont, calc_context::operator, RADIO_DEC_ID, RADIO_HEX_ID, calc_context::stack_value, sysfont, and wtk_basic_frame_get_custom_data().
| static void calc_update_display | ( | struct calc_context * | calc | ) | [static] |
Update calculator display.
Update the display of the calculator with the new value, in the selected number base.
| calc | Context for calculator |
Definition at line 156 of file app_calc.c.
References assert, CALC_HEX, calc_context::disp_value, calc_context::display_lbl, MAX_DIGITS, calc_context::mode, snprintf(), calc_context::text, and wtk_label_change().
Referenced by calc_frame_command_handler().
1.6.3