diff --git a/Nasal/canvas/gui/Widget.nas b/Nasal/canvas/gui/Widget.nas index d852cdc10..0ec18e096 100644 --- a/Nasal/canvas/gui/Widget.nas +++ b/Nasal/canvas/gui/Widget.nas @@ -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; diff --git a/Nasal/canvas/gui/dialogs/MessageBox.nas b/Nasal/canvas/gui/dialogs/MessageBox.nas index 8b0ae1dc9..76e6065d3 100644 --- a/Nasal/canvas/gui/dialogs/MessageBox.nas +++ b/Nasal/canvas/gui/dialogs/MessageBox.nas @@ -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; diff --git a/Nasal/canvas/gui/styles/DefaultStyle.nas b/Nasal/canvas/gui/styles/DefaultStyle.nas index 22ee8bbbc..8291c18ce 100644 --- a/Nasal/canvas/gui/styles/DefaultStyle.nas +++ b/Nasal/canvas/gui/styles/DefaultStyle.nas @@ -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) { diff --git a/Nasal/canvas/gui/widgets/Button.nas b/Nasal/canvas/gui/widgets/Button.nas index 65429792b..c388a2aee 100644 --- a/Nasal/canvas/gui/widgets/Button.nas +++ b/Nasal/canvas/gui/widgets/Button.nas @@ -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;