Skip to content

Commit

Permalink
nodecontainer layed out with some functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
viperscape committed May 3, 2015
1 parent 41b00a1 commit de1e99e
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 17 deletions.
63 changes: 63 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,72 @@
extern crate conrod;
extern crate elmesque;
extern crate opengl_graphics;

pub use toolpane::{ToolPane};
pub use graph::{graphs};

pub mod toolpane;
pub mod node;
pub mod graph;


use conrod::{Ui,Label,Button,Positionable,Sizeable};
use opengl_graphics::glyph_cache::GlyphCache;
// we have to track actions outside of a conrod widget, from what I understand, for us to manipulate widget to widget
// hence the nodecontainer, which lays out the node object visually, and controls its appearance
pub struct NodeContainer {
xy: [f64;2],
drag: bool,
collapse: bool,
destroy: bool,
sidx: usize, //start index
}

impl NodeContainer {
pub fn new(idx: usize, xy:[f64;2]) -> NodeContainer {
NodeContainer {
xy: xy,
drag: false,
collapse: false,
destroy: false,
// we need a starting index so conrod is happy, it'd make more sense if conrod returned an index when creating the widgets; instead we'll track manually
sidx: idx,
}
}
pub fn draw(&mut self, ui: &mut Ui<GlyphCache>) {
// todo: update graph if we destroy node
if self.destroy { return } // probably should do a real drop!

let idx = self.sidx;
Button::new() //this should be a press-action, not a release; fixme with custom widget! also conrod should have a drag controller widget, which is basically what we're building
.xy(self.xy[0], self.xy[1])
.dimensions(100.0,20.0)
.react(|| { self.drag = !self.drag; })
.set(idx,ui);

Button::new()
.right(5.0)
.dimensions(20.0,20.0)
.react(|| { self.collapse = !self.collapse; })
.set(idx+1,ui);

Button::new()
.right(5.0)
.dimensions(20.0,20.0)
.react(|| { self.destroy=true; })
.set(idx+2,ui);

if !self.collapse {
Label::new(&idx.to_string())
.down_from(idx, 5.0)
.set(idx+3,ui);
}
}

pub fn update(&mut self, xy: [f64;2]) {
// check for destroy until we formally remove nodecontainer
if !self.destroy && self.drag {
self.xy = xy;
}
}
}
40 changes: 23 additions & 17 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
extern crate mush;

use mush::{ToolPane};
use mush::{NodeContainer};

extern crate conrod;
extern crate glutin_window;
extern crate opengl_graphics;
extern crate piston;

use conrod::{Background, Button, Colorable, Labelable, Sizeable, Theme, Ui,
use conrod::{Background, Button, Toggle , Colorable, Labelable, Sizeable, Theme, Ui,
Positionable, TextBox, CustomWidget, Position};
use glutin_window::GlutinWindow;
use opengl_graphics::{ GlGraphics, OpenGL };
Expand All @@ -33,36 +33,42 @@ fn main () {
.samples(4)
);

// window.window.set_window_resize_callback(Some(resized as fn(u32,u32)));

let event_iter = window.events().ups(180).max_fps(60);
let mut gl = GlGraphics::new(opengl);
let font_path = Path::new("fonts/SourceCodePro-Regular.otf");
let theme = Theme::default();
let glyph_cache = GlyphCache::new(&font_path).unwrap();
let ui = &mut Ui::new(glyph_cache, theme);

let mut count: u32 = 0;

let mut ui = &mut Ui::new(glyph_cache, theme);

let mut cont = NodeContainer::new(0,[120.0,120.0]);
let mut cont2 = NodeContainer::new(6,[400.0,200.0]); //for now trakc index manually, so no overlaps. It may be best to use a NodePane controller, which handles this state/count

for event in event_iter {
ui.handle_event(&event);

if let Some(args) = event.render_args() {
gl.draw(args.viewport(), |_, gl| {

// Draw the background.
// Background::new().rgb(0.2, 0.2, 0.2).draw(ui, gl);


mush::node::Node::new()
.label("Thingy")
.xy(100.0, 100.0)
.dimensions(100.0, 40.0)
.set(2, ui);

Background::new().rgb(0.2, 0.2, 0.2).draw(ui, gl); //this swaps buffers for us

cont.update(ui.mouse.xy);
cont.draw(&mut ui);

cont2.update(ui.mouse.xy);
cont2.draw(&mut ui);

/* mush::node::Node::new()
.label("Thingy")
.xy(100.0, 100.0)
.dimensions(100.0, 40.0)
.set(2, ui);*/

// Draw our Ui!
ui.draw(gl);

});
}
}
Expand Down

0 comments on commit de1e99e

Please sign in to comment.