Skip to content

Commit

Permalink
UI: UIHyperLink improvements
Browse files Browse the repository at this point in the history
- fixed AutoSize (using UILabel's code)
- added Callback for click
  • Loading branch information
gildor2 committed Sep 16, 2019
1 parent 4719543 commit b0574c8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
24 changes: 12 additions & 12 deletions UI/BaseDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,19 +601,9 @@ void UILabel::Create(UICreateContext& ctx)

UIHyperLink::UIHyperLink(const char* text, const char* link /*, ETextAlign align*/)
: UILabel(text /*, align*/)
, Link(link)
, Link(link ? link : "")
{}

void UIHyperLink::UpdateSize(UIBaseDialog* dialog)
{
if (MinWidth == 0)
{
int labelWidth;
MeasureTextSize(*Label, &labelWidth, NULL, dialog->GetWnd());
MinWidth = labelWidth;
}
}

void UIHyperLink::Create(UICreateContext& ctx)
{
Id = ctx.dialog->GenerateDialogId();
Expand Down Expand Up @@ -650,9 +640,19 @@ void UIHyperLink::Create(UICreateContext& ctx)

bool UIHyperLink::HandleCommand(int id, int cmd, LPARAM lParam)
{
// Note: disabled control will display blue hyper link anyway. To override that, should use extra code
// https://social.msdn.microsoft.com/Forums/vstudio/en-US/bd54bd30-e21f-4dc7-a77f-88de02c63f72/changing-link-label-color-for-syslink?forum=vcgeneral

if (cmd == NM_CLICK || cmd == NM_RETURN || cmd == STN_CLICKED) // STN_CLICKED for WC_STATIC fallback
{
ShellExecute(NULL, "open", *Link, NULL, NULL, SW_SHOW);
if (Callback)
{
Callback(this);
}
else if (!Link.IsEmpty())
{
ShellExecute(NULL, "open", *Link, NULL, NULL, SW_SHOW);
}
}
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions UI/BaseDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,14 +391,14 @@ class UILabel : public UIElement
class UIHyperLink : public UILabel
{
DECLARE_UI_CLASS(UIHyperLink, UILabel);
DECLARE_CALLBACK(Callback);
public:
UIHyperLink(const char* text, const char* link /*, ETextAlign align = TA_Left*/); // align is not working
UIHyperLink(const char* text, const char* link = NULL /*, ETextAlign align = TA_Left*/); // align is not working
UIHyperLink& SetAutoSize() { return (ThisClass&)Super::SetAutoSize(); }

protected:
FString Link;

virtual void UpdateSize(UIBaseDialog* dialog) override;
virtual void Create(UICreateContext& ctx) override;
virtual bool HandleCommand(int id, int cmd, LPARAM lParam) override;
};
Expand Down

0 comments on commit b0574c8

Please sign in to comment.