Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
alt-art committed Jul 16, 2021
2 parents 637331c + b2be27d commit d6a490f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 17 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "lorem"
description = "Lorem Ipsun generator"
version = "0.1.1"
description = "Lorem Ipsum generator"
version = "0.2.0"
authors = ["alt-art <[email protected]>"]
repository="https://github.com/alt-art/lorem"
license = "GPL-3.0-or-later"
Expand All @@ -15,7 +15,6 @@ rand = "0.8.4"
glib = "0.14.2"
gtk = "0.14.0"
gdk = "0.14.0"
gio = "0.14.0"

[package.metadata.deb]
maintainer = "Pedro Mendes <[email protected]>"
Expand Down
9 changes: 8 additions & 1 deletion src/lorem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl Lorem {
}
}

pub fn get_phrase(self, min: u32, max: u32) -> String {
pub fn get_phrase(self, min: u32, max: u32, output_type: &str) -> String {
let mut rng = rand::thread_rng();
let count:u32;
if min >= max {
Expand All @@ -43,6 +43,9 @@ impl Lorem {
let quantity = Uniform::from(10..20);
let mut phrase = String::new();
for _ in 0..count {
if output_type == "HTML" {
phrase.push_str("<p>");
}
for _ in 0..sentences.sample(&mut rng) {
let mut first_word = self.get_words(1);
first_word = first_word.first_to_uppper_case();
Expand All @@ -52,6 +55,10 @@ impl Lorem {
phrase = phrase.trim_matches(',').to_string();
phrase.push_str(". ");
}
if output_type == "HTML" {
phrase.pop();
phrase.push_str("</p>");
}
phrase.push_str("\n\n")
}
phrase.trim().to_string()
Expand Down
21 changes: 11 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
extern crate gio;
extern crate gtk;
extern crate gdk;
extern crate glib;

use gtk::prelude::*;
use glib::clone;

use gtk::{ApplicationWindow, Builder, Label, Button, Adjustment, Clipboard};
use gtk::{ApplicationWindow, Builder, Label, Button, Adjustment, Clipboard, ComboBoxText};

mod lorem;
use lorem::Lorem;

fn generate(label: gtk::Label, min: u32, max: u32) {
fn generate(label: gtk::Label, min: u32, max: u32, output_type: &str) {
let lorem = Lorem::new();
label.set_text(&lorem.get_phrase(min, max));
label.set_text(&lorem.get_phrase(min, max, output_type));
}

fn build_ui(application: &gtk::Application) {
Expand All @@ -25,16 +20,22 @@ fn build_ui(application: &gtk::Application) {
let label: Label = builder.object("label").expect("Cound't get Label");
let min_adjustment: Adjustment = builder.object("min_adjust").expect("Cound't get Adjustment");
let max_adjustment: Adjustment = builder.object("max_adjust").expect("Cound't get Adjustment");
let output_type: ComboBoxText = builder.object("output_type").expect("Cound't get ComboBoxText");
let gen_button: Button = builder.object("gen").expect("Cound't get Button");
gen_button.connect_clicked(clone!(@weak label => move |_| {
generate(label, min_adjustment.value() as u32, max_adjustment.value() as u32);
generate(
label,
min_adjustment.value() as u32,
max_adjustment.value() as u32,
output_type.active_text().unwrap().as_str()
);
}));
let copy_button: Button = builder.object("copy").expect("Cound't get Button");
copy_button.connect_clicked(clone!(@weak label => move |_| {
let clipboard = Clipboard::get(&gdk::SELECTION_CLIPBOARD);
clipboard.set_text(&label.text());
}));
generate(label, 2, 3);
generate(label, 2, 3, "Text");
window.set_application(Some(application));
window.show_all();
}
Expand Down
23 changes: 22 additions & 1 deletion src/resources/lorem.glade
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Author: alt-art
<property name="position">1</property>
</packing>
</child>
<child type="title">
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
Expand Down Expand Up @@ -169,6 +169,27 @@ Author: alt-art
</packing>
</child>
</object>
<packing>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="output_type">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="active">1</property>
<property name="active_id">1</property>
<items>
<item id="0" translatable="yes">HTML</item>
<item id="1" translatable="yes">Text</item>
</items>
</object>
<packing>
<property name="position">3</property>
</packing>
</child>
<child type="title">
<placeholder/>
</child>
</object>
</child>
Expand Down

0 comments on commit d6a490f

Please sign in to comment.