Verified Commit a0d8310c authored by Zander Brown's avatar Zander Brown 🇬🇧
Browse files

Fix after rebase, avoid double changed when fliping

parent 46eebb90
/*Redefine those variables so we can tweak them later*/
@define-color foreground_color @theme_fg_color;
@define-color background_color @theme_bg_color;
.main-window decoration {
box-shadow: 0 2px 2px 2px darker(@background_color);
}
.main-window.devel headerbar {
background: transparent -gtk-icontheme("system-run-symbolic") 80% 0/128px 128px no-repeat,
linear-gradient(to left,
mix(darker(@background_color), @background_color, 0.5) 0%,
darker(@background_color) 25%);
color: alpha(@foreground_color, 0.4);
}
.main-window headerbar {
background: mix(darker(@background_color), @background_color, 0.7);
border-bottom: 1px solid darker(@background_color);
box-shadow: 0 1px @foreground_color;
}
.main-window headerbar entry {
/* background-color: lighter(@background_color); */
/* color: @foreground_color; */
border: 1px solid darker(@background_color);
border-right: 0;
}
.main-window headerbar button:not(.titlebutton),
.main-window headerbar button:not(.titlebutton):active,
.main-window headerbar button:not(.titlebutton):focus,
.main-window headerbar button:not(.titlebutton):backdrop
{
color: @foreground_color;
background: lighter(@background_color);
border: 1px solid darker(@background_color);
box-shadow: 0 0; /* FIXME: Use a better shadow instead */
text-shadow: 0 0;
}
.main-window headerbar button:hover{
background: mix(lighter(@background_color), @background_color, .3);
border: 1px solid mix(darker(@background_color), @background_color, .5);
}
.main-window headerbar .titlebutton,
.main-window headerbar .titlebutton:active,
.main-window headerbar .titlebutton:focus,
.main-window headerbar .titlebutton:backdrop {
color: @foreground_color;
border: 1px solid transparent; /* Hackish way to avoid the weird title button resize on hover */
box-shadow: 0 0; /* FIXME: Use a better shadow instead */
text-shadow: 0 0;
}
.main-window .menu {
background: lighter(@background_color);
border: 1px solid darker(@background_color);
}
.main-window .menu label {
color: darker(@foreground_color);
}
.main-window .menu modelbutton:hover{
background-color: mix(@background_color, lighter(@background_color), 0.1);
}
.main-window .main-container {
background: @background_color;
......
......@@ -92,7 +92,7 @@ impl Application {
let bg_colour = self.window.state.borrow_mut().bg_colour.to_hex_string();
let fg_colour = self.window.state.borrow_mut().fg_colour.to_hex_string();
update_styles(&self.sender, fg_color, bg_color);
update_styles(&self.sender, fg_colour, bg_colour);
}
pub fn run(&self) {
......
......@@ -4,18 +4,20 @@ use crate::config::{APP_ID, PROFILE};
use crate::contrast_level::ContrastLevelBar;
use crate::contrast_preview::ContrastPreview;
use crate::libhandy::HeaderBarExt;
use crate::styles::update_styles;
use crate::window_state::WindowState;
use gtk::prelude::{BoxExt, BuilderExtManual, ButtonExt, ContainerExt, EditableSignals, EntryExt, MenuButtonExt, StyleContextExt, WidgetExt};
use glib::ObjectExt;
use gtk::prelude::{BoxExt, BuilderExtManual, ButtonExt, ContainerExt, EditableSignals, MenuButtonExt, StyleContextExt, WidgetExt};
use gtk::Inhibit;
use std::cell::RefCell;
use std::rc::Rc;
use crate::styles::update_styles;
pub struct Window {
pub widget: gtk::ApplicationWindow,
appmenu_button: gtk::MenuButton,
fg_entry: ColourEntry,
bg_entry: ColourEntry,
reverse_btn: gtk::Button,
headerbar: libhandy::HeaderBar,
pub state: Rc<RefCell<WindowState>>,
levelbar: Rc<RefCell<ContrastLevelBar>>,
......@@ -36,6 +38,8 @@ impl Window {
let fg_entry = ColourEntry::new("Foreground Colour".to_string());
fg_entry.entry.set_name("fg");
let reverse_btn = gtk::Button::new();
let state = Rc::new(RefCell::new(WindowState::init(settings)));
let levelbar = Rc::new(RefCell::new(ContrastLevelBar::new()));
levelbar.borrow_mut().set_contrast_level(state.borrow_mut().contrast_level);
......@@ -51,6 +55,7 @@ impl Window {
appmenu_button,
fg_entry,
bg_entry,
reverse_btn,
headerbar,
state,
levelbar,
......@@ -84,50 +89,67 @@ impl Window {
let state = self.state.clone();
let level_bar = self.levelbar.clone();
let preview = self.preview.clone();
let on_entry_changed = move |entry: &gtk::Entry| {
let colour = entry.get_text().unwrap();
let colour = colour.as_str();
if entry.get_name().unwrap() == "bg" {
state.borrow_mut().set_bg_colour(Some(colour));
} else {
state.borrow_mut().set_fg_colour(Some(colour));
}
let fg_entry = self.fg_entry.clone();
let bg_entry = self.bg_entry.clone();
let sender = self.sender.clone();
let on_entry_changed = move |_entry: &gtk::Entry| {
let fg_colour = fg_entry.get_text();
let bg_colour = bg_entry.get_text();
state.borrow_mut().set_bg_colour(Some(&bg_colour));
state.borrow_mut().set_fg_colour(Some(&fg_colour));
let contarst_level = state.borrow_mut().contrast_level;
level_bar.borrow_mut().set_contrast_level(contarst_level);
preview.borrow_mut().set_contrast_level(contarst_level);
};
self.bg_entry.entry.connect_changed(on_entry_changed.clone());
self.fg_entry.entry.connect_changed(on_entry_changed.clone());
}
update_styles(&sender, fg_colour, bg_colour);
};
fn setup_widgets(&self) {
let container = gtk::Box::new(gtk::Orientation::Vertical, 0);
container.get_style_context().add_class("main-container");
container.show();
let bg_handle = self.bg_entry.entry.connect_changed(on_entry_changed.clone());
let fg_handle = self.fg_entry.entry.connect_changed(on_entry_changed.clone());
let reverse_btn = gtk::Button::new();
reverse_btn.set_halign(gtk::Align::Center);
let reverse_img = gtk::Image::new_from_icon_name(Some("network-transmit-receive-symbolic"), gtk::IconSize::Button);
reverse_img.show();
reverse_btn.set_image(Some(&reverse_img));
reverse_btn.show();
let state = self.state.clone();
let level_bar = self.levelbar.clone();
let preview = self.preview.clone();
let fg_entry = self.fg_entry.clone();
let bg_entry = self.bg_entry.clone();
let sender = self.sender.clone();
reverse_btn.connect_clicked(move |_| {
self.reverse_btn.connect_clicked(move |_| {
fg_entry.entry.block_signal(&fg_handle);
bg_entry.entry.block_signal(&bg_handle);
let fg_colour = fg_entry.get_text();
let bg_colour = bg_entry.get_text();
bg_entry.set_text(Some(fg_colour));
fg_entry.set_text(Some(bg_colour));
fg_entry.set_text(Some(bg_colour.clone()));
bg_entry.set_text(Some(fg_colour.clone()));
fg_entry.entry.unblock_signal(&fg_handle);
bg_entry.entry.unblock_signal(&bg_handle);
state.borrow_mut().set_bg_colour(Some(&bg_colour));
state.borrow_mut().set_fg_colour(Some(&fg_colour));
let contarst_level = state.borrow_mut().contrast_level;
level_bar.borrow_mut().set_contrast_level(contarst_level);
preview.borrow_mut().set_contrast_level(contarst_level);
update_styles(&sender, fg_colour, bg_colour);
});
}
fn setup_widgets(&self) {
let container = gtk::Box::new(gtk::Orientation::Vertical, 0);
container.get_style_context().add_class("main-container");
container.show();
self.reverse_btn.set_halign(gtk::Align::Center);
let reverse_img = gtk::Image::new_from_icon_name(Some("network-transmit-receive-symbolic"), gtk::IconSize::Button);
reverse_img.show();
self.reverse_btn.set_image(Some(&reverse_img));
self.reverse_btn.show();
let entries_container = gtk::Box::new(gtk::Orientation::Horizontal, 0);
entries_container.pack_start(&self.bg_entry.widget, false, false, 6);
entries_container.pack_start(&reverse_btn, false, false, 6);
entries_container.pack_start(&self.reverse_btn, false, false, 6);
entries_container.pack_start(&self.fg_entry.widget, false, false, 6);
entries_container.set_halign(gtk::Align::Center);
entries_container.show();
......
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