Skip to content

Commit 54a2c35

Browse files
committed
export iui::draw again and fix it up
1 parent 88434ab commit 54a2c35

File tree

7 files changed

+43
-40
lines changed

7 files changed

+43
-40
lines changed

iui/src/controls/area.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
33
use controls::Control;
44
use draw;
5-
use std::os::raw::c_int;
65
use std::mem;
6+
use std::os::raw::c_int;
77
use ui::UI;
88
pub use ui_sys::uiExtKey as ExtKey;
99
use ui_sys::{
@@ -30,11 +30,11 @@ impl RustAreaHandler {
3030
fn new(_ctx: &UI, trait_object: Box<AreaHandler>) -> Box<RustAreaHandler> {
3131
return Box::new(RustAreaHandler {
3232
ui_area_handler: uiAreaHandler {
33-
Draw: draw,
34-
MouseEvent: mouse_event,
35-
MouseCrossed: mouse_crossed,
36-
DragBroken: drag_broken,
37-
KeyEvent: key_event,
33+
Draw: Some(draw),
34+
MouseEvent: Some(mouse_event),
35+
MouseCrossed: Some(mouse_crossed),
36+
DragBroken: Some(drag_broken),
37+
KeyEvent: Some(key_event),
3838
},
3939
trait_object: trait_object,
4040
});
@@ -116,7 +116,7 @@ impl RustAreaHandler {
116116
}
117117
}
118118

119-
define_control!{
119+
define_control! {
120120
/// A space on which the application can draw custom content.
121121
/// Area is a Control that represents a blank canvas that a program can draw on as
122122
/// it wishes. Areas also receive keyboard and mouse events, and programs can react
@@ -170,8 +170,8 @@ impl Area {
170170
let mut rust_area_handler = RustAreaHandler::new(ctx, area_handler);
171171
let area = Area::from_raw(ui_sys::uiNewScrollingArea(
172172
&mut *rust_area_handler as *mut RustAreaHandler as *mut uiAreaHandler,
173-
width,
174-
height,
173+
width as i32,
174+
height as i32,
175175
));
176176
mem::forget(rust_area_handler);
177177
area
@@ -188,7 +188,7 @@ impl Area {
188188
/// If called on a non-scrolling `Area`, this function's behavior is undefined.
189189
pub unsafe fn set_size(&self, _ctx: &UI, width: u64, height: u64) {
190190
// TODO: Check if the area is scrolling?
191-
unsafe { ui_sys::uiAreaSetSize(self.uiArea, width as i64, height as i64) }
191+
ui_sys::uiAreaSetSize(self.uiArea, width as i32, height as i32);
192192
}
193193

194194
/// Queues the entire `Area` to be redrawn. This function returns immediately;
@@ -205,7 +205,7 @@ impl Area {
205205
/// If called on a non-scrolling `Area`, this function's behavior is undefined.
206206
pub unsafe fn scroll_to(&self, _ctx: &UI, x: f64, y: f64, width: f64, height: f64) {
207207
// TODO: Make some way to check whether the given area is scrolling or not.
208-
unsafe { ui_sys::uiAreaScrollTo(self.uiArea, x, y, width, height) }
208+
ui_sys::uiAreaScrollTo(self.uiArea, x, y, width, height);
209209
}
210210
}
211211

@@ -253,11 +253,11 @@ impl AreaDrawParams {
253253
}
254254

255255
bitflags! {
256-
pub flags Modifiers: u8 {
257-
const MODIFIER_CTRL = 1 << 0,
258-
const MODIFIER_ALT = 1 << 1,
259-
const MODIFIER_SHIFT = 1 << 2,
260-
const MODIFIER_SUPER = 1 << 3,
256+
pub struct Modifiers: u8 {
257+
const MODIFIER_CTRL = 1 << 0;
258+
const MODIFIER_ALT = 1 << 1;
259+
const MODIFIER_SHIFT = 1 << 2;
260+
const MODIFIER_SUPER = 1 << 3;
261261
}
262262
}
263263

iui/src/controls/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ mod entry;
1919
pub use self::entry::*;
2020
mod progressbar;
2121
pub use self::progressbar::*;
22+
mod area;
23+
pub use self::area::*;
2224

2325
/// A generic UI control. Any UI control can be turned into this type.
2426
///

iui/src/draw/brush.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::marker::PhantomData;
22
use std::ptr;
3-
use ui::UI;
3+
use draw::DrawContext;
44
use ui_sys::{self, uiDrawBrush};
55

66
pub use ui_sys::uiDrawBrushGradientStop as BrushGradientStop;
@@ -22,7 +22,7 @@ pub struct BrushRef<'a> {
2222
}
2323

2424
impl Brush {
25-
pub fn as_ui_draw_brush_ref(&self, _ctx: &UI) -> BrushRef {
25+
pub fn as_ui_draw_brush_ref(&self, _ctx: &DrawContext) -> BrushRef {
2626
match *self {
2727
Brush::Solid(ref solid_brush) => BrushRef {
2828
ui_draw_brush: uiDrawBrush {

iui/src/draw/context.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use draw::{Brush, Path, StrokeParams, Transform};
2-
use ui::UI;
32
use ui_sys::{self, uiDrawContext};
43

54
/// Drawing context, used to draw custom content on the screen.
@@ -20,10 +19,10 @@ impl DrawContext {
2019
}
2120

2221
/// Draw a stroke on this DrawContext which runs along the given Path, with the given Brush and StrokeParams.
23-
pub fn stroke(&self, ctx: &UI, path: &Path, brush: &Brush, stroke_params: &StrokeParams) {
22+
pub fn stroke(&self, path: &Path, brush: &Brush, stroke_params: &StrokeParams) {
2423
unsafe {
25-
let brush = brush.as_ui_draw_brush_ref(ctx);
26-
let stroke_params = stroke_params.as_stroke_params_ref(ctx);
24+
let brush = brush.as_ui_draw_brush_ref(self);
25+
let stroke_params = stroke_params.as_stroke_params_ref(self);
2726
ui_sys::uiDrawStroke(
2827
self.ui_draw_context,
2928
path.ptr(),
@@ -34,25 +33,25 @@ impl DrawContext {
3433
}
3534

3635
/// Draw a fill on this DrawContext using the given Path using the given Brush.
37-
pub fn fill(&self, ctx: &UI, path: &Path, brush: &Brush) {
36+
pub fn fill(&self, path: &Path, brush: &Brush) {
3837
unsafe {
39-
let brush = brush.as_ui_draw_brush_ref(ctx);
38+
let brush = brush.as_ui_draw_brush_ref(self);
4039
ui_sys::uiDrawFill(self.ui_draw_context, path.ptr(), brush.ptr())
4140
}
4241
}
4342

4443
/// Transform this DrawContext by the given Transform.
45-
pub fn transform(&self, _ctx: &UI, txform: &Transform) {
44+
pub fn transform(&self, txform: &Transform) {
4645
unsafe { ui_sys::uiDrawTransform(self.ui_draw_context, txform.ptr()) }
4746
}
4847

4948
/// Open a modal allowing the user to save the contents of this DrawContext.
50-
pub fn save(&self, _ctx: &UI) {
49+
pub fn save(&self) {
5150
unsafe { ui_sys::uiDrawSave(self.ui_draw_context) }
5251
}
5352

5453
/// Open a modal allowing the user to load the contents of a DrawContext onto this one.
55-
pub fn restore(&self, _ctx: &UI) {
54+
pub fn restore(&self) {
5655
unsafe { ui_sys::uiDrawRestore(self.ui_draw_context) }
5756
}
5857
}

iui/src/draw/path.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::os::raw::c_int;
2-
use ui::UI;
2+
use draw::DrawContext;
33
use ui_sys::{self, uiDrawPath};
44

55
pub use ui_sys::uiDrawFillMode as FillMode;
@@ -15,21 +15,21 @@ impl Drop for Path {
1515
}
1616

1717
impl Path {
18-
pub fn new(_ctx: &UI, fill_mode: FillMode) -> Path {
18+
pub fn new(_ctx: &DrawContext, fill_mode: FillMode) -> Path {
1919
unsafe {
2020
Path {
2121
ui_draw_path: ui_sys::uiDrawNewPath(fill_mode),
2222
}
2323
}
2424
}
2525

26-
pub fn new_figure(&self, _ctx: &UI, x: f64, y: f64) {
26+
pub fn new_figure(&self, _ctx: &DrawContext, x: f64, y: f64) {
2727
unsafe { ui_sys::uiDrawPathNewFigure(self.ui_draw_path, x, y) }
2828
}
2929

3030
pub fn new_figure_with_arc(
3131
&self,
32-
_ctx: &UI,
32+
_ctx: &DrawContext,
3333
x_center: f64,
3434
y_center: f64,
3535
radius: f64,
@@ -50,13 +50,13 @@ impl Path {
5050
}
5151
}
5252

53-
pub fn line_to(&self, _ctx: &UI, x: f64, y: f64) {
53+
pub fn line_to(&self, _ctx: &DrawContext, x: f64, y: f64) {
5454
unsafe { ui_sys::uiDrawPathLineTo(self.ui_draw_path, x, y) }
5555
}
5656

5757
pub fn arc_to(
5858
&self,
59-
_ctx: &UI,
59+
_ctx: &DrawContext,
6060
x_center: f64,
6161
y_center: f64,
6262
radius: f64,
@@ -79,7 +79,7 @@ impl Path {
7979

8080
pub fn bezier_to(
8181
&self,
82-
_ctx: &UI,
82+
_ctx: &DrawContext,
8383
c1x: f64,
8484
c1y: f64,
8585
c2x: f64,
@@ -90,15 +90,15 @@ impl Path {
9090
unsafe { ui_sys::uiDrawPathBezierTo(self.ui_draw_path, c1x, c1y, c2x, c2y, end_x, end_y) }
9191
}
9292

93-
pub fn close_figure(&self, _ctx: &UI) {
93+
pub fn close_figure(&self, _ctx: &DrawContext) {
9494
unsafe { ui_sys::uiDrawPathCloseFigure(self.ui_draw_path) }
9595
}
9696

97-
pub fn add_rectangle(&self, _ctx: &UI, x: f64, y: f64, width: f64, height: f64) {
97+
pub fn add_rectangle(&self, _ctx: &DrawContext, x: f64, y: f64, width: f64, height: f64) {
9898
unsafe { ui_sys::uiDrawPathAddRectangle(self.ui_draw_path, x, y, width, height) }
9999
}
100100

101-
pub fn end(&self, _ctx: &UI) {
101+
pub fn end(&self, _ctx: &DrawContext) {
102102
unsafe { ui_sys::uiDrawPathEnd(self.ui_draw_path) }
103103
}
104104

iui/src/draw/strokeparams.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use std::os::raw::c_double;
21
use std::marker::PhantomData;
3-
use ui::UI;
2+
use std::os::raw::c_double;
3+
use draw::DrawContext;
44
use ui_sys::uiDrawStrokeParams;
55

66
pub use ui_sys::uiDrawLineCap as LineCap;
@@ -23,7 +23,7 @@ pub struct StrokeParamsRef<'a> {
2323
}
2424

2525
impl StrokeParams {
26-
pub fn as_stroke_params_ref(&self, _ctx: &UI) -> StrokeParamsRef {
26+
pub fn as_stroke_params_ref(&self, _ctx: &DrawContext) -> StrokeParamsRef {
2727
StrokeParamsRef {
2828
ui_draw_stroke_params: uiDrawStrokeParams {
2929
Cap: self.cap,

iui/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
//! For code examples, see the [examples](https://github.com/LeoTindall/libui-rs/blob/master/iui/examples/)
1818
//! directory.
1919
20+
#[macro_use]
21+
extern crate bitflags;
2022
#[macro_use]
2123
extern crate failure;
2224
extern crate libc;

0 commit comments

Comments
 (0)