base ui layout code working
This commit is contained in:
parent
2ebbe3d911
commit
49501a32aa
6
dub.json
6
dub.json
@ -7,16 +7,16 @@
|
|||||||
"targetType": "executable",
|
"targetType": "executable",
|
||||||
"targetName": "Editor",
|
"targetName": "Editor",
|
||||||
"targetPath": "build",
|
"targetPath": "build",
|
||||||
"sourceFiles-linux": ["build/libvma.a", "build/libstb.a", "build/libm3d.a", "build/libcglm.a"],
|
"sourceFiles-linux": ["build/libvma.a", "build/libstb.a", "build/libm3d.a"],
|
||||||
"sourceFiles-windows": [],
|
"sourceFiles-windows": [],
|
||||||
"importPaths": ["src/editor", "src/dlib", "src/dlib/external/xxhash", "src/VulkanRenderer"],
|
"importPaths": ["src/editor", "src/dlib", "src/dlib/external/xxhash", "src/VulkanRenderer"],
|
||||||
"sourcePaths": ["src/editor", "src/dlib", "src/dlib/external/xxhash", "src/VulkanRenderer"],
|
"sourcePaths": ["src/editor", "src/dlib", "src/dlib/external/xxhash", "src/VulkanRenderer"],
|
||||||
"libs-linux": ["X11", "vulkan", "stdc++", "xfixes", "freetype"],
|
"libs-linux": ["X11", "vulkan", "stdc++", "xfixes", "freetype"],
|
||||||
"libs-windows": [],
|
"libs-windows": [],
|
||||||
"versions": ["VULKAN_DEBUG", "ENABLE_RENDERER"],
|
"versions": ["VULKAN_DEBUG", "ENABLE_RENDERER", "NO_STBI"],
|
||||||
"preGenerateCommands-linux": ["./build.sh"],
|
"preGenerateCommands-linux": ["./build.sh"],
|
||||||
"preGenerateCommands-windows": [],
|
"preGenerateCommands-windows": [],
|
||||||
"dflags": ["-P-I/usr/include/freetype2", "-Jbuild", "-Jassets"],
|
"dflags": ["-P-I/usr/include/freetype2", "-Jbuild", "-Jassets", "-Xcc=-DNO_STBI"],
|
||||||
"dflags-ldc2": ["-link-debuglib"],
|
"dflags-ldc2": ["-link-debuglib"],
|
||||||
"dflags-dmd": []
|
"dflags-dmd": []
|
||||||
},
|
},
|
||||||
|
|||||||
2
src/dlib
2
src/dlib
@ -1 +1 @@
|
|||||||
Subproject commit 617e03f917911f6f9898086720a6539756f79758
|
Subproject commit 7f4c109106eaabda180158a8f7a92c9d2e60d3db
|
||||||
@ -145,24 +145,25 @@ Cycle(EditorCtx* ctx, Inputs* inputs)
|
|||||||
|
|
||||||
Vec4[4] col0 = Vec4(0.2, 0.4, 0.8, 1.0);
|
Vec4[4] col0 = Vec4(0.2, 0.4, 0.8, 1.0);
|
||||||
Vec4[4] col1 = Vec4(0.8, 0.4, 0.2, 1.0);
|
Vec4[4] col1 = Vec4(0.8, 0.4, 0.2, 1.0);
|
||||||
Vec4[4] col_sep = Vec4(0.2, 0.8, 0.1, 1.0);
|
Vec4[4] black = Vec4(0.0, 0.0, 0.0, 1.0);
|
||||||
|
Vec4[4] green = Vec4(0.2, 0.8, 0.1, 1.0);
|
||||||
|
|
||||||
|
Push!("border_thickness", true)(ui_ctx, 10.0f);
|
||||||
Push!("size_info")(ui_ctx, MakeUISizeX(ST.Percentage, 0.5));
|
Push!("size_info")(ui_ctx, MakeUISizeX(ST.Percentage, 0.5));
|
||||||
|
|
||||||
Push!("bg_col", true)(ui_ctx, col0);
|
Push!("bg_col", true)(ui_ctx, col0);
|
||||||
UIItem* p0 = MakeItem("###p0", UIF.DrawBackground|UIF.Resizeable);
|
UIItem* p0 = MakeItem("###p0", UIF.DrawBackground|UIF.Resizeable|UIF.DrawBorder);
|
||||||
|
|
||||||
Push!("size_info", true)(ui_ctx, MakeUISize(UISize(ST.Pixels, 200.0), UISize(ST.Pixels, 80.0)));
|
Push!("size_info", true)(ui_ctx, MakeUISize(UISize(ST.Pixels, 200.0), UISize(ST.Pixels, 80.0)));
|
||||||
Push!("parent", true)(ui_ctx, p0);
|
Push!("parent", true)(ui_ctx, p0);
|
||||||
Push!("bg_col", true)(ui_ctx, col_sep);
|
Push!("bg_col", true)(ui_ctx, green);
|
||||||
Push!("padding", true)(ui_ctx, Vec2(4.0));
|
Push!("padding", true)(ui_ctx, Vec2(4.0));
|
||||||
UIItem* text = MakeItem("Haha##text", UIF.DrawBackground|UIF.DrawText);
|
UIItem* text = MakeItem("Haha##text", UIF.DrawBackground|UIF.DrawText);
|
||||||
|
|
||||||
Push!("size_info", true)(ui_ctx, MakeUISizeX(ST.Pixels, 2.0));
|
Push!("size_info", true)(ui_ctx, MakeUISizeX(ST.Pixels, 2.0));
|
||||||
Push!("bg_col", true)(ui_ctx, col_sep);
|
Push!("bg_col", true)(ui_ctx, black);
|
||||||
UIItem* sep = MakeItem("###sep", UIF.Draggable|UIF.DrawBackground|UIF.ResizeAdjacent);
|
UIItem* sep = MakeItem("###sep", UIF.Draggable|UIF.DrawBackground|UIF.ResizeAdjacent);
|
||||||
|
|
||||||
|
Push!("layout_axis", true)(ui_ctx, A2D.Y);
|
||||||
Push!("bg_col", true)(ui_ctx, col1);
|
Push!("bg_col", true)(ui_ctx, col1);
|
||||||
UIItem* p1 = MakeItem("###p1", UIF.DrawBackground|UIF.Resizeable);
|
UIItem* p1 = MakeItem("###p1", UIF.DrawBackground|UIF.Resizeable);
|
||||||
|
|
||||||
@ -193,6 +194,7 @@ Cycle(EditorCtx* ctx, Inputs* inputs)
|
|||||||
Push!("bg_col", true)(ui_ctx, c4);
|
Push!("bg_col", true)(ui_ctx, c4);
|
||||||
Push!("size_info", true)(ui_ctx, MakeUISizeY(ST.Percentage, 0.35));
|
Push!("size_info", true)(ui_ctx, MakeUISizeY(ST.Percentage, 0.35));
|
||||||
MakeItem("###c4", UIF.DrawBackground);
|
MakeItem("###c4", UIF.DrawBackground);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
UIPanel* root = ctx.base_panel;
|
UIPanel* root = ctx.base_panel;
|
||||||
|
|
||||||
|
|||||||
@ -562,6 +562,8 @@ MakeItem(T)(T k, UIFlags flags = UIF.None) if(is(T: UIKey) || StringType!T)
|
|||||||
|
|
||||||
item.last_frame = ctx.frame;
|
item.last_frame = ctx.frame;
|
||||||
|
|
||||||
|
item.padding += item.border_thickness;
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -780,7 +782,7 @@ EndUI()
|
|||||||
{
|
{
|
||||||
if(item.size_info[axis].type == ST.Pixels)
|
if(item.size_info[axis].type == ST.Pixels)
|
||||||
{
|
{
|
||||||
item.size.v[axis] = item.size_info[axis].value + item.padding.v[axis];
|
item.size.v[axis] = item.size_info[axis].value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -789,7 +791,7 @@ EndUI()
|
|||||||
{
|
{
|
||||||
if(item.size_info[axis].type == ST.Percentage)
|
if(item.size_info[axis].type == ST.Percentage)
|
||||||
{
|
{
|
||||||
if(item.layout_axis == axis && item.flags & UIF.Resizeable)
|
if(item.parent.layout_axis == axis && item.flags & UIF.Resizeable)
|
||||||
{
|
{
|
||||||
item.size_info[axis].value = item.resize_pct;
|
item.size_info[axis].value = item.resize_pct;
|
||||||
}
|
}
|
||||||
@ -821,7 +823,7 @@ EndUI()
|
|||||||
// Violations
|
// Violations
|
||||||
for(UIItem* item = ctx.root; !Nil(item); item = Recurse!(true)(item, g_UI_NIL))
|
for(UIItem* item = ctx.root; !Nil(item); item = Recurse!(true)(item, g_UI_NIL))
|
||||||
{
|
{
|
||||||
f32 size = item.size[axis]; // InnerSize!(axis)(item);
|
f32 size = InnerSize!(axis)(item);
|
||||||
|
|
||||||
if(axis == item.layout_axis)
|
if(axis == item.layout_axis)
|
||||||
{
|
{
|
||||||
@ -883,12 +885,11 @@ EndUI()
|
|||||||
f32 pos = 0.0;
|
f32 pos = 0.0;
|
||||||
for(UIItem* item = ctx.root; !Nil(item);)
|
for(UIItem* item = ctx.root; !Nil(item);)
|
||||||
{
|
{
|
||||||
// This padding idea is FUCKED
|
f32 inner_pos = pos + item.parent.padding.v[axis];
|
||||||
f32 padding = !Nil(item.parent) ? item.parent.border_thickness : 0.0;
|
|
||||||
f32 next_pos = 0.0;
|
f32 next_pos = 0.0;
|
||||||
f32 end_pos = pos + item.size.v[axis];
|
f32 end_pos = inner_pos + item.size.v[axis];
|
||||||
|
|
||||||
item.rect.p0.v[axis] = pos + padding;
|
item.rect.p0.v[axis] = inner_pos;
|
||||||
item.rect.p1.v[axis] = end_pos;
|
item.rect.p1.v[axis] = end_pos;
|
||||||
|
|
||||||
assert(!isNaN(item.rect.p0.v[axis]));
|
assert(!isNaN(item.rect.p0.v[axis]));
|
||||||
@ -910,7 +911,7 @@ EndUI()
|
|||||||
if(!Nil(p.next))
|
if(!Nil(p.next))
|
||||||
{
|
{
|
||||||
item = p.next;
|
item = p.next;
|
||||||
pos = item.parent.layout_axis == axis ? item.prev.rect.p1.v[axis] : item.prev.rect.p0.v[axis];
|
pos = item.parent.layout_axis == axis ? item.prev.rect.p1.v[axis] : item.parent.rect.p0.v[axis];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -961,8 +962,8 @@ RenderItems(UIItem* root)
|
|||||||
{
|
{
|
||||||
// DrawRect
|
// DrawRect
|
||||||
Vertex* v = GetVertex(ctx);
|
Vertex* v = GetVertex(ctx);
|
||||||
v.dst_start = item.rect.p0 + item.border_thickness;
|
v.dst_start = item.rect.p0; // - item.border_thickness;
|
||||||
v.dst_end = item.rect.p1 - item.border_thickness;
|
v.dst_end = item.rect.p1; // + item.border_thickness;
|
||||||
v.cols = item.bg_col;
|
v.cols = item.bg_col;
|
||||||
v.corner_radius = item.corner_radius;
|
v.corner_radius = item.corner_radius;
|
||||||
|
|
||||||
@ -1416,7 +1417,7 @@ DrawGlyph(UIItem* item, Glyph* glyph, f32* x_pos, f32 y)
|
|||||||
pragma(inline) f32
|
pragma(inline) f32
|
||||||
InnerSize(Axis2D axis)(UIItem* item)
|
InnerSize(Axis2D axis)(UIItem* item)
|
||||||
{
|
{
|
||||||
return clamp(item.size[axis] - item.border_thickness*2.0, 0.0, f32.max);
|
return clamp(item.size[axis] - item.padding.v[axis]*2.0, 0.0, f32.max);
|
||||||
}
|
}
|
||||||
|
|
||||||
pragma(inline) Vertex*
|
pragma(inline) Vertex*
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user