From 09920126ddcc84d98e333287566d8483ad3410a8 Mon Sep 17 00:00:00 2001 From: StapleButter Date: Mon, 2 Oct 2017 01:58:09 +0200 Subject: add support for setting an explicit min size for libui controls. for now only supported by uiArea. --- src/libui_sdl/libui/common/control.c | 12 ++++++++++++ src/libui_sdl/libui/ui.h | 3 +++ src/libui_sdl/libui/windows/area.cpp | 8 +++++--- src/libui_sdl/main.cpp | 1 + 4 files changed, 21 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/libui_sdl/libui/common/control.c b/src/libui_sdl/libui/common/control.c index 771a29d..f811728 100644 --- a/src/libui_sdl/libui/common/control.c +++ b/src/libui_sdl/libui/common/control.c @@ -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; } diff --git a/src/libui_sdl/libui/ui.h b/src/libui_sdl/libui/ui.h index d072ac2..f1937e2 100644 --- a/src/libui_sdl/libui/ui.h +++ b/src/libui_sdl/libui/ui.h @@ -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 *); diff --git a/src/libui_sdl/libui/windows/area.cpp b/src/libui_sdl/libui/windows/area.cpp index 3257631..74fe768 100644 --- a/src/libui_sdl/libui/windows/area.cpp +++ b/src/libui_sdl/libui/windows/area.cpp @@ -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) diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index 241d9b7..1d5fcae 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -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; -- cgit v1.2.3