Giter VIP home page Giter VIP logo

Comments (6)

bolt-blue avatar bolt-blue commented on May 28, 2024

This is pretty much what I have for the current POC.
I'm sure it's flawed, but I'm still fairly new to nuklear.

// Temporarily use rand for some colours later
#define RandomI32(min, max) ((min) + ((max) - (min)) * ((double)rand() / INT32_MAX) + 0.5)
srand(0xdeadbeef);

struct nk_command_buffer *out = nk_window_get_canvas(ctx);
struct nk_rect bounds;

struct nk_style_window old_style = ctx->style.window;

// Make layout easier to work with
// TODO: Account for spacing/padding when using nk_layout_space_xxx ?
ctx->style.window.spacing = nk_vec2(0, 0);
ctx->style.window.group_padding = nk_vec2(0, 0);

u32 card_count = 3;

for (u32 i = 0; i < card_count; i++) {
    // TODO: How to colour the area defined here
    // Rounded rect would be nice probably
    nk_layout_space_begin(ctx, NK_STATIC, 70, 3);
    nk_layout_space_push(ctx, nk_rect(0, 0, 60, 60));

    if (nk_group_begin(ctx, "item image", NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR)) {
        // For some reason this still needs to be smaller than the space pushed above
        // else the circle will get clipped; how much smaller exactly, I'm not yet sure
        nk_layout_row_static(ctx, 55, 55, 1);
        nk_widget(&bounds, ctx);
        nk_fill_circle(out, bounds,
        nk_rgb(RandomI32(0, 255), RandomI32(0, 255), RandomI32(0, 255)));
        nk_group_end(ctx);
    }
    nk_layout_space_push(ctx, nk_rect(70, 0, 180, 60));
    if (nk_group_begin(ctx, "item detail", NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR)) {
        nk_layout_row_static(ctx, 20, 180, 1);
        nk_label(ctx, "Foo", NK_TEXT_LEFT);
        nk_label(ctx, "Bar", NK_TEXT_LEFT);
        nk_label(ctx, "Baz", NK_TEXT_LEFT);
        nk_group_end(ctx);
    }
    nk_layout_space_end(ctx);
}

ctx->style.window = old_style;

from nuklear.

RobLoach avatar RobLoach commented on May 28, 2024

Would love to have some cards implemented 👍

from nuklear.

bolt-blue avatar bolt-blue commented on May 28, 2024

I've forked and started to test the idea.
https://github.com/bolt-blue/Nuklear/tree/feat/card

Would love some advice as I don't know the code base well enough to know if I'm making the "best" decisions.

I've based a new nk_card_begin on nk_group_scrolled_offset_begin.

It's effectively a limited version, with the addition of a background coloured rectangle that can be rounded.

I figured the general usage for a card might mostly match that of a nk_group_***, at least in that it would be nice to be able to nest group(s) inside it.

Is this a good direction?

Is the use of NK_WINDOW_DYNAMIC reasonable? In my exploration, I've noticed some comment that it's deprecated.
I used it because my original layout test involved nk_group_.
Using groups inside a card requires the group to also be flagged with NK_WINDOW_DYNAMIC in order to take on the background colour as well.

Other comments in the code describe some of my thoughts and concerns.

I'm definitely open to suggestions.
I'd be happy if nk_card_ did more manual drawing if that would help, but I think the hurdle I see is how to handle groups.
Originally, I wondered if I could base the code solely on nk_button_ but I believe it would be insufficient for typical card use cases.

from nuklear.

bolt-blue avatar bolt-blue commented on May 28, 2024

Specifically, there's only one commit at the moment to show the basic idea.
bolt-blue@a142456

from nuklear.

bolt-blue avatar bolt-blue commented on May 28, 2024

Added an example/demo to my fork.
See https://github.com/bolt-blue/Nuklear/tree/feat/card.

$ cd example
$ make card
$ cd bin && ./card

If anyone has thoughts, opinions, criticism, suggestions, I'd be grateful to hear them.

It's doing pretty much all that I want from it at the moment, though there are definitely improvements to be made.

Just hoping I can get some second opinions from those more experienced than I.

from nuklear.

bolt-blue avatar bolt-blue commented on May 28, 2024

This is what the demo looks like. It's the first basic example that came to mind, but given that nk_card is built on groups, a card can be many things.
As long as it doesn't need scrolling.

nuklear_card-demo

from nuklear.

Related Issues (20)

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.