Skip to content

Drawing

flaui.lib.system.drawing

This module provides a wrapper class for System.Drawing namespace objects. It also defines an Enum class KnownColor that specifies the known system colors. Wrapper class for System.Drawing namespace objects

Color

Represents an ARGB (alpha, red, green, blue) color from System.Drawing.Color object

from_argb(argb=None, alpha=None, base_color=None, red=None, green=None, blue=None) staticmethod

Creates a ColorData object from various input formats matching C# System.Drawing.Color

Parameters:

Name Type Description Default
argb Optional[int]

A value specifying the 32-bit ARGB value, defaults to None

None
alpha Optional[int]

The alpha component. Valid values are 0 through 255, defaults to None

None
base_color Optional[ColorData]

The System.Drawing.Color from which to create the new System.Drawing.Color, defaults to None

None
red Optional[int]

The red component. Valid values are 0 through 255, defaults to None

None
green Optional[int]

The green component. Valid values are 0 through 255, defaults to None

None
blue Optional[int]

The blue component. Valid values are 0 through 255, defaults to None

None

Returns:

Type Description
ColorData

The ColorData object representing the color.

Raises:

Type Description
ValueError

On invalid input combination

Source code in flaui/lib/system/drawing.py
@staticmethod
def from_argb(
    argb: Optional[int] = None,
    alpha: Optional[int] = None,
    base_color: Optional[ColorData] = None,
    red: Optional[int] = None,
    green: Optional[int] = None,
    blue: Optional[int] = None,
) -> ColorData:
    """
    Creates a ColorData object from various input formats matching C# System.Drawing.Color

    :param argb: A value specifying the 32-bit ARGB value, defaults to None
    :param alpha: The alpha component. Valid values are 0 through 255, defaults to None
    :param base_color: The System.Drawing.Color from which to create the new System.Drawing.Color, defaults to None
    :param red: The red component. Valid values are 0 through 255, defaults to None
    :param green: The green component. Valid values are 0 through 255, defaults to None
    :param blue: The blue component. Valid values are 0 through 255, defaults to None
    :raises ValueError: On invalid input combination
    :return: The ColorData object representing the color.
    """

    # Check for valid input combinations
    if all(
        x is not None for x in [alpha, red, green, blue]
    ):  # Check if all components are provided (including None)
        # ARGB with all components provided
        return ColorData(cs_object=CSColor.FromArgb(alpha, red, green, blue))
    elif all(x is not None for x in [red, green, blue]) and alpha is None:
        # RGB with implicit alpha 255
        return ColorData(cs_object=CSColor.FromArgb(red, green, blue))
    elif alpha is not None and base_color is not None:
        # Set alpha for existing color
        return ColorData(cs_object=CSColor.FromArgb(alpha, base_color.cs_object))
    elif argb is not None and any([alpha, red, green, blue]) is False:
        # Single ARGB value
        alpha = (argb >> 24) & 0xFF  # Extract alpha (shift 24 bits and mask with 0xFF)
        red = (argb >> 16) & 0xFF  # Extract red (shift 16 bits and mask with 0xFF)
        green = (argb >> 8) & 0xFF  # Extract green (shift 8 bits and mask with 0xFF)
        blue = argb & 0xFF  # Extract blue (mask with 0xFF)
        return ColorData(cs_object=CSColor.FromArgb(alpha, red, green, blue))
    else:
        raise ValueError("Invalid arguments sent as input, cannot create ColorData object.")

from_known_color(known_color) staticmethod

Creates a System.Drawing.Color structure from the specified predefined color.

Parameters:

Name Type Description Default
known_color KnownColor

An element of the System.Drawing.KnownColor enumeration.

required

Returns:

Type Description
ColorData

The System.Drawing.Color that this method creates.

Source code in flaui/lib/system/drawing.py
@staticmethod
def from_known_color(known_color: KnownColor) -> ColorData:
    """Creates a System.Drawing.Color structure from the specified predefined color.

    :param known_color: An element of the System.Drawing.KnownColor enumeration.
    :return: The System.Drawing.Color that this method creates.
    """
    return ColorData(cs_object=CSColor.FromKnownColor(known_color.value))

from_name(name) staticmethod

Creates a System.Drawing.Color structure from the specified name of a predefined color.

Parameters:

Name Type Description Default
name str

A string that is the name of a predefined color. Valid names are the same as the names of the elements of the System.Drawing.KnownColor enumeration.

required

Returns:

Type Description
ColorData

The System.Drawing.Color that this method creates.

Source code in flaui/lib/system/drawing.py
@staticmethod
def from_name(name: str) -> ColorData:
    """Creates a System.Drawing.Color structure from the specified name of a predefined
    color.

    :param name: A string that is the name of a predefined color. Valid names are the same as
    the names of the elements of the System.Drawing.KnownColor enumeration.
    :return: The System.Drawing.Color that this method creates.
    """
    return ColorData(cs_object=CSColor.FromName(name))

ColorData

Bases: BaseSettings

Represents an ARGB (alpha, red, green, blue) System.Drawing.Color color object.

a property

Gets the alpha component value of this System.Drawing.Color structure.

Returns:

Type Description
bytes

The alpha component value of this System.Drawing.Color.

b property

