Investigation: install a custom stylesheet
This commit is contained in:
parent
0280000854
commit
aacc4ca041
3 changed files with 114 additions and 7 deletions
|
|
@ -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')
|
||||
]
|
||||
|
||||
#
|
||||
|
|
|
|||
|
|
@ -30,19 +30,43 @@
|
|||
|
||||
|
||||
#include "stage/gtk-base.hpp"
|
||||
#include "lib/searchpath.hpp"
|
||||
#include "lib/error.hpp"
|
||||
#include "lib/util.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
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<Cairo::Context> const& cox)
|
||||
Canvas::on_draw(CairoC cox)
|
||||
{
|
||||
if (shallDraw_)
|
||||
{
|
||||
|
|
|
|||
51
research/gtk-style-experiment.css
Normal file
51
research/gtk-style-experiment.css
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
gtk-style-experiment.css - investigate GTKs CSS implementation
|
||||
|
||||
Copyright (C) Lumiera.org
|
||||
2019, Hermann Vosseler <Ichthyostega@web.de>
|
||||
|
||||
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;
|
||||
}
|
||||
Loading…
Reference in a new issue