Commit af6eac1b authored by Bilal Elmoussaoui's avatar Bilal Elmoussaoui

Responsive banner viewer

this is not something that would go in the final producT.
We need to get an upstream issue fixed first
parent 621eedb5
Pipeline #103685 passed with stages
in 18 minutes and 3 seconds
......@@ -18,7 +18,54 @@
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<placeholder/>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="has_tooltip">True</property>
<property name="halign">end</property>
<property name="valign">center</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="margin">40</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">GNOME APP</property>
<style>
<class name="head" />
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Yet an other description</property>
<style>
<class name="summary" />
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<style>
<class name="banner"/>
......
......@@ -205,17 +205,21 @@ Software's source code can be found &lt;a href="https://gitlab.gnome.org/GNOME/g
<property name="can_focus">False</property>
<property name="relative_to">errors_togglebtn</property>
<child>
<object class="GtkBox" id="errors_container">
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">12</property>
<property name="orientation">vertical</property>
<property name="can_focus">True</property>
<property name="width_request">340</property>
<property name="height_request">60</property>
<child>
<placeholder/>
<object class="GtkBox" id="errors_container">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<placeholder/>
</child>
</object>
</child>
<style>
<class name="errors-container"/>
</style>
</object>
</child>
</object>
......
......@@ -44,10 +44,11 @@ impl Banner {
source_buffer.set_highlight_syntax(true);
undo_manager.begin_not_undoable_action();
source_buffer.set_text(&self.banner.css);
source_buffer.set_text(&self.banner.css.trim());
undo_manager.end_not_undoable_action();
source_view.set_monospace(true);
source_view.set_indent_width(2);
let scheme = sourceview::StyleSchemeManager::get_default().map_or(None, |scm| scm.get_scheme("solarized-light")).unwrap();
source_buffer.set_style_scheme(Some(&scheme));
......@@ -70,6 +71,29 @@ impl Banner {
let css = buffer.get_text(&start, &end, true).unwrap();
banner_widget.inject_css(&css);
});
// responsive classes
let banner: gtk::Box = self.builder.get_object("banner").unwrap();
banner.connect_size_allocate(move |banner, allocate| {
let mut added_class = String::from("");
let mut sizes_classes = vec!["sm", "lg", "md"];
println!("size {} ", allocate.width);
if allocate.width <= 400 {
added_class.push_str("sm");
} else if allocate.width <= 650 {
added_class.push_str("md");
} else {
added_class.push_str("lg");
}
let ctx = banner.get_style_context();
ctx.add_class(&added_class);
sizes_classes.retain(|c| {
let class: String = c.to_owned().to_string();
if class != added_class {
ctx.remove_class(&class);
}
false
});
});
}
fn inject_css(&self, css: &str) {
......@@ -82,7 +106,7 @@ impl Banner {
css = css.replace(url, cache_path);
}
let css = format!(".banner{{ {} }}", css);
// let css = format!(".banner{{ {} }}", css);
let banner_id = &self.banner.id;
let provider = gtk::CssProvider::new();
......@@ -93,6 +117,6 @@ impl Banner {
self.sender.send(Action::AddError(banner_id.to_string(), err.to_string())).unwrap();
}
};
ctx.add_provider(&provider, 300);
ctx.add_provider(&provider, 600);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment