Skip to content

The main purpose of this demo is to provide a code template for creating GUIs for RUST code projects moving forward.

License

Notifications You must be signed in to change notification settings

iotandwearablesguy/clipboardcircle

Repository files navigation

Project logo

Calculations_of_a_Circle

Status


A simple demo of the use of the GTK4 package.

🧐 About

Screen1

Screen2

Screen shots of the app.

Three input fields.

  1. The first takes the radius of the circle accepts once the submit button is pressed and displays answer when the calculate button is press.
  2. The second takes the radious and calculates the circumference of a circle. with similar actions.
  3. The final adds Terry to any text string.

The demo is built using the container method, where each block of the GUI is built within a container as shown in the code below.
The variable btn is the button, with_label shows the adjacent text as the label for the button, btn.connected_clicked will upon the btn being clicked grab the text in the screen as a String, text.trim().parse::().unwrap() causes the String of text to be a type f32.

let from_entry = gtk::Entry::builder()
    .placeholder_text("Radius")
    .build();
text_container.append(&from_entry);
let btn = gtk::Button::with_label("Enter");
btn.connect_clicked(clone!(@weak clipboard, @weak from_entry => move |_btn| {
    let text = from_entry.text();
    let radius: f32 = text.trim().parse::<f32>().unwrap();
    let circum_circle: f32 = radius * 2. * 3.1415;
    let circumanswer = circum_circle.to_string();
    clipboard.set_text(&circumanswer)
   }));

🏁 Purpose and Getting Going

The main purpose of this demo is to provide a code template for creating GUIs for RUST code projects moving forward. This is really part one of two. In this first demo/template the layout is constructed in a strict Box Builder container style. Using this paradaigm each element is added in a container stacked progressively downward in the window. The other builder approach not included here is a grid builder pattern. These builder patterns rely on constructed pre-defined widgets which can be selected from here

Alternatively a non-builder pattern can be used in gtk which they call a Composite Template. Where GTK allows for a custom layout to describe the user interface with a markup language - they use XML. see the documentation at (https://gtk-rs.org/gtk4-rs/stable/latest/book/composite_templates.html)

Build

Build using the "cargo run" command.

Docs

Using "cargo doc" generates the documentation in the .../src/target/docs directory.

Debug

Automatically sets up debugging on the MacOS using VScode and LLDB Code extensions.

Prerequisites

Need Vscode with extensions:

  • rust-analyzer
  • code lldb

⛏️ Built Using

✍️ Author

🎉 Acknowledgements

  • Thank You GTK-RS

LICENSE

O'Shea-Dishongh No Harm License© 2022 Terrance O'Shea & Katherine Dishongh

http://github.com/terryo-iotandwearablesguy

Subject to the following conditions:

  1. That the below copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

  2. That any use of the Software under this license never be used for harmful purposes, permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction,including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so subject to the aforementioned restrictions.

"Harmful purposes" as used herein means to not harm destroy or otherwise restrict humans, animals, or the environment. "Harmful purposes" includes, inter alia, the creation of weaponry, the guidance of weapons, limitation of food and services, damaging, contaminating or otherwise hazardous to the environmnet in any form, and/or restricting the freedom or movement of people.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE

About

The main purpose of this demo is to provide a code template for creating GUIs for RUST code projects moving forward.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published