Changeset 9c7dc8e in mainline for uspace/app/calculator/calculator.c
- Timestamp:
- 2021-03-01T10:50:25Z (3 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- cd74fa8
- Parents:
- 77ffa01
- git-author:
- Jiri Svoboda <jiri@…> (2021-02-28 10:50:05)
- git-committer:
- Jiri Svoboda <jiri@…> (2021-03-01 10:50:25)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/calculator/calculator.c
r77ffa01 r9c7dc8e 95 95 } stack_item_t; 96 96 97 /** Dimensions. Most of this should not be needed with auto layout */ 98 typedef struct { 99 gfx_rect_t entry_rect; 100 gfx_coord2_t btn_orig; 101 gfx_coord2_t btn_stride; 102 gfx_coord2_t btn_dim; 103 } calc_geom_t; 104 97 105 typedef struct { 98 106 ui_t *ui; 107 ui_resource_t *ui_res; 99 108 ui_pbutton_t *btn_eval; 100 109 ui_pbutton_t *btn_clear; … … 113 122 ui_pbutton_t *btn_8; 114 123 ui_pbutton_t *btn_9; 124 calc_geom_t geom; 115 125 } calc_t; 116 126 … … 650 660 } 651 661 652 static errno_t calc_button_create( ui_resource_t *ui_res, ui_fixed_t *fixed,662 static errno_t calc_button_create(calc_t *calc, ui_fixed_t *fixed, 653 663 int x, int y, const char *text, ui_pbutton_cb_t *cb, void *arg, 654 664 ui_pbutton_t **rbutton) … … 658 668 errno_t rc; 659 669 660 rc = ui_pbutton_create( ui_res, text, &pb);670 rc = ui_pbutton_create(calc->ui_res, text, &pb); 661 671 if (rc != EOK) { 662 672 printf("Error creating button.\n"); … … 666 676 ui_pbutton_set_cb(pb, cb, arg); 667 677 668 rect.p0.x = 10 + 60* x;669 rect.p0.y = 90 + 45* y;670 rect.p1.x = 60 + 60 *x;671 rect.p1.y = 125 + 45 *y;678 rect.p0.x = calc->geom.btn_orig.x + calc->geom.btn_stride.x * x; 679 rect.p0.y = calc->geom.btn_orig.y + calc->geom.btn_stride.y * y; 680 rect.p1.x = rect.p0.x + calc->geom.btn_dim.x; 681 rect.p1.y = rect.p0.y + calc->geom.btn_dim.y; 672 682 ui_pbutton_set_rect(pb, &rect); 673 683 … … 696 706 ui_wnd_params_t params; 697 707 ui_window_t *window; 698 gfx_rect_t rect;699 708 calc_t calc; 700 709 errno_t rc; … … 732 741 params.rect.p1.y = 270; 733 742 743 if (ui_is_textmode(ui)) { 744 calc.geom.entry_rect.p0.x = 4; 745 calc.geom.entry_rect.p0.y = 2; 746 calc.geom.entry_rect.p1.x = 60; 747 calc.geom.entry_rect.p1.y = 4; 748 calc.geom.btn_orig.x = 4; 749 calc.geom.btn_orig.y = 4; 750 calc.geom.btn_dim.x = 12; 751 calc.geom.btn_dim.y = 7; 752 calc.geom.btn_stride.x = 15; 753 calc.geom.btn_stride.y = 6; 754 } else { 755 calc.geom.entry_rect.p0.x = 15; 756 calc.geom.entry_rect.p0.y = 45; 757 calc.geom.entry_rect.p1.x = 235; 758 calc.geom.entry_rect.p1.y = 70; 759 calc.geom.btn_orig.x = 10; 760 calc.geom.btn_orig.y = 90; 761 calc.geom.btn_dim.x = 50; 762 calc.geom.btn_dim.y = 35; 763 calc.geom.btn_stride.x = 60; 764 calc.geom.btn_stride.y = 45; 765 } 766 734 767 rc = ui_window_create(ui, ¶ms, &window); 735 768 if (rc != EOK) { … … 742 775 743 776 ui_res = ui_window_get_res(window); 777 calc.ui_res = ui_res; 744 778 745 779 rc = ui_fixed_create(&fixed); … … 755 789 } 756 790 757 rect.p0.x = 15; 758 rect.p0.y = 45; 759 rect.p1.x = 235; 760 rect.p1.y = 70; 761 ui_entry_set_rect(display, &rect); 791 ui_entry_set_rect(display, &calc.geom.entry_rect); 762 792 ui_entry_set_halign(display, gfx_halign_right); 763 793 … … 768 798 } 769 799 770 rc = calc_button_create( ui_res, fixed, 0, 0, "7", &calc_pbutton_cb,800 rc = calc_button_create(&calc, fixed, 0, 0, "7", &calc_pbutton_cb, 771 801 (void *) "7", &calc.btn_7); 772 802 if (rc != EOK) 773 803 return rc; 774 804 775 rc = calc_button_create( ui_res, fixed, 1, 0, "8", &calc_pbutton_cb,805 rc = calc_button_create(&calc, fixed, 1, 0, "8", &calc_pbutton_cb, 776 806 (void *) "8", &calc.btn_8); 777 807 if (rc != EOK) 778 808 return rc; 779 809 780 rc = calc_button_create( ui_res, fixed, 2, 0, "9", &calc_pbutton_cb,810 rc = calc_button_create(&calc, fixed, 2, 0, "9", &calc_pbutton_cb, 781 811 (void *) "9", &calc.btn_9); 782 812 if (rc != EOK) 783 813 return rc; 784 814 785 rc = calc_button_create( ui_res, fixed, 3, 0, "/", &calc_pbutton_cb,815 rc = calc_button_create(&calc, fixed, 3, 0, "/", &calc_pbutton_cb, 786 816 (void *) "/", &calc.btn_div); 787 817 if (rc != EOK) 788 818 return rc; 789 819 790 rc = calc_button_create( ui_res, fixed, 0, 1, "4", &calc_pbutton_cb,820 rc = calc_button_create(&calc, fixed, 0, 1, "4", &calc_pbutton_cb, 791 821 (void *) "4", &calc.btn_4); 792 822 if (rc != EOK) 793 823 return rc; 794 824 795 rc = calc_button_create( ui_res, fixed, 1, 1, "5", &calc_pbutton_cb,825 rc = calc_button_create(&calc, fixed, 1, 1, "5", &calc_pbutton_cb, 796 826 (void *) "5", &calc.btn_5); 797 827 if (rc != EOK) 798 828 return rc; 799 829 800 rc = calc_button_create( ui_res, fixed, 2, 1, "6", &calc_pbutton_cb,830 rc = calc_button_create(&calc, fixed, 2, 1, "6", &calc_pbutton_cb, 801 831 (void *) "6", &calc.btn_6); 802 832 if (rc != EOK) 803 833 return rc; 804 834 805 rc = calc_button_create( ui_res, fixed, 3, 1, "*", &calc_pbutton_cb,835 rc = calc_button_create(&calc, fixed, 3, 1, "*", &calc_pbutton_cb, 806 836 (void *) "*", &calc.btn_mul); 807 837 if (rc != EOK) 808 838 return rc; 809 839 810 rc = calc_button_create( ui_res, fixed, 0, 2, "1", &calc_pbutton_cb,840 rc = calc_button_create(&calc, fixed, 0, 2, "1", &calc_pbutton_cb, 811 841 (void *) "1", &calc.btn_1); 812 842 if (rc != EOK) 813 843 return rc; 814 844 815 rc = calc_button_create( ui_res, fixed, 1, 2, "2", &calc_pbutton_cb,845 rc = calc_button_create(&calc, fixed, 1, 2, "2", &calc_pbutton_cb, 816 846 (void *) "2", &calc.btn_2); 817 847 if (rc != EOK) 818 848 return rc; 819 849 820 rc = calc_button_create( ui_res, fixed, 2, 2, "3", &calc_pbutton_cb,850 rc = calc_button_create(&calc, fixed, 2, 2, "3", &calc_pbutton_cb, 821 851 (void *) "3", &calc.btn_3); 822 852 if (rc != EOK) 823 853 return rc; 824 854 825 rc = calc_button_create( ui_res, fixed, 3, 2, "-", &calc_pbutton_cb,855 rc = calc_button_create(&calc, fixed, 3, 2, "-", &calc_pbutton_cb, 826 856 (void *) "-", &calc.btn_sub); 827 857 if (rc != EOK) 828 858 return rc; 829 859 830 rc = calc_button_create( ui_res, fixed, 0, 3, "0", &calc_pbutton_cb,860 rc = calc_button_create(&calc, fixed, 0, 3, "0", &calc_pbutton_cb, 831 861 (void *) "0", &calc.btn_0); 832 862 if (rc != EOK) 833 863 return rc; 834 864 835 rc = calc_button_create( ui_res, fixed, 1, 3, "C", &calc_clear_cb,865 rc = calc_button_create(&calc, fixed, 1, 3, "C", &calc_clear_cb, 836 866 (void *) "C", &calc.btn_clear); 837 867 if (rc != EOK) 838 868 return rc; 839 869 840 rc = calc_button_create( ui_res, fixed, 2, 3, "=", &calc_eval_cb,870 rc = calc_button_create(&calc, fixed, 2, 3, "=", &calc_eval_cb, 841 871 (void *) "=", &calc.btn_eval); 842 872 if (rc != EOK) 843 873 return rc; 844 874 845 rc = calc_button_create( ui_res, fixed, 3, 3, "+", &calc_pbutton_cb,875 rc = calc_button_create(&calc, fixed, 3, 3, "+", &calc_pbutton_cb, 846 876 (void *) "+", &calc.btn_add); 847 877 if (rc != EOK)
Note:
See TracChangeset
for help on using the changeset viewer.