Changeset 1eaead4 in mainline
- Timestamp:
- 2023-02-07T16:11:53Z (21 months ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0366d09d
- Parents:
- 7c5320c
- Location:
- uspace
- Files:
-
- 15 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/uidemo/uidemo.c
r7c5320c r1eaead4 1 1 /* 2 * Copyright (c) 202 2Jiri Svoboda2 * Copyright (c) 2023 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 51 51 #include <ui/promptdialog.h> 52 52 #include <ui/resource.h> 53 #include <ui/tab.h> 54 #include <ui/tabset.h> 53 55 #include <ui/ui.h> 54 56 #include <ui/window.h> … … 615 617 params.rect.p0.x = 0; 616 618 params.rect.p0.y = 0; 617 params.rect.p1.x = 4 4;618 params.rect.p1.y = 2 3;619 params.rect.p1.x = 46; 620 params.rect.p1.y = 25; 619 621 } else { 620 622 params.rect.p0.x = 0; 621 623 params.rect.p0.y = 0; 622 params.rect.p1.x = 25 0;623 params.rect.p1.y = 370;624 params.rect.p1.x = 255; 625 params.rect.p1.y = 410; 624 626 } 625 627 … … 743 745 rect.p0.x = 4; 744 746 rect.p0.y = 30; 745 rect.p1.x = 2 16;747 rect.p1.x = 251; 746 748 rect.p1.y = 52; 747 749 } 750 748 751 ui_menu_bar_set_rect(demo.mbar, &rect); 749 752 … … 754 757 } 755 758 759 rc = ui_tab_set_create(ui_res, &demo.tabset); 760 if (rc != EOK) { 761 printf("Error creating tab set.\n"); 762 return rc; 763 } 764 765 /* FIXME: Auto layout */ 766 if (ui_is_textmode(ui)) { 767 rect.p0.x = 2; 768 rect.p0.y = 2; 769 rect.p1.x = 44; 770 rect.p1.y = 24; 771 } else { 772 rect.p0.x = 8; 773 rect.p0.y = 53; 774 rect.p1.x = 250; 775 rect.p1.y = 405; 776 } 777 778 ui_tab_set_set_rect(demo.tabset, &rect); 779 780 rc = ui_tab_create(demo.tabset, "Basic", &demo.tbasic); 781 if (rc != EOK) { 782 printf("Error creating tab.\n"); 783 return rc; 784 } 785 786 rc = ui_tab_create(demo.tabset, "Lists", &demo.tlists); 787 if (rc != EOK) { 788 printf("Error creating tab.\n"); 789 return rc; 790 } 791 792 rc = ui_fixed_add(demo.fixed, ui_tab_set_ctl(demo.tabset)); 793 if (rc != EOK) { 794 printf("Error adding control to layout.\n"); 795 return rc; 796 } 797 798 rc = ui_fixed_create(&demo.bfixed); 799 if (rc != EOK) { 800 printf("Error creating fixed layout.\n"); 801 return rc; 802 } 803 756 804 rc = ui_entry_create(window, "", &demo.entry); 757 805 if (rc != EOK) { … … 762 810 /* FIXME: Auto layout */ 763 811 if (ui_is_textmode(ui)) { 764 rect.p0.x = 2;765 rect.p0.y = 3;766 rect.p1.x = 39;767 rect.p1.y = 4;812 rect.p0.x = 4; 813 rect.p0.y = 5; 814 rect.p1.x = 41; 815 rect.p1.y = 6; 768 816 } else { 769 817 rect.p0.x = 15; 770 rect.p0.y = 53;818 rect.p0.y = 88; 771 819 rect.p1.x = 205; 772 rect.p1.y = 78;820 rect.p1.y = 113; 773 821 } 774 822 … … 776 824 ui_entry_set_halign(demo.entry, gfx_halign_center); 777 825 778 rc = ui_fixed_add(demo. fixed, ui_entry_ctl(demo.entry));826 rc = ui_fixed_add(demo.bfixed, ui_entry_ctl(demo.entry)); 779 827 if (rc != EOK) { 780 828 printf("Error adding control to layout.\n"); … … 790 838 /* FIXME: Auto layout */ 791 839 if (ui_is_textmode(ui)) { 792 rect.p0.x = 2;793 rect.p0.y = 5;794 rect.p1.x = 4 2;795 rect.p1.y = 6;840 rect.p0.x = 4; 841 rect.p0.y = 7; 842 rect.p1.x = 41; 843 rect.p1.y = 8; 796 844 } else { 797 845 rect.p0.x = 60; 798 rect.p0.y = 88;846 rect.p0.y = 123; 799 847 rect.p1.x = 160; 800 rect.p1.y = 1 01;848 rect.p1.y = 136; 801 849 } 802 850 … … 804 852 ui_label_set_halign(demo.label, gfx_halign_center); 805 853 806 rc = ui_fixed_add(demo. fixed, ui_label_ctl(demo.label));854 rc = ui_fixed_add(demo.bfixed, ui_label_ctl(demo.label)); 807 855 if (rc != EOK) { 808 856 printf("Error adding control to layout.\n"); … … 820 868 /* FIXME: Auto layout */ 821 869 if (ui_is_textmode(ui)) { 822 rect.p0.x = 2;823 rect.p0.y = 7;824 rect.p1.x = 1 2;825 rect.p1.y = 8;870 rect.p0.x = 4; 871 rect.p0.y = 9; 872 rect.p1.x = 15; 873 rect.p1.y = 10; 826 874 } else { 827 875 rect.p0.x = 15; 828 rect.p0.y = 1 11;876 rect.p0.y = 146; 829 877 rect.p1.x = 105; 830 rect.p1.y = 1 39;878 rect.p1.y = 174; 831 879 } 832 880 … … 835 883 ui_pbutton_set_default(demo.pb1, true); 836 884 837 rc = ui_fixed_add(demo. fixed, ui_pbutton_ctl(demo.pb1));885 rc = ui_fixed_add(demo.bfixed, ui_pbutton_ctl(demo.pb1)); 838 886 if (rc != EOK) { 839 887 printf("Error adding control to layout.\n"); … … 850 898 851 899 if (ui_is_textmode(ui)) { 852 rect.p0.x = 29;853 rect.p0.y = 7;854 rect.p1.x = 39;855 rect.p1.y = 8;900 rect.p0.x = 30; 901 rect.p0.y = 9; 902 rect.p1.x = 41; 903 rect.p1.y = 10; 856 904 } else { 857 905 rect.p0.x = 115; 858 rect.p0.y = 1 11;906 rect.p0.y = 146; 859 907 rect.p1.x = 205; 860 rect.p1.y = 1 39;908 rect.p1.y = 174; 861 909 } 862 910 863 911 ui_pbutton_set_rect(demo.pb2, &rect); 864 912 865 rc = ui_fixed_add(demo. fixed, ui_pbutton_ctl(demo.pb2));913 rc = ui_fixed_add(demo.bfixed, ui_pbutton_ctl(demo.pb2)); 866 914 if (rc != EOK) { 867 915 printf("Error adding control to layout.\n"); … … 897 945 898 946 if (ui_is_textmode(ui)) { 899 off.x = 2;900 off.y = 9;947 off.x = 4; 948 off.y = 11; 901 949 } else { 902 950 off.x = 15; 903 off.y = 1 55;951 off.y = 190; 904 952 } 905 953 … … 915 963 ui_image_set_rect(demo.image, &rect); 916 964 917 rc = ui_fixed_add(demo. fixed, ui_image_ctl(demo.image));965 rc = ui_fixed_add(demo.bfixed, ui_image_ctl(demo.image)); 918 966 if (rc != EOK) { 919 967 printf("Error adding control to layout.\n"); … … 931 979 /* FIXME: Auto layout */ 932 980 if (ui_is_textmode(ui)) { 933 rect.p0.x = 2;934 rect.p0.y = 1 2;935 rect.p1.x = 1 2;936 rect.p1.y = 1 3;981 rect.p0.x = 4; 982 rect.p0.y = 14; 983 rect.p1.x = 14; 984 rect.p1.y = 15; 937 985 } else { 938 986 rect.p0.x = 15; 939 rect.p0.y = 190;987 rect.p0.y = 225; 940 988 rect.p1.x = 140; 941 rect.p1.y = 2 10;989 rect.p1.y = 245; 942 990 } 943 991 944 992 ui_checkbox_set_rect(demo.checkbox, &rect); 945 993 946 rc = ui_fixed_add(demo. fixed, ui_checkbox_ctl(demo.checkbox));994 rc = ui_fixed_add(demo.bfixed, ui_checkbox_ctl(demo.checkbox)); 947 995 if (rc != EOK) { 948 996 printf("Error adding control to layout.\n"); … … 968 1016 /* FIXME: Auto layout */ 969 1017 if (ui_is_textmode(ui)) { 970 rect.p0.x = 2;971 rect.p0.y = 1 4;972 rect.p1.x = 1 2;973 rect.p1.y = 1 5;1018 rect.p0.x = 4; 1019 rect.p0.y = 16; 1020 rect.p1.x = 14; 1021 rect.p1.y = 17; 974 1022 } else { 975 1023 rect.p0.x = 15; 976 rect.p0.y = 2 20;1024 rect.p0.y = 255; 977 1025 rect.p1.x = 140; 978 rect.p1.y = 2 40;1026 rect.p1.y = 275; 979 1027 } 980 1028 ui_rbutton_set_rect(demo.rbleft, &rect); 981 1029 982 rc = ui_fixed_add(demo. fixed, ui_rbutton_ctl(demo.rbleft));1030 rc = ui_fixed_add(demo.bfixed, ui_rbutton_ctl(demo.rbleft)); 983 1031 if (rc != EOK) { 984 1032 printf("Error adding control to layout.\n"); … … 995 1043 /* FIXME: Auto layout */ 996 1044 if (ui_is_textmode(ui)) { 997 rect.p0.x = 2;998 rect.p0.y = 1 5;999 rect.p1.x = 1 2;1000 rect.p1.y = 1 6;1045 rect.p0.x = 4; 1046 rect.p0.y = 17; 1047 rect.p1.x = 14; 1048 rect.p1.y = 18; 1001 1049 } else { 1002 1050 rect.p0.x = 15; 1003 rect.p0.y = 2 50;1051 rect.p0.y = 285; 1004 1052 rect.p1.x = 140; 1005 rect.p1.y = 270;1053 rect.p1.y = 305; 1006 1054 } 1007 1055 ui_rbutton_set_rect(demo.rbcenter, &rect); 1008 1056 ui_rbutton_select(demo.rbcenter); 1009 1057 1010 rc = ui_fixed_add(demo. fixed, ui_rbutton_ctl(demo.rbcenter));1058 rc = ui_fixed_add(demo.bfixed, ui_rbutton_ctl(demo.rbcenter)); 1011 1059 if (rc != EOK) { 1012 1060 printf("Error adding control to layout.\n"); … … 1023 1071 /* FIXME: Auto layout */ 1024 1072 if (ui_is_textmode(ui)) { 1025 rect.p0.x = 2;1026 rect.p0.y = 1 6;1027 rect.p1.x = 1 2;1028 rect.p1.y = 1 7;1073 rect.p0.x = 4; 1074 rect.p0.y = 18; 1075 rect.p1.x = 14; 1076 rect.p1.y = 19; 1029 1077 } else { 1030 1078 rect.p0.x = 15; 1031 rect.p0.y = 280;1079 rect.p0.y = 315; 1032 1080 rect.p1.x = 140; 1033 rect.p1.y = 3 00;1081 rect.p1.y = 335; 1034 1082 } 1035 1083 ui_rbutton_set_rect(demo.rbright, &rect); 1036 1084 1037 rc = ui_fixed_add(demo. fixed, ui_rbutton_ctl(demo.rbright));1085 rc = ui_fixed_add(demo.bfixed, ui_rbutton_ctl(demo.rbright)); 1038 1086 if (rc != EOK) { 1039 1087 printf("Error adding control to layout.\n"); … … 1051 1099 /* FIXME: Auto layout */ 1052 1100 if (ui_is_textmode(ui)) { 1053 rect.p0.x = 2;1054 rect.p0.y = 18;1055 rect.p1.x = 28;1056 rect.p1.y = 19;1101 rect.p0.x = 4; 1102 rect.p0.y = 20; 1103 rect.p1.x = 32; 1104 rect.p1.y = 21; 1057 1105 } else { 1058 1106 rect.p0.x = 15; 1059 rect.p0.y = 3 10;1107 rect.p0.y = 345; 1060 1108 rect.p1.x = 130; 1061 rect.p1.y = 3 30;1109 rect.p1.y = 365; 1062 1110 } 1063 1111 1064 1112 ui_slider_set_rect(demo.slider, &rect); 1065 1113 1066 rc = ui_fixed_add(demo. fixed, ui_slider_ctl(demo.slider));1114 rc = ui_fixed_add(demo.bfixed, ui_slider_ctl(demo.slider)); 1067 1115 if (rc != EOK) { 1068 1116 printf("Error adding control to layout.\n"); … … 1080 1128 /* FIXME: Auto layout */ 1081 1129 if (ui_is_textmode(ui)) { 1082 rect.p0.x = 2;1083 rect.p0.y = 2 0;1084 rect.p1.x = 4 0;1085 rect.p1.y = 2 1;1130 rect.p0.x = 4; 1131 rect.p0.y = 22; 1132 rect.p1.x = 42; 1133 rect.p1.y = 23; 1086 1134 } else { 1087 1135 rect.p0.x = 15; 1088 rect.p0.y = 3 40;1136 rect.p0.y = 375; 1089 1137 rect.p1.x = 220; 1090 rect.p1.y = 3 63;1138 rect.p1.y = 398; 1091 1139 } 1092 1140 … … 1096 1144 ui_scrollbar_through_length(demo.hscrollbar) / 4); 1097 1145 1098 rc = ui_fixed_add(demo. fixed, ui_scrollbar_ctl(demo.hscrollbar));1146 rc = ui_fixed_add(demo.bfixed, ui_scrollbar_ctl(demo.hscrollbar)); 1099 1147 if (rc != EOK) { 1100 1148 printf("Error adding control to layout.\n"); … … 1112 1160 /* FIXME: Auto layout */ 1113 1161 if (ui_is_textmode(ui)) { 1114 rect.p0.x = 4 0;1115 rect.p0.y = 3;1116 rect.p1.x = 4 1;1117 rect.p1.y = 2 0;1162 rect.p0.x = 42; 1163 rect.p0.y = 5; 1164 rect.p1.x = 43; 1165 rect.p1.y = 22; 1118 1166 } else { 1119 1167 rect.p0.x = 220; 1120 rect.p0.y = 53;1168 rect.p0.y = 88; 1121 1169 rect.p1.x = 243; 1122 rect.p1.y = 3 40;1170 rect.p1.y = 375; 1123 1171 } 1124 1172 … … 1128 1176 ui_scrollbar_through_length(demo.vscrollbar) / 4); 1129 1177 1130 rc = ui_fixed_add(demo.fixed, ui_scrollbar_ctl(demo.vscrollbar)); 1131 if (rc != EOK) { 1132 printf("Error adding control to layout.\n"); 1133 return rc; 1134 } 1178 rc = ui_fixed_add(demo.bfixed, ui_scrollbar_ctl(demo.vscrollbar)); 1179 if (rc != EOK) { 1180 printf("Error adding control to layout.\n"); 1181 return rc; 1182 } 1183 1184 ui_tab_add(demo.tbasic, ui_fixed_ctl(demo.bfixed)); 1135 1185 1136 1186 ui_window_add(window, ui_fixed_ctl(demo.fixed)); -
uspace/app/uidemo/uidemo.h
r7c5320c r1eaead4 1 1 /* 2 * Copyright (c) 202 2Jiri Svoboda2 * Copyright (c) 2023 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 48 48 #include <ui/scrollbar.h> 49 49 #include <ui/slider.h> 50 #include <ui/tab.h> 51 #include <ui/tabset.h> 50 52 #include <ui/ui.h> 51 53 #include <ui/window.h> … … 56 58 ui_window_t *window; 57 59 ui_fixed_t *fixed; 60 ui_fixed_t *bfixed; 58 61 ui_menu_bar_t *mbar; 59 62 ui_menu_t *mfile; … … 61 64 ui_menu_t *mpreferences; 62 65 ui_menu_t *mhelp; 66 ui_tab_set_t *tabset; 67 ui_tab_t *tbasic; 68 ui_tab_t *tlists; 63 69 ui_entry_t *entry; 64 70 ui_image_t *image; -
uspace/lib/ui/include/ui/paint.h
r7c5320c r1eaead4 1 1 /* 2 * Copyright (c) 202 2Jiri Svoboda2 * Copyright (c) 2023 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 71 71 extern errno_t ui_paint_unmaxicon(ui_resource_t *, gfx_coord2_t *, gfx_coord_t, 72 72 gfx_coord_t, gfx_coord_t, gfx_coord_t); 73 extern errno_t ui_paint_text_box_custom(ui_resource_t *, gfx_rect_t *, 74 ui_box_chars_t *, gfx_color_t *); 73 75 extern errno_t ui_paint_text_box(ui_resource_t *, gfx_rect_t *, 74 76 ui_box_style_t, gfx_color_t *); -
uspace/lib/ui/meson.build
r7c5320c r1eaead4 1 1 # 2 # Copyright (c) 202 2Jiri Svoboda2 # Copyright (c) 2023 Jiri Svoboda 3 3 # All rights reserved. 4 4 # … … 52 52 'src/scrollbar.c', 53 53 'src/slider.c', 54 'src/tab.c', 55 'src/tabset.c', 56 'src/testctl.c', 54 57 'src/ui.c', 55 58 'src/wdecor.c', … … 81 84 'test/scrollbar.c', 82 85 'test/slider.c', 86 'test/tab.c', 87 'test/tabset.c', 88 'test/testctl.c', 83 89 'test/ui.c', 84 90 'test/wdecor.c', -
uspace/lib/ui/src/paint.c
r7c5320c r1eaead4 1 1 /* 2 * Copyright (c) 202 2Jiri Svoboda2 * Copyright (c) 2023 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 632 632 } 633 633 634 /** Paint a text box. 634 /** Paint a custom text box. 635 * 636 * Paint a text box using user-provided box chars. 635 637 * 636 638 * @param resource UI resource 637 639 * @param rect Rectangle inside which to paint the box 638 640 * @param style Box style 641 * @param boxc Box characters 639 642 * @param color Color 640 643 * @return EOK on success or an error code 641 644 */ 642 errno_t ui_paint_text_box (ui_resource_t *resource, gfx_rect_t *rect,643 ui_box_ style_t style, gfx_color_t *color)645 errno_t ui_paint_text_box_custom(ui_resource_t *resource, gfx_rect_t *rect, 646 ui_box_chars_t *boxc, gfx_color_t *color) 644 647 { 645 648 errno_t rc; … … 653 656 gfx_coord_t y; 654 657 char *str = NULL; 655 ui_box_chars_t *boxc = NULL;656 658 657 659 gfx_rect_points_sort(rect, &srect); … … 661 663 if (dim.x < 2 || dim.y < 2) 662 664 return EOK; 665 666 gfx_text_fmt_init(&fmt); 667 fmt.font = resource->font; 668 fmt.color = color; 669 670 bufsz = str_size(boxc->c[0][0]) + 671 str_size(boxc->c[0][1]) * (dim.x - 2) + 672 str_size(boxc->c[0][2]) + 1; 673 674 str = malloc(bufsz); 675 if (str == NULL) 676 return ENOMEM; 677 678 /* Top edge and corners */ 679 680 str_cpy(str, bufsz, boxc->c[0][0]); 681 off = str_size(boxc->c[0][0]); 682 683 for (i = 1; i < dim.x - 1; i++) { 684 str_cpy(str + off, bufsz - off, boxc->c[0][1]); 685 off += str_size(boxc->c[0][1]); 686 } 687 688 str_cpy(str + off, bufsz - off, boxc->c[0][2]); 689 off += str_size(boxc->c[0][2]); 690 str[off] = '\0'; 691 692 pos = rect->p0; 693 rc = gfx_puttext(&pos, &fmt, str); 694 if (rc != EOK) 695 goto error; 696 697 /* Vertical edges */ 698 for (y = rect->p0.y + 1; y < rect->p1.y - 1; y++) { 699 pos.y = y; 700 701 pos.x = rect->p0.x; 702 rc = gfx_puttext(&pos, &fmt, boxc->c[1][0]); 703 if (rc != EOK) 704 goto error; 705 706 pos.x = rect->p1.x - 1; 707 rc = gfx_puttext(&pos, &fmt, boxc->c[1][2]); 708 if (rc != EOK) 709 goto error; 710 } 711 712 /* Bottom edge and corners */ 713 714 str_cpy(str, bufsz, boxc->c[2][0]); 715 off = str_size(boxc->c[2][0]); 716 717 for (i = 1; i < dim.x - 1; i++) { 718 str_cpy(str + off, bufsz - off, boxc->c[2][1]); 719 off += str_size(boxc->c[2][1]); 720 } 721 722 str_cpy(str + off, bufsz - off, boxc->c[2][2]); 723 off += str_size(boxc->c[2][2]); 724 str[off] = '\0'; 725 726 pos.x = rect->p0.x; 727 pos.y = rect->p1.y - 1; 728 rc = gfx_puttext(&pos, &fmt, str); 729 if (rc != EOK) 730 goto error; 731 732 free(str); 733 return EOK; 734 error: 735 if (str != NULL) 736 free(str); 737 return rc; 738 } 739 740 /** Paint a text box. 741 * 742 * Paint a text box with the specified style. 743 * 744 * @param resource UI resource 745 * @param rect Rectangle inside which to paint the box 746 * @param style Box style 747 * @param color Color 748 * @return EOK on success or an error code 749 */ 750 errno_t ui_paint_text_box(ui_resource_t *resource, gfx_rect_t *rect, 751 ui_box_style_t style, gfx_color_t *color) 752 { 753 ui_box_chars_t *boxc = NULL; 663 754 664 755 switch (style) { … … 674 765 return EINVAL; 675 766 676 gfx_text_fmt_init(&fmt); 677 fmt.font = resource->font; 678 fmt.color = color; 679 680 bufsz = str_size(boxc->c[0][0]) + 681 str_size(boxc->c[0][1]) * (dim.x - 2) + 682 str_size(boxc->c[0][2]) + 1; 683 684 str = malloc(bufsz); 685 if (str == NULL) 686 return ENOMEM; 687 688 /* Top edge and corners */ 689 690 str_cpy(str, bufsz, boxc->c[0][0]); 691 off = str_size(boxc->c[0][0]); 692 693 for (i = 1; i < dim.x - 1; i++) { 694 str_cpy(str + off, bufsz - off, boxc->c[0][1]); 695 off += str_size(boxc->c[0][1]); 696 } 697 698 str_cpy(str + off, bufsz - off, boxc->c[0][2]); 699 off += str_size(boxc->c[0][2]); 700 str[off] = '\0'; 701 702 pos = rect->p0; 703 rc = gfx_puttext(&pos, &fmt, str); 704 if (rc != EOK) 705 goto error; 706 707 /* Vertical edges */ 708 for (y = rect->p0.y + 1; y < rect->p1.y - 1; y++) { 709 pos.y = y; 710 711 pos.x = rect->p0.x; 712 rc = gfx_puttext(&pos, &fmt, boxc->c[1][0]); 713 if (rc != EOK) 714 goto error; 715 716 pos.x = rect->p1.x - 1; 717 rc = gfx_puttext(&pos, &fmt, boxc->c[1][2]); 718 if (rc != EOK) 719 goto error; 720 } 721 722 /* Bottom edge and corners */ 723 724 str_cpy(str, bufsz, boxc->c[2][0]); 725 off = str_size(boxc->c[2][0]); 726 727 for (i = 1; i < dim.x - 1; i++) { 728 str_cpy(str + off, bufsz - off, boxc->c[2][1]); 729 off += str_size(boxc->c[2][1]); 730 } 731 732 str_cpy(str + off, bufsz - off, boxc->c[2][2]); 733 off += str_size(boxc->c[2][2]); 734 str[off] = '\0'; 735 736 pos.x = rect->p0.x; 737 pos.y = rect->p1.y - 1; 738 rc = gfx_puttext(&pos, &fmt, str); 739 if (rc != EOK) 740 goto error; 741 742 free(str); 743 return EOK; 744 error: 745 if (str != NULL) 746 free(str); 747 return rc; 767 return ui_paint_text_box_custom(resource, rect, boxc, color); 748 768 } 749 769 -
uspace/lib/ui/src/window.c
r7c5320c r1eaead4 452 452 * @param window Window 453 453 * @param control Control 454 * @return EOK on success, ENOMEM if out of memory455 454 */ 456 455 void ui_window_add(ui_window_t *window, ui_control_t *control) -
uspace/lib/ui/test/control.c
r7c5320c r1eaead4 33 33 #include <pcut/pcut.h> 34 34 #include <ui/control.h> 35 #include <ui/testctl.h> 35 36 #include <stdbool.h> 36 37 #include <types/ui/event.h> 38 #include "../private/testctl.h" 37 39 38 40 PCUT_INIT; 39 41 40 42 PCUT_TEST_SUITE(control); 41 42 static void test_ctl_destroy(void *);43 static errno_t test_ctl_paint(void *);44 static ui_evclaim_t test_ctl_kbd_event(void *, kbd_event_t *);45 static ui_evclaim_t test_ctl_pos_event(void *, pos_event_t *);46 static void test_ctl_unfocus(void *, unsigned);47 48 static ui_control_ops_t test_ctl_ops = {49 .destroy = test_ctl_destroy,50 .paint = test_ctl_paint,51 .kbd_event = test_ctl_kbd_event,52 .pos_event = test_ctl_pos_event,53 .unfocus = test_ctl_unfocus54 };55 56 /** Test response */57 typedef struct {58 /** Claim to return */59 ui_evclaim_t claim;60 /** Result code to return */61 errno_t rc;62 63 /** @c true iff destroy was called */64 bool destroy;65 66 /** @c true iff paint was called */67 bool paint;68 69 /** @c true iff kbd_event was called */70 bool kbd;71 /** Keyboard event that was sent */72 kbd_event_t kevent;73 74 /** @c true iff pos_event was called */75 bool pos;76 /** Position event that was sent */77 pos_event_t pevent;78 79 /** @c true iff unfocus was called */80 bool unfocus;81 /** Number of remaining foci that was sent */82 unsigned unfocus_nfocus;83 } test_resp_t;84 43 85 44 /** Allocate and deallocate control */ … … 89 48 errno_t rc; 90 49 91 rc = ui_control_new(& test_ctl_ops, NULL, &control);50 rc = ui_control_new(&ui_test_ctl_ops, NULL, &control); 92 51 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 93 52 PCUT_ASSERT_NOT_NULL(control); … … 105 64 PCUT_TEST(destroy) 106 65 { 107 ui_ control_t *control = NULL;108 test_resp_t resp;66 ui_test_ctl_t *testctl = NULL; 67 ui_tc_resp_t resp; 109 68 errno_t rc; 110 69 111 rc = ui_ control_new(&test_ctl_ops, &resp, &control);70 rc = ui_test_ctl_create(&resp, &testctl); 112 71 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 113 PCUT_ASSERT_NOT_NULL( control);72 PCUT_ASSERT_NOT_NULL(testctl); 114 73 115 74 resp.rc = EOK; 116 75 resp.destroy = false; 117 76 118 ui_control_destroy( control);77 ui_control_destroy(ui_test_ctl_ctl(testctl)); 119 78 PCUT_ASSERT_TRUE(resp.destroy); 120 79 } … … 123 82 PCUT_TEST(paint) 124 83 { 125 ui_ control_t *control = NULL;126 test_resp_t resp;84 ui_test_ctl_t *testctl = NULL; 85 ui_tc_resp_t resp; 127 86 errno_t rc; 128 87 129 rc = ui_ control_new(&test_ctl_ops, &resp, &control);88 rc = ui_test_ctl_create(&resp, &testctl); 130 89 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 131 PCUT_ASSERT_NOT_NULL( control);90 PCUT_ASSERT_NOT_NULL(testctl); 132 91 133 92 resp.rc = EOK; 134 93 resp.paint = false; 135 94 136 rc = ui_control_paint( control);95 rc = ui_control_paint(ui_test_ctl_ctl(testctl)); 137 96 PCUT_ASSERT_ERRNO_VAL(resp.rc, rc); 138 97 PCUT_ASSERT_TRUE(resp.paint); … … 141 100 resp.paint = false; 142 101 143 rc = ui_control_paint( control);102 rc = ui_control_paint(ui_test_ctl_ctl(testctl)); 144 103 PCUT_ASSERT_ERRNO_VAL(resp.rc, rc); 145 104 PCUT_ASSERT_TRUE(resp.paint); 146 105 147 ui_ control_delete(control);106 ui_test_ctl_destroy(testctl); 148 107 } 149 108 … … 151 110 PCUT_TEST(kbd_event) 152 111 { 153 ui_ control_t *control = NULL;154 test_resp_t resp;112 ui_test_ctl_t *testctl = NULL; 113 ui_tc_resp_t resp; 155 114 kbd_event_t event; 156 115 ui_evclaim_t claim; 157 116 errno_t rc; 158 117 159 rc = ui_ control_new(&test_ctl_ops, &resp, &control);118 rc = ui_test_ctl_create(&resp, &testctl); 160 119 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 161 PCUT_ASSERT_NOT_NULL( control);120 PCUT_ASSERT_NOT_NULL(testctl); 162 121 163 122 resp.claim = ui_claimed; … … 168 127 event.c = '@'; 169 128 170 claim = ui_control_kbd_event( control, &event);129 claim = ui_control_kbd_event(ui_test_ctl_ctl(testctl), &event); 171 130 PCUT_ASSERT_EQUALS(resp.claim, claim); 172 131 PCUT_ASSERT_TRUE(resp.kbd); … … 176 135 PCUT_ASSERT_INT_EQUALS(resp.kevent.c, event.c); 177 136 178 ui_ control_delete(control);137 ui_test_ctl_destroy(testctl); 179 138 } 180 139 … … 182 141 PCUT_TEST(pos_event) 183 142 { 184 ui_ control_t *control = NULL;185 test_resp_t resp;143 ui_test_ctl_t *testctl = NULL; 144 ui_tc_resp_t resp; 186 145 pos_event_t event; 187 146 ui_evclaim_t claim; 188 147 errno_t rc; 189 148 190 rc = ui_ control_new(&test_ctl_ops, &resp, &control);149 rc = ui_test_ctl_create(&resp, &testctl); 191 150 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 192 PCUT_ASSERT_NOT_NULL( control);151 PCUT_ASSERT_NOT_NULL(testctl); 193 152 194 153 resp.claim = ui_claimed; … … 200 159 event.vpos = 4; 201 160 202 claim = ui_control_pos_event( control, &event);161 claim = ui_control_pos_event(ui_test_ctl_ctl(testctl), &event); 203 162 PCUT_ASSERT_EQUALS(resp.claim, claim); 204 163 PCUT_ASSERT_TRUE(resp.pos); … … 209 168 PCUT_ASSERT_INT_EQUALS(resp.pevent.vpos, event.vpos); 210 169 211 ui_ control_delete(control);170 ui_test_ctl_destroy(testctl); 212 171 } 213 172 … … 215 174 PCUT_TEST(unfocus) 216 175 { 217 ui_ control_t *control = NULL;218 test_resp_t resp;176 ui_test_ctl_t *testctl = NULL; 177 ui_tc_resp_t resp; 219 178 errno_t rc; 220 179 221 rc = ui_ control_new(&test_ctl_ops, &resp, &control);180 rc = ui_test_ctl_create(&resp, &testctl); 222 181 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 223 PCUT_ASSERT_NOT_NULL( control);182 PCUT_ASSERT_NOT_NULL(testctl); 224 183 225 184 resp.unfocus = false; 226 185 227 ui_control_unfocus( control, 42);186 ui_control_unfocus(ui_test_ctl_ctl(testctl), 42); 228 187 PCUT_ASSERT_TRUE(resp.unfocus); 229 188 PCUT_ASSERT_INT_EQUALS(42, resp.unfocus_nfocus); 230 189 231 ui_control_delete(control); 232 } 233 234 static void test_ctl_destroy(void *arg) 235 { 236 test_resp_t *resp = (test_resp_t *) arg; 237 238 resp->destroy = true; 239 } 240 241 static errno_t test_ctl_paint(void *arg) 242 { 243 test_resp_t *resp = (test_resp_t *) arg; 244 245 resp->paint = true; 246 return resp->rc; 247 } 248 249 static ui_evclaim_t test_ctl_kbd_event(void *arg, kbd_event_t *event) 250 { 251 test_resp_t *resp = (test_resp_t *) arg; 252 253 resp->kbd = true; 254 resp->kevent = *event; 255 256 return resp->claim; 257 } 258 259 static ui_evclaim_t test_ctl_pos_event(void *arg, pos_event_t *event) 260 { 261 test_resp_t *resp = (test_resp_t *) arg; 262 263 resp->pos = true; 264 resp->pevent = *event; 265 266 return resp->claim; 267 } 268 269 static void test_ctl_unfocus(void *arg, unsigned nfocus) 270 { 271 test_resp_t *resp = (test_resp_t *) arg; 272 273 resp->unfocus = true; 274 resp->unfocus_nfocus = nfocus; 190 ui_test_ctl_destroy(testctl); 275 191 } 276 192 -
uspace/lib/ui/test/main.c
r7c5320c r1eaead4 1 1 /* 2 * Copyright (c) 202 2Jiri Svoboda2 * Copyright (c) 2023 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 52 52 PCUT_IMPORT(scrollbar); 53 53 PCUT_IMPORT(slider); 54 PCUT_IMPORT(tab); 55 PCUT_IMPORT(tabset); 56 PCUT_IMPORT(testctl); 54 57 PCUT_IMPORT(ui); 55 58 PCUT_IMPORT(wdecor); -
uspace/lib/ui/test/paint.c
r7c5320c r1eaead4 1 1 /* 2 * Copyright (c) 202 2Jiri Svoboda2 * Copyright (c) 2023 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 75 75 } testgc_bitmap_t; 76 76 77 /** Test box characters */ 78 static ui_box_chars_t test_box_chars = { 79 { 80 { "A", "B", "C" }, 81 { "D", " ", "E" }, 82 { "F", "G", "H" } 83 } 84 }; 85 77 86 /** Paint bevel */ 78 87 PCUT_TEST(bevel) … … 466 475 /* Paint text box */ 467 476 rc = ui_paint_text_box(resource, &rect, ui_box_single, color); 477 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 478 479 gfx_color_delete(color); 480 ui_resource_destroy(resource); 481 rc = gfx_context_delete(gc); 482 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 483 } 484 485 /** Paint custom text box */ 486 PCUT_TEST(text_box_custom) 487 { 488 errno_t rc; 489 gfx_context_t *gc = NULL; 490 ui_resource_t *resource = NULL; 491 gfx_color_t *color = NULL; 492 test_gc_t tgc; 493 gfx_rect_t rect; 494 495 memset(&tgc, 0, sizeof(tgc)); 496 rc = gfx_context_new(&ops, &tgc, &gc); 497 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 498 499 rc = ui_resource_create(gc, false, &resource); 500 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 501 PCUT_ASSERT_NOT_NULL(resource); 502 503 rc = gfx_color_new_rgb_i16(1, 2, 3, &color); 504 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 505 506 rect.p0.x = 10; 507 rect.p0.y = 20; 508 rect.p1.x = 30; 509 rect.p1.y = 40; 510 511 /* Paint text box */ 512 rc = ui_paint_text_box_custom(resource, &rect, &test_box_chars, color); 468 513 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 469 514 -
uspace/lib/ui/test/wdecor.c
r7c5320c r1eaead4 137 137 PCUT_TEST(set_rect) 138 138 { 139 gfx_context_t *gc = NULL; 140 test_gc_t tgc; 141 ui_resource_t *resource = NULL; 139 142 ui_wdecor_t *wdecor; 140 143 gfx_rect_t rect; 141 144 errno_t rc; 142 145 143 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor); 146 memset(&tgc, 0, sizeof(tgc)); 147 rc = gfx_context_new(&ops, &tgc, &gc); 148 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 149 150 rc = ui_resource_create(gc, false, &resource); 151 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 152 PCUT_ASSERT_NOT_NULL(resource); 153 154 rc = ui_wdecor_create(resource, "Hello", ui_wds_none, &wdecor); 144 155 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 145 156 … … 156 167 157 168 ui_wdecor_destroy(wdecor); 169 ui_resource_destroy(resource); 170 171 rc = gfx_context_delete(gc); 172 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 158 173 } 159 174 … … 445 460 PCUT_TEST(close_btn_clicked) 446 461 { 462 gfx_context_t *gc = NULL; 463 test_gc_t tgc; 464 ui_resource_t *resource = NULL; 447 465 ui_wdecor_t *wdecor; 448 466 gfx_rect_t rect; … … 450 468 errno_t rc; 451 469 452 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor); 470 memset(&tgc, 0, sizeof(tgc)); 471 rc = gfx_context_new(&ops, &tgc, &gc); 472 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 473 474 rc = ui_resource_create(gc, false, &resource); 475 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 476 PCUT_ASSERT_NOT_NULL(resource); 477 478 rc = ui_wdecor_create(resource, "Hello", ui_wds_decorated, &wdecor); 453 479 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 454 480 … … 468 494 469 495 ui_wdecor_destroy(wdecor); 496 ui_resource_destroy(resource); 497 498 rc = gfx_context_delete(gc); 499 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 470 500 } 471 501 … … 788 818 PCUT_TEST(get_rsztype) 789 819 { 820 gfx_context_t *gc = NULL; 821 test_gc_t tgc; 822 ui_resource_t *resource = NULL; 790 823 ui_wdecor_t *wdecor; 791 824 gfx_rect_t rect; … … 794 827 errno_t rc; 795 828 796 rc = ui_wdecor_create(NULL, "Hello", ui_wds_resizable, &wdecor); 829 memset(&tgc, 0, sizeof(tgc)); 830 rc = gfx_context_new(&ops, &tgc, &gc); 831 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 832 833 rc = ui_resource_create(gc, false, &resource); 834 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 835 PCUT_ASSERT_NOT_NULL(resource); 836 837 rc = ui_wdecor_create(resource, "Hello", ui_wds_resizable, &wdecor); 797 838 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 798 839 … … 874 915 /* Non-resizable window */ 875 916 876 rc = ui_wdecor_create( NULL, "Hello", ui_wds_none, &wdecor);917 rc = ui_wdecor_create(resource, "Hello", ui_wds_none, &wdecor); 877 918 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 878 919 … … 890 931 891 932 ui_wdecor_destroy(wdecor); 933 ui_resource_destroy(resource); 934 935 rc = gfx_context_delete(gc); 936 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 892 937 } 893 938 … … 918 963 PCUT_TEST(frame_pos_event) 919 964 { 965 gfx_context_t *gc = NULL; 966 test_gc_t tgc; 967 ui_resource_t *resource = NULL; 920 968 ui_wdecor_t *wdecor; 921 969 gfx_rect_t rect; … … 924 972 errno_t rc; 925 973 926 rc = ui_wdecor_create(NULL, "Hello", ui_wds_resizable, &wdecor); 974 memset(&tgc, 0, sizeof(tgc)); 975 rc = gfx_context_new(&ops, &tgc, &gc); 976 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 977 978 rc = ui_resource_create(gc, false, &resource); 979 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 980 PCUT_ASSERT_NOT_NULL(resource); 981 982 rc = ui_wdecor_create(resource, "Hello", ui_wds_resizable, &wdecor); 927 983 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 928 984 … … 960 1016 961 1017 ui_wdecor_destroy(wdecor); 1018 ui_resource_destroy(resource); 1019 1020 rc = gfx_context_delete(gc); 1021 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 962 1022 } 963 1023
Note:
See TracChangeset
for help on using the changeset viewer.