TrayTempo v0.2.0 : minuteur Pomodoro Windows en Nim avec interface intuitive
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
## floating.nim
|
||||
## =============
|
||||
## Fenêtre flottante compacte : un petit panneau toujours au-dessus qui affiche
|
||||
## la phase et le temps restant en grand. Utile pour voir l'état du minuteur
|
||||
## d'un coup d'œil sans ouvrir le menu tray. Draggable à la souris.
|
||||
|
||||
import winim/lean
|
||||
|
||||
var
|
||||
fHwnd: HWND
|
||||
fLabel: HWND
|
||||
fFont: HFONT
|
||||
|
||||
proc floatingProc(hwnd: HWND, msg: UINT, wParam: WPARAM, lParam: LPARAM): LRESULT {.stdcall.} =
|
||||
case msg
|
||||
of WM_LBUTTONDOWN:
|
||||
# Permet de déplacer la fenêtre en la glissant.
|
||||
discard SendMessage(hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0)
|
||||
return 0
|
||||
of WM_DESTROY:
|
||||
fHwnd = 0
|
||||
return 0
|
||||
else:
|
||||
discard
|
||||
return DefWindowProc(hwnd, msg, wParam, lParam)
|
||||
|
||||
proc floatingVisible*(): bool =
|
||||
fHwnd != 0
|
||||
|
||||
proc updateFloating*(text: string) =
|
||||
## Met à jour le texte affiché (phase + temps restant).
|
||||
if fHwnd != 0 and fLabel != 0:
|
||||
discard SetWindowTextW(fLabel, text)
|
||||
|
||||
proc showFloating*() =
|
||||
## Affiche (ou crée) la fenêtre flottante en bas à droite de l'écran.
|
||||
if fHwnd != 0:
|
||||
discard ShowWindow(fHwnd, SW_SHOW)
|
||||
return
|
||||
|
||||
let inst = GetModuleHandleW(nil)
|
||||
|
||||
var wc: WNDCLASSW
|
||||
wc.lpfnWndProc = cast[WNDPROC](floatingProc)
|
||||
wc.hInstance = inst
|
||||
wc.lpszClassName = L"TrayTempoFloatingClass"
|
||||
wc.hbrBackground = cast[HBRUSH](COLOR_WINDOW + 1)
|
||||
discard RegisterClass(&wc)
|
||||
|
||||
let w = 240'i32
|
||||
let h = 56'i32
|
||||
let scrW = GetSystemMetrics(SM_CXSCREEN)
|
||||
let scrH = GetSystemMetrics(SM_CYSCREEN)
|
||||
|
||||
fHwnd = CreateWindowExW(WS_EX_TOPMOST or WS_EX_TOOLWINDOW,
|
||||
L"TrayTempoFloatingClass", L"TrayTempo",
|
||||
WS_POPUP or WS_BORDER or WS_VISIBLE,
|
||||
scrW - w - 24, scrH - h - 80, w, h,
|
||||
0, 0, inst, nil)
|
||||
|
||||
# Police large et lisible (accessibilité : texte agrandi).
|
||||
fFont = CreateFontW(24, 0, 0, 0, FW_BOLD, 0, 0, 0, DEFAULT_CHARSET,
|
||||
0, 0, CLEARTYPE_QUALITY, 0, L"Segoe UI")
|
||||
|
||||
fLabel = CreateWindowExW(0, L"STATIC", L"", WS_CHILD or WS_VISIBLE or SS_CENTER,
|
||||
0, 0, w, h, fHwnd, cast[HMENU](1), inst, nil)
|
||||
discard SendMessage(fLabel, WM_SETFONT, cast[WPARAM](fFont), 1)
|
||||
|
||||
proc hideFloating*() =
|
||||
if fHwnd != 0:
|
||||
discard DestroyWindow(fHwnd)
|
||||
fHwnd = 0
|
||||
fLabel = 0
|
||||
if fFont != 0:
|
||||
discard DeleteObject(fFont)
|
||||
fFont = 0
|
||||
Reference in New Issue
Block a user