Skip to content

Commit

Permalink
add flresters (#9)
Browse files Browse the repository at this point in the history
* add flresters

* add demo/flerrands

* add demo/flerrands

* add cicd

* fix fldialect and add fltext

* fix fldialect

* fix switch in fldialect

* fix pad button in flcalculator

* delete fltext

* add Scroll and change method to flerrands
  • Loading branch information
Artem V. Ageev authored May 20, 2024
1 parent 9eac541 commit eb99515
Show file tree
Hide file tree
Showing 15 changed files with 572 additions and 234 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
name: Build

on:
push:
branches:
- master
pull_request:
branches:
- master
schedule:
- cron: '30 13 * * *'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ${{ matrix.os }}
timeout-minutes: 120
strategy:
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest

steps:
- name: Download deps
shell: bash
run: |
if [[ ${RUNNER_OS} == "Linux" ]]; then
sudo apt-get update
sudo apt-get install -y lib{pango1.0,x11,xext,xft,xinerama,mpv}-dev\
lib{xcursor,xrender,xfixes,webkit2gtk-4.1,vlc,png,gl1-mesa}-dev\
ninja-build libglu1-mesa-dev
fi
- uses: actions/checkout@v2
- uses: seanmiddleditch/gha-setup-ninja@master
- name: build cfltk
run: |
git clone https://github.com/MoAlyousef/cfltk
pushd cfltk || return 1
git submodule update --init --recursive
case ${RUNNER_OS} in
Linux ) cmake -Bbin -GNinja -DFLTK_USE_SYSTEM_LIBPNG=OFF -DFLTK_USE_SYSTEM_LIBJPEG=OFF -DFLTK_USE_SYSTEM_ZLIB=OFF -DCFLTK_LINK_IMAGES=ON -DOpenGL_GL_PREFERENCE=GLVND -DFLTK_BUILD_GL=ON -DCFLTK_USE_OPENGL=ON -DCFLTK_SINGLE_THREADED=OFF -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCFLTK_CARGO_BUILD=ON -DFLTK_BUILD_EXAMPLES=OFF -DFLTK_BUILD_TEST=OFF -DFLTK_OPTION_LARGE_FILE=ON -DFLTK_BUILD_HTML_DOCS=OFF -DFLTK_BUILD_PDF_DOCS=OFF -DCMAKE_INSTALL_PREFIX=bin -DCMAKE_BUILD_TYPE=Release -DFLTK_GRAPHICS_CAIRO=ON -DFLTK_USE_PANGO=ON -DFLTK_BACKEND_WAYLAND=OFF;;
macOS ) cmake -Bbin -GNinja -DFLTK_USE_SYSTEM_LIBPNG=OFF -DFLTK_USE_SYSTEM_LIBJPEG=OFF -DFLTK_USE_SYSTEM_ZLIB=OFF -DCFLTK_LINK_IMAGES=ON -DOpenGL_GL_PREFERENCE=GLVND -DFLTK_BUILD_GL=ON -DCFLTK_USE_OPENGL=ON -DCFLTK_SINGLE_THREADED=OFF -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCFLTK_CARGO_BUILD=ON -DFLTK_BUILD_EXAMPLES=OFF -DFLTK_BUILD_TEST=OFF -DFLTK_OPTION_LARGE_FILE=ON -DFLTK_BUILD_HTML_DOCS=OFF -DFLTK_BUILD_PDF_DOCS=OFF -DCMAKE_INSTALL_PREFIX=bin -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES=x86_64;;
* ) cmake -Bbin -GNinja -DFLTK_USE_SYSTEM_LIBPNG=OFF -DFLTK_USE_SYSTEM_LIBJPEG=OFF -DFLTK_USE_SYSTEM_ZLIB=OFF -DCFLTK_LINK_IMAGES=ON -DOpenGL_GL_PREFERENCE=GLVND -DFLTK_BUILD_GL=ON -DCFLTK_USE_OPENGL=ON -DCFLTK_SINGLE_THREADED=OFF -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCFLTK_CARGO_BUILD=ON -DFLTK_BUILD_EXAMPLES=OFF -DFLTK_BUILD_TEST=OFF -DFLTK_OPTION_LARGE_FILE=ON -DFLTK_BUILD_HTML_DOCS=OFF -DFLTK_BUILD_PDF_DOCS=OFF -DCMAKE_INSTALL_PREFIX=bin -DCMAKE_BUILD_TYPE=Release;;
esac
cmake --build bin --parallel --target install
export CFLTK_BUNDLE_DIR="${PWD}/bin/lib"
shell: bash
- name: Build cairo
working-directory: demos/cairo
shell: bash
run: |
if [[ ${RUNNER_OS} == "Linux" ]]; then
cargo build --quiet || cargo build --verbose
fi
- name: Build flerrands
working-directory: demos/flerrands
shell: bash
run: |
if [[ ${RUNNER_OS} == "Linux" ]]; then
cargo build --quiet || cargo build --verbose
fi
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,9 @@ cargo run --example flpicture
### [FlPicture](/examples/flpicture.rs)

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

