From 42e87852eb9fd894cf7ad0989fd2a1cc2c164a89 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 16 Oct 2025 23:54:39 +0200 Subject: [PATCH] Add Edit::ToggleLineNumbers() to the sample Make it a bit simpler to show line numbers when showing the minimap. --- samples/stc/edit.cpp | 4 ++++ samples/stc/edit.h | 3 +++ samples/stc/stctest.cpp | 4 ++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/samples/stc/edit.cpp b/samples/stc/edit.cpp index 127615d33f..b2cf3c68ba 100644 --- a/samples/stc/edit.cpp +++ b/samples/stc/edit.cpp @@ -320,6 +320,10 @@ void Edit::OnIndentGuide (wxCommandEvent &WXUNUSED(event)) { } void Edit::OnLineNumber (wxCommandEvent &WXUNUSED(event)) { + ToggleLineNumbers(); +} + +void Edit::ToggleLineNumbers() { SetMarginWidth (m_LineNrID, GetMarginWidth (m_LineNrID) == 0? m_LineNrMargin: 0); } diff --git a/samples/stc/edit.h b/samples/stc/edit.h index c02d8e489e..b8a331f81d 100644 --- a/samples/stc/edit.h +++ b/samples/stc/edit.h @@ -131,6 +131,9 @@ public: wxString GetFilename () {return m_filename;} void SetFilename (const wxString &filename) {m_filename = filename;} + // Toggle showing line numbers in the margin. + void ToggleLineNumbers(); + private: // file wxString m_filename; diff --git a/samples/stc/stctest.cpp b/samples/stc/stctest.cpp index 95c5241636..a19f53ac5d 100644 --- a/samples/stc/stctest.cpp +++ b/samples/stc/stctest.cpp @@ -1616,8 +1616,8 @@ void App::ShowDocumentMap(wxWindow* parent) auto* const edit = new Edit(splitter); edit->LoadFile("stctest.cpp"); - // Show line numbers and hide the other margins not used here. - edit->SetMarginWidth(0, edit->GetTextExtent("99999").x); + // Show line numbers in the margin, which are hidden by default. + edit->ToggleLineNumbers(); edit->SetWrapMode(wxSTC_WRAP_WORD); edit->SetWrapVisualFlags(wxSTC_WRAPVISUALFLAG_END);