Skip to content

Commit

Permalink
fix calendar, egui-demo, ffmpeg, flresters
Browse files Browse the repository at this point in the history
  • Loading branch information
Artem V. Ageev committed Apr 1, 2024
1 parent 83843b2 commit 02ea696
Show file tree
Hide file tree
Showing 16 changed files with 218 additions and 50 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ jobs:
working-directory: csv
run: cargo build --verbose
shell: bash
- name: Build egui-demo
run: cargo build --verbose
working-directory: egui-demo
shell: bash
- name: Build femtovg
working-directory: femtovg
run: cargo build --verbose
Expand Down Expand Up @@ -167,10 +171,6 @@ jobs:
fi
working-directory: xterm
shell: bash
- name: Build egui-demo
run: cargo build --verbose
working-directory: egui-demo
shell: bash
- name: Build terminal
run: cargo build --verbose
working-directory: terminal
Expand Down
4 changes: 2 additions & 2 deletions calendar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
fltk = "1"
chrono = "0.4"
fltk = "^1.4"
chrono = "^0.4"
9 changes: 3 additions & 6 deletions calendar/src/calendar.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use chrono::DateTime;
use chrono::Datelike;
use chrono::Local;
use chrono::NaiveDate;
use chrono::{DateTime, Datelike, Local, NaiveDate};
use fltk::{app, draw, enums::*, menu, prelude::*, table, window};
use std::{cell::RefCell, rc::Rc};

Expand Down Expand Up @@ -93,14 +90,14 @@ impl Calendar {
_ => (),
});

let curr_rc = curr.clone();
let curr_rc = curr;
// redraw table when the month changes
month_choice.set_callback(move |c| {
*curr_rc.borrow_mut() = c.value() + 1;
c.parent().unwrap().redraw();
});

