Skip to content

Commit

Permalink
Minor toolbar button fixes and tweaks
Browse files Browse the repository at this point in the history
- Fix potential crash on opening recent file from start page
- Increase rounding slightly on edge of toolbar buttons
  • Loading branch information
sirjuddington committed Nov 1, 2024
1 parent 5378db9 commit 5b29249
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/MainEditor/UI/StartPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ class RecentFileButton : public SToolBarButton
filename_{ path.fileName() }
{
action_wx_id_offset_ = index;
click_can_delete_ = true;

wxWindow::SetBackgroundColour(backgroundColour());
wxWindow::SetForegroundColour(wxColour(app::isDarkTheme() ? LINK_COLOUR_DARK : LINK_COLOUR_LIGHT));
Expand Down
11 changes: 7 additions & 4 deletions src/UI/SToolBar/SToolBarButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,15 +320,15 @@ void SToolBarButton::drawContent(wxGraphicsContext* gc, bool mouse_over)
auto width_inner = width - (2. * pad_outer_);
auto height = GetSize().y;
auto height_inner = height - (2. * pad_outer_);
auto scale_px = 1;
auto scale_px = FromDIP(2);

// Draw toggled border/background
if (isChecked())
{
// Draw border
gc->SetBrush(*wxTRANSPARENT_BRUSH);
gc->SetPen(wxPen(col_hilight, scale_px));
gc->DrawRoundedRectangle(pad_outer_, pad_outer_, width_inner, height_inner, 1);
gc->DrawRoundedRectangle(pad_outer_, pad_outer_, width_inner, height_inner, FromDIP(2));
}

// Draw border on mouseover
Expand All @@ -345,7 +345,7 @@ void SToolBarButton::drawContent(wxGraphicsContext* gc, bool mouse_over)
// Draw border
gc->SetBrush(col_trans);
gc->SetPen(*wxTRANSPARENT_PEN);
gc->DrawRoundedRectangle(pad_outer_, pad_outer_, width_inner, height_inner, 1);
gc->DrawRoundedRectangle(pad_outer_, pad_outer_, width_inner, height_inner, FromDIP(2));
}

auto icon = icon_.GetBitmapFor(this);
Expand Down Expand Up @@ -496,6 +496,9 @@ void SToolBarButton::onMouseEvent(wxMouseEvent& e)
else
sendClickedEvent();

if (click_can_delete_)
return;

pressed_ = false;
refresh = true;
}
Expand All @@ -505,7 +508,7 @@ void SToolBarButton::onMouseEvent(wxMouseEvent& e)
parent_window->SetStatusText("");
}

if (refresh && !IsBeingDeleted())
if (refresh)
{
Update();
Refresh();
Expand Down
6 changes: 6 additions & 0 deletions src/UI/SToolBar/SToolBarButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ class SToolBarButton : public wxControl
int text_offset_ = 0; // Space between icon and text
bool exact_fit_ = true;

// Recent file buttons on the start page can potentially be deleted after
// being clicked (as the recent file list is updated). This is needed to
// avoid crashes due to the button being deleted while still executing the
// mouse event handler.
bool click_can_delete_ = false;

void setup(bool show_name, string_view icon);
void sendClickedEvent();
void updateSize();
Expand Down

0 comments on commit 5b29249

Please sign in to comment.