better to_rgba() macro
This commit is contained in:
parent
78e2c64da6
commit
9aa0d58d68
@ -29,12 +29,12 @@ fn ElemEvents! Ctx.button(&ctx, String label, Rect size, bool state = false)
|
||||
// no interaction should occur so just return
|
||||
if (elem.bounds.is_null()) { return ElemEvents{}; }
|
||||
|
||||
Color col = uint_to_rgba(0x0000ffff);
|
||||
Color col = 0x0000ffffu.to_rgba();
|
||||
elem.events = ctx.get_elem_events(elem);
|
||||
if (state) {
|
||||
col = uint_to_rgba(0xff0000ff);
|
||||
col = 0xff0000ffu.to_rgba();
|
||||
} else if (ctx.elem_focus(elem) || elem.events.mouse_hover) {
|
||||
col = uint_to_rgba(0xff00ffff);
|
||||
col = 0xff00ffffu.to_rgba();
|
||||
}
|
||||
|
||||
// Draw the button
|
||||
@ -64,12 +64,12 @@ fn ElemEvents! Ctx.button_label(&ctx, String label, Rect size = Rect{0,0,short.m
|
||||
elem.bounds = ctx.position_element(parent, btn_size, true);
|
||||
if (elem.bounds.is_null()) { return ElemEvents{}; }
|
||||
|
||||
Color col = uint_to_rgba(0x0000ffff);
|
||||
Color col = 0x0000ffffu.to_rgba();
|
||||
elem.events = ctx.get_elem_events(elem);
|
||||
if (state) {
|
||||
col = uint_to_rgba(0xff0000ff);
|
||||
col = 0xff0000ffu.to_rgba();
|
||||
} else if (ctx.elem_focus(elem) || elem.events.mouse_hover) {
|
||||
col = uint_to_rgba(0xff00ffff);
|
||||
col = 0xff00ffffu.to_rgba();
|
||||
}
|
||||
|
||||
// Draw the button
|
||||
|
@ -103,7 +103,7 @@ fn void! Ctx.push_rect(&ctx, Rect rect, Color color, bool do_border = false, boo
|
||||
}
|
||||
|
||||
// TODO: add texture id
|
||||
fn void! Ctx.push_sprite(&ctx, Rect bounds, Rect texture, Id texture_id, Color hue = uint_to_rgba(0xffffffff))
|
||||
fn void! Ctx.push_sprite(&ctx, Rect bounds, Rect texture, Id texture_id, Color hue = 0xffffffffu.to_rgba())
|
||||
{
|
||||
Cmd cmd = {
|
||||
.type = CMD_SPRITE,
|
||||
@ -115,7 +115,7 @@ fn void! Ctx.push_sprite(&ctx, Rect bounds, Rect texture, Id texture_id, Color h
|
||||
ctx.push_cmd(&cmd)!;
|
||||
}
|
||||
|
||||
fn void! Ctx.push_string(&ctx, Rect bounds, String text, Color hue = uint_to_rgba(0xffffffff))
|
||||
fn void! Ctx.push_string(&ctx, Rect bounds, String text, Color hue = 0xffffffffu.to_rgba())
|
||||
{
|
||||
if (text.len == 0) {
|
||||
return;
|
||||
|
@ -67,15 +67,6 @@ fault UgError {
|
||||
WRONG_ELEMENT_TYPE,
|
||||
}
|
||||
|
||||
macro Color uint_to_rgba(uint $u) {
|
||||
return Color{
|
||||
.r = (char)(($u >> 24) & 0xff),
|
||||
.g = (char)(($u >> 16) & 0xff),
|
||||
.b = (char)(($u >> 8) & 0xff),
|
||||
.a = (char)(($u >> 0) & 0xff)
|
||||
};
|
||||
}
|
||||
|
||||
const Rect DIV_FILL = { .x = 0, .y = 0, .w = 0, .h = 0 };
|
||||
|
||||
const uint STACK_STEP = 10;
|
||||
@ -218,9 +209,9 @@ fn void! Ctx.init(&ctx)
|
||||
ctx.style.border = Rect{2, 2, 2, 2};
|
||||
ctx.style.padding = Rect{1, 1, 1, 1};
|
||||
ctx.style.radius = 5;
|
||||
ctx.style.bgcolor = uint_to_rgba(0x282828ff);
|
||||
ctx.style.fgcolor = uint_to_rgba(0xfbf1c7ff);
|
||||
ctx.style.brcolor = uint_to_rgba(0xd79921ff);
|
||||
ctx.style.bgcolor = 0x282828ffu.to_rgba();
|
||||
ctx.style.fgcolor = 0xfbf1c7ffu.to_rgba();
|
||||
ctx.style.brcolor = 0xd79921ffu.to_rgba();
|
||||
}
|
||||
|
||||
fn void Ctx.free(&ctx)
|
||||
@ -301,7 +292,7 @@ $if 1:
|
||||
.w = 4,
|
||||
.h = 4,
|
||||
},
|
||||
.rect.color = uint_to_rgba(0xff00ffff)
|
||||
.rect.color = 0xff00ffffu.to_rgba()
|
||||
};
|
||||
ctx.cmd_queue.enqueue(&cmd)!;
|
||||
$endif
|
||||
|
@ -192,3 +192,13 @@ macro Point Point.min(Point a, Point b)
|
||||
struct Color{
|
||||
char r, g, b, a;
|
||||
}
|
||||
|
||||
macro Color uint.to_rgba(uint u)
|
||||
{
|
||||
return Color{
|
||||
.r = (char)((u >> 24) & 0xff),
|
||||
.g = (char)((u >> 16) & 0xff),
|
||||
.b = (char)((u >> 8) & 0xff),
|
||||
.a = (char)((u >> 0) & 0xff)
|
||||
};
|
||||
}
|
||||
|
@ -21,8 +21,8 @@ fn ElemEvents! Ctx.slider_hor(&ctx,
|
||||
Rect size,
|
||||
float* value,
|
||||
float hpercent = 0.25,
|
||||
Color bgcolor = uint_to_rgba(0x0000ffff),
|
||||
Color handlecolor = uint_to_rgba(0x0ff000ff))
|
||||
Color bgcolor = 0x0000ffffu.to_rgba(),
|
||||
Color handlecolor = 0x0ff000ffu.to_rgba())
|
||||
{
|
||||
Id id = ctx.gen_id(label)!;
|
||||
|
||||
@ -84,8 +84,8 @@ fn ElemEvents! Ctx.slider_ver(&ctx,
|
||||
Rect size,
|
||||
float* value,
|
||||
float hpercent = 0.25,
|
||||
Color bgcolor = uint_to_rgba(0x0000ffff),
|
||||
Color handlecolor = uint_to_rgba(0x0ff000ff))
|
||||
Color bgcolor = 0x0000ffffu.to_rgba(),
|
||||
Color handlecolor = 0x0ff000ffu.to_rgba())
|
||||
{
|
||||
Id id = ctx.gen_id(label)!;
|
||||
|
||||
|
19
test/test_color.c3
Normal file
19
test/test_color.c3
Normal file
@ -0,0 +1,19 @@
|
||||
import std::io;
|
||||
|
||||
struct Color { short r,g,b,a; }
|
||||
|
||||
macro Color uint.to_rgba(uint u)
|
||||
{
|
||||
return Color{
|
||||
.r = (char)((u >> 24) & 0xff),
|
||||
.g = (char)((u >> 16) & 0xff),
|
||||
.b = (char)((u >> 8) & 0xff),
|
||||
.a = (char)((u >> 0) & 0xff)
|
||||
};
|
||||
}
|
||||
|
||||
fn void main(String[] args)
|
||||
{
|
||||
uint col = args[1].to_uint()!!;
|
||||
io::printn(col.to_rgba());
|
||||
}
|
Loading…
Reference in New Issue
Block a user