let curr_year_rc = curr_year.clone();
let curr_year_rc = curr_year;
// redraw table when the year changes
year_choice.set_callback(move |c| {
*curr_year_rc.borrow_mut() = c.value() + 1900;
Expand Down
23 changes: 11 additions & 12 deletions calendar/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
#![forbid(unsafe_code)]
mod calendar;

use fltk::{
prelude::*,
*,
};
use chrono::prelude::*;
use fltk::{prelude::*, *};

fn main() {
let app = app::App::default().with_scheme(app::Scheme::Gtk);
app::background(0xd3, 0xd3, 0xd3);
let mut win = window::Window::new(100, 100, 400, 300, "");
win.make_resizable(true);
let mut but = button::Button::new(160, 200, 80, 40, "Click");
win.end();
win.show();
but.set_callback(move |_| {
button::Button::new(160, 200, 80, 40, "Click").set_callback(move |_| {
let cal = calendar::Calendar::default(); // or calendar::Calendar::new(200, 100);
let date = cal.get_date();
println!("{:?}", date);
Expand All @@ -24,5 +16,12 @@ fn main() {
println!("{:?}", date.day());
}
});
app.run().unwrap();
win.make_resizable(true);
win.end();
win.show();
app::background(0xd3, 0xd3, 0xd3);
app::App::default()
.with_scheme(app::Scheme::Gtk)
.run()
.unwrap();
}
16 changes: 4 additions & 12 deletions egui-demo/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
use egui_backend::{
egui,
fltk::{
enums::*,
prelude::*,
*,
},
fltk::{enums::*, prelude::*, *},
gl, DpiScaling,
};
use fltk_egui as egui_backend;
use std::rc::Rc;
use std::{
cell::RefCell,
time::Instant
};
use std::{cell::RefCell, rc::Rc, time::Instant};

const SCREEN_WIDTH: u32 = 800;
const SCREEN_HEIGHT: u32 = 600;
Expand All @@ -38,7 +30,7 @@ fn main() {
slider.set_slider_size(0.20);
slider.set_color(Color::Blue.inactive());
slider.set_selection_color(Color::Red);
col.set_size(&mut slider, 20);
col.fixed(&slider, 20);
col.end();
main_win.end();
main_win.make_resizable(true);
Expand Down Expand Up @@ -118,7 +110,7 @@ fn main() {
let paint_jobs = egui_ctx.tessellate(paint_cmds);

//Draw egui texture
painter.paint_jobs(None, paint_jobs, &egui_ctx.texture());
painter.paint_jobs(None, paint_jobs, &egui_ctx.font_image());

glut_win.swap_buffers();
glut_win.flush();
Expand Down
2 changes: 1 addition & 1 deletion ffmpeg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
fltk = "1"
fltk = "^1.4"
signal-hook = "0.3"
lazy_static = "1.4"
16 changes: 6 additions & 10 deletions ffmpeg/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
#![forbid(unsafe_code)]
use fltk::{
app,
button,
enums::{
Color,
FrameType
},
frame,
image,
app, button,
enums::{Color, FrameType},
frame, image,
prelude::*,
window,
};
Expand All @@ -29,7 +25,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
fs::create_dir(&*VIDEO_TEMP_DIR).ok();

process::Command::new("ffmpeg")
.args(&[
.args([
"-i",
"../libvlc/video.mp4",
&format!("{}/%d.bmp", &*VIDEO_TEMP_DIR),
Expand All @@ -38,7 +34,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
.status()
.unwrap();

let mut signals = Signals::new(&[SIGINT])?;
let mut signals = Signals::new([SIGINT])?;
thread::spawn(move || {
for _sig in signals.forever() {
fs::remove_dir_all(&*VIDEO_TEMP_DIR).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion flcalculator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
homepage = "https://github.com/fltk-rs"
authors = "Artem V. Ageev"
authors = ["Artem V. Ageev"]
name = "flcalculator"
version = "0.0.1"
edition = "2021"
Expand Down
2 changes: 1 addition & 1 deletion fldialect/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
homepage = "https://github.com/fltk-rs"
authors = "Artem V. Ageev"
authors = ["Artem V. Ageev"]
name = "fldialect"
version = "0.0.1"
edition = "2021"
Expand Down
6 changes: 5 additions & 1 deletion fldialect/src/components/footer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ pub struct Footer {

impl Footer {
pub fn build(flex: &mut Flex, font: i32, size: i32) -> Self {
let fonts = Vec::from(["Courier".to_string(), "Helvetica".to_string(), "Times".to_string()]);
let fonts = Vec::from([
"Courier".to_string(),
"Helvetica".to_string(),
"Times".to_string(),
]);
let mut layout = Flex::default_fill();
let mut component = Self {
layout: layout.clone(),
Expand Down
18 changes: 18 additions & 0 deletions flresters/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "flresters"
version = "0.1.1"
edition = "2021"
description = "A lightweight cross-platform Rest API tester gui built using fltk-rs"
repository = "https://github.com/MoAlyousef/resters"
license = "MIT"
categories = ["visualization"]
documentation = "https://docs.rs/resters"
readme = "README.md"
keywords = ["cross-platform", "rest", "api", "gui", "http"]

[dependencies]
fltk = { version = "^1.4" }
fltk-theme = { version="^0.7" }
ureq = { version = "2.5.0", features = ["json"] }
serde_json = "1"
json-tools = "1.1"
19 changes: 19 additions & 0 deletions flresters/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 2 additions & 0 deletions flresters/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
![flResters](assets/base_dark_linux.png "flResters")
![flResters](assets/full_dark_linux.png "flResters")
Binary file added flresters/assets/base_dark_linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added flresters/assets/full_dark_linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
141 changes: 141 additions & 0 deletions flresters/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
use {
fltk::{enums::*, prelude::*, *},
fltk_theme::{color_themes, ColorTheme},
json_tools::{Buffer, BufferType, Lexer, Span, TokenType},
ureq::Error,
};

fn main() {
let mut sbuf = text::TextBuffer::default();
let styles: Vec<text::StyleTableEntry> = [0xdc322f, 0x268bd2, 0x859900]
.into_iter()
.map(|color| text::StyleTableEntry {
color: Color::from_hex(color),
font: Font::Courier,
size: 16,
})
.collect();
let mut window = window::Window::default()
.with_size(640, 360)
.with_label("flResters")
.center_screen();
window.set_xclass("resters");
let mut flex = group::Flex::default_fill().column();
let mut header = group::Flex::default();
flex.fixed(&header, 30);
let mut choice = menu::Choice::default();
choice.add_choice("GET|POST");
choice.set_value(0);
header.fixed(&choice, 80);
header.fixed(&frame::Frame::default().with_label("https://"), 60);
let mut inp = input::Input::default();
inp.set_trigger(CallbackTrigger::EnterKeyAlways);
let mut info = button::Button::default().with_label("ℹ️");
info.set_label_size(18);
info.set_frame(FrameType::NoBox);
info.set_callback(move |_| {
dialog::message_default("Resters was created using Rust and fltk-rs. It is MIT licensed!")
});
header.fixed(&info, 30);
header.end();
header.set_pad(10);
let mut disp = text::TextDisplay::default();
disp.wrap_mode(text::WrapMode::AtBounds, 0);
disp.set_buffer(text::TextBuffer::default());
disp.set_color(Color::from_hex(0x002b36));
disp.set_highlight_data(sbuf.clone(), styles);
let mut footer = group::Flex::default();
flex.fixed(&footer, 20);
footer.fixed(&frame::Frame::default().with_label("Status: "), 80);
let mut status = frame::Frame::default().with_align(Align::Left | Align::Inside);
footer.end();
flex.end();
flex.set_pad(10);
flex.set_margin(10);
window.end();
window.make_resizable(true);
window.show();
window.set_icon(Some(image::SvgImage::from_data(SVG).unwrap()));
inp.set_callback(move |inp| {
status.set_label("");
disp.buffer().unwrap().set_text("");
sbuf.set_text("");
let mut path = inp.value();
if !path.starts_with("https://") {
path = String::from("https://") + &path;
}
let req = match choice.value() {
0 => ureq::get(&path),
1 => ureq::post(&path),
_ => unreachable!(),
};
match req.call() {
Ok(response) => {
if let Ok(json) = response.into_json::<serde_json::Value>() {
let json: String = serde_json::to_string_pretty(&json).unwrap();
disp.buffer().unwrap().set_text(&json);
fill_style_buffer(&mut sbuf, &json);
status.set_label("200 OK");
status.set_label_color(enums::Color::Yellow);
} else {
dialog::message_default("Error parsing json");
}
}
Err(Error::Status(code, response)) => {
status.set_label(&format!("{} {}", code, response.status_text()));
status.set_label_color(enums::Color::Red);
}
Err(e) => {
dialog::message_default(&e.to_string());
}
}
});
ColorTheme::new(color_themes::DARK_THEME).apply();
app::set_scheme(app::Scheme::Plastic);
app::set_font(Font::Courier);
app::App::default().run().unwrap();
}

fn fill_style_buffer(sbuf: &mut text::TextBuffer, s: &str) {
let mut local_buf = vec![b'A'; s.len()];
for token in Lexer::new(s.bytes(), BufferType::Span) {
use TokenType::*;
let c = match token.kind {
CurlyOpen | CurlyClose | BracketOpen | BracketClose | Colon | Comma | Invalid => 'A',
String => 'B',
BooleanTrue | BooleanFalse | Null => 'C',
Number => 'D',
};
if let Buffer::Span(Span { first, end }) = token.buf {
let start = first as _;
let last = end as _;
local_buf[start..last].copy_from_slice(c.to_string().repeat(last - start).as_bytes());
}
}
sbuf.set_text(&String::from_utf8_lossy(&local_buf));
}

const SVG: &str = r#"<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="254" height="93" clip-path="url(#clipPath18)" id="svg2">
<metadata id="metadata4">
<rdf:RDF>
<cc:Work rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
<dc:title/>
</cc:Work>
</rdf:RDF>
</metadata>
<defs id="defs6">
<linearGradient id="linearGradient8" x1="159" y1="91" x2="23" y2="13" gradientUnits="userSpaceOnUse" spreadMethod="reflect">
<stop id="stop10" style="stop-color:#000000;stop-opacity:0" offset="0"/>
<stop id="stop12" style="stop-color:#000000;stop-opacity:0.192" offset="0.33"/>
<stop id="stop14" style="stop-color:#000000;stop-opacity:0.5" offset="0.72"/>
<stop id="stop16" style="stop-color:#000000;stop-opacity:1" offset="1"/>
</linearGradient>
</defs>
<rect width="254" height="93" id="rect22" style="fill:#d6ddf2;stroke:#7c808d;stroke-width:4"/>
<path d="m 271,-31.5 -71,71 0,-36.5 -90,0 0,17 28,0 0,53 -46,0 0,-70 -89,0 0,87 17,0 0,-34.5 36,0 0,-17 -36,0 0,-18.5 55,0 0,70 80,0 0,-70 28,0 0,70 17,0 0,-36 71,71 z M 254,84 216.75,46.75 254,9.5" id="path24" style="fill:#7c808d;stroke:#7c808d;stroke-width:6;stroke-linejoin:round"/>
<rect width="254" height="93" id="rect26" style="fill:url(#linearGradient8)"/>
<path d="m 72,11.5 -60.5,0 0,78.5 m 0,-43 44.5,0 m 27.5,-44 0,78.5 51.5,0 m -25,-70 70,0 m -33.5,0 0,78.5 m 45,-87 0,87 m 71,-101 -57.75,57.75 57.75,57.75" id="path28" style="fill:none;stroke:#ffffff;stroke-width:17"/>
</svg>"#;

0 comments on commit 02ea696

Please sign in to comment.