diff --git a/.gitmodules b/.gitmodules index 74cac9a..1aaf5f4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,7 +1,3 @@ -[submodule "lib/grapheme.c3l/thirdparty/libgrapheme"] - path = lib/grapheme.c3l/thirdparty/libgrapheme - url = git://git.suckless.org/libgrapheme - ignore = dirty [submodule "lib/schrift.c3l/thirdparty/libschrift"] path = lib/schrift.c3l/thirdparty/libschrift url = https://github.com/tomolt/libschrift diff --git a/lib/grapheme.c3l/Makefile b/lib/grapheme.c3l/Makefile deleted file mode 100644 index 09193f1..0000000 --- a/lib/grapheme.c3l/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -all: - make -C thirdparty/libgrapheme - mkdir -p linux-x64 - cp thirdparty/libgrapheme/libgrapheme.a linux-x64/libgrapheme.a diff --git a/lib/grapheme.c3l/libgrapheme.c3i b/lib/grapheme.c3l/libgrapheme.c3i deleted file mode 100644 index 6b1c7fc..0000000 --- a/lib/grapheme.c3l/libgrapheme.c3i +++ /dev/null @@ -1,46 +0,0 @@ -module grapheme; - -const uint GRAPHEME_INVALID_CODEPOINT = 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"); diff --git a/lib/grapheme.c3l/manifest.json b/lib/grapheme.c3l/manifest.json deleted file mode 100644 index 97f04d0..0000000 --- a/lib/grapheme.c3l/manifest.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "provides": "grapheme", - "targets": { - "linux-x64": { - "dependencies": [], - "linked-libraries": ["grapheme", "c"] - } - } -} diff --git a/lib/grapheme.c3l/project.json b/lib/grapheme.c3l/project.json deleted file mode 100644 index 4b2d212..0000000 --- a/lib/grapheme.c3l/project.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "langrev": "1", - "warnings": ["no-unused"], - "dependency-search-paths": [".."], - "dependencies": ["grapheme"], - "authors": ["Alessandro Mauri ", "Laslo Hunhold "], - "version": "0.1.0", - "sources": [], - "output": "build", - "target": "linux-x64", - "features": [], - "cpu": "generic", - "opt": "O0" -} diff --git a/lib/grapheme.c3l/thirdparty/libgrapheme b/lib/grapheme.c3l/thirdparty/libgrapheme deleted file mode 160000 index 65b354f..0000000 --- a/lib/grapheme.c3l/thirdparty/libgrapheme +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 65b354f0fcb1d925f4340dbb4415ea06e8af2bec diff --git a/lib/ugui.c3l/manifest.json b/lib/ugui.c3l/manifest.json index 813ed39..e34f342 100644 --- a/lib/ugui.c3l/manifest.json +++ b/lib/ugui.c3l/manifest.json @@ -4,7 +4,7 @@ "targets" : { "linux-x64" : { "link-args" : [], - "dependencies" : ["schrift", "grapheme"], + "dependencies" : ["schrift"], "linked-libraries" : [] } } diff --git a/lib/ugui.c3l/src/input.c3 b/lib/ugui.c3l/src/input.c3 index 5a134c8..41fc703 100644 --- a/lib/ugui.c3l/src/input.c3 +++ b/lib/ugui.c3l/src/input.c3 @@ -1,10 +1,10 @@ module ugui; -import grapheme; import std::io; import std::math; import std::core::string; + bitstruct InputEvents : uint { bool resize : 0; // window size was changed bool change_focus : 1; // window focus changed @@ -71,6 +71,7 @@ const MouseButtons BTN_5 = {.btn_5 = true}; const ModKeys KEY_ANY = (ModKeys)(ModKeys.inner.max); +<* @param [&inout] ctx *> fn bool Ctx.check_key_combo(&ctx, ModKeys mod, String ...keys) { bool is_mod = (bool)(ctx.current_input.keyboard.modkeys & mod); @@ -83,6 +84,7 @@ fn bool Ctx.check_key_combo(&ctx, ModKeys mod, String ...keys) } // Window size was changed +<* @param [&inout] ctx *> fn void? Ctx.input_window_size(&ctx, short width, short height) { if (width <= 0 || height <= 0) { @@ -94,6 +96,7 @@ fn void? Ctx.input_window_size(&ctx, short width, short height) } // Window gained/lost focus +<* @param [&inout] ctx *> fn void Ctx.input_changefocus(&ctx, bool has_focus) { // FIXME: raylib only has an API to query the focus status so we have to @@ -113,6 +116,7 @@ macro Ctx.is_mouse_released(&ctx, MouseButtons btn) => (ctx.mouse_released() & b macro Ctx.is_mouse_down(&ctx, MouseButtons btn) => (ctx.mouse_down() & btn) != BTN_NONE; // Mouse Buttons down +<* @param [&inout] ctx *> fn void Ctx.input_mouse_button(&ctx, MouseButtons buttons) { ctx.current_input.mouse.updated = ctx.current_input.mouse.down ^ buttons; @@ -121,6 +125,7 @@ fn void Ctx.input_mouse_button(&ctx, MouseButtons buttons) } // Mouse was moved, report absolute position +<* @param [&inout] ctx *> fn void Ctx.input_mouse_abs(&ctx, short x, short y) { ctx.current_input.mouse.pos.x = math::clamp(x, (short)0, ctx.width); @@ -137,6 +142,7 @@ fn void Ctx.input_mouse_abs(&ctx, short x, short y) } // Mouse was moved, report relative motion +<* @param [&inout] ctx *> fn void Ctx.input_mouse_delta(&ctx, short dx, short dy) { ctx.current_input.mouse.delta.x = dx; @@ -152,6 +158,7 @@ fn void Ctx.input_mouse_delta(&ctx, short dx, short dy) ctx.current_input.events.mouse_move = dx != 0 || dy != 0; } +<* @param [&inout] ctx *> fn void Ctx.input_mouse_wheel(&ctx, short x, short y, float scale = 1.0) { ctx.current_input.mouse.scroll.x = (short)((float)-x*scale); @@ -159,25 +166,29 @@ fn void Ctx.input_mouse_wheel(&ctx, short x, short y, float scale = 1.0) ctx.current_input.events.mouse_scroll = x !=0 || y != 0; } +<* @param [&inout] ctx *> fn void Ctx.input_key_press(&ctx) { ctx.current_input.events.key_press = true; } +<* @param [&inout] ctx *> fn void Ctx.input_key_release(&ctx) { ctx.current_input.events.key_release = true; } +<* @param [&inout] ctx *> fn void Ctx.input_key_repeat(&ctx) { ctx.current_input.events.key_repeat = true; } // append utf-8 encoded text to the context text input +<* @param [&inout] ctx *> fn void Ctx.input_text_utf8(&ctx, char[] text) { - if (text.len == 0) { return; } + if (text == "") return; usz remaining = ctx.current_input.keyboard.text.len - ctx.current_input.keyboard.text_len; usz len = text.len > remaining ? remaining : text.len; @@ -187,26 +198,24 @@ fn void Ctx.input_text_utf8(&ctx, char[] text) ctx.current_input.events.text_input = true; } -fn void Ctx.input_text_unicode(&ctx, char[] text) +<* +@param [&inout] ctx +@param [in] text +*> +fn void? Ctx.input_text_unicode(&ctx, uint[] text) { - if (text.ptr == null || text.len == 0) { return; } + if (text.len == 0) return; - char[32] tmp; usz remaining = ctx.current_input.keyboard.text.len - ctx.current_input.keyboard.text_len; char[] s = ctx.current_input.keyboard.text[ctx.current_input.keyboard.text_len ..]; - usz off; - foreach (idx, cp: text) { - if (off >= remaining) { break; } - usz enc = grapheme::encode_utf8(cp, tmp[..], tmp.len); - s[off..off+enc] = tmp[..enc]; - off += enc; - } + usz off = conv::utf32to8(text, s)!; ctx.current_input.keyboard.text_len += off; ctx.current_input.events.text_input = true; } +<* @param [&inout] ctx *> fn void Ctx.input_char(&ctx, char c) { char[1] b = {c}; @@ -218,6 +227,7 @@ fn ModKeys Ctx.get_mod(&ctx) => ctx.input.keyboard.modkeys; // Modifier keys, like control or backspace // TODO: make this call repetible to input modkeys one by one +<* @param [&inout] ctx *> fn void Ctx.input_mod_keys(&ctx, ModKeys modkeys) { ctx.current_input.keyboard.modkeys = modkeys;