Skip to content

Commit

Permalink
Merge pull request #85 from SubhadeepJasu/auto_button_size
Browse files Browse the repository at this point in the history
Scale button fonts with app width
  • Loading branch information
SubhadeepJasu authored Sep 19, 2021
2 parents 041f259 + abd80f5 commit 7165615
Show file tree
Hide file tree
Showing 11 changed files with 198 additions and 24 deletions.
4 changes: 2 additions & 2 deletions data/Application.css
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@

.Pebbles_Buttons_Memory {
color: #333;
text-shadow: 0 1px alpha (#000, 0.0);
text-shadow: 0 1px alpha (#000, 0.2), 0 0 0 2px #000;
-gtk-icon-shadow: 0 1px alpha (#000, 0.0);
border-color: alpha(#000, 0.5);
background-image: linear-gradient(#ffe16b, #f9c440);
Expand Down Expand Up @@ -442,4 +442,4 @@ scrolledwindow overshoot.left {
border: 1px solid alpha(#000, 0.5);
border-radius: 4px;
background-color: alpha(@accent_color, 0.2);
}
}
12 changes: 12 additions & 0 deletions data/com.github.subhadeepjasu.pebbles.appdata.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@
<content_attribute id="money-gambling">none</content_attribute>
</content_rating>
<releases>
<release date="2021-09-19" version="2.0.2">
<description>
<p>Fixed:</p>
<ul>
<li>[Converter] Fix multiple errors in the converters</li>
</ul>
<p>Improved:</p>
<ul>
<li>[UI] Scale button font with app width (a11y)</li>
</ul>
</description>
</release>
<release date="2021-09-08" version="2.0.1">
<description>
<p>Improved:</p>
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
project (
'com.github.subhadeepjasu.pebbles',
'vala', 'c',
version: '2.0.1',
version: '2.0.2',
)

# GNOME module
Expand Down
20 changes: 16 additions & 4 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ namespace Pebbles {
.pebbles_h1 { font-size: %dpx; }
.pebbles_h2 { font-size: %dpx; }
.pebbles_h4 { font-size: %dpx; }
.pebbles_button_font_size { font-size: %dpx; }
.pebbles_button_font_size_h3 { font-size: %dpx; }
";

public PebblesApp () {
Expand All @@ -54,9 +56,12 @@ namespace Pebbles {
Timeout.add_seconds (1, () => {
if (this.get_active_window () != null) {
int height = this.get_active_window ().get_allocated_height ();
if (((MainWindow) (this.get_active_window ())).previous_height != height) {
int width = this.get_active_window ().get_allocated_width ();
if (((MainWindow) (this.get_active_window ())).previous_height != height ||
((MainWindow) (this.get_active_window ())).previous_width != width) {
((MainWindow) (this.get_active_window ())).previous_height = height;
adjust_font_responsive (height);
((MainWindow) (this.get_active_window ())).previous_width = width;
adjust_font_responsive (height, width);
}
return true;
}
Expand Down Expand Up @@ -131,12 +136,19 @@ namespace Pebbles {
private double map_range (double input, double input_start, double input_end, double output_start, double output_end) {
return output_start + ((output_end - output_start) / (input_end - input_start)) * (input - input_start);
}
private void adjust_font_responsive (int height) {
private void adjust_font_responsive (int height, int width) {
try {
var target_size_h1 = (int)map_range (double.max((double) height/600, 1), 1, 2, 40, 120);
var target_size_h2 = (int)map_range (double.max((double) height/600, 1), 1, 2, 20, 50);
var target_size_h4 = (int)map_range (double.max((double) height/600, 1), 1, 2, 10, 20);
var css = DISPLAY_FONT_SIZE_TEMPLATE.printf(target_size_h1, target_size_h2, target_size_h4);
var target_size_button = (int)map_range (double.max((double) width/1000, 1), 1, 1.5, 12, 22);
if (target_size_button < 12) target_size_button = 12;
if (target_size_button > 28) target_size_button = 28;
var css = DISPLAY_FONT_SIZE_TEMPLATE.printf(target_size_h1,
target_size_h2,
target_size_h4,
target_size_button,
target_size_button + 4);
font_size_provider.load_from_data (css, -1);
} catch (Error e) {
Process.exit(1);
Expand Down
2 changes: 2 additions & 0 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ namespace Pebbles {
bool initialized = false;

public int previous_height = 0;
public int previous_width = 0;

public MainWindow () {
settings = Pebbles.Settings.get_default ();
Expand Down Expand Up @@ -607,6 +608,7 @@ namespace Pebbles {
if ((this.common_view.get_visible_child () == this.scientific_view && this.scientific_view.button_leaflet.folded) ||
(this.common_view.get_visible_child () == this.calculus_view && this.calculus_view.button_leaflet.folded) ||
(this.common_view.get_visible_child () == this.programmer_view && this.programmer_view.button_leaflet.folded) ||
(this.common_view.get_visible_child () == this.statistics_view && this.statistics_view.button_leaflet.folded) ||
(this.common_view.get_visible_child () == this.date_view && this.date_view.get_allocated_width () < 540) ||
(this.common_view.get_visible_child () == this.conv_length_view) ||
(this.common_view.get_visible_child () == this.conv_area_view) ||
Expand Down
42 changes: 38 additions & 4 deletions src/Views/CalculusView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,11 @@ namespace Pebbles {
// Make buttons on the left
all_clear_button = new StyledButton ("AC", _("All Clear"), {"Delete"});
all_clear_button.get_style_context ().add_class (Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION);
all_clear_button.get_style_context ().add_class ("pebbles_button_font_size");
del_button = new Gtk.Button.from_icon_name ("edit-clear-symbolic", Gtk.IconSize.BUTTON);
del_button.set_tooltip_text (_("Backspace"));
del_button.get_style_context ().remove_class ("image-button");
del_button.get_style_context ().add_class ("pebbles_button_font_size");
if (display_unit.input_entry.get_text () =="0" || display_unit.input_entry.get_text () == "") {
del_button.sensitive = false;
} else {
Expand All @@ -191,27 +193,41 @@ namespace Pebbles {
del_button.sensitive = true;
});
variable_button = new StyledButton ("𝑥", _("Variable for linear expressions"), {"X"});
variable_button.get_style_context ().add_class ("pebbles_button_font_size");
divide_button = new StyledButton ("\xC3\xB7", _("Divide"));
divide_button.get_style_context ().add_class ("h3");
divide_button.get_style_context ().add_class ("pebbles_button_font_size_h3");
seven_button = new StyledButton ("7");
seven_button.get_style_context ().add_class ("pebbles_button_font_size");
eight_button = new StyledButton ("8");
eight_button.get_style_context ().add_class ("pebbles_button_font_size");
nine_button = new StyledButton ("9");
nine_button.get_style_context ().add_class ("pebbles_button_font_size");
multiply_button = new StyledButton ("\xC3\x97", _("Multiply"));
multiply_button.get_style_context ().add_class ("h3");
multiply_button.get_style_context ().add_class ("pebbles_button_font_size_h3");
four_button = new StyledButton ("4");
four_button.get_style_context ().add_class ("pebbles_button_font_size");
five_button = new StyledButton ("5");
five_button.get_style_context ().add_class ("pebbles_button_font_size");
six_button = new StyledButton ("6");
six_button.get_style_context ().add_class ("pebbles_button_font_size");
subtract_button = new StyledButton ("\xE2\x88\x92", _("Subtract"));
subtract_button.get_style_context ().add_class ("h3");
subtract_button.get_style_context ().add_class ("pebbles_button_font_size_h3");
one_button = new StyledButton ("1");
one_button.get_style_context ().add_class ("pebbles_button_font_size");
two_button = new StyledButton ("2");
two_button.get_style_context ().add_class ("pebbles_button_font_size");
three_button = new StyledButton ("3");
three_button.get_style_context ().add_class ("pebbles_button_font_size");
plus_button = new StyledButton ("+", _("Add"));
plus_button.get_style_context ().add_class ("h3");
plus_button.get_style_context ().add_class ("pebbles_button_font_size_h3");
zero_button = new StyledButton ("0");
zero_button.get_style_context ().add_class ("pebbles_button_font_size");
decimal_button = new StyledButton (Utils.get_local_radix_symbol ());
decimal_button.get_style_context ().add_class ("pebbles_button_font_size");
left_parenthesis_button = new StyledButton ("(");
left_parenthesis_button.get_style_context ().add_class ("pebbles_button_font_size");
right_parenthesis_button = new StyledButton (")");
right_parenthesis_button.get_style_context ().add_class ("pebbles_button_font_size");

button_container_left.attach (all_clear_button, 0, 0, 1, 1);
button_container_left.attach (del_button, 1, 0, 1, 1);
Expand Down Expand Up @@ -240,37 +256,53 @@ namespace Pebbles {
// Make buttons on the right
pow_root_button = new StyledButton ("x<sup>y</sup>", _("x raised to the power y"), {"Z"});
pow_root_button.get_style_context ().add_class ("Pebbles_Buttons_Function");
pow_root_button.get_style_context ().add_class ("pebbles_button_font_size");
memory_plus_button = new StyledButton ("M+", _("Add it to the value in Memory"), {"F3"});
memory_plus_button.get_style_context ().add_class ("Pebbles_Buttons_Memory");
memory_plus_button.get_style_context ().add_class ("pebbles_button_font_size");
sin_button = new StyledButton ("sin", _("Sine"), {"S"});
sin_button.get_style_context ().add_class ("Pebbles_Buttons_Function");
sin_button.get_style_context ().add_class ("pebbles_button_font_size");
sinh_button = new StyledButton ("sinh", _("Hyperbolic Sine"), {"H"});
sinh_button.get_style_context ().add_class ("Pebbles_Buttons_Function");
sinh_button.get_style_context ().add_class ("pebbles_button_font_size");
memory_minus_button = new StyledButton ("M\xE2\x88\x92", _("Subtract it from the value in Memory"), {"F4"});
memory_minus_button.get_style_context ().add_class ("Pebbles_Buttons_Memory");
memory_minus_button.get_style_context ().add_class ("pebbles_button_font_size");
cos_button = new StyledButton ("cos", _("Cosine"), {"C"});
cos_button.get_style_context ().add_class ("Pebbles_Buttons_Function");
cos_button.get_style_context ().add_class ("pebbles_button_font_size");
cosh_button = new StyledButton ("cosh", _("Hyperbolic Cosine"), {"O"});
cosh_button.get_style_context ().add_class ("Pebbles_Buttons_Function");
cosh_button.get_style_context ().add_class ("pebbles_button_font_size");
log_mod_button = new StyledButton ("Mod", _("Modulus"), {"M"});
log_mod_button.get_style_context ().add_class ("Pebbles_Buttons_Function");
log_mod_button.get_style_context ().add_class ("pebbles_button_font_size");
memory_recall_button = new StyledButton ("MR", _("Recall value from Memory"), {"F5"});
memory_recall_button.get_style_context ().add_class ("Pebbles_Buttons_Memory");
memory_recall_button.get_style_context ().add_class ("pebbles_button_font_size");
tan_button = new StyledButton ("tan", _("Tangent"), {"T"});
tan_button.get_style_context ().add_class ("Pebbles_Buttons_Function");
tan_button.get_style_context ().add_class ("pebbles_button_font_size");
tanh_button = new StyledButton ("tanh", _("Hyperbolic Tangent"), {"A"});
tanh_button.get_style_context ().add_class ("Pebbles_Buttons_Function");
tanh_button.get_style_context ().add_class ("pebbles_button_font_size");
perm_comb_button = new StyledButton ("<sup>n</sup>P\xE1\xB5\xA3", _("Permutations"), {"P"});
perm_comb_button.get_style_context ().add_class ("Pebbles_Buttons_Function");
perm_comb_button.get_style_context ().add_class ("pebbles_button_font_size");
memory_clear_button = new StyledButton ("MC", _("Memory Clear"), {"F6"});
memory_clear_button.get_style_context ().add_class ("Pebbles_Buttons_Memory");
memory_clear_button.get_style_context ().add_class ("pebbles_button_font_size");
fact_button = new StyledButton ("!", _("Factorial"), {"F"});
fact_button.get_style_context ().add_class ("Pebbles_Buttons_Function");
fact_button.get_style_context ().add_class ("pebbles_button_font_size");
constant_button = new StyledButton (constant_label_1, constant_desc_1, {"R"});
constant_button.get_style_context ().add_class ("Pebbles_Buttons_Function");
constant_button.get_style_context ().add_class ("pebbles_button_font_size");
last_answer_button = new StyledButton ("Ans", _("Last answer"), {"F7"});
last_answer_button.sensitive = false;
last_answer_button.get_style_context ().add_class ("Pebbles_Buttons_Function");
last_answer_button.get_style_context ().add_class ("pebbles_button_font_size");

// Make integration section
var integration_grid = new Gtk.Grid ();
Expand All @@ -280,6 +312,7 @@ namespace Pebbles {
integration_button = new StyledButton ("\xE2\x88\xAB", _("Definite Integral (Upper limit 'u' and Lower limit 'l')"), {"I"});
integration_button.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
integration_button.get_style_context ().add_class ("suggested-override");
integration_button.get_style_context ().add_class ("pebbles_button_font_size");
integration_button.margin_top = 5;
integration_button.margin_start = 2;

Expand Down Expand Up @@ -341,6 +374,7 @@ namespace Pebbles {
derivation_button = new StyledButton ("dy/dx", _("Derivative (at a point x)"), {"D"});
derivation_button.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
derivation_button.get_style_context ().add_class ("suggested-override");
derivation_button.get_style_context ().add_class ("pebbles_button_font_size");
derivation_button.margin_top = 5;
derivation_button.margin_start = 2;

Expand Down
13 changes: 13 additions & 0 deletions src/Views/CommonKeyPadConverter.vala
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,32 @@ namespace Pebbles {
del_button = new Gtk.Button.from_icon_name ("edit-clear-symbolic", Gtk.IconSize.BUTTON);
del_button.set_tooltip_text (_("Backspace"));
del_button.get_style_context ().remove_class ("image-button");
del_button.get_style_context ().add_class ("pebbles_button_font_size");
all_clear_button = new StyledButton ("AC", (_("Clear Entry")));
all_clear_button.get_style_context ().add_class (Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION);
all_clear_button.get_style_context ().add_class ("pebbles_button_font_size");
seven_button = new StyledButton ("7");
seven_button.get_style_context ().add_class ("pebbles_button_font_size");
eight_button = new StyledButton ("8");
eight_button.get_style_context ().add_class ("pebbles_button_font_size");
nine_button = new StyledButton ("9");
nine_button.get_style_context ().add_class ("pebbles_button_font_size");
four_button = new StyledButton ("4");
four_button.get_style_context ().add_class ("pebbles_button_font_size");
five_button = new StyledButton ("5");
five_button.get_style_context ().add_class ("pebbles_button_font_size");
six_button = new StyledButton ("6");
six_button.get_style_context ().add_class ("pebbles_button_font_size");
one_button = new StyledButton ("1");
one_button.get_style_context ().add_class ("pebbles_button_font_size");
two_button = new StyledButton ("2");
two_button.get_style_context ().add_class ("pebbles_button_font_size");
three_button = new StyledButton ("3");
three_button.get_style_context ().add_class ("pebbles_button_font_size");
zero_button = new StyledButton ("0");
zero_button.get_style_context ().add_class ("pebbles_button_font_size");
decimal_button = new StyledButton (".");
decimal_button.get_style_context ().add_class ("pebbles_button_font_size");

// Arange the buttons
attach (all_clear_button, 0, 0, 1, 1);
Expand Down
1 change: 1 addition & 0 deletions src/Views/CommonNumericKeypad.vala
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ namespace Pebbles {

construct {
main_grid = new Gtk.Grid ();
this.get_style_context ().add_class ("pebbles_button_font_size");
// Make the buttons
del_button = new StyledButton ("Del", (_("Backspace")));
all_clear_button = new StyledButton ("AC", (_("All Clear")));
Expand Down
Loading

0 comments on commit 7165615

Please sign in to comment.