-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nodecontainer layed out with some functionality
- Loading branch information
1 parent
41b00a1
commit de1e99e
Showing
2 changed files
with
86 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters