Skip to content

Commit

Permalink
Merge branch 'main' into blueprint-formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
sonnyp committed Sep 9, 2023
2 parents 3bdf0a0 + e54bbad commit 94b1608
Show file tree
Hide file tree
Showing 23 changed files with 131 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ SHELL:=/bin/bash -O globstar

setup:
flatpak remote-add --user --if-not-exists flathub-beta https://flathub.org/beta-repo/flathub-beta.flatpakrepo
flatpak install --user --noninteractive flathub-beta org.gnome.Sdk//45beta org.freedesktop.Sdk.Extension.rust-stable//23.08beta org.freedesktop.Sdk.Extension.node18//23.08beta
flatpak install --or-update --user --noninteractive flathub-beta org.gnome.Platform//45beta org.gnome.Sdk//45beta org.gnome.Sdk.Docs//45beta
flatpak remote-add --user --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo
flatpak install --user --noninteractive flathub org.flatpak.Builder
flatpak install --or-update --user --noninteractive flathub org.flatpak.Builder org.freedesktop.Sdk//23.08 org.freedesktop.Sdk.Extension.rust-stable//23.08 org.freedesktop.Sdk.Extension.node18//23.08 org.freedesktop.Sdk.Extension.vala//23.08 org.freedesktop.Sdk.Extension.llvm16//23.08
npm install

lint:
Expand Down
2 changes: 2 additions & 0 deletions src/Library/demos/Advanced Buttons/code.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub fn main() {}

3 changes: 3 additions & 0 deletions src/Library/demos/Advanced Buttons/main.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env -S vala workbench.vala --pkg gtk4 --pkg libadwaita-1

public void main () {}
2 changes: 2 additions & 0 deletions src/Library/demos/Boxed Lists/code.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub fn main() {}

3 changes: 3 additions & 0 deletions src/Library/demos/Boxed Lists/main.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env -S vala workbench.vala --pkg gtk4 --pkg libadwaita-1

public void main () {}
24 changes: 24 additions & 0 deletions src/Library/demos/Calendar/code.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use crate::workbench;

pub fn main() {
let calendar: gtk::Calendar = workbench::builder().object("calendar").unwrap();

calendar.connect_day_notify(|calendar| {
println!("{}", calendar.date().format("%e").unwrap());
});

calendar.connect_month_notify(|calendar| {
println!("{}", calendar.date().format("%B").unwrap());
});

calendar.connect_year_notify(|calendar| {
println!("{}", calendar.date().format("%Y").unwrap());
});

calendar.connect_day_selected(|calendar| {
println!("{}", calendar.date().format_iso8601().unwrap());
});

calendar.mark_day(15);
}

2 changes: 2 additions & 0 deletions src/Library/demos/Center Box/code.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub fn main() {}

3 changes: 3 additions & 0 deletions src/Library/demos/Center Box/main.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env -S vala workbench.vala --pkg gtk4 --pkg libadwaita-1

public void main () {}
2 changes: 2 additions & 0 deletions src/Library/demos/Editable Label/code.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub fn main() {}

2 changes: 2 additions & 0 deletions src/Library/demos/Header Bar/code.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub fn main() {}

3 changes: 3 additions & 0 deletions src/Library/demos/Header Bar/main.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env -S vala workbench.vala --pkg gtk4 --pkg libadwaita-1

public void main () {}
2 changes: 2 additions & 0 deletions src/Library/demos/Navigation Split View/code.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub fn main() {}

3 changes: 3 additions & 0 deletions src/Library/demos/Navigation Split View/main.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env -S vala workbench.vala --pkg gtk4 --pkg libadwaita-1

public void main () {}
2 changes: 2 additions & 0 deletions src/Library/demos/Pango Markup/code.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub fn main() {}

3 changes: 3 additions & 0 deletions src/Library/demos/Pango Markup/main.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env -S vala workbench.vala --pkg gtk4 --pkg libadwaita-1

public void main () {}
2 changes: 2 additions & 0 deletions src/Library/demos/Platform Tools/code.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub fn main() {}

