Changeset a35b458 in mainline for uspace/lib/gui/label.c
- Timestamp:
- 2018-03-02T20:10:49Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gui/label.c
r3061bc1 ra35b458 50 50 if (!surface) 51 51 window_yield(lbl->widget.window); 52 52 53 53 drawctx_t drawctx; 54 54 drawctx_init(&drawctx, surface); 55 55 56 56 drawctx_set_source(&drawctx, &lbl->background); 57 57 drawctx_transfer(&drawctx, widget->hpos, widget->vpos, widget->width, 58 58 widget->height); 59 59 60 60 sysarg_t cpt_width; 61 61 sysarg_t cpt_height; 62 62 font_get_box(lbl->font, lbl->caption, &cpt_width, &cpt_height); 63 63 64 64 if ((widget->width >= cpt_width) && (widget->height >= cpt_height)) { 65 65 sysarg_t x = ((widget->width - cpt_width) / 2) + widget->hpos; 66 66 sysarg_t y = ((widget->height - cpt_height) / 2) + widget->vpos; 67 67 68 68 drawctx_set_source(&drawctx, &lbl->text); 69 69 drawctx_set_font(&drawctx, lbl->font); 70 70 71 71 if (lbl->caption) 72 72 drawctx_print(&drawctx, lbl->caption, x, y); 73 73 } 74 74 75 75 window_yield(lbl->widget.window); 76 76 } … … 80 80 if (data != NULL) { 81 81 label_t *lbl = (label_t *) widget; 82 82 83 83 const char *new_caption = (const char *) data; 84 84 lbl->caption = str_dup(new_caption); 85 85 86 86 sysarg_t cpt_width; 87 87 sysarg_t cpt_height; 88 88 font_get_box(lbl->font, lbl->caption, &cpt_width, &cpt_height); 89 89 90 90 lbl->widget.width_min = cpt_width + 4; 91 91 lbl->widget.height_min = cpt_height + 4; 92 92 lbl->widget.width_ideal = lbl->widget.width_min; 93 93 lbl->widget.height_ideal = lbl->widget.height_min; 94 94 95 95 window_refresh(lbl->widget.window); 96 96 } … … 107 107 { 108 108 label_t *lbl = (label_t *) widget; 109 109 110 110 deinit_label(lbl); 111 111 free(lbl); … … 144 144 { 145 145 widget_init(&lbl->widget, parent, data); 146 146 147 147 lbl->widget.destroy = label_destroy; 148 148 lbl->widget.reconfigure = label_reconfigure; … … 151 151 lbl->widget.handle_keyboard_event = label_handle_keyboard_event; 152 152 lbl->widget.handle_position_event = label_handle_position_event; 153 153 154 154 source_init(&lbl->background); 155 155 source_set_color(&lbl->background, background); 156 156 157 157 source_init(&lbl->text); 158 158 source_set_color(&lbl->text, text); 159 159 160 160 if (caption == NULL) 161 161 lbl->caption = NULL; 162 162 else 163 163 lbl->caption = str_dup(caption); 164 164 165 165 errno_t rc = embedded_font_create(&lbl->font, points); 166 166 if (rc != EOK) { … … 169 169 return false; 170 170 } 171 171 172 172 sysarg_t cpt_width; 173 173 sysarg_t cpt_height; 174 174 font_get_box(lbl->font, lbl->caption, &cpt_width, &cpt_height); 175 175 176 176 lbl->widget.width_min = cpt_width + 4; 177 177 lbl->widget.height_min = cpt_height + 4; 178 178 lbl->widget.width_ideal = lbl->widget.width_min; 179 179 lbl->widget.height_ideal = lbl->widget.height_min; 180 180 181 181 lbl->rewrite = on_rewrite; 182 182 183 183 return true; 184 184 } … … 190 190 if (!lbl) 191 191 return NULL; 192 192 193 193 if (init_label(lbl, parent, data, caption, points, background, text)) 194 194 return lbl; 195 195 196 196 free(lbl); 197 197 return NULL;
Note:
See TracChangeset
for help on using the changeset viewer.