Cleaned up from the previous merge and added it to the README.
This commit is contained in:
parent
d02784838e
commit
ca1079f344
|
@ -5,6 +5,9 @@ This README is being written.<br>
|
|||
|
||||
## 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**
|
||||
* 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.
|
||||
|
||||
|
|
|
@ -8,8 +8,10 @@ struct uiDateTimePicker {
|
|||
void *onChangedData;
|
||||
};
|
||||
|
||||
@interface uiprivDatePickerDelegateClass : NSObject <NSDatePickerCellDelegate> {
|
||||
struct uiprivMap *pickers;
|
||||
// TODO see if target-action works here or not; I forgot what cody271@ originally said
|
||||
// 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)doTimer:(NSTimer *)timer;
|
||||
|
@ -33,13 +35,11 @@ struct uiDateTimePicker {
|
|||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void)datePickerCell:(NSDatePickerCell *)aDatePickerCell
|
||||
validateProposedDateValue:(NSDate **)proposedDateValue
|
||||
timeInterval:(NSTimeInterval *)proposedTimeInterval
|
||||
- (void)datePickerCell:(NSDatePickerCell *)cell validateProposedDateValue:(NSDate **)proposedDateValue timeInterval:(NSTimeInterval *)proposedTimeInterval
|
||||
{
|
||||
uiDateTimePicker *d;
|
||||
|
||||
d = (uiDateTimePicker *) uiprivMapGet(self->pickers, aDatePickerCell);
|
||||
d = (uiDateTimePicker *) uiprivMapGet(self->pickers, cell);
|
||||
[NSTimer scheduledTimerWithTimeInterval:0
|
||||
target:self
|
||||
selector:@selector(doTimer:)
|
||||
|
@ -49,9 +49,11 @@ struct uiDateTimePicker {
|
|||
|
||||
- (void)doTimer:(NSTimer *)timer
|
||||
{
|
||||
NSValue *v;
|
||||
uiDateTimePicker *d;
|
||||
|
||||
d = (uiDateTimePicker *) [((NSValue *)[timer userInfo]) pointerValue];
|
||||
v = (NSValue *) [timer userInfo];
|
||||
d = (uiDateTimePicker *) [v pointerValue];
|
||||
(*(d->onChanged))(d, d->onChangedData);
|
||||
}
|
||||
|
||||
|
@ -78,6 +80,7 @@ static void defaultOnChanged(uiDateTimePicker *d, void *data)
|
|||
// do nothing
|
||||
}
|
||||
|
||||
// TODO consider using NSDateComponents iff we ever need the extra accuracy of not using NSTimeInterval
|
||||
void uiDateTimePickerTime(uiDateTimePicker *d, struct tm *time)
|
||||
{
|
||||
time_t t;
|
||||
|
@ -90,7 +93,7 @@ void uiDateTimePickerTime(uiDateTimePicker *d, struct tm *time)
|
|||
// Copy time to minimize a race condition
|
||||
// time.h functions use global non-thread-safe data
|
||||
tmbuf = *localtime(&t);
|
||||
memcpy(time, &tmbuf, sizeof(struct tm));
|
||||
memcpy(time, &tmbuf, sizeof (struct tm));
|
||||
}
|
||||
|
||||
void uiDateTimePickerSetTime(uiDateTimePicker *d, const struct tm *time)
|
||||
|
@ -99,7 +102,7 @@ void uiDateTimePickerSetTime(uiDateTimePicker *d, const struct tm *time)
|
|||
struct tm tmbuf;
|
||||
|
||||
// Copy time because mktime() modifies its argument
|
||||
memcpy(&tmbuf, time, sizeof(struct tm));
|
||||
memcpy(&tmbuf, time, sizeof (struct tm));
|
||||
t = mktime(&tmbuf);
|
||||
|
||||
[d->dp setDateValue:[NSDate dateWithTimeIntervalSince1970:t]];
|
||||
|
|
|
@ -23,11 +23,6 @@ _add_example(histogram
|
|||
${_EXAMPLE_RESOURCES_RC}
|
||||
)
|
||||
|
||||
_add_example(datetime
|
||||
datetime/main.c
|
||||
${_EXAMPLE_RESOURCES_RC}
|
||||
)
|
||||
|
||||
_add_example(cpp-multithread
|
||||
cpp-multithread/main.cpp
|
||||
${_EXAMPLE_RESOURCES_RC}
|
||||
|
@ -52,11 +47,16 @@ _add_example(timer
|
|||
${_EXAMPLE_RESOURCES_RC}
|
||||
)
|
||||
|
||||
_add_example(datetime
|
||||
datetime/main.c
|
||||
${_EXAMPLE_RESOURCES_RC}
|
||||
)
|
||||
|
||||
add_custom_target(examples
|
||||
DEPENDS
|
||||
controlgallery
|
||||
histogram
|
||||
cpp-multithread
|
||||
drawtext
|
||||
datetime
|
||||
timer)
|
||||
timer
|
||||
datetime)
|
||||
|
|
|
@ -17,7 +17,6 @@ const char *timeFormat(uiDateTimePicker *d)
|
|||
fmt = "%X";
|
||||
else
|
||||
fmt = "";
|
||||
|
||||
return fmt;
|
||||
}
|
||||
|
||||
|
@ -59,14 +58,19 @@ int onClosing(uiWindow *w, void *data)
|
|||
int main(void)
|
||||
{
|
||||
uiInitOptions o;
|
||||
const char *err;
|
||||
uiWindow *w;
|
||||
uiGrid *g;
|
||||
uiLabel *l;
|
||||
uiButton *b;
|
||||
|
||||
memset(&o, 0, sizeof (uiInitOptions));
|
||||
if (uiInit(&o) != NULL)
|
||||
abort();
|
||||
err = uiInit(&o);
|
||||
if (err != NULL) {
|
||||
fprintf(stderr, "error initializing ui: %s\n", err);
|
||||
uiFreeInitError(err);
|
||||
return 1;
|
||||
}
|
||||
|
||||
w = uiNewWindow("Date / Time", 320, 240, 0);
|
||||
uiWindowSetMargined(w, 1);
|
||||
|
|
|
@ -116,6 +116,7 @@ static void dateTimeChanged(uiprivDateTimePickerWidget *d)
|
|||
{
|
||||
g_signal_emit(d, changedSignal, 0);
|
||||
setLabel(d);
|
||||
// TODO fire event here instead?
|
||||
}
|
||||
|
||||
// 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
|
||||
// time.h functions use global non-thread-safe data
|
||||
tmbuf = *localtime(&t);
|
||||
memcpy(time, &tmbuf, sizeof(struct tm));
|
||||
memcpy(time, &tmbuf, sizeof (struct tm));
|
||||
}
|
||||
|
||||
void uiDateTimePickerSetTime(uiDateTimePicker *d, const struct tm *time)
|
||||
|
@ -588,7 +589,7 @@ void uiDateTimePickerSetTime(uiDateTimePicker *d, const struct tm *time)
|
|||
struct tm tmbuf;
|
||||
|
||||
// Copy time because mktime() modifies its argument
|
||||
memcpy(&tmbuf, time, sizeof(struct tm));
|
||||
memcpy(&tmbuf, time, sizeof (struct tm));
|
||||
t = mktime(&tmbuf);
|
||||
|
||||
uiprivDateTimePickerWidget_setTime(d->d, g_date_time_new_from_unix_local(t));
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
struct uiDateTimePicker {
|
||||
uiWindowsControl c;
|
||||
HWND hwnd;
|
||||
void(*onChanged)(uiDateTimePicker *, void *);
|
||||
void (*onChanged)(uiDateTimePicker *, void *);
|
||||
void *onChangedData;
|
||||
};
|
||||
|
||||
|
@ -191,10 +191,9 @@ void uiDateTimePickerSetTime(uiDateTimePicker *d, const struct tm *time)
|
|||
toSystemTime(time, &systime);
|
||||
if (SendMessageW(d->hwnd, DTM_SETSYSTEMTIME, GDT_VALID, (LPARAM) (&systime)) == 0)
|
||||
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->onChangedData = data;
|
||||
|
|
Loading…
Reference in New Issue