style: Use outline name as CSS class
This commit is contained in:
@ -18,6 +18,13 @@ button:active {
|
|||||||
border-color: #716e78;
|
border-color: #716e78;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
button.altline,
|
||||||
|
button.special,
|
||||||
|
button.wide {
|
||||||
|
background: #2b292f;
|
||||||
|
border-color: #3e3a44
|
||||||
|
}
|
||||||
|
|
||||||
#Return {
|
#Return {
|
||||||
background: #1c71d8;
|
background: #1c71d8;
|
||||||
border-color: #1a5fb4
|
border-color: #1a5fb4
|
||||||
@ -27,48 +34,3 @@ button:active {
|
|||||||
background: #1c71d8;
|
background: #1c71d8;
|
||||||
border-color: #3584e4;
|
border-color: #3584e4;
|
||||||
}
|
}
|
||||||
|
|
||||||
#Shift_L {
|
|
||||||
background: #2b292f;
|
|
||||||
border-color: #3e3a44
|
|
||||||
}
|
|
||||||
|
|
||||||
#Shift_L:active {
|
|
||||||
background: #1c71d8;
|
|
||||||
border-color: #3584e4;
|
|
||||||
}
|
|
||||||
|
|
||||||
#show_numbers {
|
|
||||||
background: #2b292f;
|
|
||||||
border-color: #3e3a44
|
|
||||||
}
|
|
||||||
|
|
||||||
#show_letters {
|
|
||||||
background: #2b292f;
|
|
||||||
border-color: #3e3a44
|
|
||||||
}
|
|
||||||
|
|
||||||
#show_symbols {
|
|
||||||
background: #2b292f;
|
|
||||||
border-color: #3e3a44
|
|
||||||
}
|
|
||||||
|
|
||||||
#show_numbers_from_symbols {
|
|
||||||
background: #2b292f;
|
|
||||||
border-color: #3e3a44
|
|
||||||
}
|
|
||||||
|
|
||||||
#preferences {
|
|
||||||
background: #2b292f;
|
|
||||||
border-color: #3e3a44
|
|
||||||
}
|
|
||||||
|
|
||||||
#period {
|
|
||||||
background: #2b292f;
|
|
||||||
border-color: #3e3a44
|
|
||||||
}
|
|
||||||
|
|
||||||
#BackSpace {
|
|
||||||
background: #2b292f;
|
|
||||||
border-color: #3e3a44
|
|
||||||
}
|
|
||||||
|
|||||||
@ -187,34 +187,17 @@ render_outline (cairo_t *cr,
|
|||||||
gtk_render_frame (ctx, cr, 0, 0, bounds.width, bounds.height);
|
gtk_render_frame (ctx, cr, 0, 0, bounds.width, bounds.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void render_button_in_context(EekRenderer *self,
|
||||||
render_button (EekRenderer *self,
|
cairo_t *cr,
|
||||||
cairo_t *cr,
|
GtkStyleContext *ctx,
|
||||||
struct button_place *place,
|
struct button_place *place,
|
||||||
gboolean active)
|
gboolean active) {
|
||||||
{
|
|
||||||
EekRendererPrivate *priv = eek_renderer_get_instance_private (self);
|
|
||||||
cairo_surface_t *outline_surface;
|
cairo_surface_t *outline_surface;
|
||||||
GHashTable *outline_surface_cache;
|
GHashTable *outline_surface_cache;
|
||||||
PangoLayout *layout;
|
PangoLayout *layout;
|
||||||
PangoRectangle extents = { 0, };
|
PangoRectangle extents = { 0, };
|
||||||
EekColor foreground;
|
EekColor foreground;
|
||||||
|
EekRendererPrivate *priv = eek_renderer_get_instance_private (self);
|
||||||
GtkStyleContext *ctx = priv->button_context;
|
|
||||||
/* Set the name of the button on the widget path, using the name obtained
|
|
||||||
from the button's symbol. */
|
|
||||||
g_autoptr (GtkWidgetPath) path = NULL;
|
|
||||||
path = gtk_widget_path_copy (gtk_style_context_get_path (ctx));
|
|
||||||
const char *name = squeek_button_get_name(place->button);
|
|
||||||
gtk_widget_path_iter_set_name (path, -1, name);
|
|
||||||
|
|
||||||
/* Update the style context with the updated widget path. */
|
|
||||||
gtk_style_context_set_path (ctx, path);
|
|
||||||
/* Set the state to take into account whether the button is active
|
|
||||||
(pressed) or normal. */
|
|
||||||
gtk_style_context_set_state(ctx,
|
|
||||||
active ? GTK_STATE_FLAG_ACTIVE : GTK_STATE_FLAG_NORMAL);
|
|
||||||
|
|
||||||
|
|
||||||
/* render outline */
|
/* render outline */
|
||||||
EekBounds bounds = squeek_button_get_bounds(place->button);
|
EekBounds bounds = squeek_button_get_bounds(place->button);
|
||||||
@ -225,6 +208,7 @@ render_button (EekRenderer *self,
|
|||||||
outline_surface_cache = priv->outline_surface_cache;
|
outline_surface_cache = priv->outline_surface_cache;
|
||||||
|
|
||||||
outline_surface = g_hash_table_lookup (outline_surface_cache, place->button);
|
outline_surface = g_hash_table_lookup (outline_surface_cache, place->button);
|
||||||
|
|
||||||
if (!outline_surface) {
|
if (!outline_surface) {
|
||||||
cairo_t *cr;
|
cairo_t *cr;
|
||||||
|
|
||||||
@ -251,7 +235,6 @@ render_button (EekRenderer *self,
|
|||||||
(gpointer)place->button,
|
(gpointer)place->button,
|
||||||
outline_surface);
|
outline_surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
cairo_set_source_surface (cr, outline_surface, 0.0, 0.0);
|
cairo_set_source_surface (cr, outline_surface, 0.0, 0.0);
|
||||||
cairo_paint (cr);
|
cairo_paint (cr);
|
||||||
|
|
||||||
@ -286,7 +269,6 @@ render_button (EekRenderer *self,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* render label */
|
/* render label */
|
||||||
layout = pango_cairo_create_layout (cr);
|
layout = pango_cairo_create_layout (cr);
|
||||||
eek_renderer_real_render_button_label (self, layout, place->button);
|
eek_renderer_real_render_button_label (self, layout, place->button);
|
||||||
@ -303,11 +285,42 @@ render_button (EekRenderer *self,
|
|||||||
foreground.green,
|
foreground.green,
|
||||||
foreground.blue,
|
foreground.blue,
|
||||||
foreground.alpha);
|
foreground.alpha);
|
||||||
|
|
||||||
gtk_style_context_set_state(ctx, GTK_STATE_FLAG_NORMAL);
|
|
||||||
pango_cairo_show_layout (cr, layout);
|
pango_cairo_show_layout (cr, layout);
|
||||||
cairo_restore (cr);
|
cairo_restore (cr);
|
||||||
g_object_unref (layout);
|
g_object_unref (layout);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
render_button (EekRenderer *self,
|
||||||
|
cairo_t *cr,
|
||||||
|
struct button_place *place,
|
||||||
|
gboolean active)
|
||||||
|
{
|
||||||
|
EekRendererPrivate *priv = eek_renderer_get_instance_private (self);
|
||||||
|
|
||||||
|
GtkStyleContext *ctx = priv->button_context;
|
||||||
|
/* Set the name of the button on the widget path, using the name obtained
|
||||||
|
from the button's symbol. */
|
||||||
|
g_autoptr (GtkWidgetPath) path = NULL;
|
||||||
|
path = gtk_widget_path_copy (gtk_style_context_get_path (ctx));
|
||||||
|
const char *name = squeek_button_get_name(place->button);
|
||||||
|
gtk_widget_path_iter_set_name (path, -1, name);
|
||||||
|
|
||||||
|
/* Update the style context with the updated widget path. */
|
||||||
|
gtk_style_context_set_path (ctx, path);
|
||||||
|
/* Set the state to take into account whether the button is active
|
||||||
|
(pressed) or normal. */
|
||||||
|
gtk_style_context_set_state(ctx,
|
||||||
|
active ? GTK_STATE_FLAG_ACTIVE : GTK_STATE_FLAG_NORMAL);
|
||||||
|
const char *outline_name = squeek_button_get_outline_name(place->button);
|
||||||
|
gtk_style_context_add_class(ctx, outline_name);
|
||||||
|
|
||||||
|
render_button_in_context(self, cr, ctx, place, active);
|
||||||
|
|
||||||
|
// Save and restore functions don't work if gtk_render_* was used in between
|
||||||
|
gtk_style_context_set_state(ctx, GTK_STATE_FLAG_NORMAL);
|
||||||
|
gtk_style_context_remove_class(ctx, outline_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -476,6 +476,7 @@ fn create_button(
|
|||||||
|
|
||||||
::layout::Button {
|
::layout::Button {
|
||||||
name: cname,
|
name: cname,
|
||||||
|
outline_name: CString::new(outline_name).expect("Bad outline"),
|
||||||
// TODO: do layout before creating buttons
|
// TODO: do layout before creating buttons
|
||||||
bounds: ::layout::c::Bounds {
|
bounds: ::layout::c::Bounds {
|
||||||
x: outline.bounds.x,
|
x: outline.bounds.x,
|
||||||
|
|||||||
@ -32,6 +32,7 @@ EekBounds squeek_button_get_bounds(const struct squeek_button*);
|
|||||||
const char *squeek_button_get_label(const struct squeek_button*);
|
const char *squeek_button_get_label(const struct squeek_button*);
|
||||||
const char *squeek_button_get_icon_name(const struct squeek_button*);
|
const char *squeek_button_get_icon_name(const struct squeek_button*);
|
||||||
const char *squeek_button_get_name(const struct squeek_button*);
|
const char *squeek_button_get_name(const struct squeek_button*);
|
||||||
|
const char *squeek_button_get_outline_name(const struct squeek_button*);
|
||||||
|
|
||||||
struct squeek_key *squeek_button_get_key(const struct squeek_button*);
|
struct squeek_key *squeek_button_get_key(const struct squeek_button*);
|
||||||
uint32_t *squeek_button_has_key(const struct squeek_button* button,
|
uint32_t *squeek_button_has_key(const struct squeek_button* button,
|
||||||
|
|||||||
@ -40,11 +40,6 @@ pub mod c {
|
|||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
pub struct UserData(*const c_void);
|
pub struct UserData(*const c_void);
|
||||||
|
|
||||||
/// The index in the relevant outline table
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct OutlineRef(u32);
|
|
||||||
|
|
||||||
/// Defined in eek-types.h
|
/// Defined in eek-types.h
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
@ -195,6 +190,13 @@ pub mod c {
|
|||||||
button.name.as_ptr()
|
button.name.as_ptr()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C"
|
||||||
|
fn squeek_button_get_outline_name(button: *const Button) -> *const c_char {
|
||||||
|
let button = unsafe { &*button };
|
||||||
|
button.outline_name.as_ptr()
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C"
|
pub extern "C"
|
||||||
fn squeek_button_has_key(
|
fn squeek_button_has_key(
|
||||||
@ -502,6 +504,7 @@ pub mod c {
|
|||||||
bounds: c::Bounds {
|
bounds: c::Bounds {
|
||||||
x: 0f64, y: 0f64, width: 0f64, height: 0f64
|
x: 0f64, y: 0f64, width: 0f64, height: 0f64
|
||||||
},
|
},
|
||||||
|
outline_name: CString::new("test").unwrap(),
|
||||||
label: Label::Text(CString::new(name).unwrap()),
|
label: Label::Text(CString::new(name).unwrap()),
|
||||||
state: state,
|
state: state,
|
||||||
})
|
})
|
||||||
@ -565,6 +568,8 @@ pub struct Button {
|
|||||||
/// TODO: position the buttons before they get initial bounds
|
/// TODO: position the buttons before they get initial bounds
|
||||||
/// Position relative to some origin (i.e. parent/row)
|
/// Position relative to some origin (i.e. parent/row)
|
||||||
pub bounds: c::Bounds,
|
pub bounds: c::Bounds,
|
||||||
|
/// The name of the visual class applied
|
||||||
|
pub outline_name: CString,
|
||||||
/// current state, shared with other buttons
|
/// current state, shared with other buttons
|
||||||
pub state: Rc<RefCell<KeyState>>,
|
pub state: Rc<RefCell<KeyState>>,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user