Skip to content

Commit

Permalink
add softbuf example
Browse files Browse the repository at this point in the history
  • Loading branch information
MoAlyousef committed Jul 26, 2024
1 parent 0addfc0 commit 7985349
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 11 deletions.
23 changes: 12 additions & 11 deletions csv/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,20 @@ fn main() {
let app = app::App::default().with_scheme(app::Scheme::Gtk);
app::background(79, 79, 79);
app::background2(41, 41, 41);
app::foreground(255, 255, 255);
app::foreground(150, 150, 150);
let mut wind = window::Window::default().with_size(800, 600);
wind.make_resizable(true);
let mut browser = browser::Browser::new(5, 10, 100, 520, "");
let mut frame = frame::Frame::default()
.with_size(680, 520)
.right_of(&browser, 10);
let mut row = group::Flex::default_fill().row();
wind.resizable(&row);
let mut col = group::Flex::default().column();
let mut browser = browser::Browser::default();
let mut btn = button::Button::default()
.with_label("Save image")
.with_size(100, 30)
.below_of(&frame, 15)
.center_x(&wind);
wind.make_resizable(true);
.with_label("@filesave");
// btn.set_label_color(Color::Magenta);
col.end();
col.fixed(&btn, 50);
row.fixed(&col, 100);
let mut frame = frame::Frame::default();
wind.end();
wind.show();

browser.set_type(browser::BrowserType::Hold);
Expand Down
10 changes: 10 additions & 0 deletions softbuf/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "softbuf"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
fltk = { version = "1", features = ["rwh06"] }
softbuffer = "0.4"
38 changes: 38 additions & 0 deletions softbuf/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use fltk::{prelude::*, *};
use std::num::NonZeroU32;

fn main() {
const width: u32 = 400;
const height: u32 = 300;
let a = app::App::default();
let mut w = window::Window::default().with_size(width as i32, height as i32);
w.end();
w.show();
w.wait_for_expose();

let context = softbuffer::Context::new(w.clone()).unwrap();
let mut surface = softbuffer::Surface::new(&context, w.clone()).unwrap();
surface
.resize(
NonZeroU32::new(width).unwrap(),
NonZeroU32::new(height).unwrap(),
)
.unwrap();

app::add_timeout(1.0, move || {
let mut buffer = surface.buffer_mut().unwrap();
for index in 0..(width * height) {
let y = index / width;
let x = index % width;
let red = x % 255;
let green = y % 255;
let blue = (x * y) % 255;

buffer[index as usize] = blue | (green << 8) | (red << 16);
}
buffer.present().unwrap();
});


a.run().unwrap();
}

0 comments on commit 7985349

Please sign in to comment.