Skip to content

Commit 7985349

Browse files
committed
add softbuf example
1 parent 0addfc0 commit 7985349

File tree

3 files changed

+60
-11
lines changed

3 files changed

+60
-11
lines changed

csv/src/main.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,20 @@ fn main() {
3535
let app = app::App::default().with_scheme(app::Scheme::Gtk);
3636
app::background(79, 79, 79);
3737
app::background2(41, 41, 41);
38-
app::foreground(255, 255, 255);
38+
app::foreground(150, 150, 150);
3939
let mut wind = window::Window::default().with_size(800, 600);
40-
wind.make_resizable(true);
41-
let mut browser = browser::Browser::new(5, 10, 100, 520, "");
42-
let mut frame = frame::Frame::default()
43-
.with_size(680, 520)
44-
.right_of(&browser, 10);
40+
let mut row = group::Flex::default_fill().row();
41+
wind.resizable(&row);
42+
let mut col = group::Flex::default().column();
43+
let mut browser = browser::Browser::default();
4544
let mut btn = button::Button::default()
46-
.with_label("Save image")
47-
.with_size(100, 30)
48-
.below_of(&frame, 15)
49-
.center_x(&wind);
50-
wind.make_resizable(true);
45+
.with_label("@filesave");
46+
// btn.set_label_color(Color::Magenta);
47+
col.end();
48+
col.fixed(&btn, 50);
49+
row.fixed(&col, 100);
50+
let mut frame = frame::Frame::default();
51+
wind.end();
5152
wind.show();
5253

5354
browser.set_type(browser::BrowserType::Hold);

softbuf/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "softbuf"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
fltk = { version = "1", features = ["rwh06"] }
10+
softbuffer = "0.4"

softbuf/src/main.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use fltk::{prelude::*, *};
2+
use std::num::NonZeroU32;
3+
4+
fn main() {
5+
const width: u32 = 400;
6+
const height: u32 = 300;
7+
let a = app::App::default();
8+
let mut w = window::Window::default().with_size(width as i32, height as i32);
9+
w.end();
10+
w.show();
11+
w.wait_for_expose();
12+
13+
let context = softbuffer::Context::new(w.clone()).unwrap();
14+
let mut surface = softbuffer::Surface::new(&context, w.clone()).unwrap();
15+
surface
16+
.resize(
17+
NonZeroU32::new(width).unwrap(),
18+
NonZeroU32::new(height).unwrap(),
19+
)
20+
.unwrap();
21+
22+
app::add_timeout(1.0, move || {
23+
let mut buffer = surface.buffer_mut().unwrap();
24+
for index in 0..(width * height) {
25+
let y = index / width;
26+
let x = index % width;
27+
let red = x % 255;
28+
let green = y % 255;
29+
let blue = (x * y) % 255;
30+
31+
buffer[index as usize] = blue | (green << 8) | (red << 16);
32+
}
33+
buffer.present().unwrap();
34+
});
35+
36+
37+
a.run().unwrap();
38+
}

0 commit comments

Comments
 (0)