public static void StyleSetFontSize(this NuklearContext ctx, float height) { if (ctx == null) { return; } ctx.style.font.FontSystem.Size = height; if (ctx.current != null) { ctx.LayoutResetMinRowHeight(); } }
public static void StyleSetFont(this NuklearContext ctx, nk_font font) { nk_style style; if (ctx == null) { return; } style = ctx.style; style.font = font; ctx.stacks.fonts.Clear(); if (ctx.current != null) { ctx.LayoutResetMinRowHeight(); } }
public static int nk_tree_state_base(this NuklearContext ctx, int type, nk_image img, string title, ref int state) { nk_window win; nk_panel layout; nk_style style; CommandBuffer _out_; nk_input _in_; nk_style_button button; nk_symbol_type symbol; float row_height; var item_spacing = new Vector2(); var header = new RectangleF(); var sym = new RectangleF(); var text = new nk_text(); uint ws = 0; int widget_state; if (ctx == null || ctx.current == null || ctx.current.Layout == null) { return(0); } win = ctx.current; layout = win.Layout; _out_ = win.Buffer; style = ctx.style; item_spacing = style.window.spacing; row_height = style.font.Size + 2 * style.tab.padding.Y; ctx.LayoutSetMinRowHeight(row_height); ctx.LayoutRowDynamic(row_height, 1); ctx.LayoutResetMinRowHeight(); widget_state = ctx.Widget(ref header); if (type == NK_TREE_TAB) { var background = style.tab.background; if (background.type == NK_STYLE_ITEM_IMAGE) { _out_.DrawImage(header, background.Image, nk_white); text.Background = Color.Transparent; } else { text.Background = background.Color; _out_.FillRect(header, 0, style.tab.border_color); _out_.FillRect(RectangleF.nk_shrink_rect_(header, style.tab.border), style.tab.Rounding, background.Color); } } else { text.Background = style.window.background; } _in_ = (layout.Flags & NK_WINDOW_ROM) == 0 ? ctx.input : null; _in_ = _in_ != null && widget_state == NK_WIDGET_VALID ? ctx.input : null; if (ButtonBehavior(ref ws, header, _in_, NK_BUTTON_DEFAULT)) { state = state == NK_MAXIMIZED ? NK_MINIMIZED : NK_MAXIMIZED; } if (state == NK_MAXIMIZED) { symbol = style.tab.sym_maximize; if (type == NK_TREE_TAB) { button = style.tab.tab_maximize_button; } else { button = style.tab.node_maximize_button; } } else { symbol = style.tab.sym_minimize; if (type == NK_TREE_TAB) { button = style.tab.tab_minimize_button; } else { button = style.tab.node_minimize_button; } } { sym.Width = sym.Height = style.font.Size; sym.Y = header.Y + style.tab.padding.Y; sym.X = header.X + style.tab.padding.X; DoButtonSymbol(ref ws, win.Buffer, sym, symbol, NK_BUTTON_DEFAULT, button, null, style.font); if (img != null) { sym.X = sym.X + sym.Width + 4 * item_spacing.X; win.Buffer.DrawImage(sym, img, nk_white); sym.Width = style.font.Size + style.tab.spacing.X; } } { var label = new RectangleF(); header.Width = header.Width < sym.Width + item_spacing.X ? sym.Width + item_spacing.X : header.Width; label.X = sym.X + sym.Width + item_spacing.X; label.Y = sym.Y; label.Width = header.Width - (sym.Width + item_spacing.Y + style.tab.indent); label.Height = style.font.Size; text.text = style.tab.text; text.padding = new Vector2(0, 0); _out_.WidgetText(label, title, &text, nk_text_align.NK_TEXT_LEFT, style.font); } if (state == NK_MAXIMIZED) { layout.At_x = header.X + layout.Offset.X + style.tab.indent; layout.Bounds.Width = layout.Bounds.Width < style.tab.indent ? style.tab.indent : layout.Bounds.Width; layout.Bounds.Width -= style.tab.indent + style.window.padding.X; layout.Row.tree_depth++; return(nk_true); } return(nk_false); }
public static bool nk_panel_begin(this NuklearContext ctx, string title, int panel_type) { nk_input _in_; nk_window win; nk_panel layout; CommandBuffer _out_; nk_style style; nk_font font; var scrollbar_size = new Vector2(); var panel_padding = new Vector2(); if (ctx == null || ctx.current == null || ctx.current.Layout == null) { return(false); } if ((ctx.current.Flags & NK_WINDOW_HIDDEN) != 0 || (ctx.current.Flags & NK_WINDOW_CLOSED) != 0) { ctx.current.Layout.Type = panel_type; return(false); } style = ctx.style; font = style.font; win = ctx.current; layout = win.Layout; _out_ = win.Buffer; _in_ = (win.Flags & NK_WINDOW_NO_INPUT) != 0 ? null : ctx.input; scrollbar_size = style.window.scrollbar_size; panel_padding = nk_panel_get_padding(style, panel_type); if ((win.Flags & NK_WINDOW_MOVABLE) != 0 && (win.Flags & NK_WINDOW_ROM) == 0) { bool left_mouse_down; bool left_mouse_click_in_cursor; var header = new RectangleF(); header.X = win.Bounds.X; header.Y = win.Bounds.Y; header.Width = win.Bounds.Width; if (nk_panel_has_header(win.Flags, title) != 0) { header.Height = font.Size + 2.0f * style.window.header.padding.Y; header.Height += 2.0f * style.window.header.label_padding.Y; } else { header.Height = panel_padding.Y; } left_mouse_down = _in_.mouse.buttons[NK_BUTTON_LEFT].down; left_mouse_click_in_cursor = nk_input_has_mouse_click_down_in_rect(_in_, NK_BUTTON_LEFT, header, true); if (left_mouse_down && left_mouse_click_in_cursor) { win.Bounds.X = win.Bounds.X + _in_.mouse.delta.X; win.Bounds.Y = win.Bounds.Y + _in_.mouse.delta.Y; _in_.mouse.buttons[NK_BUTTON_LEFT].clicked_pos.X += _in_.mouse.delta.X; _in_.mouse.buttons[NK_BUTTON_LEFT].clicked_pos.Y += _in_.mouse.delta.Y; ctx.style.cursor_active = ctx.style.cursors[NK_CURSOR_MOVE]; } } layout.Type = panel_type; layout.Flags = win.Flags; layout.Bounds = win.Bounds; layout.Bounds.X += panel_padding.X; layout.Bounds.Width -= 2 * panel_padding.X; if ((win.Flags & NK_WINDOW_BORDER) != 0) { layout.Border = nk_panel_get_border(style, win.Flags, panel_type); layout.Bounds = RectangleF.nk_shrink_rect_(layout.Bounds, layout.Border); } else { layout.Border = 0; } layout.At_y = layout.Bounds.Y; layout.At_x = layout.Bounds.X; layout.Max_x = 0; layout.Header_height = 0; layout.Footer_height = 0; ctx.LayoutResetMinRowHeight(); layout.Row.index = 0; layout.Row.columns = 0; layout.Row.ratio = null; layout.Row.item_width = 0; layout.Row.tree_depth = 0; layout.Row.height = panel_padding.Y; layout.Has_scrolling = nk_true; if ((win.Flags & NK_WINDOW_NO_SCROLLBAR) == 0) { layout.Bounds.Width -= scrollbar_size.X; } if (nk_panel_is_nonblock(panel_type) == 0) { layout.Footer_height = 0; if ((win.Flags & NK_WINDOW_NO_SCROLLBAR) == 0 || (win.Flags & NK_WINDOW_SCALABLE) != 0) { layout.Footer_height = scrollbar_size.Y; } layout.Bounds.Height -= layout.Footer_height; } if (nk_panel_has_header(win.Flags, title) != 0) { var text = new nk_text(); var header = new RectangleF(); nk_style_item background = null; header.X = win.Bounds.X; header.Y = win.Bounds.Y; header.Width = win.Bounds.Width; header.Height = font.Size + 2.0f * style.window.header.padding.Y; header.Height += 2.0f * style.window.header.label_padding.Y; layout.Header_height = header.Height; layout.Bounds.Y += header.Height; layout.Bounds.Height -= header.Height; layout.At_y += header.Height; if (ctx.active == win) { background = style.window.header.active; text.text = style.window.header.label_active; } else if (nk_input_is_mouse_hovering_rect(ctx.input, header)) { background = style.window.header.hover; text.text = style.window.header.label_hover; } else { background = style.window.header.normal; text.text = style.window.header.label_normal; } header.Height += 1.0f; if (background.type == NK_STYLE_ITEM_IMAGE) { text.Background = Color.Transparent; win.Buffer.DrawImage(header, background.Image, nk_white); } else { text.Background = background.Color; _out_.FillRect(header, 0, background.Color); } { var button = new RectangleF(); button.Y = header.Y + style.window.header.padding.Y; button.Height = header.Height - 2 * style.window.header.padding.Y; button.Width = button.Height; if ((win.Flags & NK_WINDOW_CLOSABLE) != 0) { var ws = (uint)0; if (style.window.header.align == NK_HEADER_RIGHT) { button.X = header.Width + header.X - (button.Width + style.window.header.padding.X); header.Width -= button.Width + style.window.header.spacing.X + style.window.header.padding.X; } else { button.X = header.X + style.window.header.padding.X; header.X += button.Width + style.window.header.spacing.X + style.window.header.padding.X; } if ( DoButtonSymbol(ref ws, win.Buffer, button, style.window.header.close_symbol, NK_BUTTON_DEFAULT, style.window.header.close_button, _in_, style.font) && (win.Flags & NK_WINDOW_ROM) == 0) { layout.Flags |= NK_WINDOW_HIDDEN; layout.Flags &= ~(uint)NK_WINDOW_MINIMIZED; } } if ((win.Flags & NK_WINDOW_MINIMIZABLE) != 0) { var ws = (uint)0; if (style.window.header.align == NK_HEADER_RIGHT) { button.X = header.Width + header.X - button.Width; if ((win.Flags & NK_WINDOW_CLOSABLE) == 0) { button.X -= style.window.header.padding.X; header.Width -= style.window.header.padding.X; } header.Width -= button.Width + style.window.header.spacing.X; } else { button.X = header.X; header.X += button.Width + style.window.header.spacing.X + style.window.header.padding.X; } if ( DoButtonSymbol(ref ws, win.Buffer, button, (layout.Flags & NK_WINDOW_MINIMIZED) != 0 ? style.window.header.maximize_symbol : style.window.header.minimize_symbol, NK_BUTTON_DEFAULT, style.window.header.minimize_button, _in_, style.font) && (win.Flags & NK_WINDOW_ROM) == 0) { layout.Flags = (layout.Flags & NK_WINDOW_MINIMIZED) != 0 ? layout.Flags & ~(uint)NK_WINDOW_MINIMIZED : layout.Flags | NK_WINDOW_MINIMIZED; } } } { var label = new RectangleF(); var t = font.width(title); text.padding = new Vector2(0, 0); label.X = header.X + style.window.header.padding.X; label.X += style.window.header.label_padding.X; label.Y = header.Y + style.window.header.label_padding.Y; label.Height = font.Size + 2 * style.window.header.label_padding.Y; label.Width = t + 2 * style.window.header.spacing.X; label.Width = (label.Width < header.X + header.Width - label.X ? label.Width : header.X + header.Width - label.X) < 0 ? 0 : label.Width < header.X + header.Width - label.X ? label.Width : header.X + header.Width - label.X; _out_.WidgetText(label, title, &text, nk_text_align.NK_TEXT_LEFT, font); } } if ((layout.Flags & NK_WINDOW_MINIMIZED) == 0 && (layout.Flags & NK_WINDOW_DYNAMIC) == 0) { var body = new RectangleF(); body.X = win.Bounds.X; body.Width = win.Bounds.Width; body.Y = win.Bounds.Y + layout.Header_height; body.Height = win.Bounds.Height - layout.Header_height; if (style.window.fixed_background.type == NK_STYLE_ITEM_IMAGE) { _out_.DrawImage(body, style.window.fixed_background.Image, nk_white); } else { _out_.FillRect(body, 0, style.window.fixed_background.Color); } } { var clip = new RectangleF(); layout.Clip = layout.Bounds; RectangleF.nk_unify(ref clip, ref win.Buffer.Clip, layout.Clip.X, layout.Clip.Y, layout.Clip.X + layout.Clip.Width, layout.Clip.Y + layout.Clip.Height); _out_.Scissor(clip); layout.Clip = clip; } return((layout.Flags & NK_WINDOW_HIDDEN) == 0 && (layout.Flags & NK_WINDOW_MINIMIZED) == 0); }