ref: ec1b85c429d3fb56bb9fe1cd22309b38a6849e2b
parent: b57b54c2d8223debedae9844098b89c6b5475637
author: Tevo <[email protected]>
date: Mon Jan 11 13:51:32 EST 2021
Manpage stub
--- a/libwidget/base.c
+++ b/libwidget/base.c
@@ -63,6 +63,12 @@
switch(alt(chans))
{
case MOUSE:
+ /*
+ * FIXME if the user clicks once, the widget handles it, then
+ * the user drags and the widget claims to not have handled it
+ * a menu will be shown for that button (if there's one), but
+ * it probably shouldn't
+ */
if(!mouseevent(ctl->root, ctl->image, ctl->image->r, mouse, ctl->c))
{
if((mouse.buttons & M_LEFT) && ctl->left != nil)
--- a/libwidget/base.h
+++ b/libwidget/base.h
@@ -75,24 +75,21 @@
u32int what;
};
-Widgetmsg* newmsg(Widget*, u32int what);
-
-#define C2I(a, b, c, d) ((a) << 24 | (b) << 16 | (c) << 8 | (d))
-
-extern void (*werror)(char*, ...);
-
Widgetctl* initwidget(Image*, Keyboardctl*, Mousectl*, Widget *root, int flags);
+void redrawwctl(Widgetctl*);
void closewidget(Widgetctl*);
-void wdefaults(Widget*);
-
-int nextid(void);
-
Point redrawwidget(Widget*, Image*, Rectangle);
-void redrawwctl(Widgetctl*);
+void freewidget(Widget*);
int kbdevent(Widget*, Image*, Rectangle, Rune, Channel* /*(Widgetmsg*)*/);
int mouseevent(Widget*, Image*, Rectangle, Mouse, Channel* /*(Widgetmsg*)*/);
-void freewidget(Widget*);
+void wdefaults(Widget*);
+int nextid(void);
+Widgetmsg* newmsg(Widget*, u32int what);
+
+#define C2I(a, b, c, d) ((a) << 24 | (b) << 16 | (c) << 8 | (d))
+
+extern void (*werror)(char*, ...);
--- a/libwidget/button.h
+++ b/libwidget/button.h
@@ -18,7 +18,7 @@
Button* newbutton(Widget*);
Button* newtextbutton(Font*, char *content);
-enum
+enum /* messages */
{
M_BUTTON_PRESSED = C2I('b', 't', 'n', 'p'),
M_BUTTON_RELEASED = C2I('b', 't', 'n', 'r')
--- a/libwidget/mkfile
+++ b/libwidget/mkfile
@@ -20,7 +20,16 @@
/sys/include/$HDR \
w-internal.h
+MANPAGES=\
+ /sys/man/2/widget
+
</sys/src/cmd/mksyslib
+install:V: $MANPAGES
+
/sys/include/$HDR: $HCOMP
cat $prereq >$target
+
+# TODO generalize
+/sys/man/2/widget: widget.2.man
+ cp $prereq $target
--- /dev/null
+++ b/libwidget/widget.2.man
@@ -1,0 +1,166 @@
+.TH WIDGET 2
+.SH NAME
+initwidget, closewidget, freewidget, redrawwidget, redrawwctl, kbdevent, mouseevent, wdefaults, nextid, newmsg, istextbox, newtextbox, isbox, newbox, newcenterbox, isbutton, newbutton, newtextbutton \- interface widgets
+.SH SYNOPSIS
+.de PB
+.PP
+.ft L
+.nf
+..
+.PB
+#include <u.h>
+#include <libc.h>
+#include <draw.h>
+#include <thread.h>
+#include <mouse.h>
+#include <keyboard.h>
+#include <String.h>
+#include <widget.h>
+.PB
+typedef struct Widget Widget;
+struct Widget
+{
+ int id;
+ char *kind;
+
+ void *aux;
+ Image *bg, *fg;
+
+ Point (*redraw)(Widget*, Image*, Rectangle);
+
+ int (*kbdevent)(Widget*, Image*, Rectangle, Rune, Channel* /*(Widgetmsg*)*/);
+ int (*mouseevent)(Widget*, Image*, Rectangle, Mouse, Channel* /*(Widgetmsg*)*/);
+
+ void (*cleanup)(Widget*);
+};
+.PB
+typedef struct Widgetctl Widgetctl;
+struct Widgetctl
+{
+ Channel *c; /* chan(Widgetmsg*)[16] */
+ Channel *kbdc; /* chan(Rune)[20] */
+ Channel *menuc; /* chan(Menumsg)[16] */
+ Channel *mousec; /* chan(Mouse)[16] */
+ Channel *resizec;
+ Widget *root;
+
+ Keyboardctl *kbd;
+ Mousectl *mouse;
+
+ Menu *left, *middle, *right;
+
+ Image *image;
+
+ int flags;
+ ...
+};
+.PB
+enum /* flags */
+{
+ FORWARD_KBD = 1<<0,
+ FORWARD_MOUSE = 1<<1
+};
+.PB
+enum /* mouse buttons */
+{
+ M_LEFT = 1<<0,
+ M_MIDDLE = 1<<1,
+ M_RIGHT = 1<<2
+};
+.PB
+typedef struct Menumsg Menumsg;
+struct Menumsg
+{
+ Menu *menu;
+ int button, hit;
+};
+.PB
+typedef struct Widgetmsg Widgetmsg;
+struct Widgetmsg
+{
+ Widget *sender;
+ u32int what;
+};
+.PB
+Widgetctl* initwidget(Image*, Keyboardctl*, Mousectl*, Widget *root, int flags);
+void redrawwctl(Widgetctl*);
+void closewidget(Widgetctl*);
+.PB
+Point redrawwidget(Widget*, Image*, Rectangle);
+void freewidget(Widget*);
+.PB
+int kbdevent(Widget*, Image*, Rectangle, Rune, Channel* /*(Widgetmsg*)*/);
+int mouseevent(Widget*, Image*, Rectangle, Mouse, Channel* /*(Widgetmsg*)*/);
+.PB
+void wdefaults(Widget*);
+int nextid(void);
+Widgetmsg* newmsg(Widget*, u32int what);
+.PB
+#define C2I(a, b, c, d) ((a) << 24 | (b) << 16 | (c) << 8 | (d))
+.PB
+extern void (*werror)(char*, ...) = sysfatal;
+.PB
+typedef struct Textbox Textbox;
+struct Textbox
+{
+ Widget;
+
+ Font *font;
+ String *content;
+ Point lastpt;
+ int selectable;
+ int editable;
+};
+.PB
+int istextbox(Widget*);
+.PB
+Textbox* newtextbox(int selectable, int editable, Font*, char *content);
+.PB
+typedef struct Box Box;
+struct Box
+{
+ Widget;
+
+ Widget *content;
+ int flags;
+
+ Point maxsize;
+ ...
+};
+.PB
+enum /* flags */
+{
+ B_CENTER_CONTENT = 1<<0
+};
+.PB
+int isbox(Widget*);
+.PB
+Box* newbox(Widget*, int flags);
+Box* newcenterbox(Widget*);
+.PB
+typedef struct Button Button;
+struct Button
+{
+ Widget;
+
+ Widget *content;
+ int pressed;
+ ...
+};
+.PB
+int isbutton(Widget*);
+.PB
+Button* newbutton(Widget*);
+Button* newtextbutton(Font*, char *content);
+.PB
+enum /* messages */
+{
+ M_BUTTON_PRESSED
+ M_BUTTON_RELEASED
+};
+.SH DESCRIPTION
+<we describe libwidget here>
+.SH DIAGNOSTICS
+These routines call the function pointed to by werror on fatal errors. The function should not return.
+.SH BUGS
+Writing widgets involves too much boilerplate code.