Skip to content

Commit 518570e

Browse files
committed
Generalized mutate
1 parent 0d33cb3 commit 518570e

File tree

5 files changed

+141
-119
lines changed

5 files changed

+141
-119
lines changed

lesson-24-x/src/interface.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use render_gl::ColorBuffer;
66
use render_gl::{DebugLines, RectMarker};
77
use std::collections::HashMap;
88
use std::collections::BTreeSet;
9+
use failure;
10+
use resources;
911

1012
struct ControlInfo {
1113
_id: Ix,
@@ -64,31 +66,34 @@ pub struct Interface {
6466
controls: HashMap<Ix, ControlInfo>,
6567
event_read_buffer: Vec<Effect>,
6668
flush_updates_set: BTreeSet<Ix>,
69+
70+
debug_lines: DebugLines,
6771
}
6872

6973
impl Interface {
70-
pub fn new(size: ElementSize) -> Interface {
74+
pub fn new(gl: &gl::Gl, resources: &resources::Resources, size: ElementSize) -> Result<Interface, failure::Error> {
7175
let tree = Tree::new();
7276

7377
let events = tree.events();
7478
let fill = tree.create_root(controls::Fill::new());
7579

7680
fill.resize(size);
7781

78-
Interface {
82+
Ok(Interface {
7983
fill,
8084
events,
8185
controls: HashMap::new(),
8286
event_read_buffer: Vec::new(),
8387
flush_updates_set: BTreeSet::new(),
84-
}
88+
debug_lines: DebugLines::new(gl, resources)?,
89+
})
8590
}
8691

8792
pub fn resize(&mut self, size: ElementSize) {
8893
self.fill.resize(size);
8994
}
9095

91-
fn process_events(&mut self, debug_lines: &DebugLines) {
96+
fn process_events(&mut self) {
9297
self.events.drain_into(&mut self.event_read_buffer);
9398
self.flush_updates_set.clear();
9499

@@ -113,12 +118,13 @@ impl Interface {
113118
}
114119

115120
for id in &self.flush_updates_set {
121+
let debug_lines = &self.debug_lines;
116122
self.controls.get_mut(id).map(|c| c.flush_updates(debug_lines));
117123
}
118124
}
119125

120-
pub fn update(&mut self, _delta: f32, debuglines: &DebugLines) {
121-
self.process_events(debuglines)
126+
pub fn update(&mut self, _delta: f32) {
127+
self.process_events()
122128
}
123129

124130
pub fn mouse_move(&mut self, _x: i32, _y: i32) {}
@@ -127,5 +133,7 @@ impl Interface {
127133

128134
pub fn mouse_up(&mut self, _x: i32, _y: i32) {}
129135

130-
pub fn render(&mut self, _gl: &gl::Gl, _target: &ColorBuffer, _vp_matrix: &na::Matrix4<f32>) {}
136+
pub fn render(&mut self, gl: &gl::Gl, target: &ColorBuffer, vp_matrix: &na::Matrix4<f32>) {
137+
self.debug_lines.render(gl, target, vp_matrix);
138+
}
131139
}

lesson-24-x/src/main.rs

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ fn run() -> Result<(), failure::Error> {
7878
viewport.set_used(&gl);
7979
color_buffer.set_clear_color(&gl, na::Vector3::new(0.3, 0.3, 0.5));
8080

81-
let mut debug_lines = render_gl::DebugLines::new(&gl, &resources)?;
82-
83-
// let mut iface = Interface::new(ui::ElementSize::Fixed { w: window_size.highdpi_width, h: window_size.highdpi_height });
84-
let mut iface = Interface::new(ui::ElementSize::Fixed { w: viewport.w, h: viewport.h });
81+
let mut iface = Interface::new(&gl, &resources, ui::ElementSize::Fixed { w: viewport.w, h: viewport.h })?;
8582

8683
// main loop
8784

@@ -104,31 +101,15 @@ fn run() -> Result<(), failure::Error> {
104101
viewport.update_size(hdpi_w as i32, hdpi_h as i32);
105102
viewport.set_used(&gl);
106103
iface.resize(ui::ElementSize::Fixed { w: hdpi_w as i32, h: hdpi_h as i32 });
107-
// iface.resize(ui::ElementSize::Auto);
108104
},
109105
_ => (),
110106
};
111-
112-
// match event {
113-
// sdl2::event::Event::KeyDown { scancode: Some(sdl2::keyboard::Scancode::C), .. } => {
114-
// side_cam = !side_cam;
115-
// },
116-
// sdl2::event::Event::KeyDown { scancode: Some(sdl2::keyboard::Scancode::I), .. } => {
117-
// debug_lines.toggle();
118-
// },
119-
// sdl2::event::Event::KeyDown { scancode: Some(sdl2::keyboard::Scancode::P), .. } => {
120-
// frame_profiler.toggle();
121-
// allocation_profiler.toggle();
122-
// gl_call_profiler.toggle();
123-
// },
124-
// _ => (),
125-
// }
126107
}
127108

128109
let delta = time.elapsed().as_fractional_secs() as f32;
129110
time = Instant::now();
130111

131-
iface.update(delta, &debug_lines);
112+
iface.update(delta);
132113

133114
unsafe {
134115
gl.Enable(gl::CULL_FACE);
@@ -146,7 +127,6 @@ fn run() -> Result<(), failure::Error> {
146127
let ui_matrix = na::Matrix4::new_nonuniform_scaling(&[1.0, -1.0, 1.0].into())
147128
* na::Matrix4::new_orthographic(left as f32, right as f32, bottom as f32, top as f32, -10.0, 10.0);
148129

149-
debug_lines.render(&gl, &color_buffer, &ui_matrix);
150130
iface.render(&gl, &color_buffer, &ui_matrix);
151131

152132
while time.elapsed() < Duration::from_millis(12) {

lib/resources/src/backend/filesystem.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::path::{Path, PathBuf};
22
use std::{io, fs};
33
use backend::{Backend, BackendSyncPoint};
44
use {ResourcePath, Error};
5-
use std::io::Read;
65

76
pub struct FileSystem {
87
root_path: PathBuf,

lib/ui/src/lib.rs

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ pub mod controls {
1010
pub struct Text;
1111

1212
impl Element for Text {
13+
fn inflate(&mut self, mut base: Base) {
14+
base.enable_update(true);
15+
}
16+
1317
fn resize(&mut self, mut _base: Base, size: ElementSize) -> Option<ResolvedSize> {
1418
match size {
1519
ElementSize::Auto => Some(ResolvedSize { w: 100, h: 60 }),
@@ -18,19 +22,7 @@ pub mod controls {
1822
}
1923
}
2024

21-
pub struct Button {
22-
min_width: i32,
23-
min_height: i32,
24-
}
25-
26-
impl Button {
27-
pub fn new() -> Button {
28-
Button {
29-
min_width: 50,
30-
min_height: 30,
31-
}
32-
}
33-
}
25+
pub struct Button;
3426

3527
impl Element for Button {
3628
fn inflate(&mut self, mut base: Base) {
@@ -57,12 +49,11 @@ pub mod controls {
5749

5850
impl Element for Fill {
5951
fn inflate(&mut self, mut base: Base) {
60-
base.add(Button::new());
61-
base.add(Button::new());
52+
base.add(Text);
53+
base.add(Button);
6254
}
6355

6456
fn resize(&mut self, mut base: Base, size: ElementSize) -> Option<ResolvedSize> {
65-
println!("fill resize: size = {:?}", size);
6657
base.layout_vertical(size, 5)
6758
}
6859
}
@@ -87,14 +78,10 @@ pub enum Effect {
8778
Transform { id: Ix, absolute_transform: na::Projective3<f32> },
8879
}
8980

90-
pub enum ResizeDecision {
91-
AutoFromChildrenVertical,
92-
}
93-
9481
pub trait Element {
9582

96-
fn inflate(&mut self, base: Base) {}
97-
fn resize(&mut self, base: Base, size: ElementSize) -> Option<ResolvedSize>;
83+
fn inflate(&mut self, _base: Base) {}
84+
fn resize(&mut self, _base: Base, _size: ElementSize) -> Option<ResolvedSize>;
9885

9986
}
10087

0 commit comments

Comments
 (0)