2024-03-14 08:42:01 +08:00
|
|
|
var bricks = window.bricks || {};
|
|
|
|
|
|
|
|
bricks.IconBar = class extends bricks.HBox {
|
|
|
|
/*
|
|
|
|
{
|
|
|
|
margin:
|
|
|
|
rate:
|
|
|
|
tools:[
|
|
|
|
{
|
|
|
|
name:
|
|
|
|
icon:
|
|
|
|
rate:
|
2024-03-14 21:32:03 +08:00
|
|
|
dynsize:
|
2024-03-14 08:42:01 +08:00
|
|
|
tip
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
constructor(opts){
|
2024-05-30 23:38:31 +08:00
|
|
|
if (! opts.cheight){
|
|
|
|
opts.cheight = 2;
|
|
|
|
}
|
2024-03-14 08:42:01 +08:00
|
|
|
super(opts);
|
|
|
|
var tools = this.opts.tools;
|
|
|
|
for (var i=0;i<tools.length;i++){
|
2024-03-14 21:32:03 +08:00
|
|
|
var w = this.build_item(tools[i]);
|
2024-03-18 18:01:56 +08:00
|
|
|
w.set_style('margin-left', this.opts.margin || '10px');
|
|
|
|
w.set_style('margin-right', this.opts.margin || '10px');
|
2024-03-14 08:42:01 +08:00
|
|
|
if (tools[i].name){
|
2024-03-19 16:39:22 +08:00
|
|
|
w.set_id(tools[i].name);
|
2024-03-14 08:42:01 +08:00
|
|
|
}
|
|
|
|
w.set_style('cursor', 'pointer');
|
|
|
|
this.add_widget(w);
|
|
|
|
}
|
2024-05-30 23:38:31 +08:00
|
|
|
this.set_style('alignItems', 'center');
|
|
|
|
// this.set_style('justifyContent', 'center');
|
2024-03-14 21:32:03 +08:00
|
|
|
}
|
|
|
|
build_item(opts){
|
2024-03-19 13:06:19 +08:00
|
|
|
var rate = opts.rate || this.opts.rate || 1;
|
2024-03-14 21:32:03 +08:00
|
|
|
var h = bricks.app.charsize * rate;
|
|
|
|
if (this.height_int < h){
|
|
|
|
this.height_int = h;
|
|
|
|
}
|
2024-03-19 13:06:19 +08:00
|
|
|
if (opts.name == 'blankicon'){
|
|
|
|
return new bricks.BlankIcon({
|
|
|
|
rate:rate,
|
|
|
|
dynsize:opts.dynsize||true
|
|
|
|
});
|
|
|
|
}
|
2024-07-12 17:06:01 +08:00
|
|
|
var opts1 = bricks.extend({}, opts);
|
|
|
|
opts1.url = opts.icon;
|
|
|
|
opts1.rate = opts.rate || rate;
|
|
|
|
opts1.dynsize = opts.dynsize||true;
|
|
|
|
var w = new bricks.Icon(opts1);
|
|
|
|
w.bind('click', this.regen_event.bind(this, opts1));
|
2024-03-14 21:32:03 +08:00
|
|
|
return w;
|
2024-03-14 08:42:01 +08:00
|
|
|
}
|
|
|
|
regen_event(desc, event){
|
|
|
|
this.dispatch(desc.name, desc);
|
|
|
|
this.dispatch('command', desc);
|
|
|
|
event.stopPropagation();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-14 21:32:03 +08:00
|
|
|
bricks.IconTextBar = class extends bricks.IconBar {
|
|
|
|
build_item(opts){
|
|
|
|
var rate = opts.rate || this.opts.rate || 1;
|
|
|
|
var o = {
|
|
|
|
width:'auto',
|
|
|
|
height:'auto',
|
|
|
|
cheight:1.3 * rate
|
|
|
|
};
|
|
|
|
if (opts.tip){
|
|
|
|
o.tip = opts.tip;
|
|
|
|
}
|
|
|
|
var box = new bricks.HBox(o);
|
|
|
|
if (opts.icon){
|
|
|
|
var desc = {
|
|
|
|
url:opts.icon,
|
|
|
|
rate:opts.rate || rate,
|
|
|
|
dynsize:opts.dynsize||true
|
|
|
|
};
|
|
|
|
var w = new bricks.Icon(desc);
|
|
|
|
box.add_widget(w);
|
|
|
|
}
|
|
|
|
if (opts.label){
|
|
|
|
var desc = {
|
|
|
|
otext:opts.label,
|
|
|
|
i18n:true,
|
|
|
|
wrap:true,
|
|
|
|
haligh:'left',
|
|
|
|
rate:opts.rate || rate,
|
|
|
|
dynsize:opts.dynsize||true
|
|
|
|
};
|
|
|
|
var w = new bricks.Text(desc);
|
|
|
|
box.add_widget(w);
|
|
|
|
}
|
|
|
|
var h = bricks.app.charsize * rate;
|
|
|
|
if (this.height_int < h){
|
|
|
|
this.height_int = h;
|
|
|
|
}
|
2024-03-19 13:06:19 +08:00
|
|
|
box.bind('click', this.regen_event.bind(this,opts));
|
2024-03-14 21:32:03 +08:00
|
|
|
return box;
|
|
|
|
}
|
|
|
|
}
|
2024-03-14 08:42:01 +08:00
|
|
|
bricks.FloatIconBar = class extends bricks.HBox {
|
|
|
|
constructor(opts){
|
|
|
|
super(opts);
|
|
|
|
this.float_w = new bricks.Icon({url:bricks_resource('imgs/float-out.png')});
|
|
|
|
this.float_w.bind('mousemove', this.show_icons.bind(this));
|
|
|
|
this.add_widget(this.float_w);
|
2024-03-14 21:32:03 +08:00
|
|
|
this.icons_box = this.build_bar(opts);
|
|
|
|
this.add_widget(this.icons_box);
|
|
|
|
this.hide_icons()
|
|
|
|
this.set_style('height', this.icons_box.height_int + 'px')
|
2024-03-14 08:42:01 +08:00
|
|
|
bricks.Body.bind('click', this.hide_icons.bind(this));
|
|
|
|
}
|
2024-03-14 21:32:03 +08:00
|
|
|
build_bar(opts){
|
|
|
|
return new bricks.IconBar(opts);
|
|
|
|
}
|
2024-03-14 08:42:01 +08:00
|
|
|
show_icons(){
|
|
|
|
this.icons_box.set_style('display', 'flex');
|
|
|
|
}
|
|
|
|
hide_icons(){
|
|
|
|
this.icons_box.set_style('display', 'none');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-14 21:32:03 +08:00
|
|
|
bricks.FloatIconTextBar = class extends bricks.FloatIconBar {
|
|
|
|
build_bar(opts){
|
|
|
|
return new bricks.IconTextBar(opts);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-14 08:42:01 +08:00
|
|
|
bricks.Factory.register('IconBar', bricks.IconBar);
|
2024-03-14 21:32:03 +08:00
|
|
|
bricks.Factory.register('IconTextBar', bricks.IconTextBar);
|
2024-03-14 08:42:01 +08:00
|
|
|
bricks.Factory.register('FloatIconBar', bricks.FloatIconBar);
|
2024-03-14 21:32:03 +08:00
|
|
|
bricks.Factory.register('FloatIconTextBar', bricks.FloatIconTextBar);
|