如何使用Rust-fltk表示例绘制自己的字符串数组



请!原谅我的英语写作技巧!。。。

我通过mycallback1例程确认sarray值已更改。(另一个函数…(然而CCD_ 3不是!。

如何绘制字符串数组,并通过函数更改字符串数组!

//..omitted
fn mycallback1(sarray : &mut [&str]) {
let max = 200 * 11;
for n in 0..max {
sarray[n] = "Array ^^^";
}
}

fn main() { 
//..omitted;
let mut sarray = [""; 200 * 11];
let max = 200 * 11;
for n in 0..max {
sarray[n] = "array ^";
}
butStock1.set_callback(Box::new(move || mycallback1(&mut sarray)));
// Called when the table is drawn then when it's redrawn due to events
table.draw_cell(Box::new(move |ctx, row, col, x, y, w, h| match ctx {
table::TableContext::StartPage => draw::set_font(Font::Helvetica, 14),
table::TableContext::ColHeader => {
let idx = col as usize;
draw_header(&format!("{}", tuple[idx]), x, y, w, h);
} // Column titles
table::TableContext::RowHeader => draw_header(&format!("{}", row + 1), x, y, w, h), // Row titles
table::TableContext::Cell => {
let idx = (row * 11 + col) as usize;
println!("Drawn {}", idx);
draw_data( &format!("{} {}", sarray[idx], idx), x, y, w, h, table_c.is_selected(row, col),); // Data in cells
}
_ => (),
}));
app.run().unwrap();
}

fltk的工作方式是,它只在"损坏;flag被设置,例如,当点击按钮时,点击会在按钮类中设置一个损坏标志,所以fltk会在下一帧中重新绘制它。

当一个表被"重绘"时,它也被重绘;"损坏";。更改数组中的值时,fltk无法知道必须重新绘制表。

因此,您可以为表或整个应用程序添加一个显式的重绘调用。

butStock1.set_callback(Box::new(move || {
mycallback1(&mut sarray);
fltk::app::redraw();
}));

最新更新