Gets the blue component value of this System.Drawing.Color structure.

Returns:

Type Description
bytes

The blue component value of this System.Drawing.Color.

g property

Gets the green component value of this System.Drawing.Color structure.

Returns:

Type Description
bytes

The green component value of this System.Drawing.Color.

is_empty property

Specifies whether this System.Drawing.Color structure is uninitialized.

Returns:

Type Description
bool

This property returns True if this color is uninitialized; otherwise, False.

is_known_color property

Gets a value indicating whether this System.Drawing.Color structure is a predefined color. Predefined colors are represented by the elements of the System.Drawing.KnownColor enumeration.

Returns:

Type Description
bool

True if this System.Drawing.Color was created from a predefined color by using either the System.Drawing.Color.FromName(System.String) method or the System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor) method; otherwise, False.

is_named_color property

Gets a value indicating whether this System.Drawing.Color structure is a named color or a member of the System.Drawing.KnownColor enumeration.

Returns:

Type Description
bool

True if this System.Drawing.Color was created by using either the System.Drawing.Color.FromName(System.String) method or the System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor) method; otherwise, False.

is_system_color property

Gets a value indicating whether this System.Drawing.Color structure is a system color. A system color is a color that is used in a Windows display element. System colors are represented by elements of the System.Drawing.KnownColor enumeration.

Returns:

Type Description
str

True if this System.Drawing.Color was created from a system color by using either the System.Drawing.Color.FromName(System.String) method or the System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor) method; otherwise, False.

name property

Gets the name of this System.Drawing.Color.

Returns:

Type Description
str

The name of this System.Drawing.Color.

r property

Gets the red component value of this System.Drawing.Color structure.

Returns:

Type Description
bytes

The red component value of this System.Drawing.Color.

equals(another_color)

Indicates whether the current object is equal to another object of the same type.

Parameters:

Name Type Description Default
another_color ColorData

An object to compare with this object.

required

Returns:

Type Description
bool

True if the current object is equal to other; otherwise, False.

Source code in flaui/lib/system/drawing.py
def equals(self, another_color: ColorData) -> bool:
    """Indicates whether the current object is equal to another object of the same type.

    :param another_color: An object to compare with this object.
    :return: True if the current object is equal to other; otherwise, False.
    """
    return self.cs_object.Equals(another_color.cs_object)

get_brightness()

Gets the hue-saturation-lightness (HSL) lightness value for this System.Drawing.Color structure.

Returns:

Type Description
float

The lightness of this System.Drawing.Color. The lightness ranges from 0.0 through 1.0, where 0.0 represents black and 1.0 represents white.

Source code in flaui/lib/system/drawing.py
def get_brightness(self) -> float:
    """Gets the hue-saturation-lightness (HSL) lightness value for this System.Drawing.Color
    structure.

    :return: The lightness of this System.Drawing.Color. The lightness ranges from 0.0 through
    1.0, where 0.0 represents black and 1.0 represents white.
    """
    return self.cs_object.GetBrightness()

get_hash_code()

Returns a hash code for this System.Drawing.Color structure.

Returns:

Type Description
int

An integer value that specifies the hash code for this System.Drawing.Color.

Source code in flaui/lib/system/drawing.py
def get_hash_code(self) -> int:
    """Returns a hash code for this System.Drawing.Color structure.

    :return: An integer value that specifies the hash code for this System.Drawing.Color.
    """
    return self.cs_object.GetHashCode()

get_hue()

Gets the hue-saturation-lightness (HSL) hue value, in degrees, for this System.Drawing.Color structure.

Returns:

Type Description
float

The hue, in degrees, of this System.Drawing.Color. The hue is measured in degrees, ranging from 0.0 through 360.0, in HSL color space.

Source code in flaui/lib/system/drawing.py
def get_hue(self) -> float:
    """Gets the hue-saturation-lightness (HSL) hue value, in degrees, for this System.Drawing.Color
    structure.

    :return: The hue, in degrees, of this System.Drawing.Color. The hue is measured in degrees,
    ranging from 0.0 through 360.0, in HSL color space.
    """
    return self.cs_object.GetHashCode()

get_saturation()

Gets the hue-saturation-lightness (HSL) saturation value for this System.Drawing.Color structure.

Returns:

Type Description
float

The saturation of this System.Drawing.Color. The saturation ranges from 0.0 through 1.0, where 0.0 is grayscale and 1.0 is the most saturated.

Source code in flaui/lib/system/drawing.py
def get_saturation(self) -> float:
    """Gets the hue-saturation-lightness (HSL) saturation value for this System.Drawing.Color
    structure.

    :return: The saturation of this System.Drawing.Color. The saturation ranges from 0.0 through
    1.0, where 0.0 is grayscale and 1.0 is the most saturated.
    """
    return self.cs_object.GetSaturation()

to_argb()

Gets the 32-bit ARGB value of this System.Drawing.Color structure.

Returns:

Type Description
int

The 32-bit ARGB value of this System.Drawing.Color.

Source code in flaui/lib/system/drawing.py
def to_argb(self) -> int:
    """Gets the 32-bit ARGB value of this System.Drawing.Color structure.

    :return: The 32-bit ARGB value of this System.Drawing.Color.
    """
    return self.cs_object.ToArgb()

