Skip to content

Controls

James Clancey edited this page Feb 10, 2022 · 8 revisions

Comet Controls

Controls in Comet are lightweight. In order to keep them lightweight, each control has only 1-2 read-only constructor parameters.

View

View is the base type for all UI in Comet. Views are composable and can have a Body. The body can be specified by the [Body] attribute, or by setting the Body function.

Attribute:

class MyView : View 
{
	[Body]
	View view() => new VStack{
		new Text("Hello World")
	};
}

Function:

class MyView : View
{
	public MyView()
	{
		Body = () => new VStack{
			new Text("Hello World")
		};
	}
}

Text

Text is used to display a string on the screen.

Constructor Parameters

Name Type Description
Value String The text value to be displayed

Example:

new Text("Hello World")

Button

A button is used to display a string on the screen.

Constructor Parameters

Name Type Description
Text String The text value to be displayed
Clicked Action The action that fires when clicked/tapped

Example:

new Button("Click me!",()=> Console.WriteLine("I was clicked"))

ActivityIndicator

Displays a loading indicator.

Constructor Parameters

Name Type Description

Example:

new ActivityIndicator()

CheckBox

Constructor Parameters

Name Type Description
IsChecked bool Toggles the checked state

Example:

new CheckBox(true)

DatePicker

A Datepicker.

Constructor Parameters

Name Type Description
Date DateTime The current value
MinimumDate DateTime The Minimum value
MaximumDate DateTime The Maximum value

Example:

new DatePicker(DateTime.Today)

Image

Displays an image.

Constructor Parameters

Name Type Description
ImageSource String,ImageSource This value can be a string or an ImageSource. If its a string it can be a file path or url

Example:

new Image("comet_logo.png")

ListView

Displays a scrollable Vertical list of items. ListView can be virtualized, or passed in an existing ICollection.

Constructor Parameters

Name Type Description
Items ICollection Optional, can be virtualized instead. If this is an ObservableCollection, the List will auto update.

Example:

Virtualized

new ListView<int>
	{
		Count = () => 100,
		ItemFor = (i) => i,
		ViewFor = (i) => new Text($"{i}")
	};

Using List

new ListView<int>(Enumerable.Range(0,100).ToList())
	{
		ViewFor = (i) => new Text($"{i}")
	};

ProgressBar

RefreshView

ScrollView

SearchBar

SecureField

ShapeView

Slider

Spacer

Stepper

TabView

TextEditor

TextField

TimePicker

Toggle

WebView

Layouts

HStack

VStack

ZStack

HGrid

VGrid

Grid