fitRectToScreen fits rectangle to screen. Input and output rectangles are in native pixels.
(hWnd win.HWND, r Rectangle)
| 195 | |
| 196 | // fitRectToScreen fits rectangle to screen. Input and output rectangles are in native pixels. |
| 197 | func fitRectToScreen(hWnd win.HWND, r Rectangle) Rectangle { |
| 198 | var mi win.MONITORINFO |
| 199 | mi.CbSize = uint32(unsafe.Sizeof(mi)) |
| 200 | |
| 201 | if !win.GetMonitorInfo(win.MonitorFromWindow( |
| 202 | hWnd, win.MONITOR_DEFAULTTOPRIMARY), &mi) { |
| 203 | |
| 204 | return r |
| 205 | } |
| 206 | |
| 207 | mon := rectangleFromRECT(mi.RcWork) |
| 208 | |
| 209 | dpi := win.GetDpiForWindow(hWnd) |
| 210 | mon.Height -= int(win.GetSystemMetricsForDpi(win.SM_CYCAPTION, dpi)) |
| 211 | |
| 212 | if r.Width <= mon.Width { |
| 213 | switch { |
| 214 | case r.X < mon.X: |
| 215 | r.X = mon.X |
| 216 | case r.X+r.Width > mon.X+mon.Width: |
| 217 | r.X = mon.X + mon.Width - r.Width |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | if r.Height <= mon.Height { |
| 222 | switch { |
| 223 | case r.Y < mon.Y: |
| 224 | r.Y = mon.Y |
| 225 | case r.Y+r.Height > mon.Y+mon.Height: |
| 226 | r.Y = mon.Y + mon.Height - r.Height |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | return r |
| 231 | } |
| 232 | |
| 233 | func (dlg *Dialog) Run() int { |
| 234 | dlg.Show() |
no test coverage detected
searching dependent graphs…