DVX_GUI/widgets/toolbar/widgetToolbar.c

119 lines
3.6 KiB
C

#define DVX_WIDGET_IMPL
// widgetToolbar.c -- Toolbar widget
//
// A horizontal container with a raised 1px bevel background, used to
// hold buttons, separators, spacers, and other control widgets in a
// strip at the top of a window. Like StatusBar, the toolbar is a
// standard HBox layout with custom paint -- child widgets position
// themselves via the generic horizontal box algorithm.
//
// The 1px raised bevel (vs the 2px used for window chrome) keeps the
// toolbar visually distinct but lightweight. The bevel's bottom shadow
// line serves as the separator between the toolbar and the content
// area below it.
//
// Tight 2px padding and spacing match the StatusBar for visual
// consistency between top and bottom chrome bars. Children (typically
// ImageButtons or small Buttons) handle their own mouse/key events.
#include "dvxWidgetPlugin.h"
#define TOOLBAR_PAD 2
#define TOOLBAR_GAP 2
static int32_t sTypeId = -1;
// ============================================================
// widgetToolbarPaint
// ============================================================
// Raised bevel with windowFace fill. The 1px bevel width is
// intentionally thinner than window chrome (2px) to keep the
// toolbar from looking too heavy.
void widgetToolbarPaint(WidgetT *w, DisplayT *d, const BlitOpsT *ops, const BitmapFontT *font, const ColorSchemeT *colors) {
(void)font;
// Draw raised background and bottom separator
BevelStyleT bevel;
bevel.highlight = colors->windowHighlight;
bevel.shadow = colors->windowShadow;
bevel.face = colors->windowFace;
bevel.width = 1;
drawBevel(d, ops, w->x, w->y, w->w, w->h, &bevel);
}
// ============================================================
// widgetToolbarGetLayoutMetrics
// ============================================================
void widgetToolbarGetLayoutMetrics(const WidgetT *w, const BitmapFontT *font, int32_t *pad, int32_t *gap, int32_t *extraTop, int32_t *borderW) {
(void)w;
(void)font;
*pad = TOOLBAR_PAD;
*gap = TOOLBAR_GAP;
*extraTop = 0;
*borderW = 0;
}
// ============================================================
// DXE registration
// ============================================================
static const WidgetClassT sClassToolbar = {
.version = WGT_CLASS_VERSION,
.flags = WCLASS_BOX_CONTAINER | WCLASS_HORIZ_CONTAINER,
.handlers = {
[WGT_METHOD_PAINT] = (void *)widgetToolbarPaint,
[WGT_METHOD_GET_LAYOUT_METRICS] = (void *)widgetToolbarGetLayoutMetrics,
}
};
// ============================================================
// Widget creation functions
// ============================================================
WidgetT *wgtToolbar(WidgetT *parent) {
WidgetT *w = widgetAlloc(parent, sTypeId);
if (w) {
w->padding = wgtPixels(2);
w->spacing = wgtPixels(2);
}
return w;
}
// ============================================================
// DXE registration
// ============================================================
static const struct {
WidgetT *(*create)(WidgetT *parent);
} sApi = {
.create = wgtToolbar
};
static const WgtIfaceT sIface = {
.basName = "Toolbar",
.props = NULL,
.propCount = 0,
.methods = NULL,
.methodCount = 0,
.events = NULL,
.eventCount = 0,
.createSig = WGT_CREATE_PARENT,
.isContainer = true
};
void wgtRegister(void) {
sTypeId = wgtRegisterClass(&sClassToolbar);
wgtRegisterApi("toolbar", &sApi);
wgtRegisterIface("toolbar", &sIface);
}