Skip to content

Commit

Permalink
Add a new Graphic Edge variant to the Graph and add a Widget::graphic…
Browse files Browse the repository at this point in the history
…s_for method to describe when a widget is solely a graphical element of some other widget. Addresses comment in PistonDevelopers#626
  • Loading branch information
mitchmindtree committed Nov 22, 2015
1 parent ccea7cf commit d664386
Show file tree
Hide file tree
Showing 20 changed files with 565 additions and 255 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ bitflags = "0.3.2"
clock_ticks = "0.1.0"
elmesque = "0.10.2"
json_io = "0.1.2"
daggy = "0.2.0"
daggy = "0.2.1"
pistoncore-input = "0.8.0"
piston2d-graphics = "0.11.0"
num = "0.1.27"
Expand Down
2 changes: 1 addition & 1 deletion src/graph/index_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl GraphIndex for widget::Index {
/// If not WidgetId is found, then tries to find a matching NodeIndex.
fn from_idx<I: GraphIndex>(other: I, map: &IndexMap) -> Option<Self> {
other.to_widget_id(map).map(|id| widget::Index::Public(id))
.or(other.to_node_index(map).map(|idx| widget::Index::Internal(idx)))
.or_else(|| other.to_node_index(map).map(|idx| widget::Index::Internal(idx)))
}

}
449 changes: 307 additions & 142 deletions src/graph/mod.rs

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub use widget::slider::Slider;
pub use widget::split::Split;
pub use widget::tabs::Tabs;
pub use widget::text_box::TextBox;
pub use widget::title_bar::TitleBar;
pub use widget::toggle::Toggle;
pub use widget::xy_pad::XYPad;

Expand All @@ -58,6 +59,7 @@ pub use widget::number_dialer::Style as NumberDialerStyle;
pub use widget::slider::Style as SliderStyle;
pub use widget::tabs::Style as TabsStyle;
pub use widget::text_box::Style as TextBoxStyle;
pub use widget::title_bar::Style as TitleBarStyle;
pub use widget::toggle::Style as ToggleStyle;
pub use widget::xy_pad::Style as XYPadStyle;

