Compare commits
No commits in common. "8cf3881b6b62d30ab1f92db7e7077ac8a2fc6f39" and "fb177c03f75b4e7bbc2d74bbb758291f6a2280da" have entirely different histories.
8cf3881b6b
...
fb177c03f7
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,3 @@
|
|||||||
*.o
|
*.o
|
||||||
*.a
|
|
||||||
build/*
|
build/*
|
||||||
**/.ccls-cache
|
**/.ccls-cache
|
||||||
|
6
TODO
6
TODO
@ -6,8 +6,6 @@
|
|||||||
[ ] Write a README.md
|
[ ] Write a README.md
|
||||||
[ ] Use an arena allocator for cache
|
[ ] Use an arena allocator for cache
|
||||||
[ ] Do not redraw if there was no update (no layout and no draw)
|
[ ] Do not redraw if there was no update (no layout and no draw)
|
||||||
[ ] Better handling of the active and focused widgets, try
|
|
||||||
to maintain focus until mouse release (fix scroll bars)
|
|
||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
[x] rect commads should have:
|
[x] rect commads should have:
|
||||||
@ -21,11 +19,11 @@
|
|||||||
|
|
||||||
## Fonts
|
## Fonts
|
||||||
[ ] Fix the missing alpha channel
|
[ ] Fix the missing alpha channel
|
||||||
[x] Fix the alignment
|
[ ] Fix the allignment
|
||||||
|
|
||||||
## Raylib
|
## Raylib
|
||||||
[ ] Implement type (Rect, Color, Point) conversion functions between rl:: and ugui::
|
[ ] Implement type (Rect, Color, Point) conversion functions between rl:: and ugui::
|
||||||
[x] Implement pixel radius rounding for border radius
|
[ ] Implement pixel radius rounding for border radius
|
||||||
|
|
||||||
## Widgets
|
## Widgets
|
||||||
[ ] Dynamic text box to implement an fps counter
|
[ ] Dynamic text box to implement an fps counter
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
all:
|
|
||||||
make -C thirdparty/libgrapheme
|
|
||||||
cp thirdparty/libgrapheme/libgrapheme.a linux-x64/libgrapheme.a
|
|
@ -1,46 +0,0 @@
|
|||||||
module grapheme;
|
|
||||||
|
|
||||||
const uint GRAPHEME_INVALID_CODEPOINT UINT32_C = 0xFFFD;
|
|
||||||
|
|
||||||
enum BidirectionalDirection {
|
|
||||||
GRAPHEME_BIDIRECTIONAL_DIRECTION_NEUTRAL,
|
|
||||||
GRAPHEME_BIDIRECTIONAL_DIRECTION_LTR,
|
|
||||||
GRAPHEME_BIDIRECTIONAL_DIRECTION_RTL,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn isz bidirectional_get_line_embedding_levels(uint *, isz, ichar *, isz) @extern("grapheme_bidirectional_get_line_embedding_levels");
|
|
||||||
|
|
||||||
fn isz bidirectional_preprocess_paragraph(uint *, isz, BidirectionalDirection, uint *, isz, BidirectionalDirection *) @extern("grapheme_bidirectional_preprocess_paragraph");
|
|
||||||
|
|
||||||
fn isz bidirectional_reorder_line(uint *, uint *, isz, uint *, isz) @extern("grapheme_bidirectional_reorder_line");
|
|
||||||
|
|
||||||
fn isz decode_utf8(char *, isz, uint *) @extern("grapheme_decode_utf8");
|
|
||||||
fn isz encode_utf8(uint, char *, isz) @extern("grapheme_encode_utf8");
|
|
||||||
|
|
||||||
fn bool is_character_break(uint, uint, ushort *) @extern("grapheme_is_character_break");
|
|
||||||
|
|
||||||
fn bool is_lowercase(uint *, isz, isz *) @extern("grapheme_is_lowercase");
|
|
||||||
fn bool is_titlecase(uint *, isz, isz *) @extern("grapheme_is_titlecase");
|
|
||||||
fn bool is_uppercase(uint *, isz, isz *) @extern("grapheme_is_uppercase");
|
|
||||||
|
|
||||||
fn bool is_lowercase_utf8(char *, isz, isz *) @extern("grapheme_is_lowercase_utf8");
|
|
||||||
fn bool is_titlecase_utf8(char *, isz, isz *) @extern("grapheme_is_titlecase_utf8");
|
|
||||||
fn bool is_uppercase_utf8(char *, isz, isz *) @extern("grapheme_is_uppercase_utf8");
|
|
||||||
|
|
||||||
fn isz next_character_break(uint *, isz) @extern("grapheme_next_character_break");
|
|
||||||
fn isz next_line_break(uint *, isz) @extern("grapheme_next_line_break");
|
|
||||||
fn isz next_sentence_break(uint *, isz) @extern("grapheme_next_sentence_break");
|
|
||||||
fn isz next_word_break(uint *, isz) @extern("grapheme_next_word_break");
|
|
||||||
|
|
||||||
fn isz next_character_break_utf8(char *, isz) @extern("grapheme_next_character_break_utf8");
|
|
||||||
fn isz next_line_break_utf8(char *, isz) @extern("grapheme_next_line_break_utf8");
|
|
||||||
fn isz next_sentence_break_utf8(char *, isz) @extern("grapheme_next_sentence_break_utf8");
|
|
||||||
fn isz next_word_break_utf8(char *, isz) @extern("grapheme_next_word_break_utf8");
|
|
||||||
|
|
||||||
fn isz to_lowercase(uint *, isz, uint *, isz) @extern("grapheme_to_lowercase");
|
|
||||||
fn isz to_titlecase(uint *, isz, uint *, isz) @extern("grapheme_to_titlecase");
|
|
||||||
fn isz to_uppercase(uint *, isz, uint *, isz) @extern("grapheme_to_uppercase");
|
|
||||||
|
|
||||||
fn isz to_lowercase_utf8(char *, isz, char *, isz) @extern("grapheme_to_lowercase_utf8");
|
|
||||||
fn isz to_titlecase_utf8(char *, isz, char *, isz) @extern("grapheme_to_titlecase_utf8");
|
|
||||||
fn isz to_uppercase_utf8(char *, isz, char *, isz) @extern("grapheme_to_uppercase_utf8");
|
|
@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"provides": "grapheme",
|
|
||||||
"targets": {
|
|
||||||
"linux-x64": {
|
|
||||||
"dependencies": [],
|
|
||||||
"linked-libraries": ["grapheme", "c"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
{
|
|
||||||
// Language version of C3.
|
|
||||||
"langrev": "1",
|
|
||||||
// Warnings used for all targets.
|
|
||||||
"warnings": ["no-unused"],
|
|
||||||
// Directories where C3 library files may be found.
|
|
||||||
"dependency-search-paths": [".."],
|
|
||||||
// Libraries to use for all targets.
|
|
||||||
"dependencies": ["grapheme"],
|
|
||||||
// Authors, optionally with email.
|
|
||||||
"authors": ["Alessandro Mauri <alemauri001@gmail.com"],
|
|
||||||
// Version using semantic versioning.
|
|
||||||
"version": "0.1.0",
|
|
||||||
// Sources compiled for all targets.
|
|
||||||
"sources": [],
|
|
||||||
// C sources if the project also compiles C sources
|
|
||||||
// relative to the project file.
|
|
||||||
// "c-sources": [ "csource/**" ],
|
|
||||||
// Output location, relative to project file.
|
|
||||||
"output": "build",
|
|
||||||
// Architecture and OS target.
|
|
||||||
// You can use 'c3c --list-targets' to list all valid targets.
|
|
||||||
// "target": "windows-x64",
|
|
||||||
"features": [
|
|
||||||
// See rcore.c3
|
|
||||||
//"SUPPORT_INTERNAL_MEMORY_MANAGEMENT",
|
|
||||||
//"SUPPORT_STANDARD_FILEIO",
|
|
||||||
//"SUPPORT_FILE_SYSTEM_FUNCTIONS",
|
|
||||||
//"SUPPORT_DATA_ENCODER",
|
|
||||||
// See text.c3
|
|
||||||
//"SUPPORT_TEXT_CODEPOINTS_MANAGEMENT",
|
|
||||||
//"SUPPORT_TEXT_C_STRING_MANAGEMENT",
|
|
||||||
//"SUPPORT_RANDOM_GENERATION",
|
|
||||||
//"SUPPORT_RAYGUI",
|
|
||||||
//"RAYGUI_NO_ICONS",
|
|
||||||
//"RAYGUI_CUSTOM_ICONS",
|
|
||||||
],
|
|
||||||
// Global settings.
|
|
||||||
// CPU name, used for optimizations in the LLVM backend.
|
|
||||||
"cpu": "generic",
|
|
||||||
// Optimization: "O0", "O1", "O2", "O3", "O4", "O5", "Os", "Oz".
|
|
||||||
"opt": "O0"
|
|
||||||
// See resources/examples/project_all_settings.json and 'c3c --list-project-properties' to see more properties.
|
|
||||||
}
|
|
1
lib/libgrapheme.c3l/thirdparty/libgrapheme
vendored
1
lib/libgrapheme.c3l/thirdparty/libgrapheme
vendored
@ -1 +0,0 @@
|
|||||||
Subproject commit 65b354f0fcb1d925f4340dbb4415ea06e8af2bec
|
|
@ -27,7 +27,7 @@ fn int main(String[] args)
|
|||||||
{
|
{
|
||||||
ugui::Ctx ui;
|
ugui::Ctx ui;
|
||||||
ui.init()!!;
|
ui.init()!!;
|
||||||
ui.font.load("/usr/share/fonts/TTF/Hack-Regular.ttf", 16, scale: 1.5)!!;
|
ui.font.load("/usr/share/fonts/TTF/FreeSans.ttf", 16, scale: 1.5)!!;
|
||||||
|
|
||||||
short width = 800;
|
short width = 800;
|
||||||
short height = 450;
|
short height = 450;
|
||||||
@ -146,10 +146,9 @@ fn int main(String[] args)
|
|||||||
.height = cmd.rect.rect.h,
|
.height = cmd.rect.rect.h,
|
||||||
.width = cmd.rect.rect.w,
|
.width = cmd.rect.rect.w,
|
||||||
};
|
};
|
||||||
float rad = cmd.rect.radius;
|
// TODO: find a way to do real pixel-perfec rounding
|
||||||
// for some weird-ass reason the straight forward inverse formula does not work
|
float round = cmd.rect.radius ? 0.2 : 0;
|
||||||
float roundness = r.width > r.height ? (2.1*rad)/r.height : (2.1*rad)/r.width;
|
rl::draw_rectangle_rounded(r, round, 2, c);
|
||||||
rl::draw_rectangle_rounded(r, roundness, 0, c);
|
|
||||||
case ugui::CmdType.CMD_UPDATE_ATLAS:
|
case ugui::CmdType.CMD_UPDATE_ATLAS:
|
||||||
rl::unload_image(font_atlas);
|
rl::unload_image(font_atlas);
|
||||||
font_atlas.data = cmd.update_atlas.raw_buffer;
|
font_atlas.data = cmd.update_atlas.raw_buffer;
|
||||||
|
@ -4,11 +4,6 @@ module ugui;
|
|||||||
// "rect" is the bounding box of the element, which includes the border and the padding (so not just the content)
|
// "rect" is the bounding box of the element, which includes the border and the padding (so not just the content)
|
||||||
fn void! Ctx.push_rect(&ctx, Rect rect, Color color, bool do_border = false, bool do_padding = false, bool do_radius = false)
|
fn void! Ctx.push_rect(&ctx, Rect rect, Color color, bool do_border = false, bool do_padding = false, bool do_radius = false)
|
||||||
{
|
{
|
||||||
// FIXME: this should be culled higher up, maybe
|
|
||||||
if (rect.w <= 0 || rect.h <= 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Rect border = ctx.style.border;
|
Rect border = ctx.style.border;
|
||||||
Rect padding = ctx.style.padding;
|
Rect padding = ctx.style.padding;
|
||||||
ushort radius = ctx.style.radius;
|
ushort radius = ctx.style.radius;
|
||||||
@ -37,14 +32,3 @@ fn void! Ctx.push_rect(&ctx, Rect rect, Color color, bool do_border = false, boo
|
|||||||
};
|
};
|
||||||
ctx.cmd_queue.enqueue(&cmd)!;
|
ctx.cmd_queue.enqueue(&cmd)!;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: add texture id
|
|
||||||
fn void! Ctx.push_sprite(&ctx, Rect bounds, Rect texture)
|
|
||||||
{
|
|
||||||
Cmd cmd = {
|
|
||||||
.type = CMD_SPRITE,
|
|
||||||
.sprite.rect = bounds,
|
|
||||||
.sprite.texture_rect = texture,
|
|
||||||
};
|
|
||||||
ctx.cmd_queue.enqueue(&cmd)!;
|
|
||||||
}
|
|
||||||
|
@ -39,7 +39,14 @@ fn void! Ctx.div_begin(&ctx, String label, Rect size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add the background to the draw stack
|
// Add the background to the draw stack
|
||||||
ctx.push_rect(c_elem.bounds, c_elem.div.color_bg)!;
|
Cmd cmd = {
|
||||||
|
.type = CMD_RECT,
|
||||||
|
.rect = {
|
||||||
|
.rect = c_elem.bounds,
|
||||||
|
.color = c_elem.div.color_bg,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
ctx.cmd_queue.enqueue(&cmd)!;
|
||||||
|
|
||||||
// TODO: check active
|
// TODO: check active
|
||||||
// TODO: check resizeable
|
// TODO: check resizeable
|
||||||
@ -88,8 +95,17 @@ fn void! Ctx.div_begin(&ctx, String label, Rect size)
|
|||||||
c_elem.div.origin_r = c_elem.div.origin_c;
|
c_elem.div.origin_r = c_elem.div.origin_c;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.push_rect(vslider, uint_to_rgba(0x999999ff))!;
|
Cmd scrl = {
|
||||||
ctx.push_rect(vhandle, uint_to_rgba(0x9999ffff))!;
|
.type = CMD_RECT,
|
||||||
|
.rect.rect = vslider,
|
||||||
|
.rect.color = uint_to_rgba(0x999999ff),
|
||||||
|
};
|
||||||
|
ctx.cmd_queue.enqueue(&scrl)!;
|
||||||
|
|
||||||
|
scrl.rect.rect = vhandle;
|
||||||
|
scrl.rect.color = uint_to_rgba(0x9999ffff);
|
||||||
|
ctx.cmd_queue.enqueue(&scrl)!;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
c_elem.div.scroll.on_y = false;
|
c_elem.div.scroll.on_y = false;
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ fn void! Ctx.init(&ctx)
|
|||||||
ctx.style.margin = Rect{2, 2, 2, 2};
|
ctx.style.margin = Rect{2, 2, 2, 2};
|
||||||
ctx.style.border = Rect{2, 2, 2, 2};
|
ctx.style.border = Rect{2, 2, 2, 2};
|
||||||
ctx.style.padding = Rect{1, 1, 1, 1};
|
ctx.style.padding = Rect{1, 1, 1, 1};
|
||||||
ctx.style.radius = 5;
|
ctx.style.radius = 4;
|
||||||
ctx.style.bgcolor = uint_to_rgba(0x282828ff);
|
ctx.style.bgcolor = uint_to_rgba(0x282828ff);
|
||||||
ctx.style.fgcolor = uint_to_rgba(0xfbf1c7ff);
|
ctx.style.fgcolor = uint_to_rgba(0xfbf1c7ff);
|
||||||
ctx.style.brcolor = uint_to_rgba(0xd79921ff);
|
ctx.style.brcolor = uint_to_rgba(0xd79921ff);
|
||||||
|
@ -42,11 +42,27 @@ fn ElemEvents! Ctx.slider_hor(&ctx, String label, Rect size)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw the slider background and handle
|
// Draw the button
|
||||||
Color bg_color = uint_to_rgba(0x0000ffff);
|
Color bg_color = uint_to_rgba(0x0000ffff);
|
||||||
Color handle_color = uint_to_rgba(0x0ff000ff);
|
Color handle_color = uint_to_rgba(0x0ff000ff);
|
||||||
ctx.push_rect(c_elem.bounds, bg_color)!;
|
|
||||||
ctx.push_rect(c_elem.slider.handle, handle_color)!;
|
Cmd cmd = {
|
||||||
|
.type = CMD_RECT,
|
||||||
|
.rect = {
|
||||||
|
.rect = c_elem.bounds,
|
||||||
|
.color = bg_color,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
ctx.cmd_queue.enqueue(&cmd)!;
|
||||||
|
|
||||||
|
cmd = Cmd{
|
||||||
|
.type = CMD_RECT,
|
||||||
|
.rect = {
|
||||||
|
.rect = c_elem.slider.handle,
|
||||||
|
.color = handle_color,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
ctx.cmd_queue.enqueue(&cmd)!;
|
||||||
|
|
||||||
return c_elem.events;
|
return c_elem.events;
|
||||||
}
|
}
|
||||||
@ -98,11 +114,27 @@ fn ElemEvents! Ctx.slider_ver(&ctx, String label, Rect size)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw the slider background and handle
|
// Draw the button
|
||||||
Color bg_color = uint_to_rgba(0x0000ffff);
|
Color bg_color = uint_to_rgba(0x0000ffff);
|
||||||
Color handle_color = uint_to_rgba(0x0ff000ff);
|
Color handle_color = uint_to_rgba(0x0ff000ff);
|
||||||
ctx.push_rect(c_elem.bounds, bg_color)!;
|
|
||||||
ctx.push_rect(c_elem.slider.handle, handle_color)!;
|
Cmd cmd = {
|
||||||
|
.type = CMD_RECT,
|
||||||
|
.rect = {
|
||||||
|
.rect = c_elem.bounds,
|
||||||
|
.color = bg_color,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
ctx.cmd_queue.enqueue(&cmd)!;
|
||||||
|
|
||||||
|
cmd = Cmd{
|
||||||
|
.type = CMD_RECT,
|
||||||
|
.rect = {
|
||||||
|
.rect = c_elem.slider.handle,
|
||||||
|
.color = handle_color,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
ctx.cmd_queue.enqueue(&cmd)!;
|
||||||
|
|
||||||
return c_elem.events;
|
return c_elem.events;
|
||||||
}
|
}
|
||||||
|
@ -21,11 +21,11 @@ fn Rect! Ctx.get_text_bounds(&ctx, String text, bool* update_atlas)
|
|||||||
if (n) { *update_atlas = true; }
|
if (n) { *update_atlas = true; }
|
||||||
} else {
|
} else {
|
||||||
text_bounds.h += line_height + line_gap;
|
text_bounds.h += line_height + line_gap;
|
||||||
line_len = 0;
|
|
||||||
}
|
|
||||||
if (line_len > text_bounds.w) {
|
if (line_len > text_bounds.w) {
|
||||||
text_bounds.w = line_len;
|
text_bounds.w = line_len;
|
||||||
}
|
}
|
||||||
|
line_len = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return text_bounds;
|
return text_bounds;
|
||||||
@ -89,20 +89,23 @@ fn void! Ctx.text_unbounded(&ctx, String label, String text)
|
|||||||
Codepoint cp = (Codepoint)c;
|
Codepoint cp = (Codepoint)c;
|
||||||
if (cp != '\n') {
|
if (cp != '\n') {
|
||||||
gp = ctx.font.get_glyph(cp)!;
|
gp = ctx.font.get_glyph(cp)!;
|
||||||
Rect gb = {
|
Cmd cmd = {
|
||||||
|
.type = CMD_SPRITE,
|
||||||
|
.sprite.rect = {
|
||||||
.x = orig.x + line_len + gp.ox,
|
.x = orig.x + line_len + gp.ox,
|
||||||
.y = orig.y + gp.oy + baseline,
|
.y = orig.y + gp.oy + baseline,
|
||||||
.w = gp.w,
|
.w = gp.w,
|
||||||
.h = gp.h,
|
.h = gp.h,
|
||||||
};
|
},
|
||||||
Rect gt = {
|
.sprite.texture_rect = {
|
||||||
.x = gp.u,
|
.x = gp.u,
|
||||||
.y = gp.v,
|
.y = gp.v,
|
||||||
.w = gp.w,
|
.w = gp.w,
|
||||||
.h = gp.h,
|
.h = gp.h,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
ctx.push_sprite(gb, gt)!;
|
|
||||||
line_len += gp.adv;
|
line_len += gp.adv;
|
||||||
|
ctx.cmd_queue.enqueue(&cmd)!;
|
||||||
} else {
|
} else {
|
||||||
orig.y += line_height + line_gap;
|
orig.y += line_height + line_gap;
|
||||||
line_len = 0;
|
line_len = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user