#include <Pt/Forms/Icon.h>

Represents an image at one or more logical sizes. More...

Public Member Functions

 Icon ()
 Creates an empty icon with a built-in provider.
 
 Icon (const Icon &icon)
 Shares images with icon until addImage() or clear().
 
 Icon (IconProvider &provider)
 Attaches provider. The icon does not own it.
 
 ~Icon ()
 Releases this copy. More...
 
Iconoperator= (const Icon &icon)
 Shares images with icon until addImage() or clear().
 
bool empty () const
 Returns true when no images are registered.
 
void clear ()
 Removes all images from this icon. More...
 
void addImage (const Gfx::Image &image)
 Registers image using its pixel size as the key. More...
 
void addImage (const Gfx::SizeF &size, const Gfx::Image &image)
 Registers image at logical size size. More...
 
void addImage (const Gfx::SizeF &size, const System::Path &path)
 Registers a file path at logical size size. More...
 
void addImage (double width, double height, const System::Path &path)
 Registers a file path at width by height.
 
const Gfx::ImagegetImage (const Gfx::SizeF &area) const
 Returns an image for the requested area. More...
 
Gfx::SizeF minimumSize () const
 Returns the smallest registered size, or an empty size.
 
Gfx::SizeF maximumSize () const
 Returns the largest registered size, or an empty size.
 

Detailed Description

An Icon is not a Widget. It supplies images to controls, which request an image for a layout area with getImage(). Label, PushButton, Panel, and list items accept an Icon through setIcon().

A default icon uses a built-in provider. Icon(IconProvider&) attaches a caller-owned provider that must outlive the icon. Copies share the same implementation until addImage() or clear() changes one copy.

addImage() registers an image or file path at a logical size. Passing only an image uses its pixel size as the key. The logical size may differ from the pixel size. Images registered by path load as PNG on first use through Application::loadImage(). A missing path produces an empty image.

getImage() returns the registered image for a requested area. The built-in provider selects the largest image that fits entirely in that area. An empty icon produces an empty image. minimumSize() and maximumSize() return the smallest and largest registered keys.

icon.addImage(Pt::Gfx::SizeF(16, 16), Pt::System::Path("app-16.png"));
icon.addImage(Pt::Gfx::SizeF(32, 32), Pt::System::Path("app-32.png"));
label.setIcon(icon, Pt::Gfx::SizeF(16, 16));
label.setText("Hello");

Constructor & Destructor Documentation

◆ ~Icon()

~Icon ( )

The last copy destroys the shared images and detaches from a custom provider.

Member Function Documentation

◆ clear()

void clear ( )

Copies of this icon are not affected.

◆ addImage() [1/3]

void addImage ( const Gfx::Image image)

Copies of this icon are not affected.

◆ addImage() [2/3]

void addImage ( const Gfx::SizeF size,
const Gfx::Image image 
)

Copies of this icon are not affected. size may differ from the image pixel size.

◆ addImage() [3/3]

void addImage ( const Gfx::SizeF size,
const System::Path path 
)

The image loads on first use. Copies of this icon are not affected.

◆ getImage()

const Gfx::Image& getImage ( const Gfx::SizeF area) const

May load a path image on first use.

Represents an image at one or more logical sizes.
Definition: Icon.h:144
Control that displays text or an icon.
Definition: Label.h:80
void setText(const Pt::String &text)
Sets the caption to text and clears any icon.
Size with floating-point width and height.
Definition: Size.h:47
void setIcon(const Icon &icon, const Gfx::SizeF &iconSize)
Shows icon instead of the caption.
void addImage(const Gfx::Image &image)
Registers image using its pixel size as the key.
Represents a path in the file-system.
Definition: Path.h:48