libui/redo/darwin/label.m

55 lines
1.1 KiB
Mathematica
Raw Normal View History

// 11 june 2015
2015-07-11 16:02:01 -05:00
#include "uipriv_darwin.h"
struct label {
uiLabel l;
2015-07-22 22:20:01 -05:00
NSTextField *label;
};
uiDefineControlType(uiLabel, uiTypeLabel, struct label)
static uintptr_t labelHandle(uiControl *c)
{
struct label *l = (struct label *) c;
2015-07-22 22:20:01 -05:00
return (uintptr_t) (l->label);
}
static char *labelText(uiLabel *ll)
{
struct label *l = (struct label *) ll;
2015-07-22 22:20:01 -05:00
return uiDarwinNSStringToText([l->label stringValue]);
}
static void labelSetText(uiLabel *ll, const char *text)
{
struct label *l = (struct label *) ll;
2015-07-22 22:20:01 -05:00
[l->label setStringValue:toNSString(text)];
// changing the text might necessitate a change in the label's size
uiControlQueueResize(uiControl(l));
}
uiLabel *uiNewLabel(const char *text)
{
struct label *l;
2015-07-22 22:20:01 -05:00
l = (struct label *) uiNewControl(uiTypeLabel());
2015-07-22 22:20:01 -05:00
l->label = [[NSTextField alloc] initWithFrame:NSZeroRect];
[l->label setStringValue:toNSString(text)];
[l->label setEditable:NO];
[l->label setSelectable:NO];
[l->label setDrawsBackground:NO];
finishNewTextField(uiControl(l), l->label, NO);
uiControl(l)->Handle = labelHandle;
uiLabel(l)->Text = labelText;
uiLabel(l)->SetText = labelSetText;
return uiLabel(l);
}