Skip to content

Commit

Permalink
add checkbuttons' example (#10)
Browse files Browse the repository at this point in the history
* add checkbuttons' example

* add inputchoice's example

* add progress's example

* add progress's example

* add checkbuttons' example

* add checkbuttons' example

* fmt

* fix flerrands

* add temperature

* add csv's demo

* add csv's demo

* add flightbooker

* add crud

* add InputChoice to FlResters

* add flglyph

* add flglyph
  • Loading branch information
Artem V. Ageev authored Jun 8, 2024
1 parent eb99515 commit bc9dd3d
Show file tree
Hide file tree
Showing 42 changed files with 1,948 additions and 549 deletions.
45 changes: 41 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,30 @@ impl Sandbox for Counter {

To run the [examples:](/examples)
```bash
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)

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

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

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

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

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

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

![FlCalculator](/assets/flcalculator.gif)
Expand All @@ -89,16 +106,36 @@ cargo run --example flpicture

![FlDialect](/assets/fldialect.gif)

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

![FlGlyph](/assets/flglyph.png)

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

![FlNetPort](/assets/flnetport.gif)
![FlNetPort](/assets/flnetport.png)

### [FlPicture](/examples/flpicture.rs)

![FlPicture](/assets/flpicture.gif)

## Demo
### [FlResters](/examples/flresters.rs)

![FlResters](/assets/flresters.png)

## Demos

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

![FlTodo](/demos/fltodo/assets/fltodo.gif)

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

![FlCSV](/demos/csv/assets/flcsv.png)

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

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

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

![FlPicture](/demos/flerrands/assets/flerrands.gif)
![Flightbooker](/demos/flightbooker/assets/flightbooker.png)
Binary file added assets/counter.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 assets/crud.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 assets/flglyph.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 removed assets/flnetport.gif
Binary file not shown.
Binary file added assets/flnetport.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 assets/flresters.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 assets/temperature.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion demos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
resolver = "2"
members = [
"cairo",
"flerrands",
"csv",
"fltodo",
"flightbooker",
]

[profile.release]
Expand Down
Binary file added demos/cairo/assets/flcairo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
206 changes: 115 additions & 91 deletions demos/cairo/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,164 +1,188 @@
#![forbid(unsafe_code)]

mod model;

use {
cairo::{Context, Format, ImageSurface},
flemish::{
app,
button::Button,
color_themes, draw,
enums::Event,
enums::{Align, Color, ColorDepth, Font, Shortcut},
frame::Frame,
group::Flex,
image::RgbImage,
menu::{MenuButton, MenuFlag},
menu::{MenuButton, MenuButtonType, MenuFlag},
prelude::*,
OnEvent, OnMenuEvent, Sandbox, Settings,
},
model::Model,
};

pub fn main() {
Counter::new().run(Settings {
#[derive(Clone, Copy)]
pub enum Message {
Inc,
Dec,
Quit,
}

fn main() {
Model::new().run(Settings {
size: (640, 360),
ignore_esc_close: true,
background: Some(Color::White),
resizable: false,
background: Some(Color::from_u32(0xfdf6e3)),
color_map: Some(color_themes::TAN_THEME),
scheme: Some(app::Scheme::Plastic),
scheme: Some(app::Scheme::Base),
..Default::default()
})
}

#[derive(Default)]
struct Counter {
value: u8,
}

#[derive(Debug, Clone, Copy)]
enum Message {
Inc,
Dec,
Quit,
}

impl Sandbox for Counter {
impl Sandbox for Model {
type Message = Message;

fn title(&self) -> String {
String::from("Cairo Buttons")
fn new() -> Self {
Self::default()
}

fn new() -> Self {
Self { value: 0u8 }
fn title(&self) -> String {
format!("{} - FlCairo", self.value())
}

fn view(&mut self) {
let mut page = Flex::default_fill().column();
let mut header = Flex::default();
let menu = MenuButton::default()
.with_label("@#menu")
.on_item_event(
"Command/Increment",
Shortcut::None,
MenuFlag::Normal,
|_| Message::Inc,
)
.on_item_event(
"Command/Decrement",
Shortcut::None,
MenuFlag::Normal,
|_| Message::Dec,
)
.on_item_event(
"Quit",
Shortcut::Ctrl | 'q',
MenuFlag::Normal,
|_| Message::Quit,
);
header.end();
header.fixed(&menu, 50);
page.set_pad(10);
page.set_margin(10);
page.fixed(&header, 30);
let hero = Flex::default();
let mut page = Flex::default()
.with_size(600, 200)
.center_of_parent()
.column();

let hero = Flex::default(); //HERO
crate::cairobutton()
.with_label("@#<")
.on_event(|_| Message::Dec);
let mut frame = Frame::default().with_label(&self.value.to_string());
frame.set_label_size(60);
.on_event(move |_| Message::Dec);
crate::frame(&self.value()).handle(crate::popup);
crate::cairobutton()
.with_label("@#>")
.on_event(|_| Message::Inc);
.on_event(move |_| Message::Inc);
hero.end();

page.end();
page.set_pad(0);
page.set_margin(0);
}

fn update(&mut self, message: Message) {
match message {
Message::Inc => {
self.value = self.value.saturating_add(1);
}
Message::Dec => {
self.value = self.value.saturating_sub(1);
}
Message::Quit => {
app::quit();
}
Message::Inc => self.inc(),
Message::Dec => self.dec(),
Message::Quit => app::quit(),
}
}
}

fn menu() -> MenuButton {
MenuButton::default()
.with_type(MenuButtonType::Popup3)
.with_label("@#menu")
.on_item_event(
"@#+ &Increment",
Shortcut::Ctrl | 'i',
MenuFlag::Normal,
move |_| Message::Inc,
)
.on_item_event(
"@#- &Decrement",
Shortcut::Ctrl | 'd',
MenuFlag::Normal,
move |_| Message::Dec,
)
.on_item_event(
"@#1+ Quit",
Shortcut::Ctrl | 'q',
MenuFlag::Normal,
move |_| Message::Quit,
)
}

fn popup(_: &mut Frame, event: Event) -> bool {
match event {
Event::Push => match app::event_mouse_button() {
app::MouseButton::Right => {
crate::menu().popup();
true
}
_ => false,
},
_ => false,
}
}

fn frame(value: &str) -> Frame {
let mut element = Frame::default().with_label(value);
element.set_label_size(60);
element
}

fn cairobutton() -> Button {
let mut element = Button::default();
element.super_draw(false);
element.draw(|w| {
draw::draw_rect_fill(w.x(), w.y(), w.w(), w.h(), Color::White);
let mut surface =
ImageSurface::create(Format::ARgb32, w.w(), w.h()).expect("Couldn’t create surface");
crate::draw_surface(&mut surface, w.w(), w.h());
if !w.value() {
element.draw(|button| {
draw::draw_rect_fill(
button.x(),
button.y(),
button.w(),
button.h(),
Color::from_u32(0xfdf6e3),
);
let mut surface = ImageSurface::create(Format::ARgb32, button.w(), button.h())
.expect("Couldn’t create surface");
crate::draw_surface(&mut surface, button.w(), button.h());
if !button.value() {
cairo_blur::blur_image_surface(&mut surface, 20);
}
surface
.with_data(|s| {
let mut img = RgbImage::new(s, w.w(), w.h(), ColorDepth::Rgba8).unwrap();
img.draw(w.x(), w.y(), w.w(), w.h());
.with_data(|surface| {
RgbImage::new(surface, button.w(), button.h(), ColorDepth::Rgba8)
.unwrap()
.draw(button.x(), button.y(), button.w(), button.h());
})
.unwrap();
draw::set_draw_color(Color::Black);
draw::set_font(Font::Helvetica, app::font_size());
if !w.value() {
if !button.value() {
draw::draw_rbox(
w.x() + 1,
w.y() + 1,
w.w() - 6,
w.h() - 6,
button.x() + 1,
button.y() + 1,
button.w() - 6,
button.h() - 6,
15,
true,
Color::White,
);
draw::draw_text2(
&w.label(),
w.x() + 1,
w.y() + 1,
w.w() - 6,
w.h() - 6,
&button.label(),
button.x() + 1,
button.y() + 1,
button.w() - 6,
button.h() - 6,
Align::Center,
);
} else {
draw::draw_rbox(
w.x() + 1,
w.y() + 1,
w.w() - 4,
w.h() - 4,
button.x() + 1,
button.y() + 1,
button.w() - 4,
button.h() - 4,
15,
true,
Color::White,
);
draw::draw_text2(
&w.label(),
w.x() + 1,
w.y() + 1,
w.w() - 4,
w.h() - 4,
&button.label(),
button.x() + 1,
button.y() + 1,
button.w() - 4,
button.h() - 4,
Align::Center,
);
}
Expand Down
18 changes: 18 additions & 0 deletions demos/cairo/src/model/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
pub struct Model {
value: u8,
}

impl Model {
pub fn default() -> Self {
Self { value: 0u8 }
}
pub fn inc(&mut self) {
self.value = self.value.saturating_add(1);
}
pub fn dec(&mut self) {
self.value = self.value.saturating_sub(1);
}
pub fn value(&self) -> String {
self.value.to_string()
}
}
13 changes: 13 additions & 0 deletions demos/csv/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "flcsv"
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 = "../../" }
csv = "^1.3"
serde = { version = "^1.0", features = ["derive"] }
lazy_static = "^1.4"
image = { version = "^0.25", default-features = false, features = ["jpeg"] }
Binary file added demos/csv/assets/flcsv.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Loading

0 comments on commit bc9dd3d

Please sign in to comment.