Changeset 0e80e40 in mainline for uspace/app/nav/panel.c
- Timestamp:
- 2021-10-25T00:32:45Z (3 years ago)
- Branches:
- master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 9f7e9bb
- Parents:
- 61784ed
- git-author:
- Jiri Svoboda <jiri@…> (2021-10-07 17:17:36)
- git-committer:
- jxsvoboda <5887334+jxsvoboda@…> (2021-10-25 00:32:45)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/nav/panel.c
r61784ed r0e80e40 35 35 */ 36 36 37 #include <dirent.h> 37 38 #include <errno.h> 38 39 #include <gfx/render.h> 40 #include <gfx/text.h> 39 41 #include <stdlib.h> 40 42 #include <str.h> 41 43 #include <ui/control.h> 42 44 #include <ui/paint.h> 45 #include <ui/resource.h> 43 46 #include "panel.h" 44 47 #include "nav.h" … … 81 84 goto error; 82 85 86 rc = gfx_color_new_ega(0x30, &panel->curs_color); 87 if (rc != EOK) 88 goto error; 89 83 90 panel->window = window; 84 91 list_initialize(&panel->entries); … … 86 93 return EOK; 87 94 error: 95 if (panel->color != NULL) 96 gfx_color_delete(panel->color); 97 if (panel->curs_color != NULL) 98 gfx_color_delete(panel->curs_color); 88 99 ui_control_delete(panel->control); 89 100 free(panel); … … 97 108 void panel_destroy(panel_t *panel) 98 109 { 99 panel_entry_t *entry; 100 101 entry = panel_first(panel); 102 while (entry != NULL) { 103 panel_entry_delete(entry); 104 entry = panel_first(panel); 105 } 106 110 gfx_color_delete(panel->color); 111 gfx_color_delete(panel->curs_color); 112 panel_clear_entries(panel); 107 113 ui_control_delete(panel->control); 108 114 free(panel); … … 117 123 gfx_context_t *gc = ui_window_get_gc(panel->window); 118 124 ui_resource_t *res = ui_window_get_res(panel->window); 125 gfx_font_t *font = ui_resource_get_font(res); 126 gfx_text_fmt_t fmt; 127 panel_entry_t *entry; 128 gfx_coord2_t pos; 129 gfx_rect_t rect; 119 130 errno_t rc; 131 132 gfx_text_fmt_init(&fmt); 120 133 121 134 rc = gfx_set_color(gc, panel->color); … … 131 144 if (rc != EOK) 132 145 return rc; 146 147 pos.x = panel->rect.p0.x + 1; 148 pos.y = panel->rect.p0.y + 1; 149 150 entry = panel->page; 151 while (entry != NULL && pos.y < panel->rect.p1.y - 1) { 152 if (entry == panel->cursor) { 153 /* Draw cursor background */ 154 rect.p0 = pos; 155 rect.p1.x = panel->rect.p1.x - 1; 156 rect.p1.y = rect.p0.y + 1; 157 158 rc = gfx_set_color(gc, panel->curs_color); 159 if (rc != EOK) 160 return rc; 161 162 rc = gfx_fill_rect(gc, &rect); 163 if (rc != EOK) 164 return rc; 165 166 fmt.color = panel->curs_color; 167 } else { 168 fmt.color = panel->color; 169 } 170 171 rc = gfx_puttext(font, &pos, &fmt, entry->name); 172 if (rc != EOK) 173 return rc; 174 175 pos.y++; 176 entry = panel_next(entry); 177 } 133 178 134 179 rc = gfx_update(gc); … … 240 285 void panel_entry_delete(panel_entry_t *entry) 241 286 { 287 if (entry->panel->cursor == entry) 288 entry->panel->cursor = NULL; 289 if (entry->panel->page == entry) 290 entry->panel->page = NULL; 291 242 292 list_remove(&entry->lentries); 243 293 free(entry->name); … … 245 295 } 246 296 297 /** Clear panel entry list. 298 * 299 * @param panel Panel 300 */ 301 void panel_clear_entries(panel_t *panel) 302 { 303 panel_entry_t *entry; 304 305 entry = panel_first(panel); 306 while (entry != NULL) { 307 panel_entry_delete(entry); 308 entry = panel_first(panel); 309 } 310 } 311 312 /** Read directory into panel entry list. 313 * 314 * @param panel Panel 315 * @param dirname Directory path 316 * @return EOK on success or an error code 317 */ 318 errno_t panel_read_dir(panel_t *panel, const char *dirname) 319 { 320 DIR *dir; 321 struct dirent *dirent; 322 errno_t rc; 323 324 dir = opendir(dirname); 325 if (dir == NULL) 326 return errno; 327 328 dirent = readdir(dir); 329 while (dirent != NULL) { 330 rc = panel_entry_append(panel, dirent->d_name, 1); 331 if (rc != EOK) 332 goto error; 333 dirent = readdir(dir); 334 } 335 336 closedir(dir); 337 338 panel->cursor = panel_first(panel); 339 panel->page = panel_first(panel); 340 return EOK; 341 error: 342 closedir(dir); 343 return rc; 344 } 345 247 346 /** Return first panel entry. 248 347 *
Note:
See TracChangeset
for help on using the changeset viewer.