delete a bunch of code
This commit is contained in:
parent
f89a0094cf
commit
1700119e57
@ -182,42 +182,6 @@ Cycle(Inputs* inputs)
|
||||
|
||||
UICtx* ui_ctx = GetCtx();
|
||||
|
||||
debug
|
||||
{
|
||||
ui_ctx.dbg = false;
|
||||
|
||||
for(InputEvent* ev = inputs.first; ev; ev = ev.next)
|
||||
{
|
||||
if(ev.key == Input.g && ev.md & MD.LeftCtrl)
|
||||
{
|
||||
ui_ctx.dbg = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UIItem* container = Container(A2D.Y, UIS2());
|
||||
UIItem* ed_container = Container(A2D.X, UISY(ST.Percentage, 0.98));
|
||||
EditorView(g_ed_ctx.base_panel);
|
||||
Pop!("parent");
|
||||
|
||||
assert(ui_ctx.parent.top.value == container);
|
||||
|
||||
StatusBar(&g_ed_ctx);
|
||||
|
||||
UIItem* cmd_item = Get("###cmd_palette");
|
||||
|
||||
bool cmd_active = Active(ES.CmdPalette);
|
||||
if(cmd_active || Ready(cmd_item))
|
||||
{
|
||||
CommandPalette(&g_ed_ctx.cmd, cmd_active);
|
||||
}
|
||||
|
||||
if(Active(ES.RunCmd))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
EndUI();
|
||||
}
|
||||
|
||||
@ -462,6 +426,7 @@ AddEditor(Panel* target, Axis2D axis)
|
||||
panel.parent = target.parent;
|
||||
|
||||
UIItem* ed_item = GetEditorItem(panel.ed);
|
||||
/*
|
||||
if(!Nil(ed_item.parent))
|
||||
{
|
||||
u64 count;
|
||||
@ -476,6 +441,7 @@ AddEditor(Panel* target, Axis2D axis)
|
||||
c.resize_pct = pct;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
FocusEditor(panel);
|
||||
}
|
||||
|
||||
1732
src/editor/ui.d
1732
src/editor/ui.d
File diff suppressed because it is too large
Load Diff
@ -39,468 +39,3 @@ struct Panel
|
||||
u64 id;
|
||||
u32 text_size;
|
||||
}
|
||||
|
||||
void
|
||||
LineCounterView(FontAtlasBuf* abuf, u64 max_line, u64 lines, i64 line_offset, f32 view_offset)
|
||||
{
|
||||
UICtx* ctx = GetCtx();
|
||||
|
||||
u64 ch_width = max_line.toChars().length;
|
||||
f32 lc_width = cast(f32)(ch_width+1)*abuf.atlas.max_advance;
|
||||
|
||||
enum UIPushInfo[] lc_params = [
|
||||
{ "layout_axis", q{ A2D.Y } },
|
||||
{ "size_info", q{ UIS2(ST.Pixels, ST.Percentage, lc_width, 1.0) } },
|
||||
];
|
||||
|
||||
mixin(PushOnce!(lc_params));
|
||||
|
||||
UIItem* line_count = MakeItem(ZERO, UIF.DrawBorder|UIF.ScissorY);
|
||||
|
||||
mixin(PushScope!("size_info", q{ UISY(ST.Pixels, abuf.atlas.line_height) } ));
|
||||
mixin(PushScope!("parent", q{ line_count } ));
|
||||
|
||||
SetElement(UIElem.LineCountText);
|
||||
u64 end_line = lines+line_offset;
|
||||
for(u64 i = line_offset; i < end_line && i < max_line; i += 1)
|
||||
{
|
||||
char[] buf = ScratchAlloc!(char)(ch_width);
|
||||
Push!("display_string")(Scratchf("%s", i));
|
||||
MakeItem(ZERO, UIF.DrawText);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
EditorTextView(UIItem* editor, Panel* p, FontAtlasBuf* abuf, u64 lines, i64 line_offset, f32 view_offset)
|
||||
{
|
||||
Editor* ed = p.ed;
|
||||
|
||||
PushLayoutAxis(A2D.Y);
|
||||
|
||||
f32 text_size = cast(f32)p.text_size;
|
||||
f32 clamp_y = cast(f32)(ed.buf.line_count-lines)*text_size;
|
||||
f32 scroll_pos = cast(f32)(ed.line_offset)*text_size;
|
||||
f32 padding = 8.0;
|
||||
|
||||
f32 scroll_target = 0.0;
|
||||
static bool toggled = true;
|
||||
static f32 t = 0.0;
|
||||
if(toggled)
|
||||
{
|
||||
scroll_target = 0.0;
|
||||
t += g_delta;
|
||||
if(t > 0.5)
|
||||
{
|
||||
toggled = !toggled;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
scroll_target = 1000.0;
|
||||
t -= g_delta;
|
||||
if(t < 0.0)
|
||||
{
|
||||
toggled = !toggled;
|
||||
}
|
||||
}
|
||||
|
||||
enum UIPushInfo[] text_view_params = [
|
||||
{ "layout_axis", q{ A2D.Y } },
|
||||
{ "size_info", q{ UIS2() } },
|
||||
{ "scroll_target", q{ Vec2(0.0, scroll_target) } },
|
||||
//{ "scroll_clamp", q{ Vec2(0.0, clamp_y) } },
|
||||
];
|
||||
mixin(PushOnce!(text_view_params));
|
||||
|
||||
SetElement(UIElem.EditorTextView);
|
||||
editor = MakeItem(editor.key, UIF.DrawBorder|UIF.ScrollY|UIF.ClampY|UIF.ScissorY|UIF.ScrollFitChildren);
|
||||
|
||||
mixin(PushScope!("parent", q{ editor }));
|
||||
|
||||
UIKey zero = ZeroKey();
|
||||
|
||||
// Cursor
|
||||
{
|
||||
LineBuffer* lb = GetLine(&ed.buf, ed.cursor_pos.y);
|
||||
|
||||
u8 ch = lb.text.length > ed.cursor_pos.y ? lb.text[ed.cursor_pos.y] : 0;
|
||||
f32 line_h = abuf.atlas.line_height;
|
||||
f32 cursor_x = CalcTextWidth(lb.text[0 .. ed.cursor_pos.x], abuf);
|
||||
f32 cursor_y = cast(f32)(ed.cursor_pos.y - line_offset)*line_h;
|
||||
Glyph* g = abuf.atlas.glyphs.length > ch ? abuf.atlas.glyphs.ptr + ch : abuf.atlas.glyphs.ptr + ' ';
|
||||
|
||||
enum UIPushInfo[] cursor_info = [
|
||||
{ "size_info", q{ UIS2(ST.Pixels, ST.Pixels, g.advance, line_h) } },
|
||||
{ "fixed_pos", q{ Vec2(cursor_x, cursor_y) } },
|
||||
];
|
||||
mixin(PushOnce!(cursor_info));
|
||||
|
||||
SetElement(UIElem.EditorTextCursor);
|
||||
UIItem* cursor = MakeItem("###cursor", UIF.DrawBackground|UIF.FixedPosition);
|
||||
}
|
||||
|
||||
mixin(PushScope!("size_info", q{ UISY(ST.TextSize) } ));
|
||||
mixin(PushScope!("syntax_highlight", q{ UISH.D } ));
|
||||
|
||||
SetElement(UIElem.EditorText);
|
||||
for(u64 i = 0; i < 200; i += 1)
|
||||
{
|
||||
MakeItem("%s", i, UIF.DrawText);
|
||||
}
|
||||
|
||||
/*
|
||||
u64 i = line_offset;
|
||||
for(LineBuffer* lb = GetLine(&ed.buf, i); !CheckNil(g_NIL_LINE_BUF, lb) && i < line_offset+lines; i += 1, lb = GetLine(&ed.buf, i))
|
||||
{
|
||||
string txt = Str(lb.text);
|
||||
u8[] tokens = cast(u8[])(lb.style);
|
||||
PushOnce!("display_string", txt, "syntax_tokens", tokens);
|
||||
|
||||
UIItem* line = MakeItem(zero, UIF.DrawText);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void
|
||||
EditorView(Panel* p)
|
||||
{
|
||||
Editor* ed = p.ed;
|
||||
UICtx* ctx = GetCtx();
|
||||
UIKey zero = ZeroKey();
|
||||
FontAtlasBuf* abuf = GetFontAtlas(p.text_size);
|
||||
|
||||
mixin(PushScope!("text_size", q{ p.text_size }));
|
||||
|
||||
if(CheckNil(g_NIL_ED, ed))
|
||||
{
|
||||
for(Panel* c = p.first; !CheckNil(g_NIL_PANEL, c); c = c.next)
|
||||
{
|
||||
EditorView(c);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(ed);
|
||||
|
||||
UIKey ed_key = MakeKey("###ed_%s", ed.editor_id);
|
||||
UIItem* editor = Get(ed_key);
|
||||
|
||||
f32 text_size = abuf.atlas.line_height;
|
||||
|
||||
u64 frame_line_offset = ed.line_offset;
|
||||
f32 frame_view_offset = -(editor.scroll_offset.y%text_size);
|
||||
|
||||
enum UIPushInfo[] c_info = [
|
||||
{ "size_info", q{ UIS2() } },
|
||||
];
|
||||
mixin(PushOnce!(c_info));
|
||||
|
||||
UIItem* container = MakeItem(zero, UIF.DrawBackground);
|
||||
|
||||
mixin(PushScope!("parent", q{ container } ));
|
||||
|
||||
u64 view_lines;
|
||||
if(editor.size.y > 0.0)
|
||||
{
|
||||
view_lines = cast(u64)floor(editor.size.y/text_size)+1;
|
||||
const u64 SCROLL_BUFFER = 4;
|
||||
|
||||
i64 start = ed.line_offset;
|
||||
i64 end = start+view_lines;
|
||||
|
||||
if(ed.cursor_pos.y < start)
|
||||
{
|
||||
u64 pos = ed.cursor_pos.y > SCROLL_BUFFER ? ed.cursor_pos.y - SCROLL_BUFFER : ed.cursor_pos.y;
|
||||
ed.line_offset = clamp(pos, 0, ed.buf.line_count);
|
||||
}
|
||||
else if(ed.cursor_pos.y > end)
|
||||
{
|
||||
ed.line_offset = clamp(ed.cursor_pos.y + SCROLL_BUFFER - view_lines, 0, ed.buf.line_count);
|
||||
}
|
||||
}
|
||||
|
||||
for(UIInput* i = ctx.events.first; !CheckNil(g_UI_NIL_INPUT, i) && g_ed_ctx.focused_panel == p && !CmdModeActive(); i = i.next)
|
||||
{
|
||||
bool taken;
|
||||
|
||||
if(i.type == UIE.Scroll)
|
||||
{
|
||||
ed.line_offset = clamp(ed.line_offset+(i.scroll*2), 0, ed.buf.line_count);
|
||||
if(ed.cursor_pos.y < ed.line_offset)
|
||||
{
|
||||
ed.cursor_pos.y = ed.line_offset;
|
||||
}
|
||||
else if(ed.cursor_pos.y > ed.line_offset+view_lines)
|
||||
{
|
||||
ed.cursor_pos.y = ed.line_offset+view_lines-1;
|
||||
}
|
||||
|
||||
taken = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
HandleInputs(p, &ctx.events);
|
||||
}
|
||||
|
||||
if(taken)
|
||||
{
|
||||
DLLRemove(&ctx.events, i, g_UI_NIL_INPUT);
|
||||
}
|
||||
|
||||
if(g_ed_ctx.focused_panel != p) break;
|
||||
if(g_ed_ctx.state == ES.CmdPalette) break;
|
||||
}
|
||||
|
||||
ed.cursor_pos = VecPos(&ed.buf);
|
||||
|
||||
u64 start = cast(u64)floor(editor.scroll_offset.y/text_size);
|
||||
LineCounterView(abuf, ed.buf.line_count, view_lines, start, frame_view_offset);
|
||||
EditorTextView(editor, p, abuf, view_lines, start, frame_view_offset);
|
||||
}
|
||||
|
||||
ResetBuffer(&ed.buf);
|
||||
}
|
||||
|
||||
UIItem*
|
||||
CommandWindow(f32 w, f32 h, f32 x, f32 y, bool active)
|
||||
{
|
||||
enum UIPushInfo[] cmd_params = [
|
||||
{ "layout_axis", q{ A2D.Y } },
|
||||
{ "fixed_pos", q{ Vec2(x, y) } },
|
||||
{ "size_info", q{ UIS2(ST.Pixels, ST.Pixels, w, h) } },
|
||||
];
|
||||
mixin(PushOnce!(cmd_params));
|
||||
|
||||
UIFlags cmd_flags = UIF.Window|UIF.FixedPosition|UIF.AnimateReady|UIF.DrawDropShadow|UIF.DrawBackground;
|
||||
if(active)
|
||||
{
|
||||
cmd_flags |= UIF.SetReady;
|
||||
}
|
||||
|
||||
SetElement(UIElem.CmdWindow);
|
||||
UIItem* window = MakeItem("###cmd_palette", cmd_flags);
|
||||
Push!("parent")(window, false);
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
UIItem*
|
||||
CommandInput(CmdPalette* cmd, string placeholder = "")
|
||||
{
|
||||
string input_str = cmd.icount ? Str(cmd.buffer[0 .. cmd.icount]) : "Search...";
|
||||
|
||||
enum UIPushInfo[] cmd_input_params = [
|
||||
{ "text_size", q{ 14 }},
|
||||
{ "size_info", q{ UISY(ST.TextSize) } },
|
||||
{ "display_string", q{ input_str } },
|
||||
];
|
||||
|
||||
mixin(PushOnce!(cmd_input_params));
|
||||
|
||||
SetElement(cmd.icount ? UIElem.CmdInput : UIElem.CmdInputEmpty);
|
||||
return MakeItem("###cmd_input", UIF.DrawBorder|UIF.DrawBackground|UIF.DrawText|UIF.Overflow);
|
||||
}
|
||||
|
||||
UIItem*
|
||||
CommandOpt(T)(CmdPalette* cmd, T opt, u64 i)
|
||||
{
|
||||
UIFlags flags = UIF.DrawBackground|UIF.AnimateHot|UIF.Clickable;
|
||||
|
||||
SetElement(i%2 ? UIElem.CmdOpt : UIElem.CmdOptAlt);
|
||||
PushLayoutAxis(A2D.Y);
|
||||
|
||||
static if(is(T == string))
|
||||
{
|
||||
PushDisplayString(cmd.opt_strs[i]);
|
||||
|
||||
UIKey k = MakeKey("###opt_%s", i);
|
||||
Hovered!(true)(k, &cmd.selected, i);
|
||||
|
||||
UIItem* item = MakeItem(k, flags|UIF.DrawText|SetHot(cmd.selected == i));
|
||||
|
||||
Signal(item);
|
||||
|
||||
return item;
|
||||
}
|
||||
else if(is(T == Command*))
|
||||
{
|
||||
UIKey k = MakeKey("###optc_%s", i);
|
||||
Hovered!(true)(k, &cmd.selected, i);
|
||||
|
||||
UIItem* optc = MakeItem(k, flags|SetHot(cmd.selected == i));
|
||||
|
||||
Signal(optc);
|
||||
|
||||
PushParent(optc, false);
|
||||
PushSizeInfo(UISY(ST.TextSize), false);
|
||||
|
||||
PushTextSize(CMD_TITLE_PX);
|
||||
PushDisplayStringCopy(cmd.commands[i].name);
|
||||
|
||||
SetElement(UIElem.CmdTitleText);
|
||||
MakeItem(ZERO, UIF.DrawText);
|
||||
|
||||
PushTextSize(CMD_SUB_PX);
|
||||
PushDisplayStringCopy(cmd.commands[i].desc);
|
||||
|
||||
SetElement(UIElem.CmdSubtitleText);
|
||||
MakeItem(ZERO, UIF.DrawText);
|
||||
|
||||
Pop!("parent", "size_info");
|
||||
|
||||
return optc;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CommandPalette(CmdPalette* cmd, bool active)
|
||||
{
|
||||
UICtx* ctx = GetCtx();
|
||||
Vec2 ext = GetExtent();
|
||||
|
||||
f32 w = ext.x*0.6;
|
||||
f32 h = ext.y*0.7;
|
||||
|
||||
UIItem* cmd_item = CommandWindow(w, h, ext.x*0.2, ext.y*0.1, active);
|
||||
|
||||
UIItem* input = CommandInput(cmd, "Search...");
|
||||
|
||||
// Command Palette Options
|
||||
{
|
||||
u32 title_px = 14;
|
||||
u32 sub_px = 10;
|
||||
f32 title_size = GetLineHeight(title_px);
|
||||
f32 sub_size = GetLineHeight(sub_px);
|
||||
f32 title_pad = 2.0f;
|
||||
f32 y_pad = 4.0;
|
||||
f32 x_pad = 8.0;
|
||||
f32 opt_height = cast(f32)(title_size + sub_size) + y_pad*2.0 + title_pad;
|
||||
|
||||
enum UIPushInfo[] cmd_opts_box_params = [
|
||||
{ "layout_axis", q{ A2D.Y }},
|
||||
{ "size_info", q{ UISY(ST.Pixels, h-opt_height) } },
|
||||
];
|
||||
|
||||
mixin(PushOnce!(cmd_opts_box_params));
|
||||
|
||||
SetElement(UIElem.CmdOptWindow);
|
||||
UIItem* opt_box = MakeItem(ZERO, UIF.DrawBorder);
|
||||
|
||||
mixin(PushScope!("parent", q{ opt_box }));
|
||||
mixin(PushScope!("size_info", q{ UISY(ST.Pixels, opt_height) } ));
|
||||
|
||||
u64 max_opts = cast(u64)ceil(h/opt_height);
|
||||
|
||||
bool opts = cast(bool)cmd.opt_strs.length;
|
||||
if(opts)
|
||||
{
|
||||
for(u64 i = 0; i < cmd.opt_strs.length && i < max_opts; i += 1)
|
||||
{
|
||||
UIItem* opt = CommandOpt(cmd, cmd.opt_strs[i], i);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(u64 i = 0; i < cmd.commands.length && i < max_opts; i += 1)
|
||||
{
|
||||
UIItem* opt = CommandOpt(cmd, &cmd.commands[i], i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(UIInput* i = ctx.events.first; !CheckNil(g_UI_NIL_INPUT, i); i = i.next)
|
||||
{
|
||||
bool taken = HandleCmdMode(cmd, i);
|
||||
|
||||
if(taken)
|
||||
{
|
||||
DLLRemove(&ctx.events, i, g_UI_NIL_INPUT);
|
||||
}
|
||||
}
|
||||
|
||||
Pop!("parent");
|
||||
}
|
||||
|
||||
void
|
||||
CommandTextInput(CmdPalette* cmd, string[] opts, void function(string) callback)
|
||||
{
|
||||
UICtx* ctx = GetCtx();
|
||||
Vec2 ext = GetExtent();
|
||||
|
||||
|
||||
}
|
||||
|
||||
UIFlags
|
||||
SetHot(bool cond)
|
||||
{
|
||||
return (cond ? UIF.SetHot : UIF.None);
|
||||
}
|
||||
|
||||
UIItem*
|
||||
Container(bool push = true)(Axis2D axis, UISize[2] size_info)
|
||||
{
|
||||
enum UIPushInfo[] container_info = [
|
||||
{ "layout_axis", q{ axis } },
|
||||
{ "size_info", q{ size_info }},
|
||||
];
|
||||
|
||||
mixin(PushOnce!(container_info));
|
||||
|
||||
UIItem* item = MakeItem(ZERO);
|
||||
|
||||
static if(push)
|
||||
{
|
||||
Push!("parent")(item, false);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
void
|
||||
StatusBar(EditorCtx* ed_ctx)
|
||||
{
|
||||
enum UIPushInfo[] bar_info = [
|
||||
{ "size_info", q{ UISY(ST.Percentage, 0.02)} },
|
||||
{ "layout_axis", q{ A2D.X} },
|
||||
];
|
||||
mixin(PushOnce!(bar_info));
|
||||
|
||||
ItemStyle* info_style = GetElementStyle(UIElem.StatusInfo);
|
||||
|
||||
Vec4 status_col = BLUE;
|
||||
string status = "Normal";
|
||||
if(ed_ctx.state == ES.InputMode)
|
||||
{
|
||||
status = "Input";
|
||||
status_col = YELLOW;
|
||||
}
|
||||
else if(ed_ctx.state == ES.CmdPalette)
|
||||
{
|
||||
status = "Command";
|
||||
status_col = RED;
|
||||
}
|
||||
|
||||
info_style.bg_col = status_col;
|
||||
|
||||
UIItem* bar = MakeItem(ZERO);
|
||||
|
||||
mixin(PushScope!("parent", q{ bar }));
|
||||
|
||||
enum UIPushInfo[] status_info = [
|
||||
{ "text_size", q{ 16 }},
|
||||
{ "size_info", q{ UISX(ST.TextSize) } },
|
||||
{ "display_string", q{ status } },
|
||||
];
|
||||
mixin(PushOnce!(status_info));
|
||||
|
||||
SetElement(UIElem.StatusInfo);
|
||||
MakeItem(ZERO, UIF.DrawBackground|UIF.DrawText|UIF.VerticalAlignText);
|
||||
|
||||
enum UIPushInfo[] rest_info = [
|
||||
{ "size_info", q{ UIS2() }},
|
||||
];
|
||||
|
||||
SetElement(UIElem.StatusMessage);
|
||||
MakeItem(ZERO, UIF.DrawBackground);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user