AWind
Dialogs.h
1 /*
2  AWind.h - Arduino window library support for Color TFT LCD Boards
3  Copyright (C)2014 Andrei Degtiarev. All right reserved
4 
5  You can find the latest version of the library at
6  https://github.com/AndreiDegtiarev/AWind
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the CC BY-NC-SA 3.0 license.
10  Please see the included documents for further information.
11 
12  Commercial use of this library requires you to buy a license that
13  will allow commercial use. This includes using the library,
14  modified or not, as a tool to sell products.
15 
16  The license applies to all part of the library including the
17  examples and tools supplied with the library.
18 */
19 #pragma once
20 #include "MainWindow.h"
21 #include "TextBoxString.h"
22 #include "DefaultDecorators.h"
23 #include "Dialog1.h"
24 
26 class Dialogs : public MainWindow, public ITouchEventReceiver
27 {
28  Button * _btnDlg1;
29  TextBoxNumber *_txtNumber1;
30  TextBoxNumber *_txtNumber2;
31 public:
33 
37  Dialogs(int wnd_width,int wnd_height):MainWindow(wnd_width,wnd_height)
38  {
39  }
41  void Initialize()
42  {
43  _btnDlg1=new Button(70,Height()/2,190,50,F("Get numbers"));
44  _btnDlg1->SetMargins(5,15);
45  _btnDlg1->RegisterTouchEventReceiver(this);
46  AddChild(_btnDlg1);
47  _txtNumber1=InitNumberFields(0,F(" Number 1:"));
48  _txtNumber2=InitNumberFields(30,F(" Number 2:"));
49  }
50 protected:
52  TextBoxNumber *InitNumberFields(int offset,const __FlashStringHelper * text)
53  {
54  Label *label=new Label(10,43+offset,150,25,text);
55  AddChild(label);
56  TextBoxNumber * txtNumber=new TextBoxNumber(130,40+offset,40,20,0);
57  txtNumber->SetNumber(0);
58  AddChild(txtNumber);
59  return txtNumber;
60  }
62  void NotifyTouch(Window *window)
63  {
64  if(window == _btnDlg1)
65  {
66  Dialog1 *dlg=(Dialog1 *)this->FindDialog(F("Dialog1"));
67  dlg->InitNumbers(_txtNumber1->GetNumber(),_txtNumber2->GetNumber());
68 
69  IDialogClosedEventReceiver::DialogResults dlgResults=this->DoDialog(dlg);
70  if(dlgResults == IDialogClosedEventReceiver::OK)
71  {
72  _txtNumber1->SetNumber(dlg->GetNumber1());
73  _txtNumber2->SetNumber(dlg->GetNumber2());
74  }
75  }
76  }
77 };
Dialogs(int wnd_width, int wnd_height)
Constructor.
Definition: Dialogs.h:37
void RegisterTouchEventReceiver(ITouchEventReceiver *touchEventReceiver)
Registers receiver for touch event.
Definition: Window.h:102
Base class for all window objects. Provides basic window functionality.
Definition: Window.h:34
float GetNumber1()
Return value from text box 1.
Definition: Dialog1.h:61
void Initialize()
Initilizes child controls.
Definition: Dialogs.h:41
Text box for numbers.
Definition: TextBoxNumber.h:24
Dialogs main window.
Definition: Dialogs.h:26
TextBoxNumber * InitNumberFields(int offset, const __FlashStringHelper *text)
create child text box fields
Definition: Dialogs.h:52
int Height()
Returns window height.
Definition: Window.h:189
void InitNumbers(float number1, float number2)
Init text box values.
Definition: Dialog1.h:55
Dialog * FindDialog(const __FlashStringHelper *id)
Finds registered dialog by the name.
Definition: MainWindow.h:69
Example Dialog with one edit, one readonly field + button that activates another dialog.
Definition: Dialog1.h:24
void NotifyTouch(Window *window)
Events routing for gui interaction (see RegisterTouchEventReceiver and public ITouchEventReceiver dec...
Definition: Dialogs.h:62
float GetNumber2()
Return value from text box 2.
Definition: Dialog1.h:66
void AddChild(Window *window)
Adds window child window.
Definition: Window.h:194
void SetNumber(float number)
Initialize window with number.
Definition: TextBoxNumber.h:74
Implement button control.
Definition: Button.h:24
Base class for main application window. Each application has to have one main window, which is root parent for all other application windows.
Definition: MainWindow.h:38
Interface that provides screen touch notifications. If you want receive this notification in the targ...
Definition: ITouchEventReceiver.h:24
Implement Label control.
Definition: Label.h:24
void SetMargins(int offset_x, int offset_y)
Defines offset from left and top for text.
Definition: TextBox.h:58