Mercurial > projects > mde
comparison mde/gui/widget/TextWidget.d @ 126:c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
EnumContent sub-contents use EnumValueContent instead of BoolContent; fixes a few small bugs.
EnumContent substrings get translated (bug fixed).
The widget manager no longer attempts to set widget sizes smaller than their minimals, even though some will not be shown.
SwitchWidget: has fixed sizableness now.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Thu, 08 Jan 2009 13:05:44 +0000 |
parents | d3b2cefd46c9 |
children | c5c38eaadb64 |
comparison
equal
deleted
inserted
replaced
125:3e648bc53bde | 126:c9843fbaac88 |
---|---|
109 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData, IContent c) { | 109 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData, IContent c) { |
110 content = c; | 110 content = c; |
111 if (content is null) throw new ContentException (this); | 111 if (content is null) throw new ContentException (this); |
112 super (mgr, parent, id); | 112 super (mgr, parent, id); |
113 | 113 |
114 Content c2 = cast(Content) content; | |
115 if (c2) // add callback if possible | |
116 c2.addCallback (&update); | |
114 adapter = mgr.renderer.getAdapter (); | 117 adapter = mgr.renderer.getAdapter (); |
115 adapter.text = content.toString(0); | 118 adapter.text = content.toString(0); |
116 } | 119 } |
117 | 120 |
118 protected: | 121 protected: |
122 void update (Content) { // callback | |
123 adapter.text = content.toString(0); | |
124 } | |
119 IContent content; | 125 IContent content; |
120 } | 126 } |
121 | 127 |
122 /// Text-box for editing a content's value. Generic − any AStringContent. | 128 /// Text-box for editing a content's value. Generic − any AStringContent. |
123 class AStringContentWidget : ATextWidget | 129 class AStringContentWidget : ATextWidget |
125 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData, IContent c) { | 131 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData, IContent c) { |
126 content = cast(AStringContent) c; | 132 content = cast(AStringContent) c; |
127 if (content is null) throw new ContentException (this); | 133 if (content is null) throw new ContentException (this); |
128 super (mgr, parent, id); | 134 super (mgr, parent, id); |
129 | 135 |
136 content.addCallback (&update); | |
130 adapter = mgr.renderer.getAdapter (); | 137 adapter = mgr.renderer.getAdapter (); |
131 adapter.text = content.toString(0); | 138 adapter.text = content.toString(0); |
132 } | 139 } |
133 | 140 |
134 override bool isWSizable () { return true; } | 141 override bool isWSizable () { return true; } |
143 } | 150 } |
144 | 151 |
145 override void keyEvent (ushort s, char[] i) { | 152 override void keyEvent (ushort s, char[] i) { |
146 adapter.text = content.keyStroke (s, i); | 153 adapter.text = content.keyStroke (s, i); |
147 adapter.index = content.editIndex; | 154 adapter.index = content.editIndex; |
148 adapter.getDimensions (mw, mh); | 155 wdim omw = mw, omh = mh; |
149 parent.minSizeChange (this, mw, mh); | 156 adapter.getDimensions (mw, mh); |
157 if (omw != mw) | |
158 parent.minWChange (this, mw); | |
159 if (omh != mh) | |
160 parent.minHChange (this, mh); | |
150 mgr.requestRedraw; | 161 mgr.requestRedraw; |
151 } | 162 } |
152 override void keyFocusLost () { | 163 override void keyFocusLost () { |
153 adapter.text = content.endEdit; // update other users of content relying on callbacks | 164 adapter.text = content.endEdit; // update other users of content relying on callbacks |
154 adapter.index; | 165 adapter.index; |
155 mgr.requestRedraw; | 166 mgr.requestRedraw; |
156 } | 167 } |
157 | 168 |
158 protected: | 169 protected: |
170 void update (Content) { // callback | |
171 adapter.text = content.toString(0); | |
172 wdim omw = mw, omh = mh; | |
173 adapter.getDimensions (mw, mh); | |
174 if (omw != mw) | |
175 parent.minWChange (this, mw); | |
176 if (omh != mh) | |
177 parent.minHChange (this, mh); | |
178 } | |
159 AStringContent content; | 179 AStringContent content; |
160 } | 180 } |