add support for setting an explicit min size for libui controls. for now only supported by uiArea.

This commit is contained in:
StapleButter 2017-10-02 01:58:09 +02:00
parent ce592a1d80
commit 09920126dd
4 changed files with 21 additions and 3 deletions

View File

@ -62,6 +62,14 @@ void uiControlSetFocus(uiControl *c)
(*(c->SetFocus))(c);
}
void uiControlSetMinSize(uiControl *c, int w, int h)
{
c->MinWidth = w;
c->MinHeight = h;
// TODO: resize if needed
}
#define uiControlSignature 0x7569436F
uiControl *uiAllocControl(size_t size, uint32_t OSsig, uint32_t typesig, const char *typenamestr)
@ -72,6 +80,10 @@ uiControl *uiAllocControl(size_t size, uint32_t OSsig, uint32_t typesig, const c
c->Signature = uiControlSignature;
c->OSSignature = OSsig;
c->TypeSignature = typesig;
c->MinWidth = -1;
c->MinHeight = -1;
return c;
}

View File

@ -73,6 +73,8 @@ struct uiControl {
void (*Enable)(uiControl *);
void (*Disable)(uiControl *);
void (*SetFocus)(uiControl *);
int MinWidth, MinHeight;
};
// TOOD add argument names to all arguments
#define uiControl(this) ((uiControl *) (this))
@ -88,6 +90,7 @@ _UI_EXTERN int uiControlEnabled(uiControl *);
_UI_EXTERN void uiControlEnable(uiControl *);
_UI_EXTERN void uiControlDisable(uiControl *);
_UI_EXTERN void uiControlSetFocus(uiControl *);
_UI_EXTERN void uiControlSetMinSize(uiControl *, int w, int h); // -1 = no minimum
_UI_EXTERN uiControl *uiAllocControl(size_t n, uint32_t OSsig, uint32_t typesig, const char *typenamestr);
_UI_EXTERN void uiFreeControl(uiControl *);

View File

@ -55,9 +55,11 @@ uiWindowsControlAllDefaults(uiArea)
static void uiAreaMinimumSize(uiWindowsControl *c, int *width, int *height)
{
// TODO
*width = 1;
*height = 1;
*width = c->c.MinWidth;
if (*width < 1) *width = 1;
*height = c->c.MinHeight;
if (*height < 1) *height = 1;
}
ATOM registerAreaClass(HICON hDefaultIcon, HCURSOR hDefaultCursor)

View File

@ -592,6 +592,7 @@ int main(int argc, char** argv)
MainDrawArea = uiNewArea(&areahandler);
uiWindowSetChild(MainWindow, uiControl(MainDrawArea));
uiControlSetMinSize(uiControl(MainDrawArea), 256, 384);
EmuRunning = 2;
RunningSomething = false;