ConstrainWinGeom constrains window geometry to fit in the screen. Size is in pixel units.
(sz, pos image.Point)
| 172 | // ConstrainWinGeom constrains window geometry to fit in the screen. |
| 173 | // Size is in pixel units. |
| 174 | func (sc *Screen) ConstrainWinGeom(sz, pos image.Point) (csz, cpos image.Point) { |
| 175 | scsz := sc.Geometry.Size() // in window coords size |
| 176 | |
| 177 | // options size are in pixel sizes, logic below works in window sizes |
| 178 | csz = sc.WinSizeFromPix(sz) |
| 179 | cpos = pos |
| 180 | |
| 181 | // fmt.Printf("sz: %v csz: %v scsz: %v\n", sz, csz, scsz) |
| 182 | // fmt.Println(string(debug.Stack())) |
| 183 | if csz.X > scsz.X { |
| 184 | csz.X = scsz.X - 10 |
| 185 | // fmt.Println("constrain x:", csz.X) |
| 186 | } |
| 187 | if csz.Y > scsz.Y { |
| 188 | csz.Y = scsz.Y - 10 |
| 189 | // fmt.Println("constrain y:", csz.Y) |
| 190 | } |
| 191 | |
| 192 | // these are windows-specific special numbers for minimized windows |
| 193 | // can be sent here for WinGeom saved geom. |
| 194 | if cpos.X == -32000 { |
| 195 | cpos.X = 0 |
| 196 | } |
| 197 | if cpos.Y == -32000 { |
| 198 | cpos.Y = 50 |
| 199 | } |
| 200 | |
| 201 | // don't go off the edge |
| 202 | if cpos.X+csz.X > scsz.X { |
| 203 | cpos.X = scsz.X - csz.X |
| 204 | } |
| 205 | if cpos.Y+csz.Y > scsz.Y { |
| 206 | cpos.Y = scsz.Y - csz.Y |
| 207 | } |
| 208 | if cpos.X < 0 { |
| 209 | cpos.X = 0 |
| 210 | } |
| 211 | if cpos.Y < 0 { |
| 212 | cpos.Y = 0 |
| 213 | } |
| 214 | |
| 215 | csz = sc.WinSizeToPix(csz) |
| 216 | return |
| 217 | } |
| 218 | |
| 219 | // InitScreenLogicalDPIFunc is a function that can be set to initialize the |
| 220 | // screen LogicalDPI values based on user preferences etc. Called just before |
no test coverage detected