|
Velvet 0.1a
A beginner-friendly C++ GUI framework built on SFML.
|
This page explains what each widget does, what properties matter, and how to use them quickly.
Window is the application host and render/event loop owner.
setBackgroundColor(unsigned int color) - set background color of the window. Use an RGBA hex like 0xRRGGBBAAadd(Widgets) - add Widgets/Layouts to the windowbool isOpen() - returns if window is openclose() - closes the windowStack is Velvet's layout primitive.
Note from the developer:
Stack is similar to a CSS flexbox. One can relate a HStack to a CSS divdisplay: flexwithflex-direction: row, and VStack toflex-direction: column. Similarly,paddingandgap,justify-contentandalign-itemsall work the similarly in Velvet.
setWidth(float), setHeight(float), setSize(float, float) - set explicit layout sizesetJustifyContent("start"|"center"|"end") - main-axis placementsetAlignItems("start"|"center"|"end") - cross-axis placementsetBackgroundColor(sf::Color) - container background fillsetGap(float) - set spacing between childrenSetting padding:
setPadding(float all) - all sidessetPadding(float x, float y) - horizontal and verticalsetPadding(float left, right, top, bottom) - individual directionsDefault padding: 8px, can be configured with the above functions
gap: spacing between children (in px)
Or the more convenient HStack and VStack:
NOTE: Stacks can be nested! You can do:
Label displays styled text. Supports a style map in the constructor.
fontPath (std::string) default: "src/assets/AdwaitaSans-Regular.ttf"fontSize (float)lineSpacing (float)letterSpacing (float)fillColor (unsigned int, RGBA hex like 0xRRGGBBAA)outlineColor (unsigned int)outlineThickness (float)fontStyle (std::string): regular, bold, italic, underlined, strikethroughbackgroundColor (unsigned int)setText(const std::string) - change the label text on runtimeoverrideStyling({...}) - Update styling keys on runtimeButton implements, well, a button. Supports a style map in the constructor.
fontPath (std::string) default: "src/assets/AdwaitaSans-Regular.ttf"fontSize (float)letterSpacing (float)fontColor (unsigned int, RGBA hex like 0xRRGGBBAA)hoverFontColor (unsigned int) font color when button is hoveredoutlineColor (unsigned int) outline of the buttonoutlineThickness (float) outline thicknessbackgroundColor (unsigned int) background color of the buttonhoverBackgroundColor (unsigned int) intended background color when button is hoveredwidth (float) width of the button; default: 200.fheight (float) height of the button; default: 50.fFires onclick callback when left mouse is pressed while hovered.
overrideStyling({...}) - Update styling keys on runtime.Slider is horizontal and emits continuous values in range [from, to].
Get current value of slider:
InputField is a single-line text box that accepts keyboard input, and shows a placeholder when empty.
fontPath (std::string) e.g. "src/assets/AdwaitaSans-Regular.ttf"fontSize (float)letterSpacing (float)fontColor (unsigned int) text color, RGBA hex like 0xRRGGBBAAoutlineColor (unsigned int) inactive border coloractiveOutlineColor (unsigned int) intended active border color when focusedbackgroundColor (unsigned int) input background fillplaceholderColor (unsigned int) color of the placeholder textwidth (float) width of the input boxoverrideStyling({...}) - Update styling keys on runtimesetPlaceholder(std::string placeholderString) - Update the placeholder textGetter functions:
std::string getContent() - Returns the current contentstd::string gePlaceholder() - Returns the current placeholderImage displays an image loaded from file.
setImage(std::string filePath)- Set the image path on runtime.setScale(float x, float y)- Set the image scale relative to the image's actual dimensions.