Skip to content

Commit

Permalink
build: set cairo as optional
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-soft committed Jan 3, 2024
1 parent bbf87b3 commit 3fc0cb5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 7 additions & 0 deletions examples/fabric/src/main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <LCUI.h>
#include <LCUI/main.h>
#ifdef HAS_CAIRO
#include <cairo.h>
#endif
#include "fabric.h"

#define M_PI 3.1415926
Expand All @@ -16,6 +18,7 @@ bool displaySpans = true;

ui_widget_prototype_t *ui_fabric_proto;

#ifdef HAS_CAIRO
// displays points
void render_points(cairo_t *cr)
{
Expand Down Expand Up @@ -50,8 +53,11 @@ void render_spans(cairo_t *cr)
cairo_stroke(cr);
}

#endif

void ui_fabric_on_frame(ui_widget_t *w)
{
#ifdef HAS_CAIRO
ui_canvas_context_t *ctx = ui_canvas_get_context(w);
cairo_surface_t *surface = cairo_image_surface_create_for_data(
ctx->buffer.bytes, CAIRO_FORMAT_RGB24, ctx->buffer.width,
Expand All @@ -72,6 +78,7 @@ void ui_fabric_on_frame(ui_widget_t *w)
cairo_surface_destroy(surface);
ui_widget_mark_dirty_rect(w, NULL, UI_BOX_TYPE_GRAPH_BOX);
ctx->release(ctx);
#endif
}

static void ui_fabric_on_mousedown(ui_widget_t *w, ui_event_t *e, void *arg)
Expand Down
5 changes: 4 additions & 1 deletion examples/fabric/xmake.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
add_requires("cairo")
add_requires("cairo", { optional = true })

target("fabric")
set_kind("binary")
add_files("src/*.c")
add_packages("cairo", "lcui")
if has_package("cairo") then
add_defines("HAS_CAIRO")
end

0 comments on commit 3fc0cb5

Please sign in to comment.