--- nono/wx/wxlogsetting.cpp 2026/04/29 17:05:16 1.1.1.2 +++ nono/wx/wxlogsetting.cpp 2026/04/29 17:05:58 1.1.1.6 @@ -10,7 +10,6 @@ #include "wxlogsetting.h" #include "wxbutton.h" -#include "wxcolor.h" #include "wxtextscreen.h" #include "mainapp.h" #include @@ -21,7 +20,7 @@ enum { ID_BUTTON0 = IDGROUP_LOGSETTING, - ID_local_end = ID_BUTTON0 + 50 * 2, // 適当 + ID_local_end = ID_BUTTON0 + 100 * 2, // 適当 }; static_assert(ID_local_end - 1 <= (int)IDGROUP_LOGSETTING_END, "ID exceeded"); @@ -29,6 +28,8 @@ static_assert(ID_local_end - 1 <= (int)I WXLogSettingPanel::WXLogSettingPanel(wxWindow *parent) : inherited(parent) { + SetName("LogSettingPanel"); + // エイリアスを持つオブジェクトだけ抜き出す for (const auto obj : gMainApp.GetObjects()) { if (obj->GetAliases().empty() == false) { @@ -66,15 +67,12 @@ WXLogSettingPanel::WXLogSettingPanel(wxW buttons.push_back(btn); // イベントを接続 - btn->Connect(NONO_EVT_BUTTON, - wxCommandEventHandler(WXLogSettingPanel::OnButton), NULL, this); + btn->Bind(NONO_EVT_BUTTON, &WXLogSettingPanel::OnButton, this); } // Sizer 使わず自前でレイアウトする。 SetAutoLayout(true); - FontChanged(); - Layout(); } // デストラクタ @@ -97,16 +95,39 @@ WXLogSettingPanel::Row2PY(int row) const return row * (GetFontHeight() + 4) + Padding; } -bool -WXLogSettingPanel::Layout() +// フォントサイズ変更 +void +WXLogSettingPanel::FontChanged() { - if (inherited::Layout() == false) { - return false; + inherited::FontChanged(); + + // 子コントロールに伝搬。 + for (auto *btn : buttons) { + btn->FontChanged(); } - FontChanged(); + Fit(); +} + +void +WXLogSettingPanel::Fit() +{ + // 行数×桁数を基本とする + int col = maxnamelen + 10; + int row = objs.size() + 1; + wxSize size(Col2PX(col) + Padding, Row2PY(row) + Padding); + + // バックバッファのサイズを固定。 + SetMinBitmapSize(size); + + SetSize(size); +} - // ボタンを配置 +bool +WXLogSettingPanel::Layout() +{ + // ボタンを再配置。 + wxSize btnsize(GetFontWidth() * 2 + 4, GetFontHeight() + 4); for (int i = 0, end = buttons.size(); i < end; i++) { int x; if (i % 2 == 0) { @@ -115,36 +136,12 @@ WXLogSettingPanel::Layout() x = Col2PX(maxnamelen + 8) - 2; } int y = Row2PY((i / 2) + 1); - buttons[i]->SetPosition(wxPoint(x - 2, y - 2)); + buttons[i]->SetSize(x - 2, y - 2, btnsize.x, btnsize.y); } return true; } -// フォントサイズ変更 -void -WXLogSettingPanel::FontChanged() -{ - inherited::FontChanged(); - - // 行数×桁数を基本とする - int col = maxnamelen + 10; - int row = objs.size() + 1; - - int width = Col2PX(col) + Padding; - int height = Row2PY(row) + Padding; - SetClientSize(width, height); - SetMinClientSize(wxSize(width, height)); - - // ボタンのサイズを変更 - wxSize sz(GetFontWidth() * 2 + 4, GetFontHeight() + 4); - for (auto *btn : buttons) { - btn->SetClientSize(sz); - btn->SetMinClientSize(sz); - btn->FontChanged(); - } -} - // 描画本体 void WXLogSettingPanel::Draw() @@ -249,9 +246,8 @@ WXLogSettingPanel::OnButton(wxCommandEve WXLogSettingWindow::WXLogSettingWindow(wxWindow *parent) : inherited(parent, wxID_ANY, _("Log Level Setting")) { - panel = new WXLogSettingPanel(this); - - DoSize(); + new WXLogSettingPanel(this); + Fit(); } // デストラクタ