removed dependency on libgrapheme
This commit is contained in:
parent
7ff787f71f
commit
a677d3f1f0
4
.gitmodules
vendored
4
.gitmodules
vendored
@ -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"]
|
[submodule "lib/schrift.c3l/thirdparty/libschrift"]
|
||||||
path = lib/schrift.c3l/thirdparty/libschrift
|
path = lib/schrift.c3l/thirdparty/libschrift
|
||||||
url = https://github.com/tomolt/libschrift
|
url = https://github.com/tomolt/libschrift
|
||||||
|
|||||||
@ -1,4 +0,0 @@
|
|||||||
all:
|
|
||||||
make -C thirdparty/libgrapheme
|
|
||||||
mkdir -p linux-x64
|
|
||||||
cp thirdparty/libgrapheme/libgrapheme.a linux-x64/libgrapheme.a
|
|
||||||
@ -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");
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"provides": "grapheme",
|
|
||||||
"targets": {
|
|
||||||
"linux-x64": {
|
|
||||||
"dependencies": [],
|
|
||||||
"linked-libraries": ["grapheme", "c"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
"langrev": "1",
|
|
||||||
"warnings": ["no-unused"],
|
|
||||||
"dependency-search-paths": [".."],
|
|
||||||
"dependencies": ["grapheme"],
|
|
||||||
"authors": ["Alessandro Mauri <alemauri001@gmail.com>", "Laslo Hunhold <dev@frign.de>"],
|
|
||||||
"version": "0.1.0",
|
|
||||||
"sources": [],
|
|
||||||
"output": "build",
|
|
||||||
"target": "linux-x64",
|
|
||||||
"features": [],
|
|
||||||
"cpu": "generic",
|
|
||||||
"opt": "O0"
|
|
||||||
}
|
|
||||||
1
lib/grapheme.c3l/thirdparty/libgrapheme
vendored
1
lib/grapheme.c3l/thirdparty/libgrapheme
vendored
@ -1 +0,0 @@
|
|||||||
Subproject commit 65b354f0fcb1d925f4340dbb4415ea06e8af2bec
|
|
||||||
@ -4,7 +4,7 @@
|
|||||||
"targets" : {
|
"targets" : {
|
||||||
"linux-x64" : {
|
"linux-x64" : {
|
||||||
"link-args" : [],
|
"link-args" : [],
|
||||||
"dependencies" : ["schrift", "grapheme"],
|
"dependencies" : ["schrift"],
|
||||||
"linked-libraries" : []
|
"linked-libraries" : []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
module ugui;
|
module ugui;
|
||||||
|
|
||||||
import grapheme;
|
|
||||||
import std::io;
|
import std::io;
|
||||||
import std::math;
|
import std::math;
|
||||||
import std::core::string;
|
import std::core::string;
|
||||||
|
|
||||||
|
|
||||||
bitstruct InputEvents : uint {
|
bitstruct InputEvents : uint {
|
||||||
bool resize : 0; // window size was changed
|
bool resize : 0; // window size was changed
|
||||||
bool change_focus : 1; // window focus 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);
|
const ModKeys KEY_ANY = (ModKeys)(ModKeys.inner.max);
|
||||||
|
|
||||||
|
<* @param [&inout] ctx *>
|
||||||
fn bool Ctx.check_key_combo(&ctx, ModKeys mod, String ...keys)
|
fn bool Ctx.check_key_combo(&ctx, ModKeys mod, String ...keys)
|
||||||
{
|
{
|
||||||
bool is_mod = (bool)(ctx.current_input.keyboard.modkeys & mod);
|
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
|
// Window size was changed
|
||||||
|
<* @param [&inout] ctx *>
|
||||||
fn void? Ctx.input_window_size(&ctx, short width, short height)
|
fn void? Ctx.input_window_size(&ctx, short width, short height)
|
||||||
{
|
{
|
||||||
if (width <= 0 || height <= 0) {
|
if (width <= 0 || height <= 0) {
|
||||||
@ -94,6 +96,7 @@ fn void? Ctx.input_window_size(&ctx, short width, short height)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Window gained/lost focus
|
// Window gained/lost focus
|
||||||
|
<* @param [&inout] ctx *>
|
||||||
fn void Ctx.input_changefocus(&ctx, bool has_focus)
|
fn void Ctx.input_changefocus(&ctx, bool has_focus)
|
||||||
{
|
{
|
||||||
// FIXME: raylib only has an API to query the focus status so we have to
|
// 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;
|
macro Ctx.is_mouse_down(&ctx, MouseButtons btn) => (ctx.mouse_down() & btn) != BTN_NONE;
|
||||||
|
|
||||||
// Mouse Buttons down
|
// Mouse Buttons down
|
||||||
|
<* @param [&inout] ctx *>
|
||||||
fn void Ctx.input_mouse_button(&ctx, MouseButtons buttons)
|
fn void Ctx.input_mouse_button(&ctx, MouseButtons buttons)
|
||||||
{
|
{
|
||||||
ctx.current_input.mouse.updated = ctx.current_input.mouse.down ^ 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
|
// Mouse was moved, report absolute position
|
||||||
|
<* @param [&inout] ctx *>
|
||||||
fn void Ctx.input_mouse_abs(&ctx, short x, short y)
|
fn void Ctx.input_mouse_abs(&ctx, short x, short y)
|
||||||
{
|
{
|
||||||
ctx.current_input.mouse.pos.x = math::clamp(x, (short)0, ctx.width);
|
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
|
// Mouse was moved, report relative motion
|
||||||
|
<* @param [&inout] ctx *>
|
||||||
fn void Ctx.input_mouse_delta(&ctx, short dx, short dy)
|
fn void Ctx.input_mouse_delta(&ctx, short dx, short dy)
|
||||||
{
|
{
|
||||||
ctx.current_input.mouse.delta.x = dx;
|
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;
|
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)
|
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);
|
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;
|
ctx.current_input.events.mouse_scroll = x !=0 || y != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<* @param [&inout] ctx *>
|
||||||
fn void Ctx.input_key_press(&ctx)
|
fn void Ctx.input_key_press(&ctx)
|
||||||
{
|
{
|
||||||
ctx.current_input.events.key_press = true;
|
ctx.current_input.events.key_press = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<* @param [&inout] ctx *>
|
||||||
fn void Ctx.input_key_release(&ctx)
|
fn void Ctx.input_key_release(&ctx)
|
||||||
{
|
{
|
||||||
ctx.current_input.events.key_release = true;
|
ctx.current_input.events.key_release = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<* @param [&inout] ctx *>
|
||||||
fn void Ctx.input_key_repeat(&ctx)
|
fn void Ctx.input_key_repeat(&ctx)
|
||||||
{
|
{
|
||||||
ctx.current_input.events.key_repeat = true;
|
ctx.current_input.events.key_repeat = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// append utf-8 encoded text to the context text input
|
// append utf-8 encoded text to the context text input
|
||||||
|
<* @param [&inout] ctx *>
|
||||||
fn void Ctx.input_text_utf8(&ctx, char[] text)
|
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 remaining = ctx.current_input.keyboard.text.len - ctx.current_input.keyboard.text_len;
|
||||||
usz len = text.len > remaining ? remaining : 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;
|
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;
|
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 ..];
|
char[] s = ctx.current_input.keyboard.text[ctx.current_input.keyboard.text_len ..];
|
||||||
|
|
||||||
usz off;
|
usz off = conv::utf32to8(text, s)!;
|
||||||
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;
|
|
||||||
}
|
|
||||||
ctx.current_input.keyboard.text_len += off;
|
ctx.current_input.keyboard.text_len += off;
|
||||||
|
|
||||||
ctx.current_input.events.text_input = true;
|
ctx.current_input.events.text_input = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<* @param [&inout] ctx *>
|
||||||
fn void Ctx.input_char(&ctx, char c)
|
fn void Ctx.input_char(&ctx, char c)
|
||||||
{
|
{
|
||||||
char[1] b = {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
|
// Modifier keys, like control or backspace
|
||||||
// TODO: make this call repetible to input modkeys one by one
|
// TODO: make this call repetible to input modkeys one by one
|
||||||
|
<* @param [&inout] ctx *>
|
||||||
fn void Ctx.input_mod_keys(&ctx, ModKeys modkeys)
|
fn void Ctx.input_mod_keys(&ctx, ModKeys modkeys)
|
||||||
{
|
{
|
||||||
ctx.current_input.keyboard.modkeys = modkeys;
|
ctx.current_input.keyboard.modkeys = modkeys;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user