summaryrefslogtreecommitdiff
path: root/src/widget/label.c
blob: 5c0c00adfcff19f8263676276878b96cc825c732 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <ui.h>

#include "uiLibrary.h"
#include "widget.h"

uiLabel* uiMakeLabel(uiPtr parent, const char* text) {
  assert(text);

  uiLabel* label = UI_NEW(uiLabel);

  *label = (uiLabel){
      .widget =
          (uiWidget){.type = uiTypeLabel,
                     .rect =
                         (uiRect){.width = (int)strlen(text) *
                                           g_ui.font->header.glyph_width,
                                  .height = g_ui.font->header.glyph_height}},
      .text = string_new(text),
  };
  WidgetSetParent(uiMakeLabelPtr(label), parent);
  return label;
}

const char* uiLabelGetText(const uiLabel* label) {
  assert(label);
  return string_data(label->text);
}