Skip to content

Commit df8cc82

Browse files
committed
Window; add title margins and height options, fix #43
1 parent 1f6a58e commit df8cc82

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

mint/Window.hx

+34-7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ typedef WindowOptions = {
2727
@:optional var focusable: Bool;
2828
/** Whether or not the window is collapsible */
2929
@:optional var collapsible: Bool;
30+
/** The x offset of the title bar (draggable label area) */
31+
@:optional var title_margin_left: Float;
32+
/** The y offset of the title bar (draggable label area) */
33+
@:optional var title_margin_top: Float;
34+
/** The offset of the title bar from the right edge (draggable label area) */
35+
@:optional var title_margin_right: Float;
36+
/** The height of the title bar (draggable label area) */
37+
@:optional var title_height: Float;
3038

3139
} //WindowOptions
3240

@@ -52,6 +60,11 @@ class Window extends Control {
5260
var drag_x : Float = 0;
5361
var drag_y : Float = 0;
5462

63+
var title_margin_top: Float = 2;
64+
var title_margin_left: Float = 2;
65+
var title_margin_right: Float = 4;
66+
var title_height: Float = 22;
67+
5568
var options : WindowOptions;
5669
var ready = false;
5770

@@ -72,6 +85,11 @@ class Window extends Control {
7285
focusable = def(options.focusable, true);
7386
collapsible = def(options.collapsible, false);
7487

88+
title_height = def(options.title_height, 22);
89+
title_margin_left = def(options.title_margin_left, 2);
90+
title_margin_top = def(options.title_margin_top, 2);
91+
title_margin_right = def(options.title_margin_right, 4);
92+
7593
resize_handle = new Control({
7694
parent : this,
7795
x: w-24, y: h-24, w: 24, h: 24,
@@ -85,7 +103,10 @@ class Window extends Control {
85103

86104
title = new Label({
87105
parent : this,
88-
x: 2, y: 2, w: w - 4, h: 22,
106+
x: title_margin_left,
107+
y: title_margin_top,
108+
w: w - title_margin_right,
109+
h: title_height,
89110
text: options.title,
90111
align : TextAlign.center,
91112
align_vertical : TextAlign.center,
@@ -97,7 +118,10 @@ class Window extends Control {
97118

98119
close_handle = new Control({
99120
parent : this,
100-
x: w - 24, y: 2, w: 22, h: 22,
121+
x: w - title_margin_right - 24,
122+
y: title_margin_top,
123+
w: 22,
124+
h: title_height,
101125
name : name + '.close',
102126
options: options.options.close_handle,
103127
internal_visible: options.visible
@@ -115,7 +139,10 @@ class Window extends Control {
115139

116140
collapse_handle = new Control({
117141
parent : this,
118-
x: closable ? w - 48 : w - 24, y: 2, w: 22, h: 22,
142+
x: closable ? w - title_margin_right - 48 : w - title_margin_right - 24,
143+
y: title_margin_top,
144+
w: 22,
145+
h: title_height,
119146
name : name + '.collapse',
120147
options: options.options.collapse_handle,
121148
internal_visible: options.visible
@@ -332,10 +359,10 @@ class Window extends Control {
332359

333360
super.bounds_changed(_dx, _dy, _dw, _dh);
334361

335-
if(close_handle != null) close_handle.x_local = w - 24;
336-
if(collapse_handle != null) collapse_handle.x_local = closable ? w - 48 : w - 24;
337-
if(title != null) title.w = w - 4;
338-
if(resize_handle != null) resize_handle.set_pos(x + w - 24, y + h - 24);
362+
if(close_handle != null) close_handle.x_local = w - title_margin_right - 24;
363+
if(collapse_handle != null) collapse_handle.x_local = closable ? w - title_margin_right - 48 : w - title_margin_right - 24;
364+
if(title != null) title.w = w - title_margin_right;
365+
if(resize_handle != null) resize_handle.set_pos(x + w - 24, y + h - 24);
339366

340367
} //bounds_changed
341368

tests/test_luxe/src/tests/KitchenSink.hx

+4-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ class KitchenSink extends State {
6565

6666
window1 = new mint.Window({
6767
parent: canvas,
68+
title_height: 48,
69+
text_size: 20,
6870
name: 'window1',
69-
title: 'window',
71+
title: 'inventory',
7072
options: {
7173
color:new Color().rgb(0x121212),
7274
color_titlebar:new Color().rgb(0x191919),
@@ -82,7 +84,7 @@ class KitchenSink extends State {
8284
parent: window1,
8385
name: 'list1',
8486
options: { view: { color:new Color().rgb(0x19191c) } },
85-
x: 4, y: 28, w: 248, h: 400-28-4
87+
x: 4, y: 54, w: 248, h: 400-54-4
8688
});
8789

8890
Main.layout.margin(_list, right, fixed, 4);

0 commit comments

Comments
 (0)