From 2a559b5d2705c24cc54ca7e5daa6bfc436fbf784 Mon Sep 17 00:00:00 2001 From: Sabrina Meindlhumer <58905866+M-Sabrina@users.noreply.github.com> Date: Fri, 8 Sep 2023 21:57:16 +0200 Subject: [PATCH 1/6] library: Add rust demo calendar (#581) * library: Add rust demo calendar * library: address comments * Update src/Library/demos/Calendar/code.rs Co-authored-by: Hofer-Julian <30049909+Hofer-Julian@users.noreply.github.com> * Update src/Library/demos/Calendar/code.rs Co-authored-by: Hofer-Julian <30049909+Hofer-Julian@users.noreply.github.com> * Update src/Library/demos/Calendar/code.rs Co-authored-by: Hofer-Julian <30049909+Hofer-Julian@users.noreply.github.com> * Update src/Library/demos/Calendar/code.rs Co-authored-by: Hofer-Julian <30049909+Hofer-Julian@users.noreply.github.com> --------- Co-authored-by: Hofer-Julian <30049909+Hofer-Julian@users.noreply.github.com> --- src/Library/demos/Calendar/code.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/Library/demos/Calendar/code.rs diff --git a/src/Library/demos/Calendar/code.rs b/src/Library/demos/Calendar/code.rs new file mode 100644 index 000000000..f185b6cfa --- /dev/null +++ b/src/Library/demos/Calendar/code.rs @@ -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); +} + From 6514c9808af3c4aee1bf6e4e867699d6578358d1 Mon Sep 17 00:00:00 2001 From: Hofer-Julian <30049909+Hofer-Julian@users.noreply.github.com> Date: Sat, 9 Sep 2023 00:13:55 +0200 Subject: [PATCH 2/6] library: Add Rust/Vala files for demos without code (#579) --- src/Library/demos/Advanced Buttons/code.rs | 2 ++ src/Library/demos/Advanced Buttons/main.vala | 3 +++ src/Library/demos/Boxed Lists/code.rs | 2 ++ src/Library/demos/Boxed Lists/main.vala | 3 +++ src/Library/demos/Center Box/code.rs | 2 ++ src/Library/demos/Center Box/main.vala | 3 +++ src/Library/demos/Editable Label/code.rs | 2 ++ src/Library/demos/Header Bar/code.rs | 2 ++ src/Library/demos/Header Bar/main.vala | 3 +++ src/Library/demos/Navigation Split View/code.rs | 2 ++ src/Library/demos/Navigation Split View/main.vala | 3 +++ src/Library/demos/Pango Markup/code.rs | 2 ++ src/Library/demos/Pango Markup/main.vala | 3 +++ src/Library/demos/Platform Tools/code.rs | 2 ++ src/Library/demos/Platform Tools/main.vala | 3 +++ src/Library/demos/Window/code.rs | 2 ++ src/Library/demos/Window/main.vala | 3 +++ 17 files changed, 42 insertions(+) create mode 100644 src/Library/demos/Advanced Buttons/code.rs create mode 100644 src/Library/demos/Advanced Buttons/main.vala create mode 100644 src/Library/demos/Boxed Lists/code.rs create mode 100644 src/Library/demos/Boxed Lists/main.vala create mode 100644 src/Library/demos/Center Box/code.rs create mode 100644 src/Library/demos/Center Box/main.vala create mode 100644 src/Library/demos/Editable Label/code.rs create mode 100644 src/Library/demos/Header Bar/code.rs create mode 100644 src/Library/demos/Header Bar/main.vala create mode 100644 src/Library/demos/Navigation Split View/code.rs create mode 100644 src/Library/demos/Navigation Split View/main.vala create mode 100644 src/Library/demos/Pango Markup/code.rs create mode 100644 src/Library/demos/Pango Markup/main.vala create mode 100644 src/Library/demos/Platform Tools/code.rs create mode 100644 src/Library/demos/Platform Tools/main.vala create mode 100644 src/Library/demos/Window/code.rs create mode 100644 src/Library/demos/Window/main.vala diff --git a/src/Library/demos/Advanced Buttons/code.rs b/src/Library/demos/Advanced Buttons/code.rs new file mode 100644 index 000000000..d3b12ab39 --- /dev/null +++ b/src/Library/demos/Advanced Buttons/code.rs @@ -0,0 +1,2 @@ +pub fn main() {} + diff --git a/src/Library/demos/Advanced Buttons/main.vala b/src/Library/demos/Advanced Buttons/main.vala new file mode 100644 index 000000000..91c413e8f --- /dev/null +++ b/src/Library/demos/Advanced Buttons/main.vala @@ -0,0 +1,3 @@ +#!/usr/bin/env -S vala workbench.vala --pkg gtk4 --pkg libadwaita-1 + +public void main () {} diff --git a/src/Library/demos/Boxed Lists/code.rs b/src/Library/demos/Boxed Lists/code.rs new file mode 100644 index 000000000..d3b12ab39 --- /dev/null +++ b/src/Library/demos/Boxed Lists/code.rs @@ -0,0 +1,2 @@ +pub fn main() {} + diff --git a/src/Library/demos/Boxed Lists/main.vala b/src/Library/demos/Boxed Lists/main.vala new file mode 100644 index 000000000..91c413e8f --- /dev/null +++ b/src/Library/demos/Boxed Lists/main.vala @@ -0,0 +1,3 @@ +#!/usr/bin/env -S vala workbench.vala --pkg gtk4 --pkg libadwaita-1 + +public void main () {} diff --git a/src/Library/demos/Center Box/code.rs b/src/Library/demos/Center Box/code.rs new file mode 100644 index 000000000..d3b12ab39 --- /dev/null +++ b/src/Library/demos/Center Box/code.rs @@ -0,0 +1,2 @@ +pub fn main() {} + diff --git a/src/Library/demos/Center Box/main.vala b/src/Library/demos/Center Box/main.vala new file mode 100644 index 000000000..91c413e8f --- /dev/null +++ b/src/Library/demos/Center Box/main.vala @@ -0,0 +1,3 @@ +#!/usr/bin/env -S vala workbench.vala --pkg gtk4 --pkg libadwaita-1 + +public void main () {} diff --git a/src/Library/demos/Editable Label/code.rs b/src/Library/demos/Editable Label/code.rs new file mode 100644 index 000000000..d3b12ab39 --- /dev/null +++ b/src/Library/demos/Editable Label/code.rs @@ -0,0 +1,2 @@ +pub fn main() {} + diff --git a/src/Library/demos/Header Bar/code.rs b/src/Library/demos/Header Bar/code.rs new file mode 100644 index 000000000..d3b12ab39 --- /dev/null +++ b/src/Library/demos/Header Bar/code.rs @@ -0,0 +1,2 @@ +pub fn main() {} + diff --git a/src/Library/demos/Header Bar/main.vala b/src/Library/demos/Header Bar/main.vala new file mode 100644 index 000000000..91c413e8f --- /dev/null +++ b/src/Library/demos/Header Bar/main.vala @@ -0,0 +1,3 @@ +#!/usr/bin/env -S vala workbench.vala --pkg gtk4 --pkg libadwaita-1 + +public void main () {} diff --git a/src/Library/demos/Navigation Split View/code.rs b/src/Library/demos/Navigation Split View/code.rs new file mode 100644 index 000000000..d3b12ab39 --- /dev/null +++ b/src/Library/demos/Navigation Split View/code.rs @@ -0,0 +1,2 @@ +pub fn main() {} + diff --git a/src/Library/demos/Navigation Split View/main.vala b/src/Library/demos/Navigation Split View/main.vala new file mode 100644 index 000000000..91c413e8f --- /dev/null +++ b/src/Library/demos/Navigation Split View/main.vala @@ -0,0 +1,3 @@ +#!/usr/bin/env -S vala workbench.vala --pkg gtk4 --pkg libadwaita-1 + +public void main () {} diff --git a/src/Library/demos/Pango Markup/code.rs b/src/Library/demos/Pango Markup/code.rs new file mode 100644 index 000000000..d3b12ab39 --- /dev/null +++ b/src/Library/demos/Pango Markup/code.rs @@ -0,0 +1,2 @@ +pub fn main() {} + diff --git a/src/Library/demos/Pango Markup/main.vala b/src/Library/demos/Pango Markup/main.vala new file mode 100644 index 000000000..91c413e8f --- /dev/null +++ b/src/Library/demos/Pango Markup/main.vala @@ -0,0 +1,3 @@ +#!/usr/bin/env -S vala workbench.vala --pkg gtk4 --pkg libadwaita-1 + +public void main () {} diff --git a/src/Library/demos/Platform Tools/code.rs b/src/Library/demos/Platform Tools/code.rs new file mode 100644 index 000000000..d3b12ab39 --- /dev/null +++ b/src/Library/demos/Platform Tools/code.rs @@ -0,0 +1,2 @@ +pub fn main() {} + diff --git a/src/Library/demos/Platform Tools/main.vala b/src/Library/demos/Platform Tools/main.vala new file mode 100644 index 000000000..91c413e8f --- /dev/null +++ b/src/Library/demos/Platform Tools/main.vala @@ -0,0 +1,3 @@ +#!/usr/bin/env -S vala workbench.vala --pkg gtk4 --pkg libadwaita-1 + +public void main () {} diff --git a/src/Library/demos/Window/code.rs b/src/Library/demos/Window/code.rs new file mode 100644 index 000000000..d3b12ab39 --- /dev/null +++ b/src/Library/demos/Window/code.rs @@ -0,0 +1,2 @@ +pub fn main() {} + diff --git a/src/Library/demos/Window/main.vala b/src/Library/demos/Window/main.vala new file mode 100644 index 000000000..91c413e8f --- /dev/null +++ b/src/Library/demos/Window/main.vala @@ -0,0 +1,3 @@ +#!/usr/bin/env -S vala workbench.vala --pkg gtk4 --pkg libadwaita-1 + +public void main () {} From 1396db76952e2d6263fc27e3253adc983e9dec72 Mon Sep 17 00:00:00 2001 From: Sabrina Meindlhumer <58905866+M-Sabrina@users.noreply.github.com> Date: Sat, 9 Sep 2023 10:09:45 +0200 Subject: [PATCH 3/6] library: Add rust demo styling with CSS (#582) --- src/Library/demos/Styling with CSS/code.rs | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/Library/demos/Styling with CSS/code.rs diff --git a/src/Library/demos/Styling with CSS/code.rs b/src/Library/demos/Styling with CSS/code.rs new file mode 100644 index 000000000..73959c710 --- /dev/null +++ b/src/Library/demos/Styling with CSS/code.rs @@ -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"); +} + From ff56c9b8e0db392a4a9c16c1903563df8ee5ca60 Mon Sep 17 00:00:00 2001 From: Sabrina Meindlhumer <58905866+M-Sabrina@users.noreply.github.com> Date: Sat, 9 Sep 2023 12:01:25 +0200 Subject: [PATCH 4/6] library: Adapt javascript demo text colors variable name (#584) --- src/Library/demos/Text Colors/main.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Library/demos/Text Colors/main.js b/src/Library/demos/Text Colors/main.js index 7a873e398..7ab53e63b 100644 --- a/src/Library/demos/Text Colors/main.js +++ b/src/Library/demos/Text Colors/main.js @@ -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"; @@ -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", @@ -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); } + From 393ef20578d1aa036eb9b95c401fa189f03beb9b Mon Sep 17 00:00:00 2001 From: Sabrina Meindlhumer <58905866+M-Sabrina@users.noreply.github.com> Date: Sat, 9 Sep 2023 12:10:33 +0200 Subject: [PATCH 5/6] library: Add rust demo Text Colors (#585) * library: Add rust demo Text Colors * Update src/Library/demos/Text Colors/code.rs Co-authored-by: Hofer-Julian <30049909+Hofer-Julian@users.noreply.github.com> * Update src/Library/demos/Text Colors/code.rs Co-authored-by: Hofer-Julian <30049909+Hofer-Julian@users.noreply.github.com> * Update src/Library/demos/Text Colors/code.rs Co-authored-by: Hofer-Julian <30049909+Hofer-Julian@users.noreply.github.com> * Update src/Library/demos/Text Colors/code.rs Co-authored-by: Hofer-Julian <30049909+Hofer-Julian@users.noreply.github.com> * Update src/Library/demos/Text Colors/code.rs Co-authored-by: Hofer-Julian <30049909+Hofer-Julian@users.noreply.github.com> * Update src/Library/demos/Text Colors/code.rs Co-authored-by: Hofer-Julian <30049909+Hofer-Julian@users.noreply.github.com> * library: Adapt rust demo Text Colors docstring --------- Co-authored-by: Hofer-Julian <30049909+Hofer-Julian@users.noreply.github.com> --- src/Library/demos/Text Colors/code.rs | 50 +++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/Library/demos/Text Colors/code.rs diff --git a/src/Library/demos/Text Colors/code.rs b/src/Library/demos/Text Colors/code.rs new file mode 100644 index 000000000..570dda16c --- /dev/null +++ b/src/Library/demos/Text Colors/code.rs @@ -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: >k::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() +} + From e54bbad1d2ea50428ec7c1c012b05b94e613c0e3 Mon Sep 17 00:00:00 2001 From: Sonny Piers Date: Sat, 9 Sep 2023 13:20:56 +0200 Subject: [PATCH 6/6] Freedesktop 23.08 (#586) --- Makefile | 4 ++-- src/Previewer/previewer.vala | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 1c02fa1d2..b1f8dff11 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/src/Previewer/previewer.vala b/src/Previewer/previewer.vala index 1fe5d30f4..6e54adf3c 100644 --- a/src/Previewer/previewer.vala +++ b/src/Previewer/previewer.vala @@ -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); }