diff --git a/research/SConscript b/research/SConscript index 83acc9201..86016142a 100644 --- a/research/SConscript +++ b/research/SConscript @@ -21,6 +21,7 @@ experiments = [ envR.Program('try', ['try.cpp'] + core) #### to try out , envRGtk.Program('gtk-canvas-experiment', ['gtk-canvas-experiment.cpp', 'gtk-canvas-main.cpp'] + core) , envRGtk.Program('gtk-style-experiment', ['gtk-style-experiment.cpp'] + core) + , env.GuiResource('gtk-style-experiment.css') ] # diff --git a/research/gtk-style-experiment.cpp b/research/gtk-style-experiment.cpp index d8fe28095..6b4c2c696 100644 --- a/research/gtk-style-experiment.cpp +++ b/research/gtk-style-experiment.cpp @@ -30,19 +30,43 @@ #include "stage/gtk-base.hpp" +#include "lib/searchpath.hpp" #include "lib/error.hpp" +#include "lib/util.hpp" +#include + +using util::cStr; +using std::string; namespace research { + namespace { + const string STYLESHEET_NAME{"gtk-style-experiment.css"}; + const string RESOURCE_PATH{"$ORIGIN/gui"}; + + const string CLASS_experiment{"experiment"}; + } + + using CairoC = stage::PCairoContext const&; + using StyleC = stage::PStyleContext const&; + + using stage::PStyleContext; + class Canvas : public Gtk::Layout { - bool shallDraw_; + bool shallDraw_ = false; bool recalcExtension_ = false; + StyleC style_; + public: + Canvas(StyleC refStyle) + : style_{refStyle} + { } + void adjustSize(); void enableDraw (bool); @@ -67,8 +91,12 @@ namespace research { Gtk::CheckButton toggleDraw_; Gtk::Frame frame_; Gtk::ScrolledWindow scroller_; + + PStyleContext pStyle_; Canvas canvas_; + PStyleContext setupStyle(); + void experiment_1(); void experiment_2(); }; @@ -78,11 +106,12 @@ namespace research { StyleTestPanel::StyleTestPanel() : Box{} - , twoParts_(Gtk::ORIENTATION_VERTICAL) - , buttons_() - , frame_("Gtk::StyleContext Experiments") - , scroller_() - , canvas_() + , twoParts_{Gtk::ORIENTATION_VERTICAL} + , buttons_{} + , frame_{"Gtk::StyleContext Experiments"} + , scroller_{} + , pStyle_{} + , canvas_{pStyle_} { twoParts_.pack_start(buttons_, Gtk::PACK_SHRINK); twoParts_.pack_start(frame_); @@ -120,6 +149,9 @@ namespace research { scroller_.set_border_width(10); scroller_.add(canvas_); + frame_.get_style_context()->add_class(CLASS_experiment); + pStyle_ = setupStyle(); + canvas_.adjustSize(); // show everything.... @@ -128,6 +160,29 @@ namespace research { } + + PStyleContext + StyleTestPanel::setupStyle() + { + auto screen = Gdk::Screen::get_default(); + auto css_provider = Gtk::CssProvider::create(); + try + { + css_provider->load_from_path (lib::resolveModulePath (STYLESHEET_NAME, RESOURCE_PATH)); + } + catch(Glib::Error const& failure) + { + WARN (stage, "Failure while loading stylesheet '%s': %s", cStr(STYLESHEET_NAME), cStr(failure.what())); + } + + Gtk::StyleContext::add_provider_for_screen (screen, css_provider, + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + + return PStyleContext{}; + } + + + void StyleTestPanel::experiment_1() { @@ -183,7 +238,7 @@ namespace research { bool - Canvas::on_draw(Cairo::RefPtr const& cox) + Canvas::on_draw(CairoC cox) { if (shallDraw_) { diff --git a/research/gtk-style-experiment.css b/research/gtk-style-experiment.css new file mode 100644 index 000000000..afee84d1f --- /dev/null +++ b/research/gtk-style-experiment.css @@ -0,0 +1,51 @@ +/* + gtk-style-experiment.css - investigate GTKs CSS implementation + + Copyright (C) Lumiera.org + 2019, Hermann Vosseler + + Styles and Graphics of the Lumiera GUI can be used and redistributed + under the the terms of the GNU General Public License version 2 or + above, or (at your option) under Creative Commons CC-By-SA. + +* ********************************************************/ + + +/* CSS stylesheet loaded by gtk-style-experiment.cpp on top of + * the system theme, with GTK_STYLE_PROVIDER_PRIORITY_APPLICATION + */ + + + + +/* ---------- Styles for Lumiera Widgets ---------- */ + + +/* ---------- Styles for special markup ---------- */ + + +/* special styling for the frame widget within the main window.... + * This styling will be picked up by our custom drawing code + */ + frame.experiment { + margin: 2ex 0; + border: 5px inset IndianRed; + background-color: Lime; +} + fork.timeline frame.timeline.ruler { + margin: 3ex 0; + border: 3px outset GoldenRod; + background-color: DarkCyan; +} + .track-slope-deep2 { + border-width: 10px; +} + .track-slope-deep3 { + border-width: 14px; +} + .track-slope-deep4 { + border-width: 17px; +} + .track-slope-verydeep { + border-width: 20px; +}