to_known_color()

Gets the System.Drawing.KnownColor value of this System.Drawing.Color structure.

Returns:

Type Description
KnownColor

An element of the System.Drawing.KnownColor enumeration, if the System.Drawing.Color is created from a predefined color by using either the System.Drawing.Color.FromName(System.String) method or the System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor) method; otherwise, 0.

Source code in flaui/lib/system/drawing.py
def to_known_color(self) -> KnownColor:
    """Gets the System.Drawing.KnownColor value of this System.Drawing.Color structure.

    :return: An element of the System.Drawing.KnownColor enumeration, if the System.Drawing.Color
    is created from a predefined color by using either the System.Drawing.Color.FromName(System.String)
    method or the System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor)
    method; otherwise, 0.
    """
    return KnownColor(self.cs_object.ToKnownColor())

to_string()

Converts this System.Drawing.Color structure to a human-readable string.

Returns:

Type Description
int

A string that is the name of this System.Drawing.Color, if the System.Drawing.Color is created from a predefined color by using either the System.Drawing.Color.FromName(System.String) method or the System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor) method; otherwise, a string that consists of the ARGB component names and their values.

Source code in flaui/lib/system/drawing.py
def to_string(self) -> int:
    """Converts this System.Drawing.Color structure to a human-readable string.

    :return: A string that is the name of this System.Drawing.Color, if the System.Drawing.Color
    is created from a predefined color by using either the System.Drawing.Color.FromName(System.String)
    method or the System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor)
    method; otherwise, a string that consists of the ARGB component names and their
    values.
    """
    return self.cs_object.ToString()

KnownColor

Bases: Enum

Specifies the known system colors

Point

Bases: BaseModel

Represents a Point object, works with underlying C# System.Drawing.Point object.

Note that this doesn't handle PointF object and the methods are currently listed only for Point object.

is_empty property

Indicates if the Point object is empty

Returns:

Type Description
bool

Flag True if empty else False

x property writable

Gets x-cordinate of this Point

Returns:

Type Description
int

x-cordinate of the Point

y property writable

Gets y-cordinate of this Point

Returns:

Type Description
int

y-cordinate of the Point

__add__(other)

Translates a point by a given Size

Parameters:

Name Type Description Default
other Size

Size object to add

required

Returns:

Type Description
Point

A new Point object with the translated coordinates

Source code in flaui/lib/system/drawing.py
def __add__(self, other: Size) -> Point:
    """Translates a point by a given Size

    :param other: Size object to add
    :return: A new Point object with the translated coordinates
    """
    if isinstance(other, Size):
        return Point(raw_value=self.raw_value.Add(self.raw_value, other.raw_value))  # type: ignore
    else:
        raise TypeError(f"Unsupported operand type(s) for +: 'Point' and '{type(other)}'")

__eq__(other)

Compares two Point objects for equality

Accepts any object (matches BaseModel signature) and returns False when the other object is not a Point.

Source code in flaui/lib/system/drawing.py
def __eq__(self, other: object) -> bool:
    """Compares two Point objects for equality

    Accepts any object (matches BaseModel signature) and returns False when the
    other object is not a Point.
    """
    if not isinstance(other, Point):
        return False

    return self.x == other.x and self.y == other.y

__ne__(other)

Compares two Point objects for inequality

Accepts any object (matches BaseModel signature).

Source code in flaui/lib/system/drawing.py
def __ne__(self, other: object) -> bool:
    """Compares two Point objects for inequality

    Accepts any object (matches BaseModel signature).
    """
    return not self == other

__sub__(other)

Translates the Point by the negative of the specified Size.

Parameters:

Name Type Description Default
other Size

Size object to subtract

required

Returns:

Type Description
Point

A new Point object with the translated coordinates

Source code in flaui/lib/system/drawing.py
def __sub__(self, other: Size) -> Point:
    """Translates the Point by the negative of the specified Size.

    :param other: Size object to subtract
    :return: A new Point object with the translated coordinates
    """
    if not isinstance(other, Size):
        raise TypeError(f"Unsupported operand type(s) for +: 'Point' and '{type(other)}'")

    return Point(raw_value=(self.x - other.width, self.y - other.height))  # type: ignore

add(point, size)

Adds the specified Size tot he specified Point

Parameters:

Name Type Description Default
point Point

The point to add

required
size Size

The size to add

required

Returns:

Type Description
Point

The point that is the result of the addition operation

Source code in flaui/lib/system/drawing.py
def add(self, point: Point, size: Size) -> Point:
    """Adds the specified Size tot he specified Point

    :param point: The point to add
    :param size: The size to add
    :return: The point that is the result of the addition operation
    """
    return Point(raw_value=self.raw_value.Add(point.raw_value, size.raw_value))  # type: ignore

distance(other_x=None, other_y=None, other_point=None)

Calculates the distance between two points or the distance between a point and an x/y coordinate pair.

This is similar to Distance method listed in FlaUI.Core.Tools.ExtensionMethods.

Parameters:

Name Type Description Default
other_x Optional[int]

The x-coordinate of the second point., defaults to None

None
other_y Optional[int]

The y-coordinate of the second point., defaults to None

None
other_point Optional[Point]

The second point, defaults to None

None

Returns:

