fix cursor position and text wrapping
This commit is contained in:
parent
1855da659a
commit
04849a7487
@ -603,10 +603,8 @@ TokenizeD(FlatBuffer* fb)
|
||||
Token* t = MakeToken(tk, TT.Slash, tk.pos, tk.pos+1);
|
||||
|
||||
u8 next = Peek(fb);
|
||||
Logf("%s %s", cast(char)ch, cast(char)next);
|
||||
if(next == '/')
|
||||
{
|
||||
Logf("11");
|
||||
tk.pos += 1;
|
||||
t.type = TT.Comment;
|
||||
|
||||
@ -622,7 +620,6 @@ TokenizeD(FlatBuffer* fb)
|
||||
}
|
||||
else if(next == '*')
|
||||
{
|
||||
Logf("22");
|
||||
tk.pos += 1;
|
||||
t.type = TT.Comment;
|
||||
|
||||
|
||||
@ -770,25 +770,21 @@ PrintNodes(UIItem* item)
|
||||
void
|
||||
FixViolations(UIItem* item)
|
||||
{
|
||||
// TODO: Fix this
|
||||
Axis2D axis = A2D.Y;
|
||||
for(UIItem* i = item; !Nil(i); i = Recurse(i))
|
||||
static foreach(axis; A2D.X .. A2D.Y)
|
||||
{
|
||||
if(!Nil(i.parent))
|
||||
for(UIItem* i = item; !Nil(i); i = Recurse(i))
|
||||
{
|
||||
f32 bounds_start = i.parent.rect.vec0.v[axis] - i.parent.culling.vec0.v[axis];
|
||||
if(i.rect.vec0.v[axis] < bounds_start)
|
||||
f32 total = 0.0;
|
||||
for(UIItem* c = i.first; !Nil(c); c = c.next)
|
||||
{
|
||||
i.culling.vec0.v[axis] = bounds_start - i.rect.vec0.v[axis];
|
||||
i.rect.vec0.v[axis] -= i.culling.vec0.v[axis];
|
||||
//Logf("cull start %f", i.culling.vec0.v[axis]);
|
||||
}
|
||||
|
||||
f32 bounds_end = i.parent.rect.vec1.v[axis] - i.parent.culling.vec1.v[axis];
|
||||
if(i.rect.vec1.v[axis] > bounds_end)
|
||||
{
|
||||
i.culling.vec1.v[axis] = i.rect.vec1.v[axis] - bounds_end;
|
||||
i.rect.vec1.v[axis] -= i.culling.vec1.v[axis];
|
||||
total += c.size.v[axis];
|
||||
if(total > i.size.v[axis])
|
||||
{
|
||||
f32 size = c.size.v[axis];
|
||||
f32 sub = total - i.size.v[axis];
|
||||
c.size.v[axis] = Max(size - sub, 0.0);
|
||||
i.culling.vec1.v[axis] = Min(size - sub, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -848,12 +844,6 @@ CalcPositions(alias axis)(UIItem* item)
|
||||
i.rect.vec0.v[axis] = pos;
|
||||
i.rect.vec1.v[axis] = end_pos;
|
||||
|
||||
|
||||
if(item.parent.key.text == r"###cmd_palette_input_cntr")
|
||||
{
|
||||
Logf("pos %s end_pos %s", pos, end_pos);
|
||||
}
|
||||
|
||||
assert(!isNaN(i.rect.vec0.v[axis]));
|
||||
assert(!isNaN(i.rect.vec1.v[axis]));
|
||||
|
||||
@ -1261,7 +1251,7 @@ MakeMultiline(u8[] text, f32 width, u8[] parent_id, u64 line_no, TS[] style = []
|
||||
|
||||
if(ch_w + w > scaled_width || i == text.length-1)
|
||||
{
|
||||
u64 len = i-start+1;
|
||||
u64 len = i-start;
|
||||
u8[extra_buf] buf = 0;
|
||||
(cast(char[])buf).sformat("%s%05s%05s", cast(char[])parent_id, line_no, line);
|
||||
|
||||
@ -1599,7 +1589,6 @@ ClickedCharIndex(UIItem* item)
|
||||
f32 ch_w = GlyphWidth(ctx.atlas_buf.atlas.glyphs.ptr + ch);
|
||||
if(ch_w + w > item.last_click_pos.x)
|
||||
{
|
||||
Logf("char clicked");
|
||||
//item.clicked_char_idx = i;
|
||||
break;
|
||||
}
|
||||
@ -1664,11 +1653,6 @@ BorderClicked(UIItem* item, DNode!(InputEvent)* n)
|
||||
item.signal |= (signal | UIS.BorderY1);
|
||||
}
|
||||
else taken = false;
|
||||
|
||||
if(taken)
|
||||
{
|
||||
Logf("%s Clicked or Dragged", cast(char[])item.key.hash_text);
|
||||
}
|
||||
}
|
||||
|
||||
return taken;
|
||||
|
||||
@ -404,7 +404,7 @@ EditorView(UIPanel* panel)
|
||||
{
|
||||
}
|
||||
|
||||
TextPart* tp = WrappedTextLine(buf.text, panel.id, text_size, line_no, buf.style, &pos);
|
||||
TextPart* tp = WrappedTextLine(buf.text, panel.id, text_size, line_no, buf.style, &pos, focused);
|
||||
height += (text_size * tp.count);
|
||||
if(TextClicked(tp))
|
||||
{
|
||||
@ -450,7 +450,7 @@ TextClicked(TextPart* text_part)
|
||||
}
|
||||
|
||||
TextPart*
|
||||
WrappedTextLine(u8[] text, u8[] parent_id, f32 text_size, u64 line_no, TS[] style = [], U64Vec2* hl_pos)
|
||||
WrappedTextLine(u8[] text, u8[] parent_id, f32 text_size, u64 line_no, TS[] style = [], U64Vec2* hl_pos, bool focused)
|
||||
{
|
||||
Push!("color")(Vec4(1.0));
|
||||
Push!("text_size")(text_size);
|
||||
@ -465,9 +465,11 @@ WrappedTextLine(u8[] text, u8[] parent_id, f32 text_size, u64 line_no, TS[] styl
|
||||
hl = hl_pos.x;
|
||||
}
|
||||
|
||||
f32 parent_width = parent.size.x - (parent.border_thickness * 2);
|
||||
|
||||
u64 chars;
|
||||
TextPart* tp = part;
|
||||
Node!(TextBuffer)* lines = MakeMultiline(text, parent.size.x, parent_id, line_no, style);
|
||||
Node!(TextBuffer)* lines = MakeMultiline(text, parent_width, parent_id, line_no, style);
|
||||
for(Node!(TextBuffer)* line = lines; line != null; line = line.next, tp = tp.next)
|
||||
{
|
||||
part.count += 1;
|
||||
@ -478,17 +480,16 @@ WrappedTextLine(u8[] text, u8[] parent_id, f32 text_size, u64 line_no, TS[] styl
|
||||
|
||||
tp.item.token_styles = line.value.style;
|
||||
|
||||
if(hl >= 0 && hl < tp.item.key.text.length+chars)
|
||||
if(focused && hl >= 0)
|
||||
{
|
||||
//Logf("hl %s %s %s", hl, tp.item.key.text.length, chars);
|
||||
if(hl < tp.item.key.text.length+chars)
|
||||
if(hl <= tp.item.key.text.length)
|
||||
{
|
||||
Push!("highlighted_char")(hl-chars);
|
||||
Push!("highlighted_char")(hl);
|
||||
hl = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
chars += tp.item.key.text.length;
|
||||
hl -= tp.item.key.text.length;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user