Class ImageControl
- Namespace
- SharpConsoleUI.Controls
- Assembly
- SharpConsoleUI.dll
Displays a PixelBuffer as a half-block image in a console window. Each character cell represents 2 vertical pixels.
public class ImageControl : BaseControl, IWindowControl, IDisposable, IDOMPaintable, INotifyPropertyChanged
- Inheritance
-
ImageControl
- Implements
- Inherited Members
- Extension Methods
Properties
Container
Gets or sets the parent container that hosts this control.
public override IContainer? Container { get; set; }
Property Value
ContentWidth
Gets the minimum width needed to display the control's content, including margins. Returns null if width cannot be determined. This is calculated based on content (text length, child controls, etc.) and represents the natural/intrinsic size.
public override int? ContentWidth { get; }
Property Value
- int?
Remarks
For None returns the natural pixel-buffer width plus margins,
so a host like ScrollablePanel can size its extent to the full image. For Fit / Fill / Stretch
returns null because the displayed width is layout-determined.
MinimumHeight
Minimum measured height (in cells) for the control's layout box, including margins. Does not enlarge the drawn image — only pads the measured box. Default: 0.
public int MinimumHeight { get; set; }
Property Value
MinimumWidth
Minimum measured width (in cells) for the control's layout box, including margins. Does not enlarge the drawn image — only pads the measured box. Default: 0.
public int MinimumWidth { get; set; }
Property Value
ScaleMode
How the image scales to fit available space.
public ImageScaleMode ScaleMode { get; set; }
Property Value
Source
The pixel buffer to render as an image.
public PixelBuffer? Source { get; set; }
Property Value
Methods
GetLogicalContentSize()
Gets the logical size of the control's content without rendering.
public override Size GetLogicalContentSize()
Returns
- Size
The size representing the content's natural dimensions.
Remarks
For None returns the natural cell dimensions of the source image plus margins. For Fit / Fill / Stretch returns only the margin contribution, because the image footprint is determined by the layout pass and reporting a logical size would cause hosts (e.g. scroll containers) to over-allocate extent for an auto-scaling image.
GetRenderGeometry(LayoutRect)
Computes the render rectangle (inside bounds, after margins) and
crop offsets for the current source and scale mode, without painting. Intended for use
by future graphics-protocol back-ends (e.g. Kitty/Sixel) that need to know the exposed
pixel region of the image.
protected (LayoutRect renderRect, int cropX, int cropY) GetRenderGeometry(LayoutRect bounds)
Parameters
boundsLayoutRectThe outer layout bounds assigned to this control.
Returns
- (LayoutRect renderRect, int cropX, int cropY)
A tuple of the render rectangle (inside margins) and the crop offsets into the rendered cell buffer. Returns an empty rect with zero offsets when the source is null or the available area is non-positive.
InvalidateImageCache()
Invalidates the renderer's internal cache. The next PaintDOM(CharacterBuffer, LayoutRect, LayoutRect, Color, Color) will re-render the image from the source pixel buffer. Callers that change external state which affects rendering (for example, swapping the theme that drives the container background) should invoke this to guarantee the cache is rebuilt.
public void InvalidateImageCache()
MeasureDOM(LayoutConstraints)
Measures the control's desired size given the available constraints.
public override LayoutSize MeasureDOM(LayoutConstraints constraints)
Parameters
constraintsLayoutConstraintsThe layout constraints (min/max width/height).
Returns
- LayoutSize
The desired size of the control.
PaintDOM(CharacterBuffer, LayoutRect, LayoutRect, Color, Color)
Paints the control's content directly to a CharacterBuffer.
public override void PaintDOM(CharacterBuffer buffer, LayoutRect bounds, LayoutRect clipRect, Color defaultForeground, Color defaultBackground)
Parameters
bufferCharacterBufferThe buffer to paint to.
boundsLayoutRectThe absolute bounds where the control should paint.
clipRectLayoutRectThe clipping rectangle (visible area).
defaultForegroundColorThe default foreground color from the container.
defaultBackgroundColorThe default background color from the container.