Type Description
float

Distance calculated

Source code in flaui/lib/system/drawing.py
def distance(
    self, other_x: Optional[int] = None, other_y: Optional[int] = None, other_point: Optional[Point] = None
) -> float:
    """Calculates the distance between two points or the distance between a point and an x/y coordinate pair.

    This is similar to Distance method listed in FlaUI.Core.Tools.ExtensionMethods.

    :param other_x: The x-coordinate of the second point., defaults to None
    :param other_y: The y-coordinate of the second point., defaults to None
    :param other_point: The second point, defaults to None
    :return: Distance calculated
    """
    if other_x is not None and other_y is not None:
        return sqrt((pow(self.x - other_x, 2) + pow(self.y - other_y, 2)))
    elif other_point is not None:
        return sqrt((pow(self.x - other_point.x, 2) + pow(self.y - other_point.y, 2)))
    else:
        raise ValueError(
            "Invalid arguments passed to measure distance, you need to pass x-coordinate & y-coordinate or Point object"
        )

equals(other)

Specifies whether this point instance contains the same coordinates as another point.

Parameters:

Name Type Description Default
other Point

Value to compare

required

Returns:

Type Description
bool

True if equal, else False

Source code in flaui/lib/system/drawing.py
def equals(self, other: Point) -> bool:
    """Specifies whether this point instance contains the same coordinates as another point.

    :param other: Value to compare
    :return: True if equal, else False
    """
    return self.raw_value.Equals(other.raw_value)  # type: ignore

get_hash_code()

Returns a hash code for this Point.

Returns:

Type Description
int

An integer value that specifies the hash code for this Point.

Source code in flaui/lib/system/drawing.py
def get_hash_code(self) -> int:
    """Returns a hash code for this Point.

    :return: An integer value that specifies the hash code for this Point.
    """
    return self.raw_value.GetHashCode()  # type: ignore

offset(x=None, y=None, point=None)

Translates this Point by the specified amount/specified Point

Parameters:

Name Type Description Default
x Optional[int]

x-coordinate, defaults to None

None
y Optional[int]

y-coordinate, defaults to None

None
point Optional[Point]

Point object, defaults to None

None
Source code in flaui/lib/system/drawing.py
def offset(self, x: Optional[int] = None, y: Optional[int] = None, point: Optional[Point] = None) -> None:
    """Translates this Point by the specified amount/specified Point

    :param x: x-coordinate, defaults to None
    :param y: y-coordinate, defaults to None
    :param point: Point object, defaults to None
    """
    self.raw_value.Offset(x, y) if point is None else self.raw_value.Offset(point.raw_value)  # type: ignore

parse_cs_object(v) classmethod

Parses C# Point object from System.Drawing namespace

Parameters:

Name Type Description Default
v Union[int, Tuple[int, int], Tuple[float, float], Point, Size]

Input value

required

Returns:

Type Description
Point

Parsed C# object

Source code in flaui/lib/system/drawing.py
@field_validator("raw_value")
@classmethod
def parse_cs_object(cls, v: Union[int, Tuple[int, int], Tuple[float, float], CSPoint, Size]) -> CSPoint:
    """Parses C# Point object from System.Drawing namespace

    :param v: Input value
    :return: Parsed C# object
    """
    if isinstance(v, CSPoint):
        # Always create a new Point object to avoid shared mutable state
        return CSPoint(v.X, v.Y)  # pyright: ignore[reportAttributeAccessIssue]
    if isinstance(v, Size):
        return CSPoint(v.raw_value)

    return CSPoint(v) if isinstance(v, int) else CSPoint(round(v[0]), round(v[1]))

subtract(point, size)

Returns the result of subtracting specified Size from the specified Point.

Parameters:

Name Type Description Default
point Point

Point object

required
size Size

Size object

required

Returns:

Type Description
Point

Subtracted Point object

Source code in flaui/lib/system/drawing.py
def subtract(self, point: Point, size: Size) -> Point:
    """Returns the result of subtracting specified Size from the specified Point.

    :param point: Point object
    :param size: Size object
    :return: Subtracted Point object
    """
    return Point(raw_value=self.raw_value.Subtract(point.raw_value, size.raw_value))  # type: ignore

to_size()

Explicitly converts the specified Point structure to Size structure

Returns:

Type Description
Size

Size object

Source code in flaui/lib/system/drawing.py
def to_size(self) -> Size:
    """Explicitly converts the specified Point structure to Size structure

    :return: Size object
    """
    return Size(raw_value=(self.x, self.y))

to_string()

Converts this Point to a human-readable string.

Returns:

Type Description
str

Point as readable string.

Source code in flaui/lib/system/drawing.py
def to_string(self) -> str:
    """Converts this Point to a human-readable string.

    :return: Point as readable string.
    """
    return self.raw_value.ToString()  # type: ignore

Rectangle

Bases: BaseModel

Represents a Rectangle object, works with underlying C# System.Drawing.Rectangle object.

Note that this doesn't handle RectangleF object and the methods are currently listed only for Rectangle object.

bottom property

Gets the y-coordinate that is the sum of the Y and Height property values of this Rectangle structure.

Returns:

Type Description
int

Parsed value

height property writable

Gets vertical component of this Size

Returns:

Type Description
int

