Changeset 5d466a1 in mainline
- Timestamp:
- 2021-10-25T00:32:45Z (3 years ago)
- Branches:
- master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6aa85c1
- Parents:
- 748c8bd
- git-author:
- Jiri Svoboda <jiri@…> (2021-10-03 17:33:47)
- git-committer:
- jxsvoboda <5887334+jxsvoboda@…> (2021-10-25 00:32:45)
- Location:
- uspace/app/nav
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/nav/meson.build
r748c8bd r5d466a1 29 29 deps = [ 'ui' ] 30 30 src = files( 31 'menu.c', 31 32 'nav.c', 32 33 ) -
uspace/app/nav/nav.c
r748c8bd r5d466a1 37 37 #include <gfx/coord.h> 38 38 #include <stdio.h> 39 #include <stdlib.h> 39 40 #include <str.h> 40 41 #include <ui/fixed.h> 41 #include <ui/label.h>42 42 #include <ui/resource.h> 43 43 #include <ui/ui.h> 44 44 #include <ui/window.h> 45 #include "menu.h" 45 46 #include "nav.h" 47 48 static errno_t navigator_create(const char *, navigator_t **); 49 static void navigator_destroy(navigator_t *); 46 50 47 51 static void wnd_close(ui_window_t *, void *); … … 63 67 } 64 68 65 /** Run navigator on the specified display. */ 66 static errno_t navigator_run(const char *display_spec) 69 /** Create navigator. 70 * 71 * @param display_spec Display specification 72 * @param rnavigator Place to store pointer to new navigator 73 * @return EOK on success or ane error code 74 */ 75 static errno_t navigator_create(const char *display_spec, 76 navigator_t **rnavigator) 67 77 { 68 ui_t *ui = NULL;78 navigator_t *navigator; 69 79 ui_wnd_params_t params; 70 ui_window_t *window = NULL;71 navigator_t navigator;72 gfx_rect_t rect;73 ui_resource_t *ui_res;74 80 errno_t rc; 75 81 76 rc = ui_create(display_spec, &ui); 82 navigator = calloc(1, sizeof(navigator_t)); 83 if (navigator == NULL) 84 return ENOMEM; 85 86 rc = ui_create(display_spec, &navigator->ui); 77 87 if (rc != EOK) { 78 88 printf("Error creating UI on display %s.\n", display_spec); 79 return rc;89 goto error; 80 90 } 81 91 82 92 ui_wnd_params_init(¶ms); 83 93 params.caption = "Navigator"; 84 if (ui_is_textmode(ui)) { 85 params.rect.p0.x = 0; 86 params.rect.p0.y = 0; 87 params.rect.p1.x = 24; 88 params.rect.p1.y = 5; 89 } else { 90 params.rect.p0.x = 0; 91 params.rect.p0.y = 0; 92 params.rect.p1.x = 200; 93 params.rect.p1.y = 60; 94 params.style &= ~ui_wds_decorated; 95 params.placement = ui_wnd_place_full_screen; 96 97 rc = ui_window_create(navigator->ui, ¶ms, &navigator->window); 98 if (rc != EOK) { 99 printf("Error creating window.\n"); 100 goto error; 94 101 } 95 102 96 memset((void *) &navigator, 0, sizeof(navigator)); 97 navigator.ui = ui; 103 ui_window_set_cb(navigator->window, &window_cb, (void *) navigator); 98 104 99 rc = ui_ window_create(ui, ¶ms, &window);105 rc = ui_fixed_create(&navigator->fixed); 100 106 if (rc != EOK) { 101 printf("Error creating window.\n");102 return rc;107 printf("Error creating fixed layout.\n"); 108 goto error; 103 109 } 104 110 105 ui_window_set_cb(window, &window_cb, (void *) &navigator); 106 navigator.window = window; 111 ui_window_add(navigator->window, ui_fixed_ctl(navigator->fixed)); 107 112 108 ui_res = ui_window_get_res(window); 113 rc = nav_menu_create(navigator, &navigator->menu); 114 if (rc != EOK) 115 goto error; 109 116 110 rc = ui_ fixed_create(&navigator.fixed);117 rc = ui_window_paint(navigator->window); 111 118 if (rc != EOK) { 112 printf("Error creating fixed layout.\n");113 return rc;119 printf("Error painting window.\n"); 120 goto error; 114 121 } 115 122 116 rc = ui_label_create(ui_res, "Hello!", &navigator.label); 117 if (rc != EOK) { 118 printf("Error creating label.\n"); 123 *rnavigator = navigator; 124 return EOK; 125 error: 126 navigator_destroy(navigator); 127 return rc; 128 } 129 130 static void navigator_destroy(navigator_t *navigator) 131 { 132 if (navigator->menu != NULL) 133 nav_menu_destroy(navigator->menu); 134 if (navigator->window != NULL) 135 ui_window_destroy(navigator->window); 136 if (navigator->ui != NULL) 137 ui_destroy(navigator->ui); 138 free(navigator); 139 } 140 141 /** Run navigator on the specified display. */ 142 static errno_t navigator_run(const char *display_spec) 143 { 144 navigator_t *navigator; 145 errno_t rc; 146 147 rc = navigator_create(display_spec, &navigator); 148 if (rc != EOK) 119 149 return rc; 120 }121 150 122 ui_window_get_app_rect(window, &rect); 123 ui_label_set_rect(navigator.label, &rect); 124 ui_label_set_halign(navigator.label, gfx_halign_center); 125 ui_label_set_valign(navigator.label, gfx_valign_center); 151 ui_run(navigator->ui); 126 152 127 rc = ui_fixed_add(navigator.fixed, ui_label_ctl(navigator.label)); 128 if (rc != EOK) { 129 printf("Error adding control to layout.\n"); 130 return rc; 131 } 132 133 ui_window_add(window, ui_fixed_ctl(navigator.fixed)); 134 135 rc = ui_window_paint(window); 136 if (rc != EOK) { 137 printf("Error painting window.\n"); 138 return rc; 139 } 140 141 ui_run(ui); 142 143 ui_window_destroy(window); 144 ui_destroy(ui); 145 153 navigator_destroy(navigator); 146 154 return EOK; 147 155 } … … 149 157 static void print_syntax(void) 150 158 { 151 printf("Syntax: nav igator[-d <display-spec>]\n");159 printf("Syntax: nav [-d <display-spec>]\n"); 152 160 } 153 161 -
uspace/app/nav/nav.h
r748c8bd r5d466a1 1 1 /* 2 * Copyright (c) 202 0Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 39 39 #include <display.h> 40 40 #include <ui/fixed.h> 41 #include <ui/label.h>42 41 #include <ui/ui.h> 43 42 #include <ui/window.h> 44 43 45 44 /** Navigator */ 46 typedef struct { 45 typedef struct navigator { 46 /** User interface */ 47 47 ui_t *ui; 48 /** Window */ 48 49 ui_window_t *window; 50 /** Fixed layout */ 49 51 ui_fixed_t *fixed; 50 ui_label_t *label; 52 /** Menu */ 53 struct nav_menu *menu; 51 54 } navigator_t; 52 55
Note:
See TracChangeset
for help on using the changeset viewer.