Skip to content

Commit 2b3a17c

Browse files
authored
Merge pull request #698 from pdfpc/fix-696
Fix 696
2 parents 9817cb3 + e5f4ea9 commit 2b3a17c

File tree

2 files changed

+44
-17
lines changed

2 files changed

+44
-17
lines changed

src/classes/window/presenter.vala

+4
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,10 @@ namespace pdfpc.Window {
791791
this.toolbox.update();
792792
}
793793

794+
protected override void resize_gui() {
795+
this.toolbox.on_window_resize(this.window_w, this.window_h);
796+
}
797+
794798
/**
795799
* Ask for the page to jump to
796800
*/

src/classes/window/toolbox.vala

+40-17
Original file line numberDiff line numberDiff line change
@@ -160,33 +160,23 @@ namespace pdfpc.Window {
160160

161161
Gtk.Orientation orientation = Gtk.Orientation.HORIZONTAL;
162162
bool tbox_inverse = false;
163-
int tb_offset = (int) (0.02*presenter.window_h);
164163

165-
int tbox_x = 0, tbox_y = 0;
166164
switch (Options.toolbox_direction) {
167165
case Options.ToolboxDirection.LtoR:
168166
orientation = Gtk.Orientation.HORIZONTAL;
169167
tbox_inverse = false;
170-
tbox_x = (int) (0.15*presenter.window_w) + tb_offset;
171-
tbox_y = (int) (0.70*presenter.window_h) + tb_offset;
172168
break;
173169
case Options.ToolboxDirection.RtoL:
174170
orientation = Gtk.Orientation.HORIZONTAL;
175171
tbox_inverse = true;
176-
tbox_x = (int) (0.15*presenter.window_w) - tb_offset;
177-
tbox_y = (int) (0.70*presenter.window_h) + tb_offset;
178172
break;
179173
case Options.ToolboxDirection.TtoB:
180174
orientation = Gtk.Orientation.VERTICAL;
181175
tbox_inverse = false;
182-
tbox_x = 0*presenter.window_w + tb_offset;
183-
tbox_y = 0*presenter.window_h + tb_offset;
184176
break;
185177
case Options.ToolboxDirection.BtoT:
186178
orientation = Gtk.Orientation.VERTICAL;
187179
tbox_inverse = true;
188-
tbox_x = 0*presenter.window_w + tb_offset;
189-
tbox_y = 0*presenter.window_h + tb_offset;
190180
break;
191181
}
192182
toolbox = new Gtk.Box(orientation, 0);
@@ -222,7 +212,7 @@ namespace pdfpc.Window {
222212
button_panel.set_homogeneous(true);
223213

224214
if (Options.toolbox_minimized) {
225-
button_panel.hide();
215+
button_panel.set_child_visible(false);
226216
}
227217
if (tbox_inverse) {
228218
this.toolbox.pack_end(button_panel);
@@ -231,12 +221,8 @@ namespace pdfpc.Window {
231221
}
232222

233223
tb.clicked.connect(() => {
234-
var state = button_panel.visible;
235-
if (state) {
236-
button_panel.hide();
237-
} else {
238-
button_panel.show();
239-
}
224+
var state = button_panel.get_child_visible();
225+
button_panel.set_child_visible(!state);
240226
});
241227

242228
tb = add_button(button_panel, tbox_inverse, "empty.svg",
@@ -301,6 +287,9 @@ namespace pdfpc.Window {
301287
this.controller.queue_pen_surface_draws();
302288
});
303289

290+
int tbox_x, tbox_y;
291+
calculate_position(presenter.window_w, presenter.window_h,
292+
out tbox_x, out tbox_y);
304293
this.put(this.toolbox, tbox_x, tbox_y);
305294
}
306295

@@ -328,5 +317,39 @@ namespace pdfpc.Window {
328317
scale_button.hide();
329318
}
330319
}
320+
321+
protected void calculate_position(int w, int h, out int x, out int y) {
322+
double fx = 0.0, fy = 0.0;
323+
double offset = 0.02*h;
324+
325+
switch (Options.toolbox_direction) {
326+
case Options.ToolboxDirection.LtoR:
327+
fx = 0.15*w + offset;
328+
fy = 0.70*h + offset;
329+
break;
330+
case Options.ToolboxDirection.RtoL:
331+
fx = 0.15*w - offset;
332+
fy = 0.70*h + offset;
333+
break;
334+
case Options.ToolboxDirection.TtoB:
335+
fx = 0*w + offset;
336+
fy = 0*h + offset;
337+
break;
338+
case Options.ToolboxDirection.BtoT:
339+
fx = 0*w + offset;
340+
fy = 0*h + offset;
341+
break;
342+
}
343+
344+
x = (int) fx;
345+
y = (int) fy;
346+
}
347+
348+
public void on_window_resize(int w, int h) {
349+
int x, y;
350+
calculate_position(w, h, out x, out y);
351+
352+
this.move(this.toolbox, x, y);
353+
}
331354
}
332355
}

0 commit comments

Comments
 (0)