## Demo

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

![FlPicture](/demos/flerrands/assets/flerrands.gif)
2 changes: 1 addition & 1 deletion demos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
resolver = "2"
members = [
"cairo",
"rmp",
"flerrands",
]

[profile.release]
Expand Down
2 changes: 1 addition & 1 deletion demos/rmp/Cargo.toml → demos/flerrands/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "rmp"
name = "flerrands"
version = "0.1.0"
edition = "2021"

Expand Down
Binary file added demos/flerrands/assets/flerrands.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
169 changes: 169 additions & 0 deletions demos/flerrands/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
#![forbid(unsafe_code)]

use {
flemish::{
app,
button::{Button, CheckButton},
color_themes,
enums::{FrameType, Shortcut},
frame::Frame,
group::{Flex,Scroll},
input::Input,
menu::{MenuButton, MenuFlag},
prelude::*,
OnEvent, OnMenuEvent, Sandbox, Settings,
},
serde::{Deserialize, Serialize},
std::{env, fs},
};

pub fn main() {
let mut app = Model::new();
app.run(Settings {
size: app.size,
resizable: true,
ignore_esc_close: true,
color_map: Some(color_themes::DARK_THEME),
scheme: Some(app::Scheme::Base),
..Default::default()
})
}

const NAME: &str = "FlErrands";
const PATH: &str = "/.config/";
const PAD: i32 = 10;
const HEIGHT: i32 = PAD * 3;
const WINDOW_WIDTH: i32 = 360;
const WINDOW_HEIGHT: i32 = 640;

#[derive(Deserialize, Serialize)]
struct Task {
status: bool,
description: String,
}

#[derive(Deserialize, Serialize)]
struct Model {
size: (i32, i32),
tasks: Vec<Task>,
}

#[derive(Clone)]
enum Message {
New(String),
Delete(usize),
Check(usize),
Change((usize, String)),
Quit,
}

impl Sandbox for Model {
type Message = Message;

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

fn new() -> Self {
let file = env::var("HOME").unwrap() + PATH + NAME;
let default = Self {
size: (WINDOW_WIDTH, WINDOW_HEIGHT),
tasks: Vec::new(),
};
if let Ok(value) = fs::read(file) {
if let Ok(value) = rmp_serde::from_slice(&value) {
value
} else {
default
}
} else {
default
}
}

fn view(&mut self) {
let mut page = Flex::default_fill().column();
let mut header = Flex::default(); // HEADER
header.fixed(&crate::menu(), 50);
let description = Input::default();
let add = Button::default().with_label("@#+");
header.fixed(&add, HEIGHT);
add.on_event(move |_| Message::New(description.value()));
header.end();
let scroll = Scroll::default().with_size(324, 600);
let mut hero = Flex::default_fill().column(); // HERO
for (idx, task) in self.tasks.iter().enumerate() {
let mut row = Flex::default();
let mut status = CheckButton::default();
status.set_value(task.status);
row.fixed(&status, HEIGHT);
status.on_event(move |_| Message::Check(idx));
let mut description = Input::default();
description.set_value(&task.description);
match self.tasks[idx].status {
true => description.deactivate(),
false => description.activate(),
}
description.on_event(move |input| Message::Change((idx, input.value())));
let delete = Button::default().with_label("@#1+");
row.fixed(&delete, HEIGHT);
delete.on_event(move |_| Message::Delete(idx));
row.end();
row.set_pad(0);
hero.fixed(&row, HEIGHT)
}
hero.end();
scroll.end();
let footer = Flex::default();
Frame::default().with_label(&format!("All tasks: {}", self.tasks.len()));
footer.end(); // FOOTER
page.end();
{
page.set_frame(FrameType::FlatBox);
page.set_pad(PAD);
page.set_margin(PAD);
page.fixed(&header, HEIGHT);
page.fixed(&footer, HEIGHT);
for mut flex in [header, hero, footer] {
flex.set_pad(0);
flex.set_margin(0);
}
}
}

fn update(&mut self, message: Message) {
match message {
Message::Quit => self.quit(),
Message::Delete(idx) => {
self.tasks.remove(idx);
}
Message::Change((idx, value)) => self.tasks[idx].description = value,
Message::Check(idx) => self.tasks[idx].status = !self.tasks[idx].status,
Message::New(description) => self.tasks.push(Task {
status: false,
description,
}),
}
}
}

impl Model {
fn quit(&mut self) {
let file = env::var("HOME").unwrap() + PATH + NAME;
let window = app::first_window().unwrap();
self.size = (window.width(), window.height());
fs::write(file, rmp_serde::to_vec(&self).unwrap()).unwrap();
app::quit();
}
}

fn menu() -> MenuButton {
let mut element = MenuButton::default().with_label("@#menu").on_item_event(
"@#1+ &Quit",
Shortcut::Ctrl | 'q',
MenuFlag::Normal,
|_| Message::Quit,
);
element.set_tooltip("Menu");
element
}
Loading

0 comments on commit eb99515

Please sign in to comment.