Comments (5)
No problem.
Btw. feel free to make a PR with x11-cairo backend (or wayland-cairo - didn't look at the source, so don't know which one 😉) - we're not strict about backend implementations and merge anything what makes sense for future users. Cairo is certainly an interesting backend!
from nuklear.
I think nk_rawfb_drawimage
is incomplete since &rawfb->font_text
is hard coded:
https://github.com/Immediate-Mode-UI/Nuklear/blob/master/demo/x11_rawfb/nuklear_rawfb.h#L1010
I hacked around it like this to make an nk_image_ptr()
test work:
NK_API void
nk_rawfb_drawimage(const struct rawfb_context *rawfb,
const int x, const int y, const int w, const int h,
const struct nk_image *img, const struct nk_color *col)
{
struct nk_rect src_rect;
struct nk_rect dst_rect;
src_rect.x = img->region[0];
src_rect.y = img->region[1];
src_rect.w = img->region[2];
src_rect.h = img->region[3];
dst_rect.x = x;
dst_rect.y = y;
dst_rect.w = w;
dst_rect.h = h;
if (img->handle.ptr == NULL) { // probably a dangerous assumption?
nk_rawfb_stretch_image(&rawfb->fb, &rawfb->font_tex, &dst_rect, &src_rect, &rawfb->scissors, col);
return;
}
struct rawfb_image rimg = {
.pixels = img->handle.ptr,
.w = img->w,
.h = img->h,
.pitch = img->w*sizeof(uint32_t),
.pl = PIXEL_LAYOUT_XBGR_8888,
.format = NK_FONT_ATLAS_RGBA32,
};
nk_rawfb_stretch_image(&rawfb->fb, &rimg, &dst_rect, &src_rect, &rawfb->scissors, &nk_none);
}
Then using it:
void *ptr = <raw RGBA buffer>;
struct nk_image img = nk_image_ptr(ptr);
img.w = w;
img.h = h;
img.region[2] = w;
img.region[3] = h;
nk_image(&ctx, img);
Other bits that tripped me up for a while:
- Pay attention to how
nk_rawfb_int2color
handles byte order on the target platform. The PIXEL_LAYOUT_XBGR_8888 above was necessary for my colors to appear correctly, but YMMV. nk_rawfb_stretch_image
overrides foreground color which is fine for font and buttons, but not for actual images. I had to tweak it to optionally disable the foreground color and transfer pixels unchanged except for alpha blending.struct nk_image
doesn't allow passing through a pitch value even thoughstruct rawfb_image
does support it. So make surepitch == w*sizeof(uint32)
.
from nuklear.
This is great feedback! Could you please make a PR with the suggestions and findings?
The backends are mainly for demonstration purposes as everybody has slightly different needs. Therefore they might be incomplete or less tested. Our main focus is on the library itself (just nuklear.h
), which is backend-agnostic (see our new reviewers guide in readme 😉).
from nuklear.
Will do, but I've hacked around elsewhere too, such as extending nk_rawfb_init for loading other fonts, and adding an endianness check. Something PR-worthy may come out of it eventually!
In my case rawfb is drawing directly to an SDL2 streaming texture, which is then displayed over a window background drawn with the vanilla SDL2 renderer.
from nuklear.
Fwiw, I've failed to get around to doing a PR for rawfb and probably won't now, sorry. Ended up replacing most of the rawfb code with Cairo software rendering: https://github.com/seanpringle/nuklear_cairo
from nuklear.
Related Issues (20)
- colorpicker - can't change hue before changing val/sat first HOT 1
- center window title at the middle HOT 2
- Cannot avoid STB_RECT_PACK_IMPLEMENTATION / STB_TRUETYPE_IMPLEMENTATION HOT 1
- Knob widgets HOT 1
- glfw Opengl4 demo Segmentation fault HOT 6
- Possible fix/improvement for d3d12 demo
- Resizing main nuklear window's height depending on inner content size HOT 1
- Is there some kind of multicombobox? HOT 9
- GDI+ (gdip), Text Input Copy/Paste/Ctrl+A not working HOT 5
- Create a SDL backend File_Browser HOT 1
- Way to "Grey out"/disable a widget? HOT 2
- Incorrect returned value in nk_group_scrolled_offset_begin
- Errors Reported By Facebook Infer
- Using SDL_GetWindowBordersSize() messes up everything. HOT 3
- Line chart performance: boxes on points make line charts much slower than without HOT 1
- Is it possible to know whether input is captured?
- Creating a nk_image with the sdl_renderer backend HOT 2
- Errors in compiling https://immediate-mode-ui.github.io/Nuklear/doc/#nuklear/example
- Two Issues with Fonts
- Inconsistent grabbing behavior in demos (click and drag property) HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nuklear.