Skip to content

Commit 5586f54

Browse files
committed
pull out path fill modes into an enum
1 parent 183b170 commit 5586f54

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

iui/examples/canvas.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,18 @@ extern crate iui;
22
extern crate ui_sys;
33

44
use iui::controls::{
5-
Area, AreaDrawParams, AreaHandler, AreaMouseEvent, HorizontalBox, LayoutStrategy,
5+
Area, AreaDrawParams, AreaHandler, HorizontalBox, LayoutStrategy,
66
};
7-
use iui::draw::{Brush, Path, SolidBrush};
7+
use iui::draw::{Brush, Path, SolidBrush, FillMode};
88
use iui::prelude::*;
99
use std::f64::consts::PI;
10-
use ui_sys::uiDrawFillModeWinding;
1110

1211
struct HandleCanvas {}
1312
impl AreaHandler for HandleCanvas {
1413
fn draw(&mut self, _area: &Area, draw_params: &AreaDrawParams) {
1514
let ctx = &draw_params.context;
1615

17-
let path = Path::new(ctx, uiDrawFillModeWinding);
16+
let path = Path::new(ctx, FillMode::Winding);
1817
path.add_rectangle(ctx, 0., 0., draw_params.area_width, draw_params.area_height);
1918
path.end(ctx);
2019

@@ -27,7 +26,7 @@ impl AreaHandler for HandleCanvas {
2726

2827
draw_params.context.fill(&path, &brush);
2928

30-
let path = Path::new(ctx, uiDrawFillModeWinding);
29+
let path = Path::new(ctx, FillMode::Winding);
3130
for i in 0..100 {
3231
let x = i as f64 / 100.;
3332
let y = ((x * PI * 2.).sin() + 1.) / 2.;

iui/src/draw/path.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
use std::os::raw::c_int;
21
use draw::DrawContext;
3-
use ui_sys::{self, uiDrawPath};
4-
5-
pub use ui_sys::uiDrawFillMode as FillMode;
2+
use std::os::raw::c_int;
3+
use ui_sys::{self, uiDrawFillMode, uiDrawFillModeAlternate, uiDrawFillModeWinding, uiDrawPath};
64

75
pub struct Path {
86
ui_draw_path: *mut uiDrawPath,
@@ -14,11 +12,26 @@ impl Drop for Path {
1412
}
1513
}
1614

15+
#[derive(Clone, Copy, PartialEq)]
16+
pub enum FillMode {
17+
Winding,
18+
Alternate,
19+
}
20+
21+
impl FillMode {
22+
fn into_ui_fillmode(self) -> uiDrawFillMode {
23+
match self {
24+
FillMode::Winding => uiDrawFillModeWinding,
25+
FillMode::Alternate => uiDrawFillModeAlternate,
26+
}
27+
}
28+
}
29+
1730
impl Path {
1831
pub fn new(_ctx: &DrawContext, fill_mode: FillMode) -> Path {
1932
unsafe {
2033
Path {
21-
ui_draw_path: ui_sys::uiDrawNewPath(fill_mode),
34+
ui_draw_path: ui_sys::uiDrawNewPath(fill_mode.into_ui_fillmode()),
2235
}
2336
}
2437
}

0 commit comments

Comments
 (0)