1
0
Fork 0

canvas.gui: tweak label size hints and text color.

This commit is contained in:
Thomas Geymayer 2014-06-21 16:07:15 +02:00
parent ca96c27ab2
commit 4b00bb3067
4 changed files with 30 additions and 17 deletions

View file

@ -122,7 +122,11 @@ gui.Widget = {
},
# protected:
_MAX_SIZE: 32768, # size for "no size-limit"
_onStateChange: func {},
_onStateChange: func
{
if( me._view != nil and me._view.update != nil )
me._view.update(me);
},
_setView: func(view)
{
me._view = view;

View file

@ -117,7 +117,7 @@ var MessageBox = {
vbox.addSpacing(MARGIN);
var w = vbox.sizeHint()[0];
var w = math.max(300, vbox.sizeHint()[0]);
dlg.setSize(w, math.max(130, vbox.heightForWidth(w)));
return me;

View file

@ -203,22 +203,28 @@ DefaultStyle.widgets.label = {
}
me._createElement("text", "text")
.set("text", text)
.set("fill", "black");
.set("text", text);
var hfw_func = nil;
var min_width = me._text.maxWidth() + 4;
var width_hint = min_width;
if( model._cfg.get("wordWrap", 0) )
{
var m = me;
model.setHeightForWidthFunc(func(w) m.heightForWidth(w));
}
else
{
var min_width = me._text.maxWidth() + 4;
model.setMinimumSize([min_width, 14]);
model.setSizeHint([min_width, 24]);
hfw_func = func(w) m.heightForWidth(w);
min_width = math.min(32, min_width);
# prefer approximately quadratic text blocks
if( width_hint > 24 )
width_hint = int(math.sqrt(width_hint * 24));
}
return me;
model.setHeightForWidthFunc(hfw_func);
model.setMinimumSize([min_width, 14]);
model.setSizeHint([width_hint, 24]);
return me.update(model);
},
setImage: func(model, img)
{
@ -250,6 +256,14 @@ DefaultStyle.widgets.label = {
return math.max(14, me._text.heightForWidth(w - 4));
},
update: func(model)
{
if( me['_text'] != nil )
{
var color_name = model._windowFocus() ? "fg_color" : "backdrop_fg_color";
me._text.set("fill", me._style.getColor(color_name));
}
},
# protected:
_createElement: func(name, type)
{

View file

@ -54,11 +54,6 @@ gui.widgets.Button = {
return me;
},
# protected:
_onStateChange: func
{
if( me._view != nil )
me._view.update(me);
},
_setView: func(view)
{
var el = view._root;