Skip to content

Commit

Permalink
Add rust demo Flow Box (#575)
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Sabrina authored Sep 5, 2023
1 parent 68e3055 commit 676c02e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/Library/demos/Flow Box/code.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use crate::workbench;
use adw::prelude::*;
use std::str;

pub fn main() {
let flowbox: gtk::FlowBox = workbench::builder().object("flowbox").unwrap();
for code in 128513..=128591 {
let tmp = char::from_u32(code).unwrap();
add_emoji(&flowbox, &tmp.to_string());
}
flowbox.connect_child_activated(|_, item| {
// FlowBoxChild -> AdwBin -> Label
let emoji = item
.child()
.unwrap()
.downcast::<adw::Bin>()
.unwrap()
.child()
.unwrap()
.downcast::<gtk::Label>()
.unwrap()
.label();
let emoji = emoji.chars().next().unwrap();
println!("Unicode:{:X}", emoji as u32);
});
}

pub fn add_emoji(flowbox: &gtk::FlowBox, unicode: &str) {
let label = gtk::Label::builder()
.vexpand(true)
.hexpand(true)
.label(unicode)
.css_classes(["emoji"])
.build();
let item = adw::Bin::builder()
.child(&label)
.width_request(100)
.height_request(100)
.css_classes(["card"])
.build();
flowbox.append(&item);
}
1 change: 1 addition & 0 deletions src/about.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ ${getBlueprintVersion()}
"Adeel Ahmed Qureshi https://github.com/itsAdee",
"Muhammad Bilal https://github.com/mbilal234",
"Onkar https://github.com/onkarrai06",
"Sabrina Meindlhumer https://github.com/m-sabrina",
// Add yourself as
// "John Doe",
// or
Expand Down

0 comments on commit 676c02e

Please sign in to comment.