Add minimal XFrame example program per widget (547) for cdoc.lightgui.com
Each examples/<Widget>.cpp is a minimal complete program: window + widget (setup mirrors the widget demo) + standard event loop. Built, run under Xvfb and screenshotted for the C widget docs.
This commit is contained in:
1 parent
541fd842dc
commit
4ecf42407b
547 files changed
+37000
No files matched your search
@@ -0,0 +1,67 @@
|
||||
// GtkStackSwitcher -- minimal XFrame example (C++).
|
||||
// Build: g++ -std=c++17 -I/opt/lightgui/widgets/components -I/opt/lightgui/widgets GtkStackSwitcher.cpp -lX11 -o GtkStackSwitcher
|
||||
// Run under Xvfb (or a real X server); close the window to quit.
|
||||
// Setup mirrors the widget's own demo in widgets/components/GtkStackSwitcher/main_GtkStackSwitcher.cpp.
|
||||
#include "GtkStackSwitcher/GtkStackSwitcher.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
int main() {
|
||||
Display* display = XOpenDisplay(nullptr);
|
||||
if (!display) { return 1; }
|
||||
int screen = DefaultScreen(display);
|
||||
Window window = XCreateSimpleWindow(display, RootWindow(display, screen), 100, 100, 800, 600, 1, BlackPixel(display, screen), WhitePixel(display, screen));
|
||||
XStoreName(display, window, "GtkStackSwitcher - XFrame demo");
|
||||
XSelectInput(display, window, ExposureMask | KeyPressMask | StructureNotifyMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask);
|
||||
Atom deleteWindowMessage = XInternAtom(display, "WM_DELETE_WINDOW", False);
|
||||
XSetWMProtocols(display, window, &deleteWindowMessage, 1);
|
||||
XMapWindow(display, window);
|
||||
GC gc = DefaultGC(display, screen);
|
||||
SStyle_Manager styles(display, window, screen, gc);
|
||||
styles.add_style_ex("default", Srgb{225, 225, 225}, Srgb{120, 120, 120}, Srgb{60, 60, 60}, Srgb{20, 20, 20}, 6, 1, "-misc-fixed-medium-r-normal--13-*");
|
||||
styles.add_style_ex("dark", Srgb{45, 45, 48}, Srgb{20, 20, 22}, Srgb{200, 200, 200}, Srgb{240, 240, 240}, 6, 1, "-misc-fixed-medium-r-normal--13-*");
|
||||
styles.set_active_style_byName("default");
|
||||
GtkStackSwitcher widget(display, screen, window, gc, &styles, 40, 40, 340, 200);
|
||||
widget.draw();
|
||||
XFlush(display);
|
||||
bool running = true;
|
||||
while (running) {
|
||||
XEvent event;
|
||||
XNextEvent(display, &event);
|
||||
bool handled = false;
|
||||
switch (event.type) {
|
||||
case Expose:
|
||||
handled = true;
|
||||
break;
|
||||
case ButtonPress:
|
||||
handled = widget.on_button_press(event.xbutton.x, event.xbutton.y, event.xbutton.button);
|
||||
break;
|
||||
case ButtonRelease:
|
||||
handled = widget.on_button_release(event.xbutton.x, event.xbutton.y, event.xbutton.button);
|
||||
break;
|
||||
case MotionNotify:
|
||||
handled = widget.on_motion(event.xmotion.x, event.xmotion.y);
|
||||
break;
|
||||
case KeyPress: {
|
||||
char buffer[32];
|
||||
KeySym key = 0;
|
||||
int n = XLookupString(&event.xkey, buffer, (int)sizeof(buffer) - 1, &key, nullptr);
|
||||
buffer[n] = 0;
|
||||
handled = widget.on_key(key, buffer);
|
||||
break;
|
||||
}
|
||||
case ClientMessage:
|
||||
if ((Atom)event.xclient.data.l[0] == deleteWindowMessage) {
|
||||
running = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (handled) {
|
||||
XClearWindow(display, window);
|
||||
widget.draw();
|
||||
XFlush(display);
|
||||
}
|
||||
}
|
||||
XCloseDisplay(display);
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user