@@ -117,12 +117,37 @@ impl RustAreaHandler {
117
117
}
118
118
119
119
define_control ! {
120
- /// A control which takes up space on which the application can draw custom content.
120
+ /// A space on which the application can draw custom content.
121
+ /// Area is a Control that represents a blank canvas that a program can draw on as
122
+ /// it wishes. Areas also receive keyboard and mouse events, and programs can react
123
+ /// to those as they see fit. Drawing and event handling are handled through an
124
+ /// instance of a type that implements `AreaHandler` that every `Area` has; see
125
+ /// `AreaHandler` for details.
126
+ ///
127
+ /// There are two types of areas. Non-scrolling areas are rectangular and have no
128
+ /// scrollbars. Programs can draw on and get mouse events from any point in the
129
+ /// `Area`, and the size of the Area is decided by package ui itself, according to
130
+ /// the layout of controls in the Window the Area is located in and the size of said
131
+ /// Window. There is no way to query the Area's size or be notified when its size
132
+ /// changes; instead, you are given the area size as part of the draw and mouse event
133
+ /// handlers, for use solely within those handlers.
134
+ ///
135
+ /// Scrolling areas have horziontal and vertical scrollbars. The amount that can be
136
+ /// scrolled is determined by the area's size, which is decided by the programmer
137
+ /// (both when creating the Area and by a call to SetSize). Only a portion of the
138
+ /// Area is visible at any time; drawing and mouse events are automatically adjusted
139
+ /// to match what portion is visible, so you do not have to worry about scrolling in
140
+ /// your event handlers. AreaHandler has more information.
141
+ ///
142
+ /// The internal coordinate system of an Area is points, which are floating-point and
143
+ /// device-independent. For more details, see `AreaHandler`. The size of a scrolling
144
+ /// Area must be an exact integer number of points
121
145
rust_type: Area ,
122
146
sys_type: uiArea
123
147
}
124
148
125
149
impl Area {
150
+ /// Creates a new non-scrolling area.
126
151
pub fn new ( ctx : & UI , area_handler : Box < AreaHandler > ) -> Area {
127
152
unsafe {
128
153
let mut rust_area_handler = RustAreaHandler :: new ( ctx, area_handler) ;
@@ -134,6 +159,7 @@ impl Area {
134
159
}
135
160
}
136
161
162
+ /// Creates a new scrolling area.
137
163
pub fn new_scrolling (
138
164
ctx : & UI ,
139
165
area_handler : Box < AreaHandler > ,
@@ -156,28 +182,58 @@ impl Area {
156
182
Area { uiArea : ui_area }
157
183
}
158
184
159
- pub fn set_size ( & self , _ctx : & UI , width : i64 , height : i64 ) {
185
+ /// Sets the size of the area in points.
186
+ ///
187
+ /// # Unsafety
188
+ /// If called on a non-scrolling `Area`, this function's behavior is undefined.
189
+ pub unsafe fn set_size ( & self , _ctx : & UI , width : u64 , height : u64 ) {
190
+ // TODO: Check if the area is scrolling?
160
191
unsafe { ui_sys:: uiAreaSetSize ( self . uiArea , width, height) }
161
192
}
162
193
194
+ /// Queues the entire `Area` to be redrawn. This function returns immediately;
195
+ /// the `Area` is redrawn when the UI thread is next non-busy.
163
196
pub fn queue_redraw_all ( & self , _ctx : & UI ) {
164
197
unsafe { ui_sys:: uiAreaQueueRedrawAll ( self . uiArea ) }
165
198
}
166
199
167
- pub fn scroll_to ( & self , _ctx : & UI , x : f64 , y : f64 , width : f64 , height : f64 ) {
200
+ /// Scrolls the Area to show the given rectangle. This behavior is somewhat
201
+ /// implementation defined, but you can assume that as much of the given rectangle
202
+ /// as possible will be visible after this call.
203
+ ///
204
+ /// # Unsafety
205
+ /// If called on a non-scrolling `Area`, this function's behavior is undefined.
206
+ pub unsafe fn scroll_to ( & self , _ctx : & UI , x : f64 , y : f64 , width : f64 , height : f64 ) {
207
+ // TODO: Make some way to check whether the given area is scrolling or not.
168
208
unsafe { ui_sys:: uiAreaScrollTo ( self . uiArea , x, y, width, height) }
169
209
}
170
210
}
171
211
212
+ /// Provides a drawing context that can be used to draw on an Area, and tells you
213
+ /// where to draw. See `AreaHandler` for introductory information.
214
+ ///
215
+ /// Height and width values can change at any time, without generating an event,
216
+ /// so do not save them elsewhere.
217
+ ///
218
+ /// The clipping rectangle parameters specify the only area in which drawing is allowed.
219
+ /// The system will ensure nothing is drawn outside that area, but drawing is far faster
220
+ /// if the program does not attempt to put things out of bounds.
172
221
pub struct AreaDrawParams {
222
+ /// The `DrawContext` on which to draw. See `DrawContext` for how to draw.
173
223
pub context : draw:: DrawContext ,
174
224
225
+ /// The width of the `Area`, for non-scrolling `Area`s.
175
226
pub area_width : f64 ,
227
+ /// The height of the `Area`, for non-scrolling `Area`s.
176
228
pub area_height : f64 ,
177
229
230
+ /// Leftmost position of the clipping rectangle.
178
231
pub clip_x : f64 ,
232
+ /// Topmost position of the clipping rectangle.
179
233
pub clip_y : f64 ,
234
+ /// Width of the clipping rectangle.
180
235
pub clip_width : f64 ,
236
+ /// Height of the clipping rectangle.
181
237
pub clip_height : f64 ,
182
238
}
183
239
@@ -206,6 +262,7 @@ bitflags! {
206
262
}
207
263
208
264
#[ derive( Copy , Clone , Debug ) ]
265
+ /// Represents a mouse event in an `Area`.
209
266
pub struct AreaMouseEvent {
210
267
pub x : f64 ,
211
268
pub y : f64 ,
@@ -224,7 +281,6 @@ pub struct AreaMouseEvent {
224
281
}
225
282
226
283
impl AreaMouseEvent {
227
- // TODO: check if UI is initialized?
228
284
pub fn from_ui_area_mouse_event ( ui_area_mouse_event : & uiAreaMouseEvent ) -> AreaMouseEvent {
229
285
AreaMouseEvent {
230
286
x : ui_area_mouse_event. X ,
@@ -234,13 +290,15 @@ impl AreaMouseEvent {
234
290
down : ui_area_mouse_event. Down ,
235
291
up : ui_area_mouse_event. Up ,
236
292
count : ui_area_mouse_event. Count ,
237
- modifiers : Modifiers :: from_bits ( ui_area_mouse_event. Modifiers as u8 ) . unwrap ( ) ,
293
+ modifiers : Modifiers :: from_bits ( ui_area_mouse_event. Modifiers as u8 )
294
+ . unwrap_or ( Modifiers :: empty ( ) ) ,
238
295
held_1_to_64 : ui_area_mouse_event. Held1To64 ,
239
296
}
240
297
}
241
298
}
242
299
243
300
#[ derive( Copy , Clone , Debug ) ]
301
+ /// A keypress or key release event for an `Area`.
244
302
pub struct AreaKeyEvent {
245
303
pub key : u8 ,
246
304
pub ext_key : ExtKey ,
@@ -250,13 +308,14 @@ pub struct AreaKeyEvent {
250
308
}
251
309
252
310
impl AreaKeyEvent {
253
- // TODO: check if UI is initialized?
254
311
pub fn from_ui_area_key_event ( ui_area_key_event : & uiAreaKeyEvent ) -> AreaKeyEvent {
255
312
AreaKeyEvent {
256
313
key : ui_area_key_event. Key as u8 ,
257
314
ext_key : ui_area_key_event. ExtKey ,
258
- modifier : Modifiers :: from_bits ( ui_area_key_event. Modifier as u8 ) . unwrap ( ) ,
259
- modifiers : Modifiers :: from_bits ( ui_area_key_event. Modifiers as u8 ) . unwrap ( ) ,
315
+ modifier : Modifiers :: from_bits ( ui_area_key_event. Modifier as u8 )
316
+ . unwrap_or ( Modifiers :: empty ( ) ) ,
317
+ modifiers : Modifiers :: from_bits ( ui_area_key_event. Modifiers as u8 )
318
+ . unwrap_or ( Modifiers :: empty ( ) ) ,
260
319
up : ui_area_key_event. Up != 0 ,
261
320
}
262
321
}
0 commit comments