Update to latest zwidget
This commit is contained in:
parent
22c788afc4
commit
d08b9b8568
23 changed files with 607 additions and 432 deletions
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
CheckboxLabel::CheckboxLabel(Widget* parent) : Widget(parent)
|
||||
{
|
||||
SetStyleClass("checkbox-label");
|
||||
}
|
||||
|
||||
void CheckboxLabel::SetText(const std::string& value)
|
||||
|
|
@ -42,17 +43,17 @@ void CheckboxLabel::OnPaint(Canvas* canvas)
|
|||
{
|
||||
if (checked)
|
||||
{
|
||||
canvas->fillRect(Rect::xywh(0.0, GetHeight() * 0.5 - 6.0, 10.0, 10.0), Colorf::fromRgba8(100, 100, 100));
|
||||
canvas->fillRect(Rect::xywh(1.0, GetHeight() * 0.5 - 5.0, 8.0, 8.0), Colorf::fromRgba8(51, 51, 51));
|
||||
canvas->fillRect(Rect::xywh(2.0, GetHeight() * 0.5 - 4.0, 6.0, 6.0), Colorf::fromRgba8(226, 223, 219));
|
||||
canvas->fillRect(Rect::xywh(0.0, GetHeight() * 0.5 - 6.0, 10.0, 10.0), GetStyleColor("checked-outer-border-color"));
|
||||
canvas->fillRect(Rect::xywh(1.0, GetHeight() * 0.5 - 5.0, 8.0, 8.0), GetStyleColor("checked-inner-border-color"));
|
||||
canvas->fillRect(Rect::xywh(2.0, GetHeight() * 0.5 - 4.0, 6.0, 6.0), GetStyleColor("checked-color"));
|
||||
}
|
||||
else
|
||||
{
|
||||
canvas->fillRect(Rect::xywh(0.0, GetHeight() * 0.5 - 6.0, 10.0, 10.0), Colorf::fromRgba8(99, 99, 99));
|
||||
canvas->fillRect(Rect::xywh(1.0, GetHeight() * 0.5 - 5.0, 8.0, 8.0), Colorf::fromRgba8(51, 51, 51));
|
||||
canvas->fillRect(Rect::xywh(0.0, GetHeight() * 0.5 - 6.0, 10.0, 10.0), GetStyleColor("unchecked-outer-border-color"));
|
||||
canvas->fillRect(Rect::xywh(1.0, GetHeight() * 0.5 - 5.0, 8.0, 8.0), GetStyleColor("unchecked-inner-border-color"));
|
||||
}
|
||||
|
||||
canvas->drawText(Point(14.0, GetHeight() - 5.0), Colorf::fromRgba8(255, 255, 255), text);
|
||||
canvas->drawText(Point(14.0, GetHeight() - 5.0), GetStyleColor("color"), text);
|
||||
}
|
||||
|
||||
bool CheckboxLabel::OnMouseDown(const Point& pos, InputKey key)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
LineEdit::LineEdit(Widget* parent) : Widget(parent)
|
||||
{
|
||||
SetNoncontentSizes(5.0, 3.0, 5.0, 3.0);
|
||||
SetStyleClass("lineedit");
|
||||
|
||||
timer = new Timer(this);
|
||||
timer->FuncExpired = [=]() { OnTimerExpired(); };
|
||||
|
|
@ -1067,18 +1067,6 @@ std::string LineEdit::GetVisibleTextAfterSelection()
|
|||
}
|
||||
}
|
||||
|
||||
void LineEdit::OnPaintFrame(Canvas* canvas)
|
||||
{
|
||||
double w = GetFrameGeometry().width;
|
||||
double h = GetFrameGeometry().height;
|
||||
Colorf bordercolor = Colorf::fromRgba8(100, 100, 100);
|
||||
canvas->fillRect(Rect::xywh(0.0, 0.0, w, h), Colorf::fromRgba8(38, 38, 38));
|
||||
canvas->fillRect(Rect::xywh(0.0, 0.0, w, 1.0), bordercolor);
|
||||
canvas->fillRect(Rect::xywh(0.0, h - 1.0, w, 1.0), bordercolor);
|
||||
canvas->fillRect(Rect::xywh(0.0, 0.0, 1.0, h - 0.0), bordercolor);
|
||||
canvas->fillRect(Rect::xywh(w - 1.0, 0.0, 1.0, h - 0.0), bordercolor);
|
||||
}
|
||||
|
||||
void LineEdit::OnPaint(Canvas* canvas)
|
||||
{
|
||||
std::string txt_before = GetVisibleTextBeforeSelection();
|
||||
|
|
@ -1101,21 +1089,21 @@ void LineEdit::OnPaint(Canvas* canvas)
|
|||
{
|
||||
// Draw selection box.
|
||||
Rect selection_rect = GetSelectionRect();
|
||||
canvas->fillRect(selection_rect, HasFocus() ? Colorf::fromRgba8(100, 100, 100) : Colorf::fromRgba8(68, 68, 68));
|
||||
canvas->fillRect(selection_rect, HasFocus() ? GetStyleColor("selection-color") : GetStyleColor("no-focus-selection-color"));
|
||||
}
|
||||
|
||||
// Draw text before selection
|
||||
if (!txt_before.empty())
|
||||
{
|
||||
canvas->drawText(Point(0.0, canvas->verticalTextAlign().baseline), Colorf::fromRgba8(255, 255, 255), txt_before);
|
||||
canvas->drawText(Point(0.0, canvas->verticalTextAlign().baseline), GetStyleColor("color"), txt_before);
|
||||
}
|
||||
if (!txt_selected.empty())
|
||||
{
|
||||
canvas->drawText(Point(size_before.width, canvas->verticalTextAlign().baseline), Colorf::fromRgba8(255, 255, 255), txt_selected);
|
||||
canvas->drawText(Point(size_before.width, canvas->verticalTextAlign().baseline), GetStyleColor("color"), txt_selected);
|
||||
}
|
||||
if (!txt_after.empty())
|
||||
{
|
||||
canvas->drawText(Point(size_before.width + size_selected.width, canvas->verticalTextAlign().baseline), Colorf::fromRgba8(255, 255, 255), txt_after);
|
||||
canvas->drawText(Point(size_before.width + size_selected.width, canvas->verticalTextAlign().baseline), GetStyleColor("color"), txt_after);
|
||||
}
|
||||
|
||||
// draw cursor
|
||||
|
|
@ -1124,7 +1112,7 @@ void LineEdit::OnPaint(Canvas* canvas)
|
|||
if (cursor_blink_visible)
|
||||
{
|
||||
Rect cursor_rect = GetCursorRect();
|
||||
canvas->fillRect(cursor_rect, Colorf::fromRgba8(255, 255, 255));
|
||||
canvas->fillRect(cursor_rect, GetStyleColor("color"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
ListView::ListView(Widget* parent) : Widget(parent)
|
||||
{
|
||||
SetNoncontentSizes(10.0, 10.0, 3.0, 10.0);
|
||||
SetStyleClass("listview");
|
||||
|
||||
scrollbar = new Scrollbar(this);
|
||||
scrollbar->FuncScroll = [=]() { OnScrollbarScroll(); };
|
||||
|
|
@ -67,6 +67,9 @@ void ListView::OnPaint(Canvas* canvas)
|
|||
double w = GetWidth() - scrollbar->GetPreferredWidth() - 2.0;
|
||||
double h = 20.0;
|
||||
|
||||
Colorf textColor = GetStyleColor("color");
|
||||
Colorf selectionColor = GetStyleColor("selection-color");
|
||||
|
||||
int index = 0;
|
||||
for (const std::string& item : items)
|
||||
{
|
||||
|
|
@ -75,27 +78,15 @@ void ListView::OnPaint(Canvas* canvas)
|
|||
{
|
||||
if (index == selectedItem)
|
||||
{
|
||||
canvas->fillRect(Rect::xywh(x - 2.0, itemY, w, h), Colorf::fromRgba8(100, 100, 100));
|
||||
canvas->fillRect(Rect::xywh(x - 2.0, itemY, w, h), selectionColor);
|
||||
}
|
||||
canvas->drawText(Point(x, y + 15.0), Colorf::fromRgba8(255, 255, 255), item);
|
||||
canvas->drawText(Point(x, y + 15.0), textColor, item);
|
||||
}
|
||||
y += h;
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
void ListView::OnPaintFrame(Canvas* canvas)
|
||||
{
|
||||
double w = GetFrameGeometry().width;
|
||||
double h = GetFrameGeometry().height;
|
||||
Colorf bordercolor = Colorf::fromRgba8(100, 100, 100);
|
||||
canvas->fillRect(Rect::xywh(0.0, 0.0, w, h), Colorf::fromRgba8(38, 38, 38));
|
||||
canvas->fillRect(Rect::xywh(0.0, 0.0, w, 1.0), bordercolor);
|
||||
canvas->fillRect(Rect::xywh(0.0, h - 1.0, w, 1.0), bordercolor);
|
||||
canvas->fillRect(Rect::xywh(0.0, 0.0, 1.0, h - 0.0), bordercolor);
|
||||
canvas->fillRect(Rect::xywh(w - 1.0, 0.0, 1.0, h - 0.0), bordercolor);
|
||||
}
|
||||
|
||||
bool ListView::OnMouseDown(const Point& pos, InputKey key)
|
||||
{
|
||||
SetFocus();
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
PushButton::PushButton(Widget* parent) : Widget(parent)
|
||||
{
|
||||
SetNoncontentSizes(10.0, 5.0, 10.0, 5.0);
|
||||
SetStyleClass("pushbutton");
|
||||
}
|
||||
|
||||
void PushButton::SetText(const std::string& value)
|
||||
|
|
@ -25,52 +25,32 @@ double PushButton::GetPreferredHeight() const
|
|||
return 30.0;
|
||||
}
|
||||
|
||||
void PushButton::OnPaintFrame(Canvas* canvas)
|
||||
{
|
||||
double w = GetFrameGeometry().width;
|
||||
double h = GetFrameGeometry().height;
|
||||
Colorf bordercolor = Colorf::fromRgba8(100, 100, 100);
|
||||
Colorf buttoncolor = Colorf::fromRgba8(68, 68, 68);
|
||||
if (buttonDown)
|
||||
buttoncolor = Colorf::fromRgba8(88, 88, 88);
|
||||
else if (hot)
|
||||
buttoncolor = Colorf::fromRgba8(78, 78, 78);
|
||||
canvas->fillRect(Rect::xywh(0.0, 0.0, w, h), buttoncolor);
|
||||
canvas->fillRect(Rect::xywh(0.0, 0.0, w, 1.0), bordercolor);
|
||||
canvas->fillRect(Rect::xywh(0.0, h - 1.0, w, 1.0), bordercolor);
|
||||
canvas->fillRect(Rect::xywh(0.0, 0.0, 1.0, h - 0.0), bordercolor);
|
||||
canvas->fillRect(Rect::xywh(w - 1.0, 0.0, 1.0, h - 0.0), bordercolor);
|
||||
}
|
||||
|
||||
void PushButton::OnPaint(Canvas* canvas)
|
||||
{
|
||||
Rect box = canvas->measureText(text);
|
||||
canvas->drawText(Point((GetWidth() - box.width) * 0.5, GetHeight() - 5.0), Colorf::fromRgba8(255, 255, 255), text);
|
||||
canvas->drawText(Point((GetWidth() - box.width) * 0.5, GetHeight() - 5.0), GetStyleColor("color"), text);
|
||||
}
|
||||
|
||||
void PushButton::OnMouseMove(const Point& pos)
|
||||
{
|
||||
if (!hot)
|
||||
if (GetStyleState().empty())
|
||||
{
|
||||
hot = true;
|
||||
Update();
|
||||
SetStyleState("hover");
|
||||
}
|
||||
}
|
||||
|
||||
bool PushButton::OnMouseDown(const Point& pos, InputKey key)
|
||||
{
|
||||
SetFocus();
|
||||
buttonDown = true;
|
||||
Update();
|
||||
SetStyleState("down");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PushButton::OnMouseUp(const Point& pos, InputKey key)
|
||||
{
|
||||
if (buttonDown)
|
||||
if (GetStyleState() == "down")
|
||||
{
|
||||
buttonDown = false;
|
||||
hot = false;
|
||||
SetStyleState("");
|
||||
Repaint();
|
||||
Click();
|
||||
}
|
||||
|
|
@ -79,16 +59,14 @@ bool PushButton::OnMouseUp(const Point& pos, InputKey key)
|
|||
|
||||
void PushButton::OnMouseLeave()
|
||||
{
|
||||
hot = false;
|
||||
buttonDown = false;
|
||||
Update();
|
||||
SetStyleState("");
|
||||
}
|
||||
|
||||
void PushButton::OnKeyDown(InputKey key)
|
||||
{
|
||||
if (key == InputKey::Space || key == InputKey::Enter)
|
||||
{
|
||||
buttonDown = true;
|
||||
SetStyleState("down");
|
||||
Update();
|
||||
}
|
||||
}
|
||||
|
|
@ -97,8 +75,7 @@ void PushButton::OnKeyUp(InputKey key)
|
|||
{
|
||||
if (key == InputKey::Space || key == InputKey::Enter)
|
||||
{
|
||||
buttonDown = false;
|
||||
hot = false;
|
||||
SetStyleState("");
|
||||
Repaint();
|
||||
Click();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
Scrollbar::Scrollbar(Widget* parent) : Widget(parent)
|
||||
{
|
||||
SetStyleClass("scrollbar");
|
||||
UpdatePartPositions();
|
||||
|
||||
mouse_down_timer = new Timer(this);
|
||||
|
|
@ -294,8 +295,8 @@ void Scrollbar::OnPaint(Canvas* canvas)
|
|||
part_button_increment.render_box(canvas, rect_button_increment);
|
||||
*/
|
||||
|
||||
canvas->fillRect(Rect::shrink(Rect::xywh(0.0, 0.0, GetWidth(), GetHeight()), 4.0, 0.0, 4.0, 0.0), Colorf::fromRgba8(33, 33, 33));
|
||||
canvas->fillRect(Rect::shrink(rect_thumb, 4.0, 0.0, 4.0, 0.0), Colorf::fromRgba8(58, 58, 58));
|
||||
canvas->fillRect(Rect::shrink(Rect::xywh(0.0, 0.0, GetWidth(), GetHeight()), 4.0, 0.0, 4.0, 0.0), GetStyleColor("track-color"));
|
||||
canvas->fillRect(Rect::shrink(rect_thumb, 4.0, 0.0, 4.0, 0.0), GetStyleColor("thumb-color"));
|
||||
}
|
||||
|
||||
// Calculates positions of all parts. Returns true if thumb position was changed compared to previously, false otherwise.
|
||||
|
|
|
|||
|
|
@ -98,10 +98,6 @@ void TabWidget::OnBarCurrentChanged()
|
|||
OnCurrentChanged();
|
||||
}
|
||||
|
||||
void TabWidget::OnPaintFrame(Canvas* canvas)
|
||||
{
|
||||
}
|
||||
|
||||
void TabWidget::OnGeometryChanged()
|
||||
{
|
||||
double w = GetWidth();
|
||||
|
|
@ -115,7 +111,7 @@ void TabWidget::OnGeometryChanged()
|
|||
|
||||
TabBar::TabBar(Widget* parent) : Widget(parent)
|
||||
{
|
||||
SetNoncontentSizes(20.0, 0.0, 20.0, 0.0);
|
||||
SetStyleClass("tabbar");
|
||||
}
|
||||
|
||||
int TabBar::AddTab(const std::string& label)
|
||||
|
|
@ -187,13 +183,6 @@ int TabBar::GetTabIndex(TabBarTab* tab)
|
|||
return -1;
|
||||
}
|
||||
|
||||
void TabBar::OnPaintFrame(Canvas* canvas)
|
||||
{
|
||||
double w = GetFrameGeometry().width;
|
||||
double h = GetFrameGeometry().height;
|
||||
canvas->fillRect(Rect::xywh(0.0, 0.0, w, h), Colorf::fromRgba8(38, 38, 38));
|
||||
}
|
||||
|
||||
void TabBar::OnGeometryChanged()
|
||||
{
|
||||
double w = GetWidth();
|
||||
|
|
@ -211,7 +200,7 @@ void TabBar::OnGeometryChanged()
|
|||
|
||||
TabBarTab::TabBarTab(Widget* parent) : Widget(parent)
|
||||
{
|
||||
SetNoncontentSizes(15.0, 0.0, 15.0, 0.0);
|
||||
SetStyleClass("tabbar-tab");
|
||||
}
|
||||
|
||||
void TabBarTab::SetText(const std::string& text)
|
||||
|
|
@ -257,7 +246,7 @@ void TabBarTab::SetCurrent(bool value)
|
|||
if (IsCurrent != value)
|
||||
{
|
||||
IsCurrent = value;
|
||||
Update();
|
||||
SetStyleState(value ? "active" : "");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -268,20 +257,6 @@ double TabBarTab::GetPreferredWidth() const
|
|||
return x;
|
||||
}
|
||||
|
||||
void TabBarTab::OnPaintFrame(Canvas* canvas)
|
||||
{
|
||||
double w = GetFrameGeometry().width;
|
||||
double h = GetFrameGeometry().height;
|
||||
if (IsCurrent)
|
||||
{
|
||||
canvas->fillRect(Rect::xywh(0.0, 0.0, w, h), Colorf::fromRgba8(51, 51, 51));
|
||||
}
|
||||
else if (hot)
|
||||
{
|
||||
canvas->fillRect(Rect::xywh(0.0, 0.0, w, h), Colorf::fromRgba8(45, 45, 45));
|
||||
}
|
||||
}
|
||||
|
||||
void TabBarTab::OnGeometryChanged()
|
||||
{
|
||||
double x = 0.0;
|
||||
|
|
@ -300,10 +275,9 @@ void TabBarTab::OnGeometryChanged()
|
|||
|
||||
void TabBarTab::OnMouseMove(const Point& pos)
|
||||
{
|
||||
if (!hot)
|
||||
if (GetStyleState().empty())
|
||||
{
|
||||
hot = true;
|
||||
Update();
|
||||
SetStyleState("hover");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -321,7 +295,8 @@ bool TabBarTab::OnMouseUp(const Point& pos, InputKey key)
|
|||
|
||||
void TabBarTab::OnMouseLeave()
|
||||
{
|
||||
hot = false;
|
||||
if (GetStyleState() == "hover")
|
||||
SetStyleState("");
|
||||
Update();
|
||||
}
|
||||
|
||||
|
|
@ -329,7 +304,7 @@ void TabBarTab::OnMouseLeave()
|
|||
|
||||
TabWidgetStack::TabWidgetStack(Widget* parent) : Widget(parent)
|
||||
{
|
||||
SetNoncontentSizes(20.0, 5.0, 20.0, 5.0);
|
||||
SetStyleClass("tabwidget-stack");
|
||||
}
|
||||
|
||||
void TabWidgetStack::SetCurrentWidget(Widget* widget)
|
||||
|
|
@ -347,10 +322,6 @@ void TabWidgetStack::SetCurrentWidget(Widget* widget)
|
|||
}
|
||||
}
|
||||
|
||||
void TabWidgetStack::OnPaintFrame(Canvas* canvas)
|
||||
{
|
||||
}
|
||||
|
||||
void TabWidgetStack::OnGeometryChanged()
|
||||
{
|
||||
if (CurrentWidget)
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
TextEdit::TextEdit(Widget* parent) : Widget(parent)
|
||||
{
|
||||
SetNoncontentSizes(8.0, 8.0, 8.0, 8.0);
|
||||
SetStyleClass("textedit");
|
||||
|
||||
timer = new Timer(this);
|
||||
timer->FuncExpired = [=]() { OnTimerExpired(); };
|
||||
|
|
@ -961,6 +961,7 @@ void TextEdit::LayoutLines(Canvas* canvas)
|
|||
sel_end = selection_start;
|
||||
}
|
||||
|
||||
Colorf textColor = GetStyleColor("color");
|
||||
Point draw_pos;
|
||||
for (size_t i = (size_t)vert_scrollbar->GetPosition(); i < lines.size(); i++)
|
||||
{
|
||||
|
|
@ -969,9 +970,9 @@ void TextEdit::LayoutLines(Canvas* canvas)
|
|||
{
|
||||
line.layout.Clear();
|
||||
if (!line.text.empty())
|
||||
line.layout.AddText(line.text, font, Colorf::fromRgba8(255, 255, 255));
|
||||
line.layout.AddText(line.text, font, textColor);
|
||||
else
|
||||
line.layout.AddText(" ", font, Colorf::fromRgba8(255, 255, 255)); // Draw one space character to get the correct height
|
||||
line.layout.AddText(" ", font, textColor); // Draw one space character to get the correct height
|
||||
line.layout.Layout(canvas, GetWidth());
|
||||
line.box = Rect(draw_pos, line.layout.GetSize());
|
||||
line.invalidated = false;
|
||||
|
|
@ -992,7 +993,7 @@ void TextEdit::LayoutLines(Canvas* canvas)
|
|||
if (cursor_blink_visible && cursor_pos.y == i)
|
||||
{
|
||||
line.layout.SetCursorPos(cursor_pos.x);
|
||||
line.layout.SetCursorColor(Colorf::fromRgba8(255, 255, 255));
|
||||
line.layout.SetCursorColor(textColor);
|
||||
line.layout.ShowCursor();
|
||||
}
|
||||
}
|
||||
|
|
@ -1006,18 +1007,6 @@ void TextEdit::LayoutLines(Canvas* canvas)
|
|||
UpdateVerticalScroll();
|
||||
}
|
||||
|
||||
void TextEdit::OnPaintFrame(Canvas* canvas)
|
||||
{
|
||||
double w = GetFrameGeometry().width;
|
||||
double h = GetFrameGeometry().height;
|
||||
Colorf bordercolor = Colorf::fromRgba8(100, 100, 100);
|
||||
canvas->fillRect(Rect::xywh(0.0, 0.0, w, h), Colorf::fromRgba8(38, 38, 38));
|
||||
canvas->fillRect(Rect::xywh(0.0, 0.0, w, 1.0), bordercolor);
|
||||
canvas->fillRect(Rect::xywh(0.0, h - 1.0, w, 1.0), bordercolor);
|
||||
canvas->fillRect(Rect::xywh(0.0, 0.0, 1.0, h - 0.0), bordercolor);
|
||||
canvas->fillRect(Rect::xywh(w - 1.0, 0.0, 1.0, h - 0.0), bordercolor);
|
||||
}
|
||||
|
||||
void TextEdit::OnPaint(Canvas* canvas)
|
||||
{
|
||||
LayoutLines(canvas);
|
||||
|
|
|
|||
|
|
@ -56,5 +56,5 @@ void TextLabel::OnPaint(Canvas* canvas)
|
|||
x = GetWidth() - canvas->measureText(text).width;
|
||||
}
|
||||
|
||||
canvas->drawText(Point(x, GetHeight() - 5.0), Colorf::fromRgba8(255, 255, 255), text);
|
||||
canvas->drawText(Point(x, GetHeight() - 5.0), GetStyleColor("color"), text);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue