Skip to content

Commit

Permalink
Tweak calculation of default font for dimensions and window size.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Wootten committed May 17, 2018
1 parent 956ac2c commit b7ec2d1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
16 changes: 5 additions & 11 deletions src/Gnonogram_view.vala
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ public class View : Gtk.ApplicationWindow {

/**PRIVATE**/
private const uint PROGRESS_DELAY_MSEC = 500;
private const int GRID_COLUMN_SPACING = 6;
private const int GRID_BORDER = 6;
private const int BOTTOM_BORDER = 24;
private const int END_BORDER = BOTTOM_BORDER + GRID_COLUMN_SPACING;

private string BRAND_STYLESHEET = """
@define-color textColorPrimary %s;
Expand Down Expand Up @@ -462,15 +458,13 @@ public class View : Gtk.ApplicationWindow {
monitor_area = Utils.get_monitor_area (screen, window);
}

/* Window height excluding header is approx 1.4 * grid height
* Window width approx 1.25 * grid width.
* Cell dimensions approx 2.0 * font height
/* Cell dimensions approx 2.0 * font height
* Make allowance for unusable monitor height - approx 10%;
* These equations are related to the inverse of those used in labelbox to calculate its dimensions
*/

var max_h = (double)(monitor_area.height * 0.90) / ((double)rows * 2.55 + 4.4);
var max_w = (double)(monitor_area.width * 0.95) / ((double)cols * 2.4 + 3.2);
var max_h = (double)(monitor_area.height * Gnonograms.USABLE_MONITOR_HEIGHT - Gnonograms.HEADER_HEIGHT - 2 * Gnonograms.GRID_BORDER) / ((double)rows * (1.0 + Gnonograms.TYPICAL_MAX_BLOCKS_RATIO * Gnonograms.FONT_ASPECT_RATIO) * 2.0);
var max_w = (double)(monitor_area.width * Gnonograms.USABLE_MONITOR_WIDTH - 2 * Gnonograms.GRID_BORDER - Gnonograms.GRID_COLUMN_SPACING) / ((double)cols * (1.0 + Gnonograms.TYPICAL_MAX_BLOCKS_RATIO / FONT_ASPECT_RATIO) * 2.0);

return double.min (max_h, max_w);
}
Expand All @@ -482,8 +476,8 @@ public class View : Gtk.ApplicationWindow {
}

var monitor_area = Utils.get_monitor_area (screen, window);
var w = int.min ((int)(monitor_area.width), row_clue_box.min_width + column_clue_box.min_width + END_BORDER);
var h = int.min ((int)(monitor_area.height * 0.9), row_clue_box.min_height + column_clue_box.min_height + BOTTOM_BORDER);
var w = int.min ((int)(monitor_area.width * Gnonograms.USABLE_MONITOR_WIDTH), row_clue_box.min_width + column_clue_box.min_width + 2 * Gnonograms.GRID_BORDER + Gnonograms.GRID_COLUMN_SPACING);
var h = int.min ((int)(monitor_area.height * USABLE_MONITOR_HEIGHT), row_clue_box.min_height + column_clue_box.min_height + 2 * Gnonograms.GRID_BORDER + Gnonograms.HEADER_HEIGHT);

var hints = Gdk.Geometry ();
hints.min_width = w;
Expand Down
9 changes: 9 additions & 0 deletions src/core/Constants.vala
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ namespace Gnonograms {
public static double MINFONTSIZE = 8.0;
public static double MAXFONTSIZE = 36.0;
public static int FAILED_PASSES = 0;

public static double FONT_ASPECT_RATIO = 1.2;
public static int HEADER_HEIGHT = Gtk.IconSize.LARGE_TOOLBAR;
public static int GRID_BORDER = 6;
public static int GRID_COLUMN_SPACING = 6;
public static double TYPICAL_MAX_BLOCKS_RATIO = 0.3;
public static double USABLE_MONITOR_HEIGHT = 0.85;
public static double USABLE_MONITOR_WIDTH = 0.95;

public const string BLOCKSEPARATOR = ", ";
public const string BLANKLABELTEXT = _("?");
public const string GAMEFILEEXTENSION = ".gno";
Expand Down
17 changes: 9 additions & 8 deletions src/widgets/Gnonogram_labelbox.vala
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public class LabelBox : Gtk.Grid {
public bool vertical_labels {get; construct;} /* True if contains column labels */

public Dimensions dimensions {get; set;}
public int min_width {get; private set; default = -1;}
public int min_height {get; private set; default = -1;}
public int min_width {get; private set;}
public int min_height {get; private set;}
public double fontheight { get; set; }

public LabelBox (Gtk.Orientation orientation) {
Expand All @@ -45,8 +45,13 @@ public class LabelBox : Gtk.Grid {
size = 0;
row_spacing = 0;
column_spacing = 0;
min_width = 0;
min_height = 0;

notify["fontheight"].connect (() => {
for (uint index = 0; index < size; index++) {
labels[index].fontheight = fontheight;
}
recalc_size ();
});

Expand All @@ -69,15 +74,11 @@ public class LabelBox : Gtk.Grid {
* If this is exceeded then label will reduce its fontsize. */
if (vertical_labels) {
min_width = (int)(c * cell);
min_height = (int)((r * 0.25 + 2) * cell * 1.1);
min_height = (int)((r * Gnonograms.TYPICAL_MAX_BLOCKS_RATIO) * cell * Gnonograms.FONT_ASPECT_RATIO);
} else {
min_width = (int)((c * 0.25 + 2) * cell * 0.8);
min_width = (int)((c * Gnonograms.TYPICAL_MAX_BLOCKS_RATIO) * cell / Gnonograms.FONT_ASPECT_RATIO);
min_height = (int)(r * cell);
}

for (uint index = 0; index < size; index++) {
labels[index].fontheight = fontheight;
}
}

public void highlight (uint index, bool is_highlight) {
Expand Down

0 comments on commit b7ec2d1

Please sign in to comment.