There could be various reasons why you will want to subclass a UI, One of the common use case is to rearrange the various parts of a control UI the way you want it.
The example below (serach for "StandardScrollbarUI.create-main-panel" in Curl help), the buttons to increment and decrement the Scrollbar are rearranged to be both at one end.
All the controls in Curl are open sourced. If you have downloaded the Curl IDE then they are already in your m/c. On a win32 m/c, by default it will be in:
C:\Program Files\Curl Corporation\Surge\7\ide\gui\controls.
Note that you may have multiple Curl (major ) versions installed and so you may have multiple directories (like 4, 5, 6) under the Surge directory above.
Some of the controls use other controls in their UIs, like the Scrollbar, Slider, CommandButton, DateField etc and some don't, like the TextField, CommandButton etc.
{curl 6.0 applet}
|| A custom Scrollbar UI.
{define-class package CustomUI {inherits StandardScrollbarUI}
{constructor package {default
control:#Scrollbar = null,
...
}
{construct-super.StandardScrollbarUI
control = control,
...
}
}
{getter private {vertical-bar?}:bool
{return self.scrollbar.direction == Orientation.vertical}
}
{method protected open {create-main-panel}:Graphic
{return
{if self.vertical-bar? then
{VBox
vorigin = "top",
halign = "left",
hstretch? = true,
framelike-stretch? = true,
control-appearance-changeable? = true,
{self.create-channel},
{self.create-decrease-button},
{self.create-increase-button}
}
else
{HBox
horigin = "left",
valign = "top",
vstretch? = true,
framelike-stretch? = true,
control-appearance-changeable? = true,
{self.create-channel},
{self.create-decrease-button},
{self.create-increase-button}
}
}
}
}
{method public open {draw-channel
renderer2d:Renderer2d,
bounds:GRect
}:void
let constant psize:Distance = renderer2d.pixel-size
let constant psize2:Distance = psize + psize
let constant psize4:Distance = psize2 + psize2
{if self.vertical-bar? then
{renderer2d.render-rectangle
-bounds.lextent + (bounds.width / 2) - psize2,
-bounds.ascent,
psize4,
bounds.height,
fill-pattern = FillPattern.gray
}
else
{renderer2d.render-rectangle
-bounds.lextent,
-bounds.ascent + (bounds.height / 2) - psize2,
bounds.width,
psize4,
fill-pattern = FillPattern.gray
}
}
}
}
{Scrollbar ui-object = {CustomUI}, direction = "horizontal"}