button: add uiButtonSetMinSize to avoid very small buttons
This commit is contained in:
parent
a0a980712e
commit
388887aaa6
|
@ -0,0 +1,9 @@
|
||||||
|
#ifndef H_COMMON_GENERAL
|
||||||
|
#define H_COMMON_GENERAL
|
||||||
|
|
||||||
|
int max(int first, int second)
|
||||||
|
{
|
||||||
|
return (first < second) ? second : first;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -37,6 +37,11 @@ static uiControl *makeBasicControlsPage(void)
|
||||||
uiBoxAppend(hbox,
|
uiBoxAppend(hbox,
|
||||||
uiControl(uiNewCheckbox("Checkbox")),
|
uiControl(uiNewCheckbox("Checkbox")),
|
||||||
0);
|
0);
|
||||||
|
uiButton *btn = uiNewButton("Wide");
|
||||||
|
uiButtonSetMinSize(btn, 150, -1);
|
||||||
|
uiBoxAppend(hbox,
|
||||||
|
uiControl(btn),
|
||||||
|
0);
|
||||||
|
|
||||||
uiBoxAppend(vbox,
|
uiBoxAppend(vbox,
|
||||||
uiControl(uiNewLabel("This is a label. Right now, labels can only span one line.")),
|
uiControl(uiNewLabel("This is a label. Right now, labels can only span one line.")),
|
||||||
|
|
1
ui.h
1
ui.h
|
@ -138,6 +138,7 @@ _UI_EXTERN char *uiButtonText(uiButton *b);
|
||||||
_UI_EXTERN void uiButtonSetText(uiButton *b, const char *text);
|
_UI_EXTERN void uiButtonSetText(uiButton *b, const char *text);
|
||||||
_UI_EXTERN void uiButtonOnClicked(uiButton *b, void (*f)(uiButton *b, void *data), void *data);
|
_UI_EXTERN void uiButtonOnClicked(uiButton *b, void (*f)(uiButton *b, void *data), void *data);
|
||||||
_UI_EXTERN uiButton *uiNewButton(const char *text);
|
_UI_EXTERN uiButton *uiNewButton(const char *text);
|
||||||
|
_UI_EXTERN void uiButtonSetMinSize(uiButton *b, int width, int height);
|
||||||
|
|
||||||
typedef struct uiBox uiBox;
|
typedef struct uiBox uiBox;
|
||||||
#define uiBox(this) ((uiBox *) (this))
|
#define uiBox(this) ((uiBox *) (this))
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
// 7 april 2015
|
// 7 april 2015
|
||||||
#include "uipriv_windows.hpp"
|
#include "uipriv_windows.hpp"
|
||||||
|
#include "../common/general.h"
|
||||||
|
|
||||||
struct uiButton {
|
struct uiButton {
|
||||||
uiWindowsControl c;
|
uiWindowsControl c;
|
||||||
HWND hwnd;
|
HWND hwnd;
|
||||||
void (*onClicked)(uiButton *, void *);
|
void (*onClicked)(uiButton *, void *);
|
||||||
void *onClickedData;
|
void *onClickedData;
|
||||||
|
int minHeight;
|
||||||
|
int minWidth;
|
||||||
};
|
};
|
||||||
|
|
||||||
static BOOL onWM_COMMAND(uiControl *c, HWND hwnd, WORD code, LRESULT *lResult)
|
static BOOL onWM_COMMAND(uiControl *c, HWND hwnd, WORD code, LRESULT *lResult)
|
||||||
|
@ -44,8 +47,8 @@ static void uiButtonMinimumSize(uiWindowsControl *c, int *width, int *height)
|
||||||
size.cx = 0; // explicitly ask for ideal size
|
size.cx = 0; // explicitly ask for ideal size
|
||||||
size.cy = 0;
|
size.cy = 0;
|
||||||
if (SendMessageW(b->hwnd, BCM_GETIDEALSIZE, 0, (LPARAM) (&size)) != FALSE) {
|
if (SendMessageW(b->hwnd, BCM_GETIDEALSIZE, 0, (LPARAM) (&size)) != FALSE) {
|
||||||
*width = size.cx;
|
*width = max(size.cx, (LONG)(b->minWidth));
|
||||||
*height = size.cy;
|
*height = max(size.cy, (LONG)(b->minHeight));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,6 +60,9 @@ static void uiButtonMinimumSize(uiWindowsControl *c, int *width, int *height)
|
||||||
uiWindowsGetSizing(b->hwnd, &sizing);
|
uiWindowsGetSizing(b->hwnd, &sizing);
|
||||||
uiWindowsSizingDlgUnitsToPixels(&sizing, NULL, &y);
|
uiWindowsSizingDlgUnitsToPixels(&sizing, NULL, &y);
|
||||||
*height = y;
|
*height = y;
|
||||||
|
|
||||||
|
*width = max(*width, b->minWidth);
|
||||||
|
*height = max(y, b->minHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void defaultOnClicked(uiButton *b, void *data)
|
static void defaultOnClicked(uiButton *b, void *data)
|
||||||
|
@ -76,6 +82,13 @@ void uiButtonSetText(uiButton *b, const char *text)
|
||||||
uiWindowsControlMinimumSizeChanged(uiWindowsControl(b));
|
uiWindowsControlMinimumSizeChanged(uiWindowsControl(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void uiButtonSetMinSize(uiButton *b, int width, int height)
|
||||||
|
{
|
||||||
|
b->minHeight = height;
|
||||||
|
b->minWidth = width;
|
||||||
|
uiWindowsControlMinimumSizeChanged(uiWindowsControl(b));
|
||||||
|
}
|
||||||
|
|
||||||
void uiButtonOnClicked(uiButton *b, void (*f)(uiButton *, void *), void *data)
|
void uiButtonOnClicked(uiButton *b, void (*f)(uiButton *, void *), void *data)
|
||||||
{
|
{
|
||||||
b->onClicked = f;
|
b->onClicked = f;
|
||||||
|
@ -88,6 +101,8 @@ uiButton *uiNewButton(const char *text)
|
||||||
WCHAR *wtext;
|
WCHAR *wtext;
|
||||||
|
|
||||||
uiWindowsNewControl(uiButton, b);
|
uiWindowsNewControl(uiButton, b);
|
||||||
|
b->minHeight = -1;
|
||||||
|
b->minWidth = -1;
|
||||||
|
|
||||||
wtext = toUTF16(text);
|
wtext = toUTF16(text);
|
||||||
b->hwnd = uiWindowsEnsureCreateControlHWND(0,
|
b->hwnd = uiWindowsEnsureCreateControlHWND(0,
|
||||||
|
|
Loading…
Reference in New Issue