Coder Social home page Coder Social logo

kiwi's People

Contributors

aferust avatar ckeen avatar emersont1 avatar mobius3 avatar stan1y avatar sundersb avatar talesm avatar wasamasa avatar zshipko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kiwi's Issues

Outdated example in README

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.

Implementing a mouse click event

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:

  • Button enters clicked state (at this point the mouse down handler fires)
  • By holding the mouse button, one can remain in this state
  • By moving the mouse button while still holding it, one can exit this state, release the mouse button and have no click trigger (at this point the mouse up handler fires)
  • However if the mouse button is released with the cursor still on the button, a mouse click handler is fired

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.

Text Block and Wrapping

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

resource.c missing for successful Cmake?

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? :)

Text in Editbox

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.

Event Queue will fill up and overflow

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);
}

How to properly remove a widget from gui

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.

kapture 2017-11-21 at 9 24 28

... or here

kapture 2017-11-21 at 10 22 16

... or here

kapture 2017-11-21 at 10 22 55

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;
}

Surface/Texture screw-ups

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?

KW_IsRectEmpty definition

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...

Please don't print errors to stderr

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.

Wrapped Text is forced to be left aligned

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

image

when I uncomment the LabelEnableWrap( line:

image

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

Implementing a message box

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:

  • Draw a composite widget that is the child of the frame that looks like a message box, then write code for deleting/hiding it and invoke that on clicking the OK-button. I've done this currently, but struggle with the deletion part. Using 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.
  • Create a new SDL2 window (and renderer?), create a new driver, create a new 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).

CHICKEN Scheme binding

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

Invalid inner scrollbox area size when using negative Y coordinates

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.

kapture 2017-11-14 at 9 56 30

But if I position items only in positive y it's fine:

kapture 2017-11-14 at 9 58 05

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;
}

Splitting up KW_Paint into KW_ProcessEvents and KW_Paint

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.

Enhancement: in new text rendering library, prevent shrinking of text

in the new text rendering, can you ensure the height of the text does not do this
Peek 2020-05-11 09-42
by making sure the empty texture goes as far down as the standard (or max?) descent of a glyph even if there are no characters with any descents (the full line height?)

image
(diagram added for clarity)

Is editbox example wrong?

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);

missing implementations

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);

Libraries order is important while compiling examples

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!
๐Ÿ‘๐Ÿ‘๐Ÿ‘

Setting a default font color

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).

Distorted Icons

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;
  }

With the lines in place (distorted)

screenshot1589056992

With the lines in commented out (fine)

screenshot1589057012

Skin Image

skin

Font inclusion into init

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.