Update to latest zwidget

This commit is contained in:
Magnus Norddahl 2024-01-19 12:35:35 +01:00
commit a48a45dd69
26 changed files with 529 additions and 547 deletions

View file

@ -286,9 +286,9 @@ void TextEdit::OnMouseMove(const Point& pos)
}
}
bool TextEdit::OnMouseDown(const Point& pos, int key)
bool TextEdit::OnMouseDown(const Point& pos, InputKey key)
{
if (key == IK_LeftMouse)
if (key == InputKey::LeftMouse)
{
CaptureMouse();
mouse_selecting = true;
@ -301,14 +301,14 @@ bool TextEdit::OnMouseDown(const Point& pos, int key)
return true;
}
bool TextEdit::OnMouseDoubleclick(const Point& pos, int key)
bool TextEdit::OnMouseDoubleclick(const Point& pos, InputKey key)
{
return true;
}
bool TextEdit::OnMouseUp(const Point& pos, int key)
bool TextEdit::OnMouseUp(const Point& pos, InputKey key)
{
if (mouse_selecting && key == IK_LeftMouse)
if (mouse_selecting && key == InputKey::LeftMouse)
{
if (ignore_mouse_events) // This prevents text selection from changing from what was set when focus was gained.
{
@ -360,9 +360,9 @@ void TextEdit::OnKeyChar(std::string chars)
}
}
void TextEdit::OnKeyDown(EInputKey key)
void TextEdit::OnKeyDown(InputKey key)
{
if (!readonly && key == IK_Enter)
if (!readonly && key == InputKey::Enter)
{
if (FuncEnterPressed)
{
@ -383,17 +383,17 @@ void TextEdit::OnKeyDown(EInputKey key)
timer->Start(500); // don't blink cursor when moving or typing.
}
if (key == IK_Enter || key == IK_Escape || key == IK_Tab)
if (key == InputKey::Enter || key == InputKey::Escape || key == InputKey::Tab)
{
// Do not consume these.
return;
}
else if (key == IK_A && GetKeyState(IK_Ctrl))
else if (key == InputKey::A && GetKeyState(InputKey::Ctrl))
{
// select all
SelectAll();
}
else if (key == IK_C && GetKeyState(IK_Ctrl))
else if (key == InputKey::C && GetKeyState(InputKey::Ctrl))
{
std::string str = GetSelection();
SetClipboardText(str);
@ -403,9 +403,9 @@ void TextEdit::OnKeyDown(EInputKey key)
// Do not consume messages on read only component (only allow CTRL-A and CTRL-C)
return;
}
else if (key == IK_Up)
else if (key == InputKey::Up)
{
if (GetKeyState(IK_Shift) && selection_length == 0)
if (GetKeyState(InputKey::Shift) && selection_length == 0)
selection_start = cursor_pos;
if (cursor_pos.y > 0)
@ -414,7 +414,7 @@ void TextEdit::OnKeyDown(EInputKey key)
cursor_pos.x = std::min(lines[cursor_pos.y].text.size(), (size_t)cursor_pos.x);
}
if (GetKeyState(IK_Shift))
if (GetKeyState(InputKey::Shift))
{
selection_length = ToOffset(cursor_pos) - ToOffset(selection_start);
}
@ -428,9 +428,9 @@ void TextEdit::OnKeyDown(EInputKey key)
Update();
undo_info.first_text_insert = true;
}
else if (key == IK_Down)
else if (key == InputKey::Down)
{
if (GetKeyState(IK_Shift) && selection_length == 0)
if (GetKeyState(InputKey::Shift) && selection_length == 0)
selection_start = cursor_pos;
if (cursor_pos.y < lines.size() - 1)
@ -439,7 +439,7 @@ void TextEdit::OnKeyDown(EInputKey key)
cursor_pos.x = std::min(lines[cursor_pos.y].text.size(), (size_t)cursor_pos.x);
}
if (GetKeyState(IK_Shift))
if (GetKeyState(InputKey::Shift))
{
selection_length = ToOffset(cursor_pos) - ToOffset(selection_start);
}
@ -454,55 +454,55 @@ void TextEdit::OnKeyDown(EInputKey key)
Update();
undo_info.first_text_insert = true;
}
else if (key == IK_Left)
else if (key == InputKey::Left)
{
Move(-1, GetKeyState(IK_Shift), GetKeyState(IK_Ctrl));
Move(-1, GetKeyState(InputKey::Shift), GetKeyState(InputKey::Ctrl));
}
else if (key == IK_Right)
else if (key == InputKey::Right)
{
Move(1, GetKeyState(IK_Shift), GetKeyState(IK_Ctrl));
Move(1, GetKeyState(InputKey::Shift), GetKeyState(InputKey::Ctrl));
}
else if (key == IK_Backspace)
else if (key == InputKey::Backspace)
{
Backspace();
}
else if (key == IK_Delete)
else if (key == InputKey::Delete)
{
Del();
}
else if (key == IK_Home)
else if (key == InputKey::Home)
{
if (GetKeyState(IK_Ctrl))
if (GetKeyState(InputKey::Ctrl))
cursor_pos = ivec2(0, 0);
else
cursor_pos.x = 0;
if (GetKeyState(IK_Shift))
if (GetKeyState(InputKey::Shift))
selection_length = ToOffset(cursor_pos) - ToOffset(selection_start);
else
ClearSelection();
Update();
MoveVerticalScroll();
}
else if (key == IK_End)
else if (key == InputKey::End)
{
if (GetKeyState(IK_Ctrl))
if (GetKeyState(InputKey::Ctrl))
cursor_pos = ivec2(lines.back().text.length(), lines.size() - 1);
else
cursor_pos.x = lines[cursor_pos.y].text.size();
if (GetKeyState(IK_Shift))
if (GetKeyState(InputKey::Shift))
selection_length = ToOffset(cursor_pos) - ToOffset(selection_start);
else
ClearSelection();
Update();
}
else if (key == IK_X && GetKeyState(IK_Ctrl))
else if (key == InputKey::X && GetKeyState(InputKey::Ctrl))
{
std::string str = GetSelection();
DeleteSelectedText();
SetClipboardText(str);
}
else if (key == IK_V && GetKeyState(IK_Ctrl))
else if (key == InputKey::V && GetKeyState(InputKey::Ctrl))
{
std::string str = GetClipboardText();
std::string::const_iterator end_str = std::remove(str.begin(), str.end(), '\r');
@ -524,7 +524,7 @@ void TextEdit::OnKeyDown(EInputKey key)
}
MoveVerticalScroll();
}
else if (GetKeyState(IK_Ctrl) && key == IK_Z)
else if (GetKeyState(InputKey::Ctrl) && key == InputKey::Z)
{
if (!readonly)
{
@ -533,7 +533,7 @@ void TextEdit::OnKeyDown(EInputKey key)
SetText(tmp);
}
}
else if (key == IK_Shift)
else if (key == InputKey::Shift)
{
if (selection_length == 0)
selection_start = cursor_pos;
@ -543,7 +543,7 @@ void TextEdit::OnKeyDown(EInputKey key)
FuncAfterEditChanged();
}
void TextEdit::OnKeyUp(EInputKey key)
void TextEdit::OnKeyUp(InputKey key)
{
}
@ -962,7 +962,7 @@ void TextEdit::LayoutLines(Canvas* canvas)
}
Point draw_pos;
for (size_t i = vert_scrollbar->GetPosition(); i < lines.size(); i++)
for (size_t i = (size_t)vert_scrollbar->GetPosition(); i < lines.size(); i++)
{
Line& line = lines[i];
if (line.invalidated)
@ -1021,7 +1021,7 @@ void TextEdit::OnPaintFrame(Canvas* canvas)
void TextEdit::OnPaint(Canvas* canvas)
{
LayoutLines(canvas);
for (size_t i = vert_scrollbar->GetPosition(); i < lines.size(); i++)
for (size_t i = (size_t)vert_scrollbar->GetPosition(); i < lines.size(); i++)
lines[i].layout.DrawLayout(canvas);
}