WIDGET
Empty widget (displays nothing but a background color if set) that can be used as a container for other widgets.
Attributes brief detailed show all inherited
Examples
You can use WIDGET for simple tasks like drawing a colored rectangle.
- <!-- draw a red rectangle -->
- <WIDGET background_color="#DD0000" width="200" height="10" />

Its true value emerges when creating custom WIDGETS (visual controls).
- <!-- create a param -->
- <PARAM id="demo_param" min="0" max="1" default="0.5" />
- <!-- use widget as a container -->
- <WIDGET id="my_widget" layout_type="layer_stack" background_color="#FFFFFF">
- <!-- draw a gradient -->
- <CANVAS opacity="1" id="canvas_1" width="50" height="50" render_script="
- double h=this.height, w=this.width;
- auto ctx=Kt::Graphics::GetCurrentContext();
- auto gradient = ctx.patterns.NewLinearGradient(0,0,0,h);
- gradient.AddColorStopRGB(0, 1,0,0); /* pos, r,g,b */
- gradient.AddColorStopRGB(demo_param, 1,0.7,0);
- gradient.AddColorStopRGB(1, 0,0.8,0);
- gradient.SelectAsSource();
- ctx.path.Clear();
- ctx.path.Arc(w/2, h/2, w/2, 0.01, 0); /* cx, cy, radius, angle_start, angle_end */
- ctx.FillPath();
- " requires="canvas_1.width;canvas_1.height;demo_param" />
- <!-- display value as text -->
- <PARAM_TEXT param_id="demo_param" text_color="#FFFFFF" />
- <!-- add an invisible knob to control parameter -->
- <INVISIBLE_PARAM_KNOB param_id="demo_param" width="100%" height="100%" />
- <!-- when parameter changes redraw canvas -->
- <ACTION_TRIGGER event_id="demo_param.value_changed" action_id="canvas_1.Invalidate" />
- </WIDGET>
- <!-- edit some of the widget parameters -->
- <CELL v_margin="10" font_size="12">
- <PARAM_TEXT_CONTROL param_id="my_widget.visible" content="visible: {value}" />
- <PARAM_TEXT_CONTROL param_id="my_widget.opacity" content="opacity: {value}" />
- <PARAM_TEXT_CONTROL param_id="my_widget.background_color.r" content="background_color.r: {value}" />
- </CELL>

While WIDGET may appear similar to CELL, it offers significantly more functionality. Unlike CELL, which is solely used for layout calculations and cannot be rendered, WIDGET can have a visible background. Additionally, it supports mouse and keyboard event handling, and includes attributes such as opacity and visible.
Comments
Please, authorize to view and post comments.