Skip to content

Commit

Permalink
Add a canvas with scroll_kids set and a list to demonstrate cropping …
Browse files Browse the repository at this point in the history
…problems
  • Loading branch information
tdaffin committed May 6, 2019
1 parent e5333bb commit b84ae50
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion backends/conrod_example_shared/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct DemoApp {
ball_color: conrod_core::Color,
sine_frequency: f32,
rust_logo: conrod_core::image::Id,
list: Vec<bool>,
}


Expand All @@ -33,6 +34,7 @@ impl DemoApp {
ball_color: conrod_core::color::WHITE,
sine_frequency: 1.0,
rust_logo: rust_logo,
list: vec![true; 16],
}
}
}
Expand Down Expand Up @@ -68,6 +70,9 @@ widget_ids! {
// The title and introduction widgets.
title,
introduction,
// Nested canvas and list
section_canvas,
list,
// Shapes.
shapes_canvas,
rounded_rectangle,
Expand Down Expand Up @@ -103,7 +108,7 @@ widget_ids! {

/// Instantiate a GUI demonstrating every widget available in conrod.
pub fn gui(ui: &mut conrod_core::UiCell, ids: &Ids, app: &mut DemoApp) {
use conrod_core::{widget, Colorable, Labelable, Positionable, Sizeable, Widget};
use conrod_core::{widget, Colorable, Borderable, Labelable, Positionable, Sizeable, Widget};
use std::iter::once;

const MARGIN: conrod_core::Scalar = 30.0;
Expand Down Expand Up @@ -143,6 +148,50 @@ pub fn gui(ui: &mut conrod_core::UiCell, ids: &Ids, app: &mut DemoApp) {
.set(ids.introduction, ui);


/////////////////////////
///// Nested canvas /////
/////////////////////////


// Nest a canvas in the scroll region to illustrate a bug
widget::Canvas::new()
.down_from(ids.introduction, 10.0)
.padded_w_of(ids.canvas, MARGIN)
.h(320.0)
.border(2.0) // border makes bug easier to see
.color(conrod_core::color::LIGHT_BLUE.alpha(0.5))
.scroll_kids() // Got to have this set for the bug to happen
.set(ids.section_canvas, ui);


////////////////
///// List /////
////////////////


let (mut items, scrollbar) = widget::List::flow_down(app.list.len())
.down_from(ids.section_canvas, 10.0)
.item_size(50.0)
.scrollbar_on_top()
.padded_w_of(ids.canvas, MARGIN)
.h(300.0)
.set(ids.list, ui);

while let Some(item) = items.next(ui) {
let i = item.i;
let label = format!("item {}: {}", i, app.list[i]);
let toggle = widget::Toggle::new(app.list[i])
.label(&label)
.label_color(conrod_core::color::WHITE)
.color(conrod_core::color::LIGHT_BLUE);
for v in item.set(toggle, ui) {
app.list[i] = v;
}
}

if let Some(s) = scrollbar { s.set(ui) }


////////////////////////////
///// Lines and Shapes /////
////////////////////////////
Expand Down

0 comments on commit b84ae50

Please sign in to comment.