Vertical component of the Size

is_empty property

Indicates if the Point object is empty

Returns:

Type Description
bool

Flag True if empty else False

left property

Gets the x-coordinate of the left edge of this Rectangle structure.

Returns:

Type Description
int

X-coordinate

location property

Gets or sets the coordinates of the upper-left corner of this Rectangle structure.

Returns:

Type Description
Point

Point object

right property

Gets the x-coordinate that is the sum of X and Width property values of this Rectangle structure.

Returns:

Type Description
int

X-coordinate

size property writable

Gets the size of this Rectangle.

Returns:

Type Description
Size

Size objects

top property

Gets the y-coordinate of the top edge of this Rectangle structure.

Returns:

Type Description
int

Y-coordinate

width property writable

Gets the width of this Rectangle structure.

Returns:

Type Description
int

Width value

x property writable

Gets the x of this Rectangle structure.

Returns:

Type Description
int

X value

y property writable

Gets the y of this Rectangle structure.

Returns:

Type Description
int

Y value

__eq__(other)

Tests whether two Rectangle structures have equal location and size.

Accepts any object (matches BaseModel signature) and returns False when the other object is not a Rectangle.

Source code in flaui/lib/system/drawing.py
def __eq__(self, other: object) -> bool:
    """Tests whether two Rectangle structures have equal location and size.

    Accepts any object (matches BaseModel signature) and returns False when the
    other object is not a Rectangle.
    """
    if not isinstance(other, Rectangle):
        return False

    return self.left == other.left and self.right == other.right

__ne__(other)

Compares two Rectangle objects for inequality

Accepts any object (matches BaseModel signature).

Source code in flaui/lib/system/drawing.py
def __ne__(self, other: object) -> bool:
    """Compares two Rectangle objects for inequality

    Accepts any object (matches BaseModel signature).
    """
    return not self == other

center()

Returns center of this rectangle as a Point object

Returns:

Type Description
Point

Point object

Source code in flaui/lib/system/drawing.py
def center(self) -> Point:
    """Returns center of this rectangle as a Point object

    :return: Point object
    """
    return Point(raw_value=(self.width / 2 + self.left, self.height / 2 + self.top))

contains(other)

Determines if the specified point is contained within this Rectangle structure.

Parameters:

Name Type Description Default
other Union[Tuple[int, int], Point]

Value to compare

required

Returns:

Type Description
bool

True if it contains, else False

Source code in flaui/lib/system/drawing.py
def contains(self, other: Union[Tuple[int, int], Point]) -> bool:
    """Determines if the specified point is contained within this Rectangle structure.

    :param other: Value to compare
    :return: True if it contains, else False
    """
    return (
        self.raw_value.Contains(other.raw_value)  # type: ignore
        if (isinstance(other, Point) or isinstance(other, Rectangle))
        else self.raw_value.Contains(other[0], other[1])  # type: ignore
    )

east(by=0)

Returns East of the rectangle as a Point object

Parameters:

Name Type Description Default
by int

Move by, defaults to 0

0

Returns:

Type Description
Point

Point object

Source code in flaui/lib/system/drawing.py
def east(self, by: int = 0) -> Point:
    """Returns East of the rectangle as a Point object

    :param by: Move by, defaults to 0
    :return: Point object
    """
    return Point(raw_value=(self.right + by, self.center().y))

equals(other)

Specifies whether this Rectangle instance contains the same coordinates as another point.

Parameters:

Name Type Description Default
other Rectangle

Value to compare

required

Returns:

Type Description
bool

True if equal, else False

Source code in flaui/lib/system/drawing.py
def equals(self, other: Rectangle) -> bool:
    """Specifies whether this Rectangle instance contains the same coordinates as another point.

    :param other: Value to compare
    :return: True if equal, else False
    """
    return self.raw_value.Equals(other.raw_value)  # type: ignore

from_ltrb(value)

Creates a Rectangle structure with the specified edge locations.

Parameters:

Name Type Description Default
value List[int]

Value to set

required

Returns:

Type Description
Rectangle

Rectangle object

Source code in flaui/lib/system/drawing.py
def from_ltrb(self, value: List[int]) -> Rectangle:
    """Creates a Rectangle structure with the specified edge locations.

    :param value: Value to set
    :return: Rectangle object
    """
    if not len(value) == 4:
        raise ValueError(
            f"The input values have to be a list of 4 integers to create a Rectangle structure, current input - {value}"
        )

    return Rectangle(raw_value=self.raw_value.FromLTRB(*value))  # type: ignore

get_hash_code()

Returns a hash code for this Rectangle.

Returns:

Type Description
int

An integer value that specifies the hash code for this Rectangle.

Source code in flaui/lib/system/drawing.py
def get_hash_code(self) -> int:
    """Returns a hash code for this Rectangle.

    :return: An integer value that specifies the hash code for this Rectangle.
    """
    return self.raw_value.GetHashCode()  # type: ignore

immediate_exterior_east()

Returns immediate exterior East

Returns:

Type Description
Point

Point object

Source code in flaui/lib/system/drawing.py
def immediate_exterior_east(self) -> Point:
    """Returns immediate exterior East

    :return: Point object
    """
    return self.east(1)

immediate_exterior_north()

