Documentation
¶
Index ¶
- Variables
- func CalcPlacementSize(m *Monitor, desiredWidth, desiredHeight, minWidth, minHeight, margin int) (width, height int)
- type DefaultMonitorMode
- type FitMode
- type Monitor
- type Point
- type Rect
- func FitToMonitor(m *Monitor, mode FitMode, window Rect, windowScale float64) (Rect, float64, error)
- func FitToNearestMonitor(monitors []Monitor, mode FitMode, window Rect, windowScale float64, ...) (Rect, float64, error)
- func GetWorkAreaForRect(monitors []Monitor, rect Rect) Rect
- func InitialPlacement(desiredWidth, desiredHeight, minWidth, minHeight, margin int) (Rect, float64)
- func LogicalToScreenRect(m Monitor, logical Rect) Rect
- func ScreenToLogicalRect(m Monitor, screen Rect) Rect
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidDimensions = errors.New("invalid dimensions: negative width or height")
ErrInvalidDimensions is returned when a window or monitor has negative dimensions
var ErrNoMonitors = errors.New("no monitors available")
ErrNoMonitors is returned when no monitors are available for fitting
Functions ¶
func CalcPlacementSize ¶ added in v0.2.1
func CalcPlacementSize(m *Monitor, desiredWidth, desiredHeight, minWidth, minHeight, margin int) (width, height int)
CalcPlacementSize calculates the window size in screen units, attempting to satisfy the desired size while fitting within monitor bounds: 1. Converts desired size to screen units using monitor's scale 2. Attempts to fit within work area minus margins 3. If needed, allows using margin area to satisfy minimum size
Parameters: - desiredWidth, desiredHeight: preferred window size in logical units - minWidth, minHeight: minimum required window size in logical units - margin: minimum distance from work area edges in logical units
Returns width and height in screen units.
Types ¶
type DefaultMonitorMode ¶ added in v0.2.1
type DefaultMonitorMode int
DefaultMonitorMode specifies how to select a monitor when no exact match is found
const ( // DefaultMonitorNull returns nil if no monitor matches the criteria DefaultMonitorNull DefaultMonitorMode = iota // DefaultMonitorPrimary returns the monitor containing (0,0) in screen coordinates, // or the first available monitor if no monitor contains (0,0) DefaultMonitorPrimary // DefaultMonitorNearest returns the monitor with smallest edge distance to the target DefaultMonitorNearest )
type Monitor ¶
Monitor represents a display monitor and its properties
func FindMonitorFromScreenPoint ¶ added in v0.2.1
func FindMonitorFromScreenPoint(monitors []Monitor, x, y int, defaultTo DefaultMonitorMode) *Monitor
FindMonitorFromScreenPoint finds the monitor that contains the given screen point. If no monitor contains the point: - DefaultMonitorNearest: returns the nearest monitor - DefaultMonitorPrimary: returns the primary monitor - DefaultMonitorNull: returns nil
func FindMonitorFromScreenRect ¶ added in v0.2.1
func FindMonitorFromScreenRect(monitors []Monitor, rect Rect, defaultTo DefaultMonitorMode) *Monitor
FindMonitorFromScreenRect finds a monitor with the largest overlap with the given rect in screen coordinates. If no monitor has overlap: - DefaultMonitorNearest: returns the monitor with smallest edge distance - DefaultMonitorPrimary: returns the primary monitor - DefaultMonitorNull: returns nil
func FindPrimaryMonitor ¶ added in v0.2.1
FindPrimaryMonitor returns the monitor containing (0,0) in screen coordinates, or the first available monitor if no monitor contains (0,0). Returns nil if no monitors are available.
type Point ¶ added in v0.2.1
type Point struct {
X, Y int
}
Point represents a point in 2D space
func LogicalToScreenPoint ¶ added in v0.2.1
LogicalToScreenPoint converts a logical point to screen coordinates for a given monitor
func ScreenToLogicalPoint ¶ added in v0.2.1
ScreenToLogicalPoint converts a screen point to logical coordinates for a given monitor
type Rect ¶
Rect represents a rectangle with coordinates in screen space
func FitToMonitor ¶
func FitToMonitor(m *Monitor, mode FitMode, window Rect, windowScale float64) (Rect, float64, error)
FitToMonitor fits a window to a specific monitor. Input window coordinates are in screen units. windowScale specifies what scale factor the window was designed for: - If 0.0: keep window as is, no rescaling needed - If > 0.0: rescale window from windowScale to monitor's scale Returns error if window or monitor has negative dimensions. Returns the fitted rect and the monitor's scale factor. If monitor is nil, returns windowScale if non-zero, otherwise 1.0.
func FitToNearestMonitor ¶
func FitToNearestMonitor(monitors []Monitor, mode FitMode, window Rect, windowScale float64, minWidth, minHeight int) (Rect, float64, error)
FitToNearestMonitor finds the most appropriate monitor and fits the window to it. Input window coordinates are in screen units. windowScale specifies what scale factor the window was designed for: - If 0.0: keep window as is, no rescaling needed - If > 0.0: rescale window from windowScale to monitor's scale minWidth and minHeight specify the minimum dimensions the window should have (in logical units). Returns error if window has negative dimensions, if no valid monitors are available, or if no monitor can fit the minimum size requirements. If no monitors are available, returns windowScale if non-zero, otherwise 1.0.
func GetWorkAreaForRect ¶ added in v0.6.0
GetWorkAreaForRect returns the work area of the monitor containing the given rect. Returns an empty Rect if no monitors are available.
func InitialPlacement ¶ added in v0.2.0
InitialPlacement calculates the initial window placement centered on a primary monitor. Window size is determined by logic implemented in CalcPlacementSize.
Parameters: - desiredWidth, desiredHeight: preferred window size in logical units - minWidth, minHeight: minimum required window size in logical units - margin: minimum distance from work area edges in logical units
Returns a Rect with the calculated window position and size in screen units, and the scale factor of the selected monitor (1.0 if no monitor is available).
func LogicalToScreenRect ¶ added in v0.2.1
LogicalToScreenRect converts logical coordinates to screen units for a given monitor
func ScreenToLogicalRect ¶ added in v0.2.1
ScreenToLogicalRect converts screen coordinates to logical units for a given monitor
Directories
¶
| Path | Synopsis |
|---|---|
|
Package units provides dimension types for specifying window sizes in pixels, em-units (relative to system font), or percentages (relative to work area).
|
Package units provides dimension types for specifying window sizes in pixels, em-units (relative to system font), or percentages (relative to work area). |