refactor(ui): adopt material::IconButton for the idle/scale/gpu mining toggles
Follow-up to c83348a: convert the three mining solo-mode header toggles
(idle-mining, thread-scaling, gpu-aware) from the hand-rolled "draw active
pill + glyph, then hit-test" idiom to material::IconButton using the restBg
(active-pill) path. Each keeps its exact behavior pixel-for-pixel: a circular
Primary-tinted pill when active (alpha 60 idle / 40 scale+gpu), a state-colored
glyph (Primary when on, muted when off), hand cursor + tooltip on hover, and
the idle button's cursor save/restore (savedCur, restored at block end) is
preserved. Completes the clean icon-button adoption; the raw-rect IsRectHovered
sites remain intentionally separate (different hit mechanism).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -124,31 +124,17 @@ void RenderMiningControls(App* app, const WalletState& state, const MiningInfo&
|
|||||||
float btnX = idleRightEdge - btnSz;
|
float btnX = idleRightEdge - btnSz;
|
||||||
float btnY = curY + (headerH - btnSz) * 0.5f;
|
float btnY = curY + (headerH - btnSz) * 0.5f;
|
||||||
|
|
||||||
// Pill background when active
|
// Idle toggle: active pill + state-colored glyph (cursor saved/restored at block end).
|
||||||
if (idleOn) {
|
material::IconButtonStyle st;
|
||||||
dl->AddRectFilled(ImVec2(btnX, btnY), ImVec2(btnX + btnSz, btnY + btnSz),
|
st.color = idleOn ? Primary() : OnSurfaceDisabled();
|
||||||
WithAlpha(Primary(), 60), btnSz * 0.5f);
|
st.restBg = idleOn ? WithAlpha(Primary(), 60) : 0;
|
||||||
}
|
st.tooltip = idleOn ? TR("mining_idle_on_tooltip") : TR("mining_idle_off_tooltip");
|
||||||
|
|
||||||
// Icon centered in button
|
|
||||||
ImVec2 icoSz = icoFont->CalcTextSizeA(icoFont->LegacySize, FLT_MAX, 0, idleIcon);
|
|
||||||
ImU32 icoCol = idleOn ? Primary() : OnSurfaceDisabled();
|
|
||||||
dl->AddText(icoFont, icoFont->LegacySize,
|
|
||||||
ImVec2(btnX + (btnSz - icoSz.x) * 0.5f, btnY + (btnSz - icoSz.y) * 0.5f),
|
|
||||||
icoCol, idleIcon);
|
|
||||||
|
|
||||||
// Click target (save/restore cursor so layout is unaffected)
|
|
||||||
ImVec2 savedCur = ImGui::GetCursorScreenPos();
|
ImVec2 savedCur = ImGui::GetCursorScreenPos();
|
||||||
ImGui::SetCursorScreenPos(ImVec2(btnX, btnY));
|
ImGui::SetCursorScreenPos(ImVec2(btnX, btnY));
|
||||||
ImGui::InvisibleButton("##IdleMining", ImVec2(btnSz, btnSz));
|
if (material::IconButton("##IdleMining", idleIcon, icoFont, ImVec2(btnSz, btnSz), st)) {
|
||||||
if (ImGui::IsItemClicked()) {
|
|
||||||
app->settings()->setMineWhenIdle(!idleOn);
|
app->settings()->setMineWhenIdle(!idleOn);
|
||||||
app->settings()->save();
|
app->settings()->save();
|
||||||
}
|
}
|
||||||
if (ImGui::IsItemHovered()) {
|
|
||||||
ImGui::SetMouseCursor(ImGuiMouseCursor_Hand);
|
|
||||||
material::Tooltip("%s", idleOn ? TR("mining_idle_on_tooltip") : TR("mining_idle_off_tooltip"));
|
|
||||||
}
|
|
||||||
|
|
||||||
idleRightEdge = btnX - 4.0f * dp;
|
idleRightEdge = btnX - 4.0f * dp;
|
||||||
|
|
||||||
@@ -157,30 +143,16 @@ void RenderMiningControls(App* app, const WalletState& state, const MiningInfo&
|
|||||||
const char* scaleIcon = threadScaling ? ICON_MD_TUNE : ICON_MD_POWER_SETTINGS_NEW;
|
const char* scaleIcon = threadScaling ? ICON_MD_TUNE : ICON_MD_POWER_SETTINGS_NEW;
|
||||||
float sBtnX = idleRightEdge - btnSz;
|
float sBtnX = idleRightEdge - btnSz;
|
||||||
float sBtnY = btnY;
|
float sBtnY = btnY;
|
||||||
|
material::IconButtonStyle st;
|
||||||
if (threadScaling) {
|
st.color = threadScaling ? Primary() : OnSurfaceMedium();
|
||||||
dl->AddRectFilled(ImVec2(sBtnX, sBtnY), ImVec2(sBtnX + btnSz, sBtnY + btnSz),
|
st.restBg = threadScaling ? WithAlpha(Primary(), 40) : 0;
|
||||||
WithAlpha(Primary(), 40), btnSz * 0.5f);
|
st.tooltip = threadScaling ? TR("mining_idle_scale_on_tooltip")
|
||||||
}
|
: TR("mining_idle_scale_off_tooltip");
|
||||||
|
|
||||||
ImVec2 sIcoSz = icoFont->CalcTextSizeA(icoFont->LegacySize, FLT_MAX, 0, scaleIcon);
|
|
||||||
ImU32 sIcoCol = threadScaling ? Primary() : OnSurfaceMedium();
|
|
||||||
dl->AddText(icoFont, icoFont->LegacySize,
|
|
||||||
ImVec2(sBtnX + (btnSz - sIcoSz.x) * 0.5f, sBtnY + (btnSz - sIcoSz.y) * 0.5f),
|
|
||||||
sIcoCol, scaleIcon);
|
|
||||||
|
|
||||||
ImGui::SetCursorScreenPos(ImVec2(sBtnX, sBtnY));
|
ImGui::SetCursorScreenPos(ImVec2(sBtnX, sBtnY));
|
||||||
ImGui::InvisibleButton("##IdleScaleMode", ImVec2(btnSz, btnSz));
|
if (material::IconButton("##IdleScaleMode", scaleIcon, icoFont, ImVec2(btnSz, btnSz), st)) {
|
||||||
if (ImGui::IsItemClicked()) {
|
|
||||||
app->settings()->setIdleThreadScaling(!threadScaling);
|
app->settings()->setIdleThreadScaling(!threadScaling);
|
||||||
app->settings()->save();
|
app->settings()->save();
|
||||||
}
|
}
|
||||||
if (ImGui::IsItemHovered()) {
|
|
||||||
ImGui::SetMouseCursor(ImGuiMouseCursor_Hand);
|
|
||||||
material::Tooltip("%s", threadScaling
|
|
||||||
? TR("mining_idle_scale_on_tooltip")
|
|
||||||
: TR("mining_idle_scale_off_tooltip"));
|
|
||||||
}
|
|
||||||
idleRightEdge = sBtnX - 4.0f * dp;
|
idleRightEdge = sBtnX - 4.0f * dp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,33 +161,18 @@ void RenderMiningControls(App* app, const WalletState& state, const MiningInfo&
|
|||||||
// When OFF: unrestricted mode, only keyboard/mouse input matters
|
// When OFF: unrestricted mode, only keyboard/mouse input matters
|
||||||
if (idleOn) {
|
if (idleOn) {
|
||||||
bool gpuAware = app->settings()->getIdleGpuAware();
|
bool gpuAware = app->settings()->getIdleGpuAware();
|
||||||
const char* gpuIcon = gpuAware ? ICON_MD_MONITOR : ICON_MD_MONITOR;
|
|
||||||
float gBtnX = idleRightEdge - btnSz;
|
float gBtnX = idleRightEdge - btnSz;
|
||||||
float gBtnY = btnY;
|
float gBtnY = btnY;
|
||||||
|
material::IconButtonStyle st;
|
||||||
if (gpuAware) {
|
st.color = gpuAware ? Primary() : OnSurfaceDisabled();
|
||||||
dl->AddRectFilled(ImVec2(gBtnX, gBtnY), ImVec2(gBtnX + btnSz, gBtnY + btnSz),
|
st.restBg = gpuAware ? WithAlpha(Primary(), 40) : 0;
|
||||||
WithAlpha(Primary(), 40), btnSz * 0.5f);
|
st.tooltip = gpuAware ? TR("mining_idle_gpu_on_tooltip")
|
||||||
}
|
: TR("mining_idle_gpu_off_tooltip");
|
||||||
|
|
||||||
ImVec2 gIcoSz = icoFont->CalcTextSizeA(icoFont->LegacySize, FLT_MAX, 0, gpuIcon);
|
|
||||||
ImU32 gIcoCol = gpuAware ? Primary() : OnSurfaceDisabled();
|
|
||||||
dl->AddText(icoFont, icoFont->LegacySize,
|
|
||||||
ImVec2(gBtnX + (btnSz - gIcoSz.x) * 0.5f, gBtnY + (btnSz - gIcoSz.y) * 0.5f),
|
|
||||||
gIcoCol, gpuIcon);
|
|
||||||
|
|
||||||
ImGui::SetCursorScreenPos(ImVec2(gBtnX, gBtnY));
|
ImGui::SetCursorScreenPos(ImVec2(gBtnX, gBtnY));
|
||||||
ImGui::InvisibleButton("##IdleGpuAware", ImVec2(btnSz, btnSz));
|
if (material::IconButton("##IdleGpuAware", ICON_MD_MONITOR, icoFont, ImVec2(btnSz, btnSz), st)) {
|
||||||
if (ImGui::IsItemClicked()) {
|
|
||||||
app->settings()->setIdleGpuAware(!gpuAware);
|
app->settings()->setIdleGpuAware(!gpuAware);
|
||||||
app->settings()->save();
|
app->settings()->save();
|
||||||
}
|
}
|
||||||
if (ImGui::IsItemHovered()) {
|
|
||||||
ImGui::SetMouseCursor(ImGuiMouseCursor_Hand);
|
|
||||||
material::Tooltip("%s", gpuAware
|
|
||||||
? TR("mining_idle_gpu_on_tooltip")
|
|
||||||
: TR("mining_idle_gpu_off_tooltip"));
|
|
||||||
}
|
|
||||||
idleRightEdge = gBtnX - 4.0f * dp;
|
idleRightEdge = gBtnX - 4.0f * dp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user