Merge ac79554528
into fea45b2d5b
This commit is contained in:
commit
33bbddf262
|
@ -109,6 +109,18 @@ static void defaultOnChanged(uiSlider *s, void *data)
|
|||
// do nothing
|
||||
}
|
||||
|
||||
void uiSliderSetRange(uiSlider *s, int min, int max)
|
||||
{
|
||||
if (min >= max) {
|
||||
int temp = min;
|
||||
min = max;
|
||||
max = temp;
|
||||
}
|
||||
|
||||
[s->slider setMinValue:min];
|
||||
[s->slider setMaxValue:max];
|
||||
}
|
||||
|
||||
uiSlider *uiNewSlider(int min, int max)
|
||||
{
|
||||
uiSlider *s;
|
||||
|
|
40
test/page4.c
40
test/page4.c
|
@ -4,6 +4,9 @@
|
|||
static uiSpinbox *spinbox;
|
||||
static uiSlider *slider;
|
||||
static uiProgressBar *pbar;
|
||||
static uiSpinbox *spinboxFrom;
|
||||
static uiSpinbox *spinboxTo;
|
||||
|
||||
|
||||
#define CHANGED(what) \
|
||||
static void on ## what ## Changed(ui ## what *this, void *data) \
|
||||
|
@ -75,6 +78,24 @@ static void selectNone(uiButton *b, void *data)
|
|||
uiRadioButtonsSetSelected(rb, -1);
|
||||
}
|
||||
|
||||
static void setSliderRange(uiSpinbox *spinbox, void *data)
|
||||
{
|
||||
uiSlider *s = data;
|
||||
|
||||
uiSliderSetRange(s, uiSpinboxValue(spinboxFrom), uiSpinboxValue(spinboxTo));
|
||||
}
|
||||
|
||||
static void onRangeSliderChanged(uiSlider *s, void *data)
|
||||
{
|
||||
char str[128];
|
||||
uiLabel *lbl = data;
|
||||
|
||||
// wonderful, vanilla snprintf() isn't in visual studio 2013 - http://blogs.msdn.com/b/vcblog/archive/2013/07/19/c99-library-support-in-visual-studio-2013.aspx
|
||||
// we can't use _snprintf() in the test suite because that's msvc-only, so oops. sprintf() it is.
|
||||
sprintf(str, "%d", uiSliderValue(s));
|
||||
uiLabelSetText(lbl, str);
|
||||
}
|
||||
|
||||
uiBox *makePage4(void)
|
||||
{
|
||||
uiBox *page4;
|
||||
|
@ -82,6 +103,7 @@ uiBox *makePage4(void)
|
|||
uiSpinbox *xsb;
|
||||
uiButton *b;
|
||||
uiSlider *xsl;
|
||||
uiLabel *lbl;
|
||||
|
||||
page4 = newVerticalBox();
|
||||
|
||||
|
@ -122,6 +144,24 @@ uiBox *makePage4(void)
|
|||
|
||||
uiBoxAppend(page4, uiControl(uiNewHorizontalSeparator()), 0);
|
||||
|
||||
lbl = uiNewLabel("100");
|
||||
uiBoxAppend(page4, uiControl(lbl), 0);
|
||||
hbox = newHorizontalBox();
|
||||
spinboxFrom = uiNewSpinbox(0, 1000);
|
||||
uiSpinboxSetValue(spinboxFrom, 100);
|
||||
uiBoxAppend(hbox, uiControl(spinboxFrom), 1);
|
||||
xsl = uiNewSlider(100, 200);
|
||||
uiSpinboxOnChanged(spinboxFrom, setSliderRange, xsl);
|
||||
uiBoxAppend(hbox, uiControl(xsl), 1);
|
||||
uiSliderOnChanged(xsl, onRangeSliderChanged, lbl);
|
||||
spinboxTo = uiNewSpinbox(0, 1000);
|
||||
uiSpinboxSetValue(spinboxTo, 200);
|
||||
uiSpinboxOnChanged(spinboxTo, setSliderRange, xsl);
|
||||
uiBoxAppend(hbox, uiControl(spinboxTo), 1);
|
||||
uiBoxAppend(page4, uiControl(hbox), 0);
|
||||
|
||||
uiBoxAppend(page4, uiControl(uiNewHorizontalSeparator()), 0);
|
||||
|
||||
cbox = uiNewCombobox();
|
||||
uiComboboxAppend(cbox, "Item 1");
|
||||
uiComboboxAppend(cbox, "Item 2");
|
||||
|
|
1
ui.h
1
ui.h
|
@ -210,6 +210,7 @@ typedef struct uiSlider uiSlider;
|
|||
_UI_EXTERN int uiSliderValue(uiSlider *s);
|
||||
_UI_EXTERN void uiSliderSetValue(uiSlider *s, int value);
|
||||
_UI_EXTERN void uiSliderOnChanged(uiSlider *s, void (*f)(uiSlider *s, void *data), void *data);
|
||||
_UI_EXTERN void uiSliderSetRange(uiSlider *s, int min, int max);
|
||||
_UI_EXTERN uiSlider *uiNewSlider(int min, int max);
|
||||
|
||||
typedef struct uiProgressBar uiProgressBar;
|
||||
|
|
|
@ -44,6 +44,20 @@ void uiSliderOnChanged(uiSlider *s, void (*f)(uiSlider *, void *), void *data)
|
|||
s->onChangedData = data;
|
||||
}
|
||||
|
||||
void uiSliderSetRange(uiSlider *s, int min, int max)
|
||||
{
|
||||
if (min >= max) {
|
||||
int temp = min;
|
||||
min = max;
|
||||
max = temp;
|
||||
}
|
||||
|
||||
// we need to inhibit sending of ::value-changed because this WILL send a ::value-changed otherwise
|
||||
g_signal_handler_block(s->range, s->onChangedSignal);
|
||||
gtk_range_set_range(s->range, min, max);
|
||||
g_signal_handler_unblock(s->range, s->onChangedSignal);
|
||||
}
|
||||
|
||||
uiSlider *uiNewSlider(int min, int max)
|
||||
{
|
||||
uiSlider *s;
|
||||
|
|
|
@ -68,6 +68,18 @@ void uiSliderOnChanged(uiSlider *s, void (*f)(uiSlider *, void *), void *data)
|
|||
s->onChangedData = data;
|
||||
}
|
||||
|
||||
void uiSliderSetRange(uiSlider *s, int min, int max)
|
||||
{
|
||||
if (min >= max) {
|
||||
int temp = min;
|
||||
min = max;
|
||||
max = temp;
|
||||
}
|
||||
|
||||
SendMessageW(s->hwnd, TBM_SETRANGEMIN, (WPARAM) TRUE, (LPARAM) min);
|
||||
SendMessageW(s->hwnd, TBM_SETRANGEMAX, (WPARAM) TRUE, (LPARAM) max);
|
||||
}
|
||||
|
||||
uiSlider *uiNewSlider(int min, int max)
|
||||
{
|
||||
uiSlider *s;
|
||||
|
|
Loading…
Reference in New Issue