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,
|
||||
uiControl(uiNewCheckbox("Checkbox")),
|
||||
0);
|
||||
uiButton *btn = uiNewButton("Wide");
|
||||
uiButtonSetMinSize(btn, 150, -1);
|
||||
uiBoxAppend(hbox,
|
||||
uiControl(btn),
|
||||
0);
|
||||
|
||||
uiBoxAppend(vbox,
|
||||
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 uiButtonOnClicked(uiButton *b, void (*f)(uiButton *b, void *data), void *data);
|
||||
_UI_EXTERN uiButton *uiNewButton(const char *text);
|
||||
_UI_EXTERN void uiButtonSetMinSize(uiButton *b, int width, int height);
|
||||
|
||||
typedef struct uiBox uiBox;
|
||||
#define uiBox(this) ((uiBox *) (this))
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
// 7 april 2015
|
||||
#include "uipriv_windows.hpp"
|
||||
#include "../common/general.h"
|
||||
|
||||
struct uiButton {
|
||||
uiWindowsControl c;
|
||||
HWND hwnd;
|
||||
void (*onClicked)(uiButton *, void *);
|
||||
void *onClickedData;
|
||||
int minHeight;
|
||||
int minWidth;
|
||||
};
|
||||
|
||||
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.cy = 0;
|
||||
if (SendMessageW(b->hwnd, BCM_GETIDEALSIZE, 0, (LPARAM) (&size)) != FALSE) {
|
||||
*width = size.cx;
|
||||
*height = size.cy;
|
||||
*width = max(size.cx, (LONG)(b->minWidth));
|
||||
*height = max(size.cy, (LONG)(b->minHeight));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -57,6 +60,9 @@ static void uiButtonMinimumSize(uiWindowsControl *c, int *width, int *height)
|
|||
uiWindowsGetSizing(b->hwnd, &sizing);
|
||||
uiWindowsSizingDlgUnitsToPixels(&sizing, NULL, &y);
|
||||
*height = y;
|
||||
|
||||
*width = max(*width, b->minWidth);
|
||||
*height = max(y, b->minHeight);
|
||||
}
|
||||
|
||||
static void defaultOnClicked(uiButton *b, void *data)
|
||||
|
@ -76,6 +82,13 @@ void uiButtonSetText(uiButton *b, const char *text)
|
|||
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)
|
||||
{
|
||||
b->onClicked = f;
|
||||
|
@ -88,6 +101,8 @@ uiButton *uiNewButton(const char *text)
|
|||
WCHAR *wtext;
|
||||
|
||||
uiWindowsNewControl(uiButton, b);
|
||||
b->minHeight = -1;
|
||||
b->minWidth = -1;
|
||||
|
||||
wtext = toUTF16(text);
|
||||
b->hwnd = uiWindowsEnsureCreateControlHWND(0,
|
||||
|
|
Loading…
Reference in New Issue