Skip to content

Commit

Permalink
Window; add title margins and height options, fix #43
Browse files Browse the repository at this point in the history
  • Loading branch information
ruby0x1 committed Sep 6, 2016
1 parent 1f6a58e commit df8cc82
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
41 changes: 34 additions & 7 deletions mint/Window.hx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ typedef WindowOptions = {
@:optional var focusable: Bool;
/** Whether or not the window is collapsible */
@:optional var collapsible: Bool;
/** The x offset of the title bar (draggable label area) */
@:optional var title_margin_left: Float;
/** The y offset of the title bar (draggable label area) */
@:optional var title_margin_top: Float;
/** The offset of the title bar from the right edge (draggable label area) */
@:optional var title_margin_right: Float;
/** The height of the title bar (draggable label area) */
@:optional var title_height: Float;

} //WindowOptions

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

var title_margin_top: Float = 2;
var title_margin_left: Float = 2;
var title_margin_right: Float = 4;
var title_height: Float = 22;

var options : WindowOptions;
var ready = false;

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

title_height = def(options.title_height, 22);
title_margin_left = def(options.title_margin_left, 2);
title_margin_top = def(options.title_margin_top, 2);
title_margin_right = def(options.title_margin_right, 4);

resize_handle = new Control({
parent : this,
x: w-24, y: h-24, w: 24, h: 24,
Expand All @@ -85,7 +103,10 @@ class Window extends Control {

title = new Label({
parent : this,
x: 2, y: 2, w: w - 4, h: 22,
x: title_margin_left,
y: title_margin_top,
w: w - title_margin_right,
h: title_height,
text: options.title,
align : TextAlign.center,
align_vertical : TextAlign.center,
Expand All @@ -97,7 +118,10 @@ class Window extends Control {

close_handle = new Control({
parent : this,
x: w - 24, y: 2, w: 22, h: 22,
x: w - title_margin_right - 24,
y: title_margin_top,
w: 22,
h: title_height,
name : name + '.close',
options: options.options.close_handle,
internal_visible: options.visible
Expand All @@ -115,7 +139,10 @@ class Window extends Control {

collapse_handle = new Control({
parent : this,
x: closable ? w - 48 : w - 24, y: 2, w: 22, h: 22,
x: closable ? w - title_margin_right - 48 : w - title_margin_right - 24,
y: title_margin_top,
w: 22,
h: title_height,
name : name + '.collapse',
options: options.options.collapse_handle,
internal_visible: options.visible
Expand Down Expand Up @@ -332,10 +359,10 @@ class Window extends Control {

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

if(close_handle != null) close_handle.x_local = w - 24;
if(collapse_handle != null) collapse_handle.x_local = closable ? w - 48 : w - 24;
if(title != null) title.w = w - 4;
if(resize_handle != null) resize_handle.set_pos(x + w - 24, y + h - 24);
if(close_handle != null) close_handle.x_local = w - title_margin_right - 24;
if(collapse_handle != null) collapse_handle.x_local = closable ? w - title_margin_right - 48 : w - title_margin_right - 24;
if(title != null) title.w = w - title_margin_right;
if(resize_handle != null) resize_handle.set_pos(x + w - 24, y + h - 24);

} //bounds_changed

Expand Down
6 changes: 4 additions & 2 deletions tests/test_luxe/src/tests/KitchenSink.hx
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ class KitchenSink extends State {

window1 = new mint.Window({
parent: canvas,
title_height: 48,
text_size: 20,
name: 'window1',
title: 'window',
title: 'inventory',
options: {
color:new Color().rgb(0x121212),
color_titlebar:new Color().rgb(0x191919),
Expand All @@ -82,7 +84,7 @@ class KitchenSink extends State {
parent: window1,
name: 'list1',
options: { view: { color:new Color().rgb(0x19191c) } },
x: 4, y: 28, w: 248, h: 400-28-4
x: 4, y: 54, w: 248, h: 400-54-4
});

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

0 comments on commit df8cc82

Please sign in to comment.