#ifndef TJD_UI_APP_CALCULATOR_VIEW_H #define TJD_UI_APP_CALCULATOR_VIEW_H #include "TjdUiAppCalculatorModel.h" #include "TjdUiAppCalculatorPresenter.h" #include "TjdUiMultiLanguageExt.h" #include "View.h" #include "components/ui_button.h" #include "components/ui_image_view.h" #include "components/ui_label.h" #include "components/ui_scroll_view.h" #include "components/ui_scroll_view_nested.h" #include "components/ui_view_group.h" #include namespace TJD { #define RESULT_LABEL_X 41 #define SHOW_NUM_MAX 13 //最大显示位数 #define abs(x) ((x > 0.0) ? (x) : (-x)) #define __this (__calculator) #define sizeof_this (sizeof(struct UiCalculator)) #define CALCULATOR_MAX_BUTTON 18 typedef struct CalButtonImgInfo { OHOS::ImageInfo *defaultInfo = nullptr; OHOS::ImageInfo *highlightInfo = nullptr; ; } ImageInfo_t; enum { NONE, ADD, SUB, MUL, DIV, EQUAL, }; struct UiCalculator { double num_1; double num_2; uint8_t cal_mode; //运算模式 uint8_t point; // BIT7记录是否有效 uint8_t error = 0; char str[SHOW_NUM_MAX]; }; class ButtonOnClickListener : public OHOS::UIView::OnClickListener { public: ButtonOnClickListener() {} ~ButtonOnClickListener() {} bool OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event); private: void ButtonOnClickCallBack(OHOS::UIView &view, const OHOS::ClickEvent &event); }; class CalculatorView : public OHOS::UIScrollView { public: CalculatorView(); ~CalculatorView(); static CalculatorView *GetInstance(); OHOS::UILabel *GetResultLabel() { return &reultLabel; } OHOS::UILabel *GetResultLabel1() { return &reultLabel1; } void CalculatorViewRefresh(); // UiCalculator * GetCalculator() {return __calculator;} private: OHOS::UILabel reultLabel; OHOS::UILabel reultLabel1; OHOS::UIButton button_[CALCULATOR_MAX_BUTTON]; ImageInfo_t imgButtonInfo[CALCULATOR_MAX_BUTTON]; ButtonOnClickListener buttonOnClickListener[CALCULATOR_MAX_BUTTON]; }; class TjdUiAppCalculatorPresenter; class TjdUiAppCalculatorView : public OHOS::View { public: TjdUiAppCalculatorView(); ~TjdUiAppCalculatorView(); static TjdUiAppCalculatorView *GetInstance(void); void OnStart() override; // void OnSetUpView() override {}; // void OnTearDownView() override {}; void OnStop() override; uint8_t GetDaysOfCurrentMonth(uint8_t month, uint16_t year); int GetDaysOfCurrentWeek(int year, int month, int day); OHOS::UIScrollView *GetMainView() { return mainView_; }; private: CalculatorView *calculatorView_{nullptr}; OHOS::UIScrollView *mainView_{nullptr}; }; } // namespace TJD #endif