TSavePictureDialog
TSavePictureDialog is a Windows & Dialogs widget in the XFrame category of LightGUI's C++ XFrame widget set.
It responds to clicks: assign widget.on_click to handle a press.
Every property below has a setter and a matching getter. The working example at the bottom of this page builds, runs, and is screenshotted under Xvfb.
Properties
| Property | Type | Default | Setter |
|---|---|---|---|
text | std::string | — | set_text |
directory | std::string | — | set_directory |
edit_background_color | Srgb | {255, 255, 255} | set_edit_background_color |
edit_background_color_rgb | (int r, int g, int b) | — | set_edit_background_color_rgb |
filename | std::string | — | set_filename |
list_background_color | Srgb | {255, 255, 255} | set_list_background_color |
list_background_color_rgb | (int r, int g, int b) | — | set_list_background_color_rgb |
picture_icon_grass_color | Srgb | {90, 165, 90} | set_picture_icon_grass_color |
picture_icon_grass_color_rgb | (int r, int g, int b) | — | set_picture_icon_grass_color_rgb |
picture_icon_sky_color | Srgb | {150, 195, 235} | set_picture_icon_sky_color |
picture_icon_sky_color_rgb | (int r, int g, int b) | — | set_picture_icon_sky_color_rgb |
preview_background_color | Srgb | {255, 255, 255} | set_preview_background_color |
preview_background_color_rgb | (int r, int g, int b) | — | set_preview_background_color_rgb |
preview_hill_color | Srgb | {60, 130, 70} | set_preview_hill_color |
preview_hill_color_rgb | (int r, int g, int b) | — | set_preview_hill_color_rgb |
preview_mountain_color | Srgb | {110, 130, 160} | set_preview_mountain_color |
preview_mountain_color_rgb | (int r, int g, int b) | — | set_preview_mountain_color_rgb |
preview_sun_color | Srgb | {250, 215, 60} | set_preview_sun_color |
preview_sun_color_rgb | (int r, int g, int b) | — | set_preview_sun_color_rgb |
selected_text_color | Srgb | {255, 255, 255} | set_selected_text_color |
selected_text_color_rgb | (int r, int g, int b) | — | set_selected_text_color_rgb |
title_bar_color | Srgb | {200, 60, 50} | set_title_bar_color |
title_bar_color_rgb | (int r, int g, int b) | — | set_title_bar_color_rgb |
title_text_color | Srgb | {255, 255, 255} | set_title_text_color |
title_text_color_rgb | (int r, int g, int b) | — | set_title_text_color_rgb |
bounds | (int x, int y, int width, int height) | — | set_bounds |
style_name | std::string | — | set_style_name |
visible | bool | true | set_visible |
enabled | bool | true | set_enabled |
Every widget also gets the shared properties visible, enabled, bounds (x, y, width, height) and style_name, plus the background / foreground colours from the active style.
Events
Callbacks this widget exposes (assign a lambda or function):
on_clickvoid()— Fires when the widget is clicked. Assign a handler:widget.on_click = [] { /* handle the click */ };
Every XFrame widget also implements the four input handlers the example's event loop calls: on_button_press(x, y, button), on_button_release(x, y, button), on_motion(x, y) and on_key(key, text). Each returns true when it handled the event; the loop then clears the window and redraws. Close the window (the WM_DELETE_WINDOW message) to quit.
Changing the font and label
XFrame widgets take their font from the style manager, not from a per-widget font property. The example's styles.add_style_ex("default", ..., 6, 1, "-misc-fixed-medium-r-normal--13-*") call sets the font (an XLFD name, here 13-point fixed) for every widget using the default style. To give one widget a different font, add a named style and point the widget at it:
styles.add_style_ex("large", Srgb{225, 225, 225}, Srgb{120, 120, 120}, Srgb{60, 60, 60}, Srgb{20, 20, 20}, 6, 1, "-misc-fixed-medium-r-normal--18-*");
widget.set_style_name("large");To change what the widget shows, set its text with widget.set_text("Hello"); and read it back with widget.get_text().
Styling: colours, border radius, line width
Border radius and the base line width are style properties, not widget properties: in add_style_ex("default", fill, outline, line, text, 6, 1, font) the 6 is the corner radius in pixels and the 1 is the border line width. Add a named style with different values and point the widget at it with set_style_name() to restyle one widget.
This widget exposes its own colour setters: set_edit_background_color(), set_list_background_color(), set_picture_icon_grass_color(), set_picture_icon_sky_color(), set_preview_background_color(), set_preview_hill_color(), set_preview_mountain_color(), set_preview_sun_color(), set_selected_text_color(), set_title_bar_color(), set_title_text_color(). They take an Srgb{r, g, b} (each component 0–255); every colour also has a set_edit_background_color_rgb(r, g, b) variant:
widget.set_edit_background_color(Srgb{200, 30, 30});Working example
Minimal complete program — window plus this widget, with the standard event loop. Runnable copy in the repo: examples/TSavePictureDialog.cpp.
// TSavePictureDialog -- minimal XFrame example (C++).
// Build: g++ -std=c++17 -I/opt/lightgui/widgets/components -I/opt/lightgui/widgets TSavePictureDialog.cpp -lX11 -o TSavePictureDialog
// Run under Xvfb (or a real X server); close the window to quit.
// Setup mirrors the widget's own demo in widgets/components/TSavePictureDialog/main_TSavePictureDialog.cpp.
#include "TSavePictureDialog/TSavePictureDialog.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, "TSavePictureDialog - 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");
TSavePictureDialog 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;
}
Build it:
g++ -std=c++17 -I/opt/lightgui/widgets/components -I/opt/lightgui/widgets TSavePictureDialog.cpp -lX11 -o TSavePictureDialog