Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add cairo's live-demo #11

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,59 @@ jobs:
if [[ ${RUNNER_OS} == "Linux" ]]; then
cargo build --quiet || cargo build --verbose
fi
- name: Build base64
working-directory: demos/base64
shell: bash
run: |
if [[ ${RUNNER_OS} == "Linux" ]]; then
cargo build --quiet || cargo build --verbose
fi
- name: Build cairo_shadow_button
working-directory: demos/cairo_shadow_button
shell: bash
run: |
if [[ ${RUNNER_OS} == "Linux" ]]; then
cargo build --quiet || cargo build --verbose
fi
- name: Build calculator
working-directory: demos/calculator
shell: bash
run: |
if [[ ${RUNNER_OS} == "Linux" ]]; then
cargo build --quiet || cargo build --verbose
fi
- name: Build csv
working-directory: demos/csv
shell: bash
run: |
if [[ ${RUNNER_OS} == "Linux" ]]; then
cargo build --quiet || cargo build --verbose
fi
- name: Build dialect
working-directory: demos/dialect
shell: bash
run: |
if [[ ${RUNNER_OS} == "Linux" ]]; then
cargo build --quiet || cargo build --verbose
fi
- name: Build flightbooker
working-directory: demos/flightbooker
shell: bash
run: |
if [[ ${RUNNER_OS} == "Linux" ]]; then
cargo build --quiet || cargo build --verbose
fi
- name: Build resters
working-directory: demos/resters
shell: bash
run: |
if [[ ${RUNNER_OS} == "Linux" ]]; then
cargo build --quiet || cargo build --verbose
fi
- name: Build sudokusolver
working-directory: demos/sudokusolver
shell: bash
run: |
if [[ ${RUNNER_OS} == "Linux" ]]; then
cargo build --quiet || cargo build --verbose
fi
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ exclude = ["./examples"]
[dependencies]
fltk = { version = "1.4" }
fltk-theme = "0.7"
fltk-table = "0.3"
fltk-grid = "0.4"
55 changes: 26 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,65 +77,62 @@ To run the [examples:](/examples)
cargo run --example counter
cargo run --example temperature
cargo run --example crud
cargo run --example flcalculator
cargo run --example fldialect
cargo run --example flglyph
cargo run --example flnetport
cargo run --example flpicture
cargo run --example flresters
...
```

### [FlCounter](/examples/counter.rs)
### [Counter](/examples/counter.rs)

![FlCalculator](/assets/counter.png)
![img](/assets/counter.png)

### [FlTemperature](/examples/temperature.rs)
### [Temperature](/examples/temperature.rs)

![FlTemperature](/assets/temperature.png)
![img](/assets/temperature.png)

### [FlCRUD](/examples/crud.rs)
### [CRUD](/examples/crud.rs)

![FlCRUD](/assets/crud.png)
![img](/assets/crud.png)

### [FlCalculator](/examples/flcalculator.rs)
### [Glyph](/examples/flglyph.rs)

![FlCalculator](/assets/flcalculator.gif)
![img](/assets/flglyph.png)

### [FlDialect](/examples/fldialect.rs)
### [NetPort](/examples/flnetport.rs)

![FlDialect](/assets/fldialect.gif)
![img](/assets/flnetport.png)

### [FlGlyph](/examples/flglyph.rs)
### [Picture](/examples/flpicture.rs)

![FlGlyph](/assets/flglyph.png)
![img](/assets/flpicture.gif)

### [FlNetPort](/examples/flnetport.rs)
## Demos

![FlNetPort](/assets/flnetport.png)
### [Cairo](/demos/cairo)

### [FlPicture](/examples/flpicture.rs)
![img](../demos/blob/master/cairo/assets/scrot.png)

![FlPicture](/assets/flpicture.gif)
### [Calculator](/demos/calculator)

### [FlResters](/examples/flresters.rs)
![img](../demos/blob/master/flcalculator/assets/flcalculator.gif)

![FlResters](/assets/flresters.png)
### [CSV](/demos/csv)

## Demos
![img](../demos/blob/master/csv/assets/csv.gif)

### [FlTodo](/demos/fltodo)
### [Dialect](/demos/dialect)

![FlTodo](/demos/fltodo/assets/fltodo.gif)
![img](../demos/blob/master/fldialect/assets/fldialect.gif)

### [FlCSV](/demos/csv)
### [Resters](/demos/resters)

![FlCSV](/demos/csv/assets/flcsv.png)
![img](../demos/blob/master/flresters/assets/flresters.gif)

### [FlCairo](/demos/cairo)
### [Todo](/demos/fltodo)

![FlCairo](/demos/cairo/assets/flcairo.png)
![img](/demos/fltodo/assets/fltodo.gif)

### [Flightbooker](/demos/flightbooker)

![Flightbooker](/demos/flightbooker/assets/flightbooker.png)
![img](/demos/flightbooker/assets/flightbooker.png)
9 changes: 8 additions & 1 deletion demos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@

resolver = "2"
members = [
"base64",
"cairo",
"cairo_shadow_button",
"calculator",
"csv",
"fltodo",
"dialect",
"flightbooker",
"resters",
"sudokusolver",
"text",
"todo",
]

[profile.release]
Expand Down
24 changes: 24 additions & 0 deletions demos/assets/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions demos/base64/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "b64converter"
version = "0.1.0"
edition = "2021"

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

[dependencies]
flemish = { path = "../../" }
base64 = "0.22"
5 changes: 5 additions & 0 deletions demos/base64/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Base64 demo

It's implementation that [program](https://github.com/andersjoern/b64converter/).

![img](https://github.com/andersjoern/b64converter/blob/master/screenshots/encode_decode.png)
128 changes: 128 additions & 0 deletions demos/base64/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
mod model;

use {
flemish::{
button::Button,
color_themes,
enums::{Color, Event, Font},
frame::Frame,
image::SvgImage,
group::{Flex, FlexType},
prelude::*,
text::{TextBuffer, TextEditor, WrapMode},
OnEvent, Sandbox, Settings,
},
model::Model,
};

const PAD: i32 = 10;
const HEIGHT: i32 = PAD * 3;
const NAME: &str = "FlBase64";

#[derive(Clone)]
pub enum Message {
Encode,
Decode,
Source(String),
Target(String),
}

fn main() {
Model::new().run(Settings {
resizable: true,
size: (360, 640),
xclass: Some(String::from(NAME)),
icon: Some(SvgImage::from_data(include_str!("../../assets/logo.svg")).unwrap()),
color_map: Some(color_themes::DARK_THEME),
..Default::default()
})
}

impl Sandbox for Model {
type Message = Message;

fn new() -> Self {
Self::default()
}

fn title(&self) -> String {
String::from(NAME)
}

fn view(&mut self) {
let mut page = Flex::default_fill().column();
{
let mut hero = Flex::default_fill();
{
crate::texteditor("Normal text", &self.decode, self.font, self.size)
.on_event(move |text| Message::Source(text.buffer().unwrap().text()));
Frame::default();
crate::texteditor("Base64 text", &self.encode, self.font, self.size)
.on_event(move |text| Message::Target(text.buffer().unwrap().text()));
}
hero.end();
hero.set_pad(0);
crate::orientation(&mut hero);
hero.handle(crate::resize);
let mut footer = Flex::default();
{
crate::button("Decode", "@<-", &mut footer).on_event(move |_| Message::Decode);
Frame::default();
crate::button("Encode", "@->", &mut footer).on_event(move |_| Message::Encode);
}
footer.end();
page.fixed(&footer, HEIGHT);
}
page.end();
page.set_pad(PAD);
page.set_margin(PAD);
}

fn update(&mut self, message: Message) {
match message {
Message::Source(value) => self.decode = value,
Message::Target(value) => self.encode = value,
Message::Encode => self.encode(),
Message::Decode => self.decode(),
}
}
}

fn texteditor(tooltip: &str, value: &str, font: i32, size: i32) -> TextEditor {
let mut element = TextEditor::default();
element.set_tooltip(tooltip);
element.set_linenumber_width(0);
element.set_buffer(TextBuffer::default());
element.wrap_mode(WrapMode::AtBounds, 0);
element.buffer().unwrap().set_text(value);
element.set_color(Color::from_hex(0x002b36));
element.set_text_color(Color::from_hex(0x93a1a1));
element.set_text_font(Font::by_index(font as usize));
element.set_text_size(size);
element
}

fn button(tooltip: &str, label: &str, flex: &mut Flex) -> Button {
let mut element = Button::default().with_label(label);
element.set_tooltip(tooltip);
element.set_label_size(HEIGHT / 2);
flex.fixed(&element, HEIGHT);
element
}

fn resize(flex: &mut Flex, event: Event) -> bool {
if event == Event::Resize {
crate::orientation(flex);
flex.fixed(&flex.child(1).unwrap(), PAD);
true
} else {
false
}
}

fn orientation(flex: &mut Flex) {
flex.set_type(match flex.width() < flex.height() {
true => FlexType::Column,
false => FlexType::Row,
});
}
29 changes: 29 additions & 0 deletions demos/base64/src/model/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use base64::{engine::general_purpose, Engine};

#[derive(Debug)]
pub struct Model {
pub decode: String,
pub encode: String,
pub font: i32,
pub size: i32,
}

impl Model {
pub fn default() -> Self {
Self {
decode: String::from("Normal text"),
encode: String::from("Base64 text"),
font: 0,
size: 14,
}
}
pub fn encode(&mut self) {
self.encode = general_purpose::STANDARD.encode(&self.decode);
}
pub fn decode(&mut self) {
self.decode = match general_purpose::STANDARD.decode(&self.encode) {
Ok(decode) => String::from_utf8(decode).unwrap(),
Err(error) => format!("{}", error),
}
}
}
4 changes: 2 additions & 2 deletions demos/cairo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "cairo_button"
name = "cairo_frame"
version = "0.1.0"
edition = "2021"

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

[dependencies]
flemish = { path = "../../" }
fltk = { version = "^1.4", features = ["use-ninja", "cairoext"] }
cairo-rs = "0.18"
cairo-blur = "^0.1"
5 changes: 5 additions & 0 deletions demos/cairo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Cairo demo

Use Cairo for custom drawing.

![img](https://github.com/fltk-rs/demos/blob/master/cairo/assets/scrot.png)
Binary file removed demos/cairo/assets/flcairo.png
Binary file not shown.
Loading