Returns immediate exterior North

Returns:

Type Description
Point

Point object

Source code in flaui/lib/system/drawing.py
def immediate_exterior_north(self) -> Point:
    """Returns immediate exterior North

    :return: Point object
    """
    return self.north(-1)

immediate_exterior_south()

Returns immediate exterior South

Returns:

Type Description
Point

Point object

Source code in flaui/lib/system/drawing.py
def immediate_exterior_south(self) -> Point:
    """Returns immediate exterior South

    :return: Point object
    """
    return self.south(1)

immediate_exterior_west()

Returns immediate exterior West

Returns:

Type Description
Point

Point object

Source code in flaui/lib/system/drawing.py
def immediate_exterior_west(self) -> Point:
    """Returns immediate exterior West

    :return: Point object
    """
    return self.west(-1)

immediate_interior_east()

Returns immediate interior East

Returns:

Type Description
Point

Point object

Source code in flaui/lib/system/drawing.py
def immediate_interior_east(self) -> Point:
    """Returns immediate interior East

    :return: Point object
    """
    return self.east(-1)

immediate_interior_north()

Returns immediate interior North

Returns:

Type Description
Point

Point object

Source code in flaui/lib/system/drawing.py
def immediate_interior_north(self) -> Point:
    """Returns immediate interior North

    :return: Point object
    """
    return self.north(1)

immediate_interior_south()

Returns immediate interior South

Returns:

Type Description
Point

Point object

Source code in flaui/lib/system/drawing.py
def immediate_interior_south(self) -> Point:
    """Returns immediate interior South

    :return: Point object
    """
    return self.south(-1)

immediate_interior_west()

Returns immediate interior West

Returns:

Type Description
Point

Point object

Source code in flaui/lib/system/drawing.py
def immediate_interior_west(self) -> Point:
    """Returns immediate interior West

    :return: Point object
    """
    return self.west(1)

inflate(value)

Enlarges this Rectangle by the specified amount.

Parameters:

Name Type Description Default
value Tuple[int, int]

Value to enlarge

required

Returns:

Type Description
Rectangle

Enlarged Rectangle

Source code in flaui/lib/system/drawing.py
def inflate(self, value: Tuple[int, int]) -> Rectangle:
    """Enlarges this Rectangle by the specified amount.

    :param value: Value to enlarge
    :return: Enlarged Rectangle
    """
    # ``Rectangle.Inflate(int, int)`` is the void *instance* overload that mutates in place;
    # use the static ``Rectangle.Inflate(rect, x, y)`` overload to return a new Rectangle.
    return Rectangle(raw_value=CSRectangle.Inflate(self.raw_value, value[0], value[1]))  # type: ignore

intersects_with(other)

Determines if this rectangle intersects with rect.

Parameters:

Name Type Description Default
other Rectangle

Value to check

required

Returns:

Type Description
bool

True if there is any intersection, otherwise False

Source code in flaui/lib/system/drawing.py
def intersects_with(self, other: Rectangle) -> bool:
    """Determines if this rectangle intersects with rect.

    :param other: Value to check
    :return: True if there is any intersection, otherwise False
    """
    return self.raw_value.IntersectsWith(other.raw_value)  # type: ignore

interset(other)

Replaces this Rectangle with the intersection of itself and the specified Rectangle. Returns a third Rectangle structure that represents the intersection of two other Rectangle structures. If there is no intersection, an empty Rectangle is returned.

Parameters:

Name Type Description Default
other Union[Rectangle, Tuple[Rectangle, Rectangle]]

Value to intersect with

required

Returns:

Type Description
Rectangle

Updated rectangle

Source code in flaui/lib/system/drawing.py
def interset(self, other: Union[Rectangle, Tuple[Rectangle, Rectangle]]) -> Rectangle:
    """Replaces this Rectangle with the intersection of itself and the specified Rectangle.
    Returns a third Rectangle structure that represents the intersection of two other Rectangle structures. If there is no intersection, an empty Rectangle is returned.

    :param other: Value to intersect with
    :return: Updated rectangle
    """
    # The single-argument instance ``Intersect(Rectangle)`` overload mutates in place and
    # returns void; use the static ``Rectangle.Intersect(a, b)`` overload, which returns the
    # intersection (an empty Rectangle when the two do not overlap).
    return Rectangle(
        raw_value=CSRectangle.Intersect(self.raw_value, other.raw_value)  # type: ignore
        if isinstance(other, Rectangle)
        else CSRectangle.Intersect(*[_.raw_value for _ in other])  # type: ignore
    )

make_even()

Makes the width and height of a rectangle a multiple of 2, if not already.

This is a direct coversion of Even method listed in FlaUI.Core.Tools.ExtensionMethods class.

Returns:

Type Description
Rectangle

A new Rectangle object with even dimensions (optional), or None if the input rectangle is None.

Source code in flaui/lib/system/drawing.py
def make_even(self) -> Rectangle:
    """
    Makes the width and height of a rectangle a multiple of 2, if not already.

    This is a direct coversion of Even method listed in FlaUI.Core.Tools.ExtensionMethods class.

    :return: A new Rectangle object with even dimensions (optional), or None if the input rectangle is None.
    """
    # In-place modification (if possible)
    try:
        if self.width % 2 == 1:
            self.width -= 1
        if self.height % 2 == 1:
            self.height -= 1

    except AttributeError:  # Handle cases where width/height are not modifiable
        raise ValueError("Something went wrong modifying width/height for the rectangle making it even.")
    else:
        # Create a new self if in-place modification is not possible
        return Rectangle(raw_value=self.raw_value)

north(by=0)

Returns North of the rectangle as a Point object

Parameters:

Name Type Description Default
by int

Move by, defaults to 0

0

Returns:

Type Description
Point

Point object

Source code in flaui/lib/system/drawing.py
def north(self, by: int = 0) -> Point:
    """Returns North of the rectangle as a Point object

    :param by: Move by, defaults to 0
    :return: Point object
    """
    return Point(raw_value=(self.center().x, self.top + by))

offset(x=None, y=None, point=None)

Adjusts the location of this rectangle by the specified amount.

Parameters:

Name Type Description Default
x Optional[int]

x-coordinate, defaults to None

None
y Optional[int]

y-coordinate, defaults to None

None
point Optional[Point]

Point object, defaults to None

None
Source code in flaui/lib/system/drawing.py
def offset(self, x: Optional[int] = None, y: Optional[int] = None, point: Optional[Point] = None) -> None:
    """Adjusts the location of this rectangle by the specified amount.

    :param x: x-coordinate, defaults to None
    :param y: y-coordinate, defaults to None
    :param point: Point object, defaults to None
    """
    self.raw_value.Offset(x, y) if point is None else self.raw_value.Offset(point.raw_value)  # type: ignore

parse_cs_object(v) classmethod

Parses C# Rectangle object from System.Drawing namespace

Parameters:

Name Type Description Default
v Union[List[int], Tuple[Point, Size], Rectangle]

Input value

required

Returns:

Type Description
Point

Parsed C# object

Source code in flaui/lib/system/drawing.py
@field_validator("raw_value")
@classmethod
def parse_cs_object(cls, v: Union[List[int], Tuple[Point, Size], CSRectangle]) -> CSPoint:
    """Parses C# Rectangle object from System.Drawing namespace

    :param v: Input value
    :return: Parsed C# object
    """
    if isinstance(v, CSRectangle):
        return v
    if isinstance(v, List) and len(v) == 4:
        return CSRectangle(*v)
    elif (isinstance(v, List) or isinstance(v, Tuple)) and (
        len(v) == 2 and isinstance(v[0], Point) and isinstance(v[1], Size)
    ):
        return CSRectangle(v[0].raw_value, v[1].raw_value)

    raise ValueError(f"Unable to parse input value to Rectable C# object, invalid input - {v}")

south(by=0)

Returns South of the rectangle as a Point object

Parameters:

Name Type Description Default
by int

Move by, defaults to 0

0

Returns:

Type Description
Point

Point object

Source code in flaui/lib/system/drawing.py
def south(self, by: int = 0) -> Point:
    """Returns South of the rectangle as a Point object

    :param by: Move by, defaults to 0
    :return: Point object
    """
    return Point(raw_value=(self.center().x, self.bottom + by))

to_string()

Converts the attributes of this Rectangle to a human-readable string.

Returns:

Type Description
str

Point as readable string.

Source code in flaui/lib/system/drawing.py
def to_string(self) -> str:
    """Converts the attributes of this Rectangle to a human-readable string.

    :return: Point as readable string.
    """
    return self.raw_value.ToString()  # type: ignore

union(others)

Gets a Rectangle structure that contains the union of two Rectangle structures.

Parameters:

Name Type Description Default
others Tuple[Rectangle, Rectangle]

Tuple of rectangles to compare

required

Returns:

Type Description
Rectangle

A Rectangle structure that bounds the union of the two Rectangle structures.

Source code in flaui/lib/system/drawing.py
def union(self, others: Tuple[Rectangle, Rectangle]) -> Rectangle:
    """Gets a Rectangle structure that contains the union of two Rectangle structures.

    :param others: Tuple of rectangles to compare
    :return: A Rectangle structure that bounds the union of the two Rectangle structures.
    """
    return Rectangle(raw_value=self.raw_value.Union(*[_.raw_value for _ in others]))  # type: ignore

west(by=0)

Returns West of the rectangle as a Point object

Parameters:

Name Type Description Default
by int

Move by, defaults to 0

0

Returns:

Type Description
Point

Point object

Source code in flaui/lib/system/drawing.py
def west(self, by: int = 0) -> Point:
    """Returns West of the rectangle as a Point object

    :param by: Move by, defaults to 0
    :return: Point object
    """
    return Point(raw_value=(self.left + by, self.center().y))

Size

Bases: BaseModel

Represents a Size object, works with underlying C# System.Drawing.Size object. Stores an ordered pair of integers, which specify a Height and Width.

Note, this does not utilize SizeF object, just works with Size object.

height property writable

Gets vertical component of this Size

Returns:

Type Description
int

Vertical component of the Size

is_empty property

Indicates if the Size object is empty

Returns:

Type Description
bool

Flag True if empty else False

width property writable

Gets horizontal component of this Size

Returns:

Type Description
int

horizontal component of the Size

__add__(other)

Translates a size by a given Size

Parameters:

Name Type Description Default
other Size

Size object to add

required

Returns:

Type Description
Size

A new Size object with the translated coordinates

Source code in flaui/lib/system/drawing.py
def __add__(self, other: CSSize) -> Size:
    """Translates a size by a given Size

    :param other: Size object to add
    :return: A new Size object with the translated coordinates
    """
    if not isinstance(other, CSSize):
        raise TypeError(f"Unsupported operand type(s) for +: 'Size' and '{type(other)}'")

    return Size(raw_value=self.raw_value.Add(self.raw_value, other))  # type: ignore

__eq__(other)

Compares two Size objects for equality

Accepts any object (matches BaseModel signature) and returns False when the other object is not a Size.

Source code in flaui/lib/system/drawing.py
def __eq__(self, other: object) -> bool:
    """Compares two Size objects for equality

    Accepts any object (matches BaseModel signature) and returns False when the
    other object is not a Size.
    """
    if not isinstance(other, Size):
        return False

    return self.width == other.width and self.height == other.height

__ne__(other)

Compares two Size objects for inequality

Accepts any object (matches BaseModel signature).

Source code in flaui/lib/system/drawing.py
def __ne__(self, other: object) -> bool:
    """Compares two Size objects for inequality

    Accepts any object (matches BaseModel signature).
    """
    return not self == other

__sub__(other)

Translates the Size by the negative of the specified Size.

Parameters:

Name Type Description Default
other Size

Size object to subtract

required

Returns:

Type Description
Size

A new Size object with the translated coordinates

Source code in flaui/lib/system/drawing.py
def __sub__(self, other: CSSize) -> Size:
    """Translates the Size by the negative of the specified Size.

    :param other: Size object to subtract
    :return: A new Size object with the translated coordinates
    """
    if not isinstance(other, CSSize):
        raise TypeError(f"Unsupported operand type(s) for +: 'Size' and '{type(other)}'")

    return Size(raw_value=(self.width - other.Width, self.height - other.Height))  # type: ignore

add(other)

Adds the specified Size tot he specified Size

Parameters:

Name Type Description Default
other Size

The size to add

required

Returns:

Type Description
Size

The size that is the result of the addition operation

Source code in flaui/lib/system/drawing.py
def add(self, other: Size) -> Size:
    """Adds the specified Size tot he specified Size

    :param other: The size to add
    :return: The size that is the result of the addition operation
    """
    return Size(raw_value=self.raw_value.Add(self.raw_value, other.raw_value))  # type: ignore

equals(other)

Specifies whether this size instance contains the same coordinates as another size.

Parameters:

Name Type Description Default
other Size

Value to compare

required

Returns:

Type Description
bool

True if equal, else False

Source code in flaui/lib/system/drawing.py
def equals(self, other: Size) -> bool:
    """Specifies whether this size instance contains the same coordinates as another size.

    :param other: Value to compare
    :return: True if equal, else False
    """
    return self.raw_value.Equals(other.raw_value)  # type: ignore

get_hash_code()

Returns a hash code for this Size.

Returns:

Type Description
int

An integer value that specifies the hash code for this Size.

Source code in flaui/lib/system/drawing.py
def get_hash_code(self) -> int:
    """Returns a hash code for this Size.

    :return: An integer value that specifies the hash code for this Size.
    """
    return self.raw_value.GetHashCode()  # type: ignore

parse_cs_object(v) classmethod

Parses C# Size object from System.Drawing namespace

Parameters:

Name Type Description Default
v Union[Tuple[int, int], Tuple[float, float], Point, Size]

Input value

required

Returns:

Type Description
Size

Parsed C# object

Source code in flaui/lib/system/drawing.py
@field_validator("raw_value")
@classmethod
def parse_cs_object(cls, v: Union[Tuple[int, int], Tuple[float, float], Point, CSSize]) -> CSSize:
    """Parses C# Size object from System.Drawing namespace

    :param v: Input value
    :return: Parsed C# object
    """
    if isinstance(v, CSSize):
        return v

    return CSSize(v.raw_value) if isinstance(v, Point) else CSSize(round(v[0]), round(v[1]))

subtract(other)

Returns the result of subtracting specified Size from the specified Size.

Parameters:

Name Type Description Default
other Size

Size object

required

Returns:

Type Description
Size

Subtracted Size object

Source code in flaui/lib/system/drawing.py
def subtract(self, other: Size) -> Size:
    """Returns the result of subtracting specified Size from the specified Size.

    :param other: Size object
    :return: Subtracted Size object
    """
    return Size(raw_value=self.raw_value.Subtract(self.raw_value, other.raw_value))  # type: ignore

to_point()

Explicitly converts Size structure to Point structure

Returns:

Type Description
Point

Parsed Point object

Source code in flaui/lib/system/drawing.py
def to_point(self) -> Point:
    """Explicitly converts Size structure to Point structure

    :return: Parsed Point object
    """
    return Point(raw_value=(self.width, self.height))

to_string()

Converts this Size to a human-readable string.

Returns:

Type Description
str

Size as readable string.

Source code in flaui/lib/system/drawing.py
def to_string(self) -> str:
    """Converts this Size to a human-readable string.

    :return: Size as readable string.
    """
    return self.raw_value.ToString()  # type: ignore