Expand All @@ -83,10 +85,10 @@ pub use position::{Corner, Depth, Direction, Dimension, Dimensions, Horizontal,
pub use position::Matrix as PositionMatrix;
pub use theme::{Align, Theme};
pub use ui::{GlyphCache, Ui, UserInput};
pub use widget::default_dimension;
pub use widget::{default_x_dimension, default_y_dimension};
pub use widget::{drag, scroll};
pub use widget::{CommonBuilder, CommonState, DrawArgs, Floating, MaybeParent, UiCell, UpdateArgs,
Widget};
pub use widget::{CommonBuilder, CommonState, CommonStyle, DrawArgs, Floating, MaybeParent, UiCell,
UpdateArgs, Widget};
pub use widget::{KidArea, KidAreaArgs};
pub use widget::CommonState as WidgetCommonState;
pub use widget::Id as WidgetId;
Expand Down
2 changes: 1 addition & 1 deletion src/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ pub mod matrix {
ui::set_current_parent_idx(ui, id);
}

let xy = ui.calc_xy(None, pos, dim, h_align, v_align);
let xy = ui.calc_xy(None, pos, dim, h_align, v_align, true);
let (half_w, half_h) = (dim[0] / 2.0, dim[1] / 2.0);
let widget_w = dim[0] / self.cols as f64;
let widget_h = dim[1] / self.rows as f64;
Expand Down
8 changes: 4 additions & 4 deletions src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,24 @@ pub struct WidgetDefault {
/// The unique style of a widget.
pub style: Box<Any>,
/// The attributes commonly shared between widgets.
pub common: widget::CommonBuilder,
pub common: widget::CommonStyle,
}

/// A **WidgetDefault** downcast to a **Widget**'s unique **Style** type.
#[derive(Copy, Clone, Debug)]
pub struct UniqueDefault<'a, T: 'a> {
/// The unique style for the widget.
pub style: &'a T,
/// Attributes that are common to between all widgets.
pub common: &'a widget::CommonBuilder,
/// Attributes that are common to all widgets.
pub common: &'a widget::CommonStyle,
}

impl WidgetDefault {
/// Constructor for a WidgetDefault.
pub fn new(style: Box<Any>) -> WidgetDefault {
WidgetDefault {
style: style,
common: widget::CommonBuilder::new(),
common: widget::CommonStyle::new(),
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/widget/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl<'a, F> Widget for Button<'a, F> where F: FnMut() {
}

fn unique_kind(&self) -> widget::Kind {
"Button"
KIND
}

fn init_state(&self) -> State {
Expand All @@ -139,11 +139,11 @@ impl<'a, F> Widget for Button<'a, F> where F: FnMut() {
}

fn default_x_dimension<C: CharacterCache>(&self, ui: &Ui<C>) -> Dimension {
widget::default_dimension(self, ui).unwrap_or(Dimension::Absolute(64.0))
widget::default_x_dimension(self, ui).unwrap_or(Dimension::Absolute(64.0))
}

fn default_y_dimension<C: CharacterCache>(&self, ui: &Ui<C>) -> Dimension {
widget::default_dimension(self, ui).unwrap_or(Dimension::Absolute(64.0))
widget::default_y_dimension(self, ui).unwrap_or(Dimension::Absolute(64.0))
}

/// Update the state of the Button.
Expand Down Expand Up @@ -184,7 +184,7 @@ impl<'a, F> Widget for Button<'a, F> where F: FnMut() {
let frame_color = style.frame_color(ui.theme());
FramedRectangle::new(dim)
.middle_of(idx)
.picking_passthrough(true)
.graphics_for(idx)
.color(color)
.frame(frame)
.frame_color(frame_color)
Expand All @@ -198,7 +198,7 @@ impl<'a, F> Widget for Button<'a, F> where F: FnMut() {
let font_size = style.label_font_size(ui.theme());
Label::new(label)
.middle_of(rectangle_idx)
.picking_passthrough(true)
.graphics_for(idx)
.color(color)
.font_size(font_size)
.set(label_idx, &mut ui);
Expand Down
19 changes: 7 additions & 12 deletions src/widget/drop_down_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ use ::{
Color,
Colorable,
Dimension,
Element,
FontSize,
Frameable,
Labelable,
NodeIndex,
Positionable,
Rect,
Rectangle,
Scalar,
Sizeable,
Theme,
Expand Down Expand Up @@ -161,11 +161,11 @@ impl<'a, F> Widget for DropDownList<'a, F> where
}

fn default_x_dimension<C: CharacterCache>(&self, ui: &Ui<C>) -> Dimension {
widget::default_dimension(self, ui).unwrap_or(Dimension::Absolute(128.0))
widget::default_x_dimension(self, ui).unwrap_or(Dimension::Absolute(128.0))
}

fn default_y_dimension<C: CharacterCache>(&self, ui: &Ui<C>) -> Dimension {
widget::default_dimension(self, ui).unwrap_or(Dimension::Absolute(32.0))
widget::default_y_dimension(self, ui).unwrap_or(Dimension::Absolute(32.0))
}

/// Update the state of the DropDownList.
Expand Down Expand Up @@ -257,10 +257,11 @@ impl<'a, F> Widget for DropDownList<'a, F> where
let canvas_shift_y = ::position::align_top_of(dim[1], canvas_dim[1]);
let canvas_xy = [xy[0], xy[1] + canvas_shift_y];
let canvas_rect = Rect::from_xy_dim(canvas_xy, canvas_dim);
Canvas::new()
Rectangle::fill([dim[0], max_visible_height])
.graphics_for(idx)
//.frame_color(::color::black().alpha(0.0))
//.dim([dim[0], max_visible_height])
.color(::color::black().alpha(0.0))
.frame_color(::color::black().alpha(0.0))
.dim([dim[0], max_visible_height])
.point(canvas_xy)
.parent(Some(idx))
.floating(true)
Expand Down Expand Up @@ -327,12 +328,6 @@ impl<'a, F> Widget for DropDownList<'a, F> where
}
}

/// Construct an Element from the given DropDownList State.
fn draw<C: CharacterCache>(_args: widget::DrawArgs<Self, C>) -> Element {
// We don't need to draw anything, as DropDownList is entirely composed of other widgets.
::elmesque::element::empty()
}

}


Expand Down
4 changes: 2 additions & 2 deletions src/widget/envelope_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,11 @@ impl<'a, E, F> Widget for EnvelopeEditor<'a, E, F>
}

fn default_x_dimension<C: CharacterCache>(&self, ui: &Ui<C>) -> Dimension {
widget::default_dimension(self, ui).unwrap_or(Dimension::Absolute(256.0))
widget::default_x_dimension(self, ui).unwrap_or(Dimension::Absolute(256.0))
}

fn default_y_dimension<C: CharacterCache>(&self, ui: &Ui<C>) -> Dimension {
widget::default_dimension(self, ui).unwrap_or(Dimension::Absolute(128.0))
widget::default_y_dimension(self, ui).unwrap_or(Dimension::Absolute(128.0))
}

/// Update the state of the EnvelopeEditor's cached state.
Expand Down
4 changes: 2 additions & 2 deletions src/widget/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ impl<'a, F, W> Widget for Matrix<F> where
}

fn default_x_dimension<C: CharacterCache>(&self, ui: &Ui<C>) -> Dimension {
widget::default_dimension(self, ui).unwrap_or(Dimension::Absolute(128.0))
widget::default_x_dimension(self, ui).unwrap_or(Dimension::Absolute(128.0))
}

fn default_y_dimension<C: CharacterCache>(&self, ui: &Ui<C>) -> Dimension {
widget::default_dimension(self, ui).unwrap_or(Dimension::Absolute(64.0))
widget::default_y_dimension(self, ui).unwrap_or(Dimension::Absolute(64.0))
}

/// Update the state of the Matrix.
Expand Down
Loading

0 comments on commit d664386

Please sign in to comment.