Cleaned up from the previous merge and added it to the README.

This commit is contained in:
Pietro Gagliardi 2018-05-13 12:05:09 -04:00
parent d02784838e
commit ca1079f344
6 changed files with 34 additions and 24 deletions

View File

@ -5,6 +5,9 @@ This README is being written.<br>
## Announcements ## Announcements
* **13 May 2018**
* Added new functions to work with uiDateTimePickers: `uiDateTimePickerTime()`, `uiDateTimePickerSetTime()`, and `uiDateTimePickerOnChanged()`. These operate on standard `<time.h>` `struct tm`s. Thanks @cody271!
* **2 May 2018** * **2 May 2018**
* On Windows, you no longer need to carry around a `libui.res` file with static builds. You do need to link in the appropriate manifest file, such as the one in the `windows/` folder (I still need to figure out exactly what is needed apart from the Common Controls v6 dependency, or at least to create a complete-ish template), or at least include it alongside your executables. This also means you should no longer see random cmake errors when building the static libraries. * On Windows, you no longer need to carry around a `libui.res` file with static builds. You do need to link in the appropriate manifest file, such as the one in the `windows/` folder (I still need to figure out exactly what is needed apart from the Common Controls v6 dependency, or at least to create a complete-ish template), or at least include it alongside your executables. This also means you should no longer see random cmake errors when building the static libraries.

View File

@ -8,8 +8,10 @@ struct uiDateTimePicker {
void *onChangedData; void *onChangedData;
}; };
@interface uiprivDatePickerDelegateClass : NSObject <NSDatePickerCellDelegate> { // TODO see if target-action works here or not; I forgot what cody271@ originally said
struct uiprivMap *pickers; // the primary advantage of the delegate is the ability to reject changes, but libui doesn't support that yet we should consider that API option as well
@interface uiprivDatePickerDelegateClass : NSObject<NSDatePickerCellDelegate> {
uiprivMap *pickers;
} }
- (void)datePickerCell:(NSDatePickerCell *)aDatePickerCell validateProposedDateValue:(NSDate **)proposedDateValue timeInterval:(NSTimeInterval *)proposedTimeInterval; - (void)datePickerCell:(NSDatePickerCell *)aDatePickerCell validateProposedDateValue:(NSDate **)proposedDateValue timeInterval:(NSTimeInterval *)proposedTimeInterval;
- (void)doTimer:(NSTimer *)timer; - (void)doTimer:(NSTimer *)timer;
@ -33,13 +35,11 @@ struct uiDateTimePicker {
[super dealloc]; [super dealloc];
} }
- (void)datePickerCell:(NSDatePickerCell *)aDatePickerCell - (void)datePickerCell:(NSDatePickerCell *)cell validateProposedDateValue:(NSDate **)proposedDateValue timeInterval:(NSTimeInterval *)proposedTimeInterval
validateProposedDateValue:(NSDate **)proposedDateValue
timeInterval:(NSTimeInterval *)proposedTimeInterval
{ {
uiDateTimePicker *d; uiDateTimePicker *d;
d = (uiDateTimePicker *) uiprivMapGet(self->pickers, aDatePickerCell); d = (uiDateTimePicker *) uiprivMapGet(self->pickers, cell);
[NSTimer scheduledTimerWithTimeInterval:0 [NSTimer scheduledTimerWithTimeInterval:0
target:self target:self
selector:@selector(doTimer:) selector:@selector(doTimer:)
@ -49,9 +49,11 @@ struct uiDateTimePicker {
- (void)doTimer:(NSTimer *)timer - (void)doTimer:(NSTimer *)timer
{ {
NSValue *v;
uiDateTimePicker *d; uiDateTimePicker *d;
d = (uiDateTimePicker *) [((NSValue *)[timer userInfo]) pointerValue]; v = (NSValue *) [timer userInfo];
d = (uiDateTimePicker *) [v pointerValue];
(*(d->onChanged))(d, d->onChangedData); (*(d->onChanged))(d, d->onChangedData);
} }
@ -78,6 +80,7 @@ static void defaultOnChanged(uiDateTimePicker *d, void *data)
// do nothing // do nothing
} }
// TODO consider using NSDateComponents iff we ever need the extra accuracy of not using NSTimeInterval
void uiDateTimePickerTime(uiDateTimePicker *d, struct tm *time) void uiDateTimePickerTime(uiDateTimePicker *d, struct tm *time)
{ {
time_t t; time_t t;
@ -90,7 +93,7 @@ void uiDateTimePickerTime(uiDateTimePicker *d, struct tm *time)
// Copy time to minimize a race condition // Copy time to minimize a race condition
// time.h functions use global non-thread-safe data // time.h functions use global non-thread-safe data
tmbuf = *localtime(&t); tmbuf = *localtime(&t);
memcpy(time, &tmbuf, sizeof(struct tm)); memcpy(time, &tmbuf, sizeof (struct tm));
} }
void uiDateTimePickerSetTime(uiDateTimePicker *d, const struct tm *time) void uiDateTimePickerSetTime(uiDateTimePicker *d, const struct tm *time)
@ -99,7 +102,7 @@ void uiDateTimePickerSetTime(uiDateTimePicker *d, const struct tm *time)
struct tm tmbuf; struct tm tmbuf;
// Copy time because mktime() modifies its argument // Copy time because mktime() modifies its argument
memcpy(&tmbuf, time, sizeof(struct tm)); memcpy(&tmbuf, time, sizeof (struct tm));
t = mktime(&tmbuf); t = mktime(&tmbuf);
[d->dp setDateValue:[NSDate dateWithTimeIntervalSince1970:t]]; [d->dp setDateValue:[NSDate dateWithTimeIntervalSince1970:t]];

View File

@ -23,11 +23,6 @@ _add_example(histogram
${_EXAMPLE_RESOURCES_RC} ${_EXAMPLE_RESOURCES_RC}
) )
_add_example(datetime
datetime/main.c
${_EXAMPLE_RESOURCES_RC}
)
_add_example(cpp-multithread _add_example(cpp-multithread
cpp-multithread/main.cpp cpp-multithread/main.cpp
${_EXAMPLE_RESOURCES_RC} ${_EXAMPLE_RESOURCES_RC}
@ -52,11 +47,16 @@ _add_example(timer
${_EXAMPLE_RESOURCES_RC} ${_EXAMPLE_RESOURCES_RC}
) )
_add_example(datetime
datetime/main.c
${_EXAMPLE_RESOURCES_RC}
)
add_custom_target(examples add_custom_target(examples
DEPENDS DEPENDS
controlgallery controlgallery
histogram histogram
cpp-multithread cpp-multithread
drawtext drawtext
datetime timer
timer) datetime)

View File

@ -17,7 +17,6 @@ const char *timeFormat(uiDateTimePicker *d)
fmt = "%X"; fmt = "%X";
else else
fmt = ""; fmt = "";
return fmt; return fmt;
} }
@ -59,14 +58,19 @@ int onClosing(uiWindow *w, void *data)
int main(void) int main(void)
{ {
uiInitOptions o; uiInitOptions o;
const char *err;
uiWindow *w; uiWindow *w;
uiGrid *g; uiGrid *g;
uiLabel *l; uiLabel *l;
uiButton *b; uiButton *b;
memset(&o, 0, sizeof (uiInitOptions)); memset(&o, 0, sizeof (uiInitOptions));
if (uiInit(&o) != NULL) err = uiInit(&o);
abort(); if (err != NULL) {
fprintf(stderr, "error initializing ui: %s\n", err);
uiFreeInitError(err);
return 1;
}
w = uiNewWindow("Date / Time", 320, 240, 0); w = uiNewWindow("Date / Time", 320, 240, 0);
uiWindowSetMargined(w, 1); uiWindowSetMargined(w, 1);

View File

@ -116,6 +116,7 @@ static void dateTimeChanged(uiprivDateTimePickerWidget *d)
{ {
g_signal_emit(d, changedSignal, 0); g_signal_emit(d, changedSignal, 0);
setLabel(d); setLabel(d);
// TODO fire event here instead?
} }
// we don't want ::toggled to be sent again // we don't want ::toggled to be sent again
@ -579,7 +580,7 @@ void uiDateTimePickerTime(uiDateTimePicker *d, struct tm *time)
// Copy time to minimize a race condition // Copy time to minimize a race condition
// time.h functions use global non-thread-safe data // time.h functions use global non-thread-safe data
tmbuf = *localtime(&t); tmbuf = *localtime(&t);
memcpy(time, &tmbuf, sizeof(struct tm)); memcpy(time, &tmbuf, sizeof (struct tm));
} }
void uiDateTimePickerSetTime(uiDateTimePicker *d, const struct tm *time) void uiDateTimePickerSetTime(uiDateTimePicker *d, const struct tm *time)
@ -588,7 +589,7 @@ void uiDateTimePickerSetTime(uiDateTimePicker *d, const struct tm *time)
struct tm tmbuf; struct tm tmbuf;
// Copy time because mktime() modifies its argument // Copy time because mktime() modifies its argument
memcpy(&tmbuf, time, sizeof(struct tm)); memcpy(&tmbuf, time, sizeof (struct tm));
t = mktime(&tmbuf); t = mktime(&tmbuf);
uiprivDateTimePickerWidget_setTime(d->d, g_date_time_new_from_unix_local(t)); uiprivDateTimePickerWidget_setTime(d->d, g_date_time_new_from_unix_local(t));

View File

@ -4,7 +4,7 @@
struct uiDateTimePicker { struct uiDateTimePicker {
uiWindowsControl c; uiWindowsControl c;
HWND hwnd; HWND hwnd;
void(*onChanged)(uiDateTimePicker *, void *); void (*onChanged)(uiDateTimePicker *, void *);
void *onChangedData; void *onChangedData;
}; };
@ -191,10 +191,9 @@ void uiDateTimePickerSetTime(uiDateTimePicker *d, const struct tm *time)
toSystemTime(time, &systime); toSystemTime(time, &systime);
if (SendMessageW(d->hwnd, DTM_SETSYSTEMTIME, GDT_VALID, (LPARAM) (&systime)) == 0) if (SendMessageW(d->hwnd, DTM_SETSYSTEMTIME, GDT_VALID, (LPARAM) (&systime)) == 0)
logLastError(L"error setting date and time"); logLastError(L"error setting date and time");
(*(d->onChanged))(d, d->onChangedData);
} }
void uiDateTimePickerOnChanged(uiDateTimePicker *d, void(*f)(uiDateTimePicker *, void *), void *data) void uiDateTimePickerOnChanged(uiDateTimePicker *d, void (*f)(uiDateTimePicker *, void *), void *data)
{ {
d->onChanged = f; d->onChanged = f;
d->onChangedData = data; d->onChangedData = data;