3 changes: 3 additions & 0 deletions src/Library/demos/Platform Tools/main.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env -S vala workbench.vala --pkg gtk4 --pkg libadwaita-1

public void main () {}
8 changes: 8 additions & 0 deletions src/Library/demos/Styling with CSS/code.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use crate::workbench;
use gtk::prelude::*;

pub fn main() {
let basic_label: gtk::Label = workbench::builder().object("basic_label").unwrap();
basic_label.add_css_class("css_text");
}

50 changes: 50 additions & 0 deletions src/Library/demos/Text Colors/code.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use crate::workbench;
use gtk::pango;

// Pango is a text layout library. It can e.g. be used for formatting text
// https://docs.rs/pango/0.18.0/pango/index.html

pub fn main() {
let label: gtk::Label = workbench::builder().object("label").unwrap();
label.connect_label_notify(update_attributes);
update_attributes(&label);
}

/// A Pango Attribute List is used to style the label
fn update_attributes(label: &gtk::Label) {
label.set_attributes(Some(&rainbow_attributes(label.label().as_str())));
}

/// Generates an Attribute List that styles the label in rainbow colors.
/// The `str` parameter is needed to detect string length + position of spaces
fn rainbow_attributes(input_str: &str) -> pango::AttrList {
let rainbow_colors = ["#D00", "#C50", "#E90", "#090", "#24E", "#55E", "#C3C"];

// Create a color array with the length needed to color all the letters
let mut color_array = Vec::new();
let mut i = 0;
while i < input_str.chars().count() {
color_array.extend_from_slice(&rainbow_colors);
i = color_array.len();
}

// Independent variable from `i` in the following loop to avoid spaces "consuming" a color
let mut color_idx = 0;
let mut attr_list_string = String::new();
for (i, character) in input_str.chars().enumerate() {
// Skip space characters
if !character.is_whitespace() {
let start_idx = i;
let end_idx = i + 1;

let color = color_array[color_idx];
color_idx += 1;
// See comment below
attr_list_string.push_str(&format!("{start_idx} {end_idx} foreground {color},"));
}
}
// For more info about the syntax for this function, see:
// https://docs.rs/pango/0.18.0/pango/struct.AttrList.html#method.from_string
pango::AttrList::from_string(&attr_list_string).unwrap()
}

7 changes: 4 additions & 3 deletions src/Library/demos/Text Colors/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Pango is a text layout library. It can be used for e.g. formatting text
// Pango is a text layout library. It can e.g. be used for formatting text
// https://gjs-docs.gnome.org/pango10~1.0/
import Pango from "gi://Pango";

Expand All @@ -8,12 +8,12 @@ updateAttributes();

function updateAttributes() {
// A Pango Attribute List is used to style the label
label.attributes = rainbow_attributes(label.label);
label.attributes = rainbowAttributes(label.label);
}

// Generates an Attribute List that styles the label in rainbow colors.
// The `str` parameter is needed to detect string length + position of spaces
function rainbow_attributes(str) {
function rainbowAttributes(str) {
const RAINBOW_COLORS = [
"#D00",
"#C50",
Expand Down Expand Up @@ -50,3 +50,4 @@ function rainbow_attributes(str) {
// https://docs.gtk.org/Pango/method.AttrList.to_string.html
return Pango.attr_list_from_string(attrListString);
}

2 changes: 2 additions & 0 deletions src/Library/demos/Window/code.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub fn main() {}

3 changes: 3 additions & 0 deletions src/Library/demos/Window/main.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env -S vala workbench.vala --pkg gtk4 --pkg libadwaita-1

public void main () {}
2 changes: 1 addition & 1 deletion src/Previewer/previewer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ namespace Workbench {
var end = section.get_end_location();
this.css_parser_error(error.message, (int)start.lines, (int)start.line_chars, (int)end.lines, (int)end.line_chars);
});
this.css.load_from_data (content, -1);
this.css.load_from_data (content.data);
Gtk.StyleContext.add_provider_for_display (Gdk.Display.get_default (), this.css , Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
}

Expand Down

0 comments on commit 94b1608

Please sign in to comment.