mobius3 / kiwi Goto Github PK
View Code? Open in Web Editor NEWKiWi: Killer Widgets
License: zlib License
KiWi: Killer Widgets
License: zlib License
I'm not sure how much of an issue this is, but in GUIs that aren't visible, there's no way (without manually changing KW_gui::evqueuesize
) to set a given GUI to ignore events when it is not being rendered and/or updated, as calling KW_ProcessEvents
will fire off any buttons if the mouse clicks over where it would be. Ignoring it will fill up the event queue of each GUI until it just overflows and causes a segmentation fault.
Proposed fix/enhancement:
KW_ClearQueue(KW_gui* gui){
SDL_LockMutex(gui->evqueuelock);
// 1000 is sufficiently large that it's not going to occur through normal use
if (gui->evqueuesize > 1000) {
gui->evqueuesize = 0;
}
SDL_UnlockMutex(gui->evqueuelock);
}
I'm currently trying out a darker design and would like to have a light font color for that, however I only found KW_SetLabelColor
for setting label font colors. This would solve it for me, but doesn't cover other widgets (like editbox or button) and is more bothersome than setting a global default like one can already do with the font (see KW_SetFont
).
I made this small demo that demonstrates the problem. When I position KW_CreateButtonAndLabel
to negative y
position the scrollbox area has wrong dimensions (innercomposite
in KW_Scrollbox
is too large). It can be seen in the following GIFs.
But if I position items only in positive y
it's fine:
This is the test source code, the commented part is where you can see the difference:
#include "SDL.h"
#include "KW_gui.h"
#include "KW_button.h"
#include "KW_scrollbox.h"
#include "KW_renderdriver_sdl2.h"
int main(int argc, char ** argv) {
SDL_Window * window;
SDL_Renderer * renderer;
KW_RenderDriver * driver;
KW_Surface * set;
KW_GUI * gui;
KW_Font * font;
KW_Rect geometry = {0, 0, 320, 240};
KW_Widget * frame, * button;
int i;
SDL_Event ev;
size_t len = 0;
/* initialize SDL */
SDL_Init(SDL_INIT_EVERYTHING);
SDL_CreateWindowAndRenderer(geometry.w, geometry.h, SDL_WINDOW_RESIZABLE, &window, &renderer);
SDL_SetRenderDrawColor(renderer, 100, 200, 100, 1);
driver = KW_CreateSDL2RenderDriver(renderer, window);
set = KW_LoadSurface(driver, "tileset.png");
/* initialize gui */
gui = KW_Init(driver, set);
font = KW_LoadFont(driver, "SourceSansPro-Semibold.ttf", 12);
KW_SetFont(gui, font);
geometry.x = (unsigned)(geometry.w * 0.0625f);
geometry.y = (unsigned)(geometry.h * .0625f);
geometry.w *= .875f;
geometry.h *= .875;
frame = KW_CreateScrollbox(gui, NULL, &geometry);
int pos_y = geometry.h;
geometry.x = 10; geometry.y = 0; geometry.h = 40; geometry.w = 230;
for (i = 0; i < 10; i++) {
geometry.y = pos_y;
KW_CreateButtonAndLabel(gui, frame, "Text label", &geometry);
pos_y -= geometry.h;
}
// for (i = 0; i < 10; i++) {
// KW_CreateButtonAndLabel(gui, frame, "Text label", &geometry);
// geometry.y += geometry.h;
// }
/* create another parent frame */
while (!SDL_QuitRequested()) {
while (SDL_PollEvent(&ev)) {
if (ev.type == SDL_WINDOWEVENT && ev.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
geometry.w = (unsigned)ev.window.data1;
geometry.h = (unsigned)ev.window.data2;
geometry.x = (unsigned)(geometry.w * 0.0625);
geometry.y = (unsigned)(geometry.h * .0625);
geometry.w *= .875f;
geometry.h *= .875;
KW_SetWidgetGeometry(frame, &geometry);
}
}
SDL_RenderClear(renderer);
KW_ProcessEvents(gui);
KW_Paint(gui);
SDL_RenderPresent(renderer);
SDL_Delay(1);
}
KW_ReleaseFont(driver, font);
KW_Quit(gui);
KW_ReleaseSurface(driver, set);
SDL_Quit();
return 0;
}
After packaging this library, I tried compiling the example in the README which emitted several warnings and an immediately segfaulting binary. It took me way longer than it should to realize that the file the example has been based on did update in the meanwhile, leaving the example outdated. Please update the example or better, replace it with a link to the repository file.
See title. This is inconsistent with the other widget font setters.
Good time of the day!
KiWi examples failed to link with 'undefined references' originated from SDL2main until I reodered libraries for each example in cmake files:
target_link_libraries(label KiWi ${SDL2_LIBRARIES} ${SDL2MAIN_LIBRARY} ${SDL2_IMAGE_LIBRARIES})
turned into
target_link_libraries(label KiWi -lmingw32 ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARIES} ${SDL2_IMAGE_LIBRARIES})
Seems like the libs should go as mingw32 - SDL2main - SDL2. This was a quick workaround just to test and go on TDM-64 and won't do at large at all. To my shame I'm not much experienced in cmake to suggest a working patch right now - finding SDL on Windows properly is a killer task...
In the rest KiWi compiles easily and with not any single warning.
I notice your project is not much active recently but you should know that I tried many GUI alternatives for SDL. KiWi has advantages before all of them. It is light, does not require many dependencies and builds wonderfully on my whimsy system. Thank you for the job, please don't stop!
๐๐๐
I am creating a binding for dlang. It took sometime to figure out how to run editbox example. KW_CreateEditbox function returns a KW_Widget* handle. But in the example, there is no something like KW_Widget* eBox = KW_CreateEditbox(.....). To run the example in d, I had to do like:
KW_Widget * e_box;
void OKClicked(KW_Widget * widget, int b){
const(char*) text = KW_GetEditboxText(e_box);
printf(text);
}
in main:
e_box = KW_CreateEditbox(gui, frame, "Edit me!", &editboxrect);
...
KW_OnMouseDown cb = cast(KW_OnMouseDown)(&OKClicked);
KW_AddWidgetMouseDownHandler(okbutton, cb);
I've noticed now that it's crucial to set the GUI font with KW_SetFont
after KW_Init
as the application will otherwise segfault. I'm not sure whether this is a deliberate decision (to support the alternative usecase of setting fonts for each widget involving them or compositions not involving text) or an API mistake. If it's the latter, why not change KW_Init
to require a KW_Font
argument and remove all KW_SetFont
calls from the examples?
This will be my probably last issue for now. I've published the code, released an egg and made an announcement. Feel free to include links to these in the README. Thanks for your help so far, I've had lots of fun working with your library :D
Where are the implementations of those declarations?
void KW_AddGUITextColorChangedHandler(KW_GUI * gui, KW_OnGUITextColorChanged handler, void * priv);
void KW_RemoveGUITextColorChangedHandler(KW_GUI * gui, KW_OnGUITextColorChanged handler, void * priv);
New widget, KW_Radio, has no documentation. @Emersont1, since it was you who added it, maybe it is better if you create it? :)
Today I've dealt with the callback side of this library and found out that for my bindings to execute Scheme callbacks correctly, I must declare KW_Paint
as a safe function. This is apparently because KW_Paint
handles both event processing and painting, unlike what its name suggests. A possible fix is documenting KW_ProcessEvents
in KW_gui.h
, removing its function call from KW_Paint
, then updating all examples to use KW_ProcessEvents
before KW_Paint
.
edit: Same thing with drag.c
after resizing its window, then any of the buttons.
Hi, i'm looking to change over to TTF_RenderText_Blended_Wrapped
for multi line text rendering in preparation for an Editbox and a scrolling box of text for longer messages. However, this will mean an additional argument of width to be passed. I'm not sure what your opinion on introducing breaking changes into the library is so should i implement it as a new RenderTextWrapped
function, or just extend the existing function and any uses within the library, and set it to not wrap if the width is set to 0
if there was a way to pull information out of the editbox that would be great, and if there is can anyone show me an example.
This is probably more due to my lack of cmake understanding but I can't get it to generate successfully.
CMake Error at src/CMakeLists.txt:51 (add_library):
Cannot find source file:
resources.c
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
.hxx .in .txx
CMake Error: CMake can not determine linker language for target: KiWi
CMake Error in src/CMakeLists.txt:
Exporting the target "KiWi" is not allowed since its linker language cannot
be determined
Any info on what is happening here? Is it just me? Can you provide a successful cmake configuration as an example, pretty please? :)
I'm not entirely sure of the purpose of lines 98-106 in KW_label_internal.c
using this example code, and the default (i think) skin:
KW_Widget * label;
KW_Rect iconrect = { .x = 0, .y = 48, .w = 24, .h = 24 };
for(int i =0;i<10;i++){
label = KW_CreateLabel(gui, frame, "Label with an icon :)", &r);
KW_SetLabelAlignment(label, KW_LABEL_ALIGN_LEFT, 0, KW_LABEL_ALIGN_TOP, 0);
KW_SetLabelIcon(label, &iconrect);
r.y+=50;
}
Currently there are mouse down and mouse up handlers for handling click events. Neither are ideal for implementing buttons that can be clicked as the actual behavior (as can be seen in GTK with zenity --info --text "foobar"
or Qt applications) is subtly different:
I don't quite understand the event handling code yet, otherwise I'd have handed in a PR. For the time being, I'll use the mouse up handler.
This is a little followup to #23. I'm wondering how can I remove a widget from its parent (completely destroy the widget).
From the comments in the code I suppose I should be using the following to destroy eg. button with label:
KW_DestroyWidget(widget, 1);
However this sometimes throws an error ("Segmentation fault") as can be seen the following GIFs. It seems to be random, sometimes it fails, sometimes it's fine.
By clicking any of the buttons I want to remove them with KW_DestroyWidget
.
... or here
... or here
The error backtrace is always the same:
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libKiWi.dylib 0x000000010b77d5be CalculateMouseOver + 30 (KW_eventwatcher.c:15)
1 libKiWi.dylib 0x000000010b77db0d MouseReleased + 253 (KW_eventwatcher.c:104)
2 libKiWi.dylib 0x000000010b77deff KW_ProcessEvents + 367 (KW_eventwatcher.c:151)
3 test-widget-removal 0x000000010b653d2a main + 922 (test-widget-removal.c:66)
4 libdyld.dylib 0x00007fff9f302235 start + 1
Test source code:
#include "SDL.h"
#include "KW_gui.h"
#include "KW_button.h"
#include "KW_scrollbox.h"
#include "KW_renderdriver_sdl2.h"
void MouseDown(KW_Widget * widget, int button) {
KW_DestroyWidget(widget, 1);
}
int main(int argc, char ** argv) {
SDL_Window * window;
SDL_Renderer * renderer;
KW_RenderDriver * driver;
KW_Surface * set;
KW_GUI * gui;
KW_Font * font;
KW_Rect geometry = {0, 0, 480, 320};
KW_Widget * frame, * button;
int i;
SDL_Event ev;
size_t len = 0;
/* initialize SDL */
SDL_Init(SDL_INIT_EVERYTHING);
SDL_CreateWindowAndRenderer(geometry.w, geometry.h, SDL_WINDOW_RESIZABLE, &window, &renderer);
SDL_SetRenderDrawColor(renderer, 100, 200, 100, 1);
driver = KW_CreateSDL2RenderDriver(renderer, window);
set = KW_LoadSurface(driver, "tileset.png");
/* initialize gui */
gui = KW_Init(driver, set);
font = KW_LoadFont(driver, "SourceSansPro-Semibold.ttf", 12);
KW_SetFont(gui, font);
geometry.x = (unsigned)(geometry.w * 0.0625f);
geometry.y = (unsigned)(geometry.h * .0625f);
geometry.w *= .875f;
geometry.h *= .875;
frame = KW_CreateScrollbox(gui, NULL, &geometry);
geometry.x = 10; geometry.y = 0; geometry.h = 40; geometry.w = 230;
for (i = 0; i < 10; i++) {
button = KW_CreateButtonAndLabel(gui, frame, "Text label", &geometry);
KW_AddWidgetMouseDownHandler(button, MouseDown);
geometry.y += geometry.h;
}
/* create another parent frame */
while (!SDL_QuitRequested()) {
while (SDL_PollEvent(&ev)) {
if (ev.type == SDL_WINDOWEVENT && ev.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
geometry.w = (unsigned)ev.window.data1;
geometry.h = (unsigned)ev.window.data2;
geometry.x = (unsigned)(geometry.w * 0.0625);
geometry.y = (unsigned)(geometry.h * .0625);
geometry.w *= .875f;
geometry.h *= .875;
KW_SetWidgetGeometry(frame, &geometry);
}
}
SDL_RenderClear(renderer);
KW_ProcessEvents(gui);
KW_Paint(gui);
SDL_RenderPresent(renderer);
SDL_Delay(1);
}
KW_ReleaseFont(driver, font);
KW_Quit(gui);
KW_ReleaseSurface(driver, set);
SDL_Quit();
return 0;
}
See KW_renderdriver_sdl2.c
for examples. This is pretty icky as I'm currently writing a CHICKEN binding for KiWi and printing to stderr does interfere with CHICKEN's error reporting mechanism (throwing exceptions) and makes it impossible to do any better as there's no way of retrieving the error message.
Why do the x and y coordinates play a role in whether a KW_Rect
is empty? And why must both the width and height be zero? Assuming a rectangle got a width of zero, but a non-zero height, the area it spans would still be zero, yet it wouldn't be considered empty...
Other than that, I sometimes get "phantom" parts of the buttons displayed which go away on the next resizing cycle, but couldn't record them.
KW_GetTilesetSurface
in KW_gui.h
specifies that it returns a KW_Surface*
, yet it doesn't in the implementation. There's a number of other surface/texture screw-ups in the docs (see KW_GetWidgetTilesetSurface
for another one). I find this pretty confusing as I've learned from experimenting with SDL that surfaces and textures are not interchangeable, in fact surfaces are the basis for creating GPU-accelerated textures.
Somewhat related question: With this in mind, what exactly are the texture-related API functions (like, KW_GetTilesetTexture
or KW_GetWidgetTilesetTexture
) for?
Code:
auto title_l = KW_CreateLabel(gui, frame,"Text Wrapping in Scrollbox\n(Horizontal Bar Disabled)", &r);
//KW_LabelEnableWrap(title_l);
KW_SetLabelAlignment(title_l, KW_LABEL_ALIGN_RIGHT, 0, KW_LABEL_ALIGN_MIDDLE, 0);
No wrapping, but centered
when I uncomment the LabelEnableWrap(
line:
The same occurs when it is set to right aligned
I'm logging this, if i have time after the checkboxes and radio buttons I'm working on, I'll work on a drop in replacement for the SDL_TTF rendering function, but this may take time
Is SDL1 support even feasible?
I'm currently writing my custom hello world example which consists of a frame with two buttons, one of which quits the program and the other one displaying a (modal) message box with a single OK-button for closing it. Ideally the latter would be a matter of using a convenience function, but that doesn't apper to exist yet. Currently I have two ideas how one could implement it:
KW_DestroyWidget
is clearly not the right solution as that yields a SIGSEGV, setting the widget's geometry to an empty rectangle hides its frame, but leaves its child widgets still visible and drawn as children of the parent frame.KW_GUI
and draw the composite widget there. What I don't really understand for that approach is how one would modify the SDL2 event loop to deal with the new window as long as it's open.Thoughts on this?
edit: I've found out that SDL2 provides SDL_ShowSimpleMessageBox
which is sort of OK as it has the desired behavior, but looks totally different from the rest of KiWi and doesn't update the parent window (leading to the infamous Windows dragging glitch).
See title. This is in the new KW_rect.h
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.