2022-07-15 15:37:19 +00:00
|
|
|
#include "Label.hpp"
|
|
|
|
#include "StaticBox.hpp"
|
|
|
|
|
|
|
|
wxFont Label::sysFont(int size, bool bold)
|
|
|
|
{
|
2022-09-21 11:44:18 +00:00
|
|
|
//#ifdef __linux__
|
|
|
|
// return wxFont{};
|
|
|
|
//#endif
|
|
|
|
#ifndef __APPLE__
|
2022-07-15 15:37:19 +00:00
|
|
|
size = size * 4 / 5;
|
|
|
|
#endif
|
2022-09-21 11:44:18 +00:00
|
|
|
|
2022-07-15 15:37:19 +00:00
|
|
|
auto face = wxString::FromUTF8("HarmonyOS Sans SC");
|
|
|
|
wxFont font{size, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, bold ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL, false, face};
|
|
|
|
font.SetFaceName(face);
|
|
|
|
if (!font.IsOk()) {
|
|
|
|
font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
|
|
|
|
if (bold) font.MakeBold();
|
|
|
|
font.SetPointSize(size);
|
|
|
|
}
|
|
|
|
return font;
|
|
|
|
}
|
2022-09-21 11:44:18 +00:00
|
|
|
wxFont Label::Head_24;
|
|
|
|
wxFont Label::Head_20;
|
|
|
|
wxFont Label::Head_18;
|
|
|
|
wxFont Label::Head_16;
|
|
|
|
wxFont Label::Head_15;
|
|
|
|
wxFont Label::Head_14;
|
|
|
|
wxFont Label::Head_13;
|
|
|
|
wxFont Label::Head_12;
|
|
|
|
wxFont Label::Head_10;
|
|
|
|
|
|
|
|
wxFont Label::Body_16;
|
|
|
|
wxFont Label::Body_15;
|
|
|
|
wxFont Label::Body_14;
|
|
|
|
wxFont Label::Body_13;
|
|
|
|
wxFont Label::Body_12;
|
|
|
|
wxFont Label::Body_11;
|
|
|
|
wxFont Label::Body_10;
|
|
|
|
wxFont Label::Body_9;
|
2022-07-15 15:37:19 +00:00
|
|
|
|
2022-09-21 11:44:18 +00:00
|
|
|
void Label::initSysFont()
|
|
|
|
{
|
|
|
|
Head_24 = Label::sysFont(24, true);
|
|
|
|
Head_20 = Label::sysFont(20, true);
|
|
|
|
Head_18 = Label::sysFont(18, true);
|
|
|
|
Head_16 = Label::sysFont(16, true);
|
|
|
|
Head_15 = Label::sysFont(15, true);
|
|
|
|
Head_14 = Label::sysFont(14, true);
|
|
|
|
Head_13 = Label::sysFont(13, true);
|
|
|
|
Head_12 = Label::sysFont(12, true);
|
|
|
|
Head_10 = Label::sysFont(10, true);
|
|
|
|
|
|
|
|
Body_16 = Label::sysFont(16, false);
|
|
|
|
Body_15 = Label::sysFont(15, false);
|
|
|
|
Body_14 = Label::sysFont(14, false);
|
|
|
|
Body_13 = Label::sysFont(13, false);
|
|
|
|
Body_12 = Label::sysFont(12, false);
|
|
|
|
Body_11 = Label::sysFont(11, false);
|
|
|
|
Body_10 = Label::sysFont(10, false);
|
|
|
|
Body_9 = Label::sysFont(9, false);
|
|
|
|
}
|
2022-07-22 09:46:10 +00:00
|
|
|
|
|
|
|
wxSize Label::split_lines(wxDC &dc, int width, const wxString &text, wxString &multiline_text)
|
|
|
|
{
|
|
|
|
multiline_text = text;
|
|
|
|
if (width > 0 && dc.GetTextExtent(text).x > width) {
|
|
|
|
size_t start = 0;
|
|
|
|
while (true) {
|
|
|
|
size_t idx = size_t(-1);
|
|
|
|
for (size_t i = start; i < multiline_text.Len(); i++) {
|
|
|
|
if (multiline_text[i] == ' ') {
|
|
|
|
if (dc.GetTextExtent(multiline_text.SubString(start, i)).x < width)
|
|
|
|
idx = i;
|
|
|
|
else {
|
|
|
|
if (idx == size_t(-1)) idx = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (idx == size_t(-1)) break;
|
|
|
|
multiline_text[idx] = '\n';
|
|
|
|
start = idx + 1;
|
|
|
|
if (dc.GetTextExtent(multiline_text.Mid(start)).x < width) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return dc.GetMultiLineTextExtent(multiline_text);
|
|
|
|
}
|
2022-07-15 15:37:19 +00:00
|
|
|
|
2022-09-09 07:05:59 +00:00
|
|
|
Label::Label(wxWindow *parent, wxString const &text, long style) : Label(parent, Body_14, text, style) {}
|
2022-07-15 15:37:19 +00:00
|
|
|
|
2022-09-09 07:05:59 +00:00
|
|
|
Label::Label(wxWindow *parent, wxFont const &font, wxString const &text, long style)
|
|
|
|
: wxStaticText(parent, wxID_ANY, text, wxDefaultPosition, wxDefaultSize, style)
|
2022-07-15 15:37:19 +00:00
|
|
|
{
|
2022-09-09 07:05:59 +00:00
|
|
|
this->font = font;
|
2022-07-15 15:37:19 +00:00
|
|
|
SetFont(font);
|
2022-08-09 09:33:13 +00:00
|
|
|
SetBackgroundColour(StaticBox::GetParentBackgroundColor(parent));
|
2022-10-19 05:35:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Label::SetLabel(const wxString& label)
|
|
|
|
{
|
|
|
|
if (GetLabel() == label)
|
|
|
|
return;
|
|
|
|
wxStaticText::SetLabel(label);
|
|
|
|
#ifdef __WXOSX__
|
|
|
|
if ((GetWindowStyle() & LB_HYPERLINK)) {
|
|
|
|
SetLabelMarkup(label);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2022-09-09 07:05:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Label::SetWindowStyleFlag(long style)
|
|
|
|
{
|
2022-10-11 06:52:48 +00:00
|
|
|
if (style == GetWindowStyle())
|
|
|
|
return;
|
2022-09-09 07:05:59 +00:00
|
|
|
wxStaticText::SetWindowStyleFlag(style);
|
|
|
|
if (style & LB_HYPERLINK) {
|
|
|
|
this->color = GetForegroundColour();
|
|
|
|
static wxColor clr_url("#00AE42");
|
2022-10-19 05:35:04 +00:00
|
|
|
SetFont(this->font.Underlined());
|
2022-09-09 07:05:59 +00:00
|
|
|
SetForegroundColour(clr_url);
|
2022-10-19 05:35:04 +00:00
|
|
|
SetCursor(wxCURSOR_HAND);
|
|
|
|
#ifdef __WXOSX__
|
|
|
|
SetLabelMarkup(GetLabel());
|
|
|
|
#endif
|
2022-09-09 07:05:59 +00:00
|
|
|
} else {
|
|
|
|
SetForegroundColour(this->color);
|
|
|
|
SetFont(this->font);
|
2022-10-19 05:35:04 +00:00
|
|
|
SetCursor(wxCURSOR_ARROW);
|
|
|
|
#ifdef __WXOSX__
|
|
|
|
auto label = GetLabel();
|
|
|
|
wxStaticText::SetLabel({});
|
|
|
|
wxStaticText::SetLabel(label);
|
|
|
|
#endif
|
2022-09-09 07:05:59 +00:00
|
|
|
}
|
|
|
|
Refresh();
|
2022-07-15 15:37:19 +00:00
|
|
|
}
|