Drawings and DrawingProperties toolbar customization
The drawings toolbar supports full customization to allow flexible integration in your application.
You can:
-
Configure the drawings toolbar with only the buttons you need.
-
Use default buttons or integrate custom ones.
-
Provide a custom button implementation, including its icon, checked state, and click behavior.
-
Use default button callbacks in your custom UI
Available Drawing Types
The following drawing types are available for selection:
// Trend LinesDrawingType.TREND_LINEDrawingType.EXTENDED_LINEDrawingType.PRICE_LINEDrawingType.INFO_LINEDrawingType.ARROWDrawingType.HORIZONTAL_RAYDrawingType.RAYDrawingType.TIME_LINEDrawingType.TREND_CHANNELDrawingType.RANGE_VOLUME_PROFILEDrawingType.ANCHORED_VOLUME_PROFILEDrawingType.REGRESSION_TREND// Fibonacci and GannsDrawingType.PITCHFORKDrawingType.FIB_RAYSDrawingType.FIB_ARCSDrawingType.FIB_CIRCLESDrawingType.FIB_RETRACEMENTDrawingType.FIB_EXTENSIONDrawingType.FIB_CHANNELDrawingType.FIB_TIMEZONEDrawingType.FIB_TIME_EXTENSIONDrawingType.FIB_TIME_RATIOSDrawingType.GANN_SQUAREDrawingType.GANN_BOXDrawingType.GANN_FANDrawingType.FIB_SPIRAL// MarkupsDrawingType.HIGHLIGHTERDrawingType.BRUSHDrawingType.PATHDrawingType.CURVEDrawingType.ARCDrawingType.ARROW_UPDrawingType.ARROW_DOWNDrawingType.OVALDrawingType.RECTANGLEDrawingType.CYCLE_BRACKETS// ElliottsDrawingType.ELLIOTT_IMPULSEDrawingType.ELLIOTT_CORRECTION// RangesDrawingType.PRICE_RANGEDrawingType.DATE_RANGEDrawingType.DATE_AND_PRICE_RANGE// AnnotationsDrawingType.PRICE_LABELDrawingType.CALLOUTDrawingType.TEXT
Configuring Toolbar Drawing Buttons Based on Available Drawing Types
To configure which drawings toolbar buttons are shown based on the available drawing types, use the setSelected method on the drawings types repository.
drawingsTypesRepo.setSelected(setOf(DrawingType.ARC,DrawingType.ARROW,DrawingType.BRUSH,))
Adding Custom Buttons
To include your own buttons in the drawings toolbar, use the DrawingsToolbarButtonConfig.Custom implementation:
var drawingsToolbarConfig: List<DrawingsToolbarButtonConfig> by remember {mutableStateOf(listOf(DrawingsToolbarButtonConfig.Custom(name = "Custom ARC",content = ToolbarButtonContent.Text(text = "ARC",isEnabled = true,onClick = {drawingsToolbarSelectorController.selectDrawing(DrawingType.ARC)},)),DrawingsToolbarButtonConfig.Add()))}
Custom Button Content Types
Text Button
Use ToolbarButtonContent.Text for text-based buttons:
ToolbarButtonContent.Text(text = "My Button",isEnabled = true,onClick = { /* your logic */ },checked = false)
Icon Button
Use ToolbarButtonContent.Icon for icon-based buttons:
ToolbarButtonContent.Icon(icon = Icons.Default.Star,isEnabled = true,onClick = { /* your logic */ },checked = false)
Default Buttons
The following default button types are available:
DrawingsToolbarButtonConfig.Add() // 'Add' button that opens a list of available drawings
Drawings Toolbar Configuration Example
Here's a complete example of how to configure the drawings toolbar:
// Configure selected drawing typesdrawingsTypesRepo.setSelected(setOf(DrawingType.ARROW,DrawingType.BRUSH,))// Configure custom toolbar buttonsvar drawingsToolbarConfig: List<DrawingsToolbarButtonConfig> by remember {mutableStateOf(listOf(DrawingsToolbarButtonConfig.Custom(name = "Custom ARC",content = ToolbarButtonContent.Text(text = "ARC",isEnabled = true,onClick = {drawingsToolbarSelectorController.selectDrawing(DrawingType.ARC)},)),DrawingsToolbarButtonConfig.Add()))}
Pass this configuration to DxChartsScreen.
DxChartsScreen(//...drawingsToolbarConfig = drawingsToolbarConfig)
Building a Custom Drawings Toolbar
You can fully implement your own UI and manually bind drawing logic. You should create controller and provide callbacks to the view:
val drawingsToolbarSelectorController = DrawingsToolbarSelectorFactory.create(this)// Example usageIconButton(onClick = { drawingsToolbarSelectorController.selectDrawing(DrawingType.ARROW) }) { ... }IconButton(onClick = { drawingsToolbarSelectorController.add() }) { ... }
Button Properties
ToolbarButtonContent.Text Properties
text: String- The text to display on the buttonisEnabled: Boolean- Whether the button is enabledonClick: () -> Unit- Click handlerchecked: Boolean- Whether the button is in checked state (default: false)
ToolbarButtonContent.Icon Properties
icon: ImageVector- The icon to display on the buttonisEnabled: Boolean- Whether the button is enabledonClick: () -> Unit- Click handlerchecked: Boolean- Whether the button is in checked state (default: false)
DrawingsToolbarButtonConfig.Custom Properties
name: String- Name of the button (default: "Custom")content: ToolbarButtonContent- The button content (Icon or Text)
DrawingsToolbarButtonConfig.Add Properties
name: String- Name of the button (default: "Add")
DrawingProperties toolbar customization
The drawing properties toolbar controls tools like magnet mode, brush, line width, and color picker. You can both configure its buttons and wire your own UI via the selector controller.
Available Buttons (DrawingPropertiesToolbarButtonConfig)
Use these default button configs or provide custom ones:
// DefaultsDrawingPropertiesToolbarButtonConfig.Magnet() // toggle magnet modeDrawingPropertiesToolbarButtonConfig.Brush() // toggle brush modeDrawingPropertiesToolbarButtonConfig.LineWidth() // open line width selectorDrawingPropertiesToolbarButtonConfig.ColorPicker() // open color picker// CustomDrawingPropertiesToolbarButtonConfig.Custom(name = "Custom ColorPicker",content = ToolbarButtonContent.Text(text = "Color",isEnabled = true,onClick = { /* custom action */ },))
Wiring configuration into DxChartsScreen
Pass the drawingPropertiesToolbarConfig list to DxChartsScreen.
var drawingPropertiesToolbarConfig: List<DrawingPropertiesToolbarButtonConfig> by remember {mutableStateOf(listOf(DrawingPropertiesToolbarButtonConfig.Magnet(),DrawingPropertiesToolbarButtonConfig.Brush(),DrawingPropertiesToolbarButtonConfig.LineWidth(),DrawingPropertiesToolbarButtonConfig.ColorPicker(),))}DxChartsScreen(// ...drawingPropertiesToolbarConfig = drawingPropertiesToolbarConfig,)
Building a Custom Drawing Properties Toolbar
You can fully implement your own UI and manually bind button logic. You should create controller and provide callbacks to the view:
// Create controller (require a ViewModelStoreOwner and DrawingsFirstClickRepo)val drawingPropertiesToolbarController = DrawingPropertiesToolbarSelectorFactory.create(owner = this,drawingsRepository = drawingsFirstClickRepo)// Example usage in ComposeIconButton(onClick = { drawingPropertiesSelectorController.selectMagnet() }) { /* ... */ }IconButton(onClick = { drawingPropertiesSelectorController.selectBrush() }) { /* ... */ }IconButton(onClick = { drawingPropertiesSelectorController.selectLineWidth() }) { /* ... */ }IconButton(onClick = { drawingPropertiesSelectorController.selectColorPicker() }